akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    deque<int> d;
    vector<int> v;
    constexpr auto size = 123456 * 2;
    d.resize(size - 1);
    iota(begin(d), end(d), 2);
    const int cut = sqrt(size);
    while (d[0] < cut) {
        v.push_back(d[0]);
        d.erase(remove_if(begin(d),
                          end(d), [n = d[0]](int x) { return x % n == 0; }),
                end(d));
    }
    v.insert(end(v), begin(d), end(d));
    while (true) {
        int n;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }
        auto r = count_if(begin(v), end(v),
                          [n](int x) { return n < x && x <= 2 * n; });
        printf("%ld\n", r);
    }
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int A,P;
    cin >> A >> P;
    P += A*3;
    cout << P/2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))
 
 // ^^^ Template ^^^ //

int main() {
	in(string, S, T);
	set<string> ans;
	loop(i, S.size()) if(T.size() + i <= S.size()){
		bool check = true;
		string tmp = S;
		loop(p, T.size()){
			if(S[i+p] == '?')
				tmp[i+p] = T[p];
			else if(S[i+p] != T[p]){
				check = false;
				break;
			}
		}
		if(check){
			loop(i, S.size())
				if(tmp[i] == '?')
					tmp[i] = 'a';
			ans.insert(tmp);
		}
	}
	if(ans.empty()) cout << "UNRESTORABLE" << endl;
	else cout << *ans.begin() << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

string toAlphabet(ll self) {
	if (self <= 0) return "";
	ll n = self % 26;
	n = (n == 0) ? 26 : n;
	string s = string() + (char)(n + 64);
	if (self == n) return s;
	return toAlphabet((self - n) / 26) + s;
}

int main() {
	ll n;
	cin >> n;
	string ans = toAlphabet(n);
	for (int i = 0; i < ans.length(); i++) {
		cout << toSmall(ans[i]);
	}
	return 0;
}

Measured memory_bytes: 3640
<?php

$input = trim(fgets(STDIN),"\r\n");
while (1) {

	$lines = explode(' ', $input);

	$height = intval($lines[0]);
	$width = intval($lines[1]);

	for ($i=0; $i < $height; $i++) { 
		
			if ($i === 0 || $i === ($height - 1)) {
				for ($j=0; $j < $width; $j++) { 
					print('#');
				}
				print("\n");
			}
			else
			{
				for ($j=0; $j < $width; $j++) { 
					if ($j === 0 || $j === ($width - 1)) 
						print('#');
					else
						print('.');
					
				}
				print("\n");
			}

			

	}
	print("\n");

	$input = trim(fgets(STDIN),"\r\n");
	if((string)$input === '0 0')
		break;
}

Measured memory_bytes: 6616
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int
using namespace std;


int main(){
 ll a,b; cin>>a>>b;
 if(a<=0 and b>=0) cout<<"Zero"<<endl;
 else if(a>0 or (abs(a) - abs(b) + 1) % 2 == 0) cout<<"Positive"<<endl;
 else cout<<"Negative"<<endl;
 return 0;
 
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  int n,c,k;
  cin >> n >> c >> k;
 
  vector<ll> a(n);
 
  rep(i,n) cin >> a[i];
  vsort(a);


  ll nb = -1;
  ll ans = 0;
  ll cus = 0;
  for(int i = 0;i < n;)
  {
    nb = a[i] + k;  // nb分には出発しないといけない
    cus = 0;        // 乗客が何人乗れるか？
    ans++;          // バスの数
    for(int j = i;j < n;j++)
    {
      if(cus + 1<= c && a[j] <= nb)
      {
        cus++;
      }
      else
      {
        i = j;  // j-1番目まで乗っている
        cus=0;  // バスはいってしまった　＆フラグ代わり
        break;
      }
    }
    if(cus != 0)
    {
      //バスが出たとき以外にここにくる。
      break;
    }
  }
 
  cout << ans << endl;
 
  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 1024
data = list(map(int, input().split()))
A, B = data[0], data[1]

def gcd(A, B):
    x = max(A, B)
    y = min(A, B)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z

def lcd(A, B):
    return A * B // gcd(A, B)

print(lcd(A, B))

Measured memory_bytes: 3060
import scala.math.sqrt

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextLong()
  val ans = (1 to math.sqrt(n).toInt).collect { case i if n % i == 0 => i + (n / i) - 2 }
  println(ans.min)
}


Measured memory_bytes: 56944
import fractions

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 arr==[]:
        arr.append([n, 1])

    return arr
    
A = list(map(int, input().split()))

B = fractions.gcd(A[0], A[1])

C = factorization(B)

if C[0][0] != 1:
    print(len(C) + 1)
else:
    print(1)

Measured memory_bytes: 5092
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N+1)
	for i := 1; i <= N; i++ {
		fmt.Scan(&A[i])
	}
	count := 0
	for i := 1; i <= N; i++ {
		if i == A[A[i]] && A[i] == A[A[A[i]]] {
			count++
		}
	}
	fmt.Println(count / 2)
}


Measured memory_bytes: 5504
n = gets.to_i
x, y = n.times.map{gets.split.map(&:to_i)}.transpose
k = 1

n.times do |i|
  k *= i+1
end
sum = 0
[*0...n].permutation(n) do |arr|
  arr.each_cons(2) do |a, b|
    t = (((x[a] - x[b])**2) + ((y[a] - y[b])**2))**(0.5)
    sum += t
  end
end
p sum / k.to_f


Measured memory_bytes: 1916
#include <iostream>
using namespace std;
int main() {
	int x, y;
	cin >> x >> y;
	if(x == y) cout << 0 << endl;
	else if(x < y){
		if(x < 0 && y > 0) cout << abs(x + y) + 1 << endl;
		else cout << y - x << endl;
	}else{
		if(x >= 0 && y <= 0) cout << abs(x + y) + 1 << endl;
		else cout << x - y + 2 << endl;
	}
	return 0;
}


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

flag1 = False
flag2 = False
result = False
for i in range(a):
    b, c = map(int, input().split())  
    
    if flag2:
        if b == c:
            result = True
    
    if flag1:
        if b == c:
            flag2= True
        
    
    if b == c:
        flag1= True
    else:
        flag1 = False
        flag2 = False        


if result:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9184
/*    三玖天下第一！！！  */
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5,inf=0x3f3f3f3f;
int n,k,len=0,lin[maxn]={},val[maxn];
priority_queue< pair<int,int> > q;
struct edge
{
	int y,next;
}e[2*maxn];
inline void insert(int xx,int yy)
{
	e[++len].next=lin[xx];
	lin[xx]=len;
	e[len].y=yy;
}
inline bool vol()
{
	while(!q.empty())
	{
		int seat=q.top().second;q.pop();
		for(int i=lin[seat];i;i=e[i].next)
		{
			if(val[e[i].y]<inf&&abs(val[e[i].y]-val[seat])==1) continue;
			else if(val[e[i].y]<inf) return 0;
			val[e[i].y]=val[seat]-1;q.push(make_pair(val[e[i].y],e[i].y));
		}
	}
	return 1;
}
inline int dread()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
inline void in()
{
	n=dread();
	for(int i=1,a,b;i<n;i++) a=dread(),b=dread(),insert(a,b),insert(b,a);
	k=dread();
	memset(val,inf,sizeof(val));
	for(int i=1;i<=k;i++) val[dread()]=dread(); 
}
inline void work()
{
	for(int i=1;i<=n;i++) if(val[i]<inf) q.push(make_pair(val[i],i));
}
inline void out()
{
	if(vol()) puts("Yes");
	else {puts("No");return;}
	for(int i=1;i<=n;i++) printf("%d\n",val[i]);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	in();
	work();
	out();
	return 0;
}


Measured memory_bytes: 4212
//https://atcoder.jp/contests/dp/tasks/dp_a

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define INF 1e9 + 5
using namespace std;

int solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);

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

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= i + k; j++)
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(a[j] - a[i]));
    }
    return dp[n - 1];
}

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

    /*  int t;
    cin >> t;

    while (t--)*/
    cout << solve();

    return 0;
}

Measured memory_bytes: 1024
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3005;
int n, vis[N][N];
double p[N], cache[N][N];

double dp(int idx, int heads)
{
	if (idx == n + 1)
		return (heads * 2 >= n);

	double &ans = cache[idx][heads];
	if (vis[idx][heads])
		return ans;

	vis[idx][heads] = 1;
	ans = p[idx] * dp(idx + 1, heads + 1) + (1 - p[idx]) * dp(idx + 1, heads);

	return ans;
}

void solve()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> p[i];
	
	cout << dp(1, 0);
}


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

	cout << setprecision(9) << fixed;
	clock_t z = clock();
	solve();
	cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

Measured memory_bytes: 210176
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
int main() {
    Int N, K; cin >> N >> K;
    Int ans = 0;
    for (Int k = K; k <= N + 1; k++) {
        Int mi = k * (k - 1) / 2;
        ans += k * N - mi - mi + 1;
        ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){
	char S[5];
	scanf("%s",S);

	if(strncmp(&S[0],&S[1],1)==0){
		if(strncmp(&S[2],&S[3],1)==0){
			if(strncmp(&S[1],&S[2],1)==0){
				printf("No");
			}else{
				printf("Yes");
			}
		}else{
			printf("No");
		}
	}else if(strncmp(&S[0],&S[2],1)==0){
		if(strncmp(&S[1],&S[3],1)==0){
			printf("Yes");
		}else{
			printf("No");
		}
	}else if(strncmp(&S[0],&S[3],1)==0){
		if(strncmp(&S[1],&S[2],1)==0){
			printf("Yes");
		}else{
			printf("No");
		}
	}else{
		printf("No");
	}

	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  ll a, b, c, d; cin >> a >> b >> c >> d;

  ll res = max(a * c, a * d);
  res = max(b * c, res);
  res = max(b * d, res);
  cout << res;
}

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

#define ll long long int

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int A,B,C;
	cin>>A>>B>>C;

	int a[] = {A,B,C};
	sort(a,a+3);
		
	if(a[0]==5){
		if(a[1]==5){
			if(a[2]==7){
				cout<<"YES"<<endl;
			}else{
				cout<<"NO"<<endl;
			}
		}else{
			cout<<"NO"<<endl;
		}
	}else{
		cout<<"NO"<<endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string color;
  cin >> N;
 
  for(int i = 0; i < N; i++) {
    cin >> color;
    if ( color == "Y" ) break; 
  }
  if (color == "Y") {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}

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

int main() {
	string s;
	cin >> s;
	int N = (int)s.size();
	using pii = pair<int, int>;
	queue<pii>toL, toR;
	vector<int>to(N, 2 * N);
	vector<int>ans(N, 0);
	FOR(i, 0, N - 1) {
		if (s[i] == 'R' && s[i + 1] == 'L') {
			to[i] = i;
			to[i + 1] = i + 1;
			toL.push({ i,i });
			toR.push({ i + 1,i + 1 });
		}
	}
	while (!toL.empty()) {
		pii a = toL.front(); toL.pop();
		int id = a.first;
		int d = abs(a.second - (id));
		ans[a.second + ((d) % 2)]++;
		if (id) {
			if (s[id - 1] == 'R') {
				to[id - 1] = a.second;
				toL.push({ id - 1,a.second });
			}
		}
	}
	while (!toR.empty()) {
		pii a = toR.front(); toR.pop();
		int id = a.first;
		int d = abs(a.second - (id));
		ans[a.second - ((d) % 2)]++;
		if (id + 1 < N) {
			if (s[id + 1] == 'L') {
				to[id + 1] = a.second;
				toR.push({ id + 1,a.second });
			}
		}
	}
	FOR(i, 0, N) {
		cout << ans[i] << " \n"[i + 1 == N];
	}
}




Measured memory_bytes: 2176
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>100:
    a=[n]*n
    print(*a)
    exit()
for i in range(k):
    b=[0]*(n+1)
    for j in range(n):
        l,r=max(0,j-a[j]),min(n,j+a[j]+1)
        b[l]+=1
        b[r]-=1
    a=Csum(b)[1:-1]
print(*a)

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

int main(){
int N,M,C;
  cin>>N>>M>>C;
  int A[N][M];
  vector<int>B(M);
  for(int i=0; i<M; i++){
   cin>>B[i];}
  for(int i=0; i<N; i++){
   for(int j=0; j<M; j++){
    cin>>A[i][j];}}
  
  int count=0;
  for(int i=0; i<N; i++){
    int ans=0;
   for(int j=0; j<M; j++){
    ans+=A[i][j]*B[j]; 
   }
    if(ans+C>0){count++;}
  }
  
  cout<<count;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

#define range(i,a,b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)

using namespace std;

char table[30][30];

int dw[4]={1,0,-1,0};
int dh[4]={0,1,0,-1};

void dfs(int w,int h){
	table[h][w]='@';
	rep(i,4){
		int nw=w+dw[i];
		int nh=h+dh[i];
		if(table[nh][nw]=='.')
			dfs(nw,nh);
	}
}

int main(void){
	int w,h;
	while(cin >> w >> h,w|h){
		int sw,sh;
		rep(i,30)rep(j,30) table[i][j]='#';
		range(i,1,h+1) range(j,1,w+1){
			cin >> table[i][j];
			if(table[i][j]=='@'){
				sh=i;
				sw=j;
			}
		}
		dfs(sw,sh);
		int ans=0;
		range(i,1,h+1) range(j,1,w+1) if(table[i][j]=='@') ans++;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  vector<string> A(N), B(M);
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<M;++i) cin>>B[i];
  bool find = false;
  bool tmp;
  for(int i=0;i<=N-M;++i) {
    for(int j=0;j<=N-M;++j) {
      tmp = true;
      for(int k=0;k<M;++k) {
        for(int l=0;l<M;++l) {
          if(A[i+k][j+l]!=B[k][l]) {
            tmp = false;
          }
        }
      }
      if(tmp) find = true;
    }
  }
  if(find) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

void slove(int a, double b){
	int n=128;
	vector<int> b1, b2;
	for(int i=0; i<8; i++){
		if(a/n != 0){
			b1.push_back(1);
			a-=n;
		}
		else {
			b1.push_back(0);
		}
		n/=2;
	}
	
	for(int i=0; i<4; i++){
		b=b*2.0;
		if(b >= 1.0){
			b2.push_back(1);
			b-=1.0;
		}
		else b2.push_back(0);
	}
	
	if(b!=0) cout << "NA";
	else{
		vector<int>::iterator it = b1.begin();
		while(it != b1.end()){
			cout << *it;
			it++;
		}
		
		cout << '.';
		
		vector<int>::iterator it2 = b2.begin();
		while(it2 != b2.end()){
			cout << *it2;
			it2++;
		}
		
	}
	cout << endl;
}

int main(){
	int a;
	double n, b;
	
	while(cin >>n){
		if(n<0) break;
		a=(int)n;   // À
		b=n-(int)n; // ¬_
		slove(a,b);
	}
}

Measured memory_bytes: 0
import math
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
X,Y = map(int,input().split())
div = 1000000007
if (X+Y)%3 != 0:
    print(0)
else:
    count = (X+Y)//3
    if count > X or count > Y :
        print(0)
    else:
        leftX = X-count
        p = 1
        for i in range(1,count+1):
            p = p*i%div
        for i in range(1,leftX+1):
            p = p*mod_inv(i,div)%div
        for i in range(1,count-leftX+1):
            p = p*mod_inv(i,div)%div
        print(p)


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

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

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int x = tx - sx, y = ty - sy;

	cout << string(y, 'U') << string(x, 'R');

	cout << string(y, 'D') << string(x, 'L');

	cout << 'L' << string(y + 1, 'U') << string(x + 1, 'R') << 'D';

	cout << 'R' << string(y + 1, 'D') << string(x + 1, 'L') << 'U';

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

start = -1
for i in range(len(S)-len(T)+1):
    match = True
    for j in range(len(T)):
        if not (S[i+j] == T[j] or S[i+j] == "?"):
            match = False
    if match:
        start = i


if start == -1:
    print('UNRESTORABLE')
else:
    result = S[:start] + T + S[start+len(T):]
    print(result.replace("?", "a"))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  ll N;
  ll a[210000];
  cin >> N;
  rep(i,N) cin >> a[i];

  vector<ll> v(N+1,0);

  rep(i,N) {
    v[a[i]]++;
  }

  ll sum = 0;
  FOR(i, 0, N) {
    sum += v[i] * (v[i]-1)/2;
  }

  rep(k, N) {
    ll res = sum;
    ll n= v[a[k]];
    res -= n * (n-1)/2;
    res += (n-1) * (n-2)/2;
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

    ll ans = 0;
    FOR(a, N + 1, 1) {
        FOR(b, N + 1, 1) {
            if (a * b >= N)
                break;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll MAX = 1000001;
const ll mod = 1000000007;
ll po(ll x, ll n ){ 
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//reopen("input.txt", "r" , stdin);
	//freopen("output.txt", "w" , stdout);
	#endif

	ll n,m,sum=0;
	cin>>n>>m;
	
	vi v(m);
	
	rep(i,m){
		cin>>v[i];
		sum+=v[i];
	}
	if(sum>n)
		cout<<-1<<el;
	else
		cout<<n-sum<<el;

	return 0;
}


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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;


int dp[N][3][3][3] , n , A , B , C , check = 0;
char ans[N][3][3][3];
string s[N];
int rec(int idx , int a , int b , int c) {
    if(a < 0 or b < 0 or c < 0) return 0;
    if(idx == n) {
        check = 1;
        return 1;
    }
    if(dp[idx][a][b][c] != -1) return dp[idx][a][b][c];
    
    int res = 0;
    if(s[idx] == "AB") {
        if(rec(idx + 1 , a + 1 , b - 1 , c)) ans[idx][a][b][c] = 'A' , res = 1;
        else if(rec(idx + 1 , a - 1 , b + 1 , c)) ans[idx][a][b][c] = 'B' , res = 1;
    }
    else if(s[idx] == "AC") {
        if(rec(idx + 1 , a + 1 , b  , c - 1)) ans[idx][a][b][c] = 'A' , res = 1;
        else if(rec(idx + 1 , a - 1 , b  , c + 1)) ans[idx][a][b][c] = 'C' , res = 1;
    }
    else {
        if(rec(idx + 1 , a , b - 1 , c + 1)) ans[idx][a][b][c] = 'C' , res = 1;
        else if(rec(idx + 1 , a , b + 1 , c - 1)) ans[idx][a][b][c] = 'B' , res = 1;
    }
    dp[idx][a][b][c] = res;
    return res;
}
void solve(int z) {
    memset(dp , -1 , sizeof dp);
    cin >> n >> A >> B >> C;
    for(int i = 0 ; i < n ; i ++) cin >> s[i];
    
    A = min(2LL , A);
    B = min(2LL , B);
    C = min(2LL , C);
    rec(0 , A , B , C);
    
    if(check == 0) cout << "No";
    else {
        cout << "Yes" << '\n';
        int i = 0;
        while(n -- ) {
            cout << ans[i][A][B][C] << '\n';
            if(ans[i][A][B][C] == 'A') {
                A ++;
                if(s[i] == "AB") B --;
                else C --;
            }
            if(ans[i][A][B][C] == 'B') {
                B ++;
                if(s[i] == "AB") A --;
                else C --;
            }
            if(ans[i][A][B][C] == 'C') {
                C ++;
                if(s[i] == "AC") A --;
                else B --;
            }
            i ++;
        }
    }
}

/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    
    return 0;
}
 



Measured memory_bytes: 62500
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n, a, ans=0;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>a;
        ans+=a;
    }
    cout<<ans-n<<endl;
    return 0;
}


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

using namespace std;

int A[200005];
int B[200005];

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	for (int i = 2; i <= n; ++i) {
		cin >> A[i];
		B[A[i]]++;
	}
	for (int i = 1; i <= n; ++i) {
		cout << B[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 5140
#include <iostream>
#include<iomanip>
#include<cmath>
#include<math.h>
#define PI 3.14159265358979323846264338327950288
using namespace std;
int main(void){
    // Your code here!
    double A,B;
    double H,M;
    cin>>A>>B>>H>>M;
    
   
    double Hangle= H*30 + M/2;
    double minangle= M*6;
    
    double angdiff= abs(Hangle- minangle);
    angdiff= angdiff >180? 360-angdiff:angdiff;
    cout<<fixed <<setprecision(20)<<sqrt(A*A + B*B - 2*A*B*cos( angdiff * PI / 180.0 ))<<endl;
    }




Measured memory_bytes: 3600
public class Main {

  private static void solve() {
    char[] s = ns();

    for (int i = 0; i < s.length; i++) {
      s[i] = 'x';
    }
    System.out.println(s);

  }

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

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

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

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

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

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

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

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

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

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

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

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



Measured memory_bytes: 24532
def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))
    A.sort(reverse=True)
    F.sort()

    l_score=-1
    r_score=10**12
    while l_score<r_score-1:
        t_score=(l_score+r_score)//2
        count=0
        for i in range(N):
            count+=max(0,A[i]-t_score//F[i])
        if count<=K:
            r_score=t_score
        else:
            l_score=t_score
    print(r_score)
if __name__=="__main__":
    main()

Measured memory_bytes: 119500
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
  
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
      cout << "Bad" << endl;
    } else {
      cout << "Good" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	char c[2][3];
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}

	if(c[0][0] == c[1][2]
		&& c[0][1] == c[1][1]
		&& c[0][2] == c[1][0]){
		cout << "YES" << endl;
	}else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import bisect
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    n, K, L, R = map(int, sys.stdin.readline().split())
    a = tuple(map(int, sys.stdin.readline().split()))
    m = n//2
    ls = [[0 for _ in range(combinations_count(m, i))] for i in range(m+1)]
    index = [0]*(m+1)
    for i in range(1 << m):
        cnt = 0
        val = 0
        for j in range(m):
            if i >> j & 1:
                cnt += 1
                val += a[j]
        ls[cnt][index[cnt]] = val
        index[cnt] += 1
    for i in range(m+1):
        ls[i].sort()
    ans = 0
    for i in range(1 << n-m):
        cnt = 0
        val = 0
        for j in range(n-m):
            if i >> j & 1:
                cnt += 1
                val += a[m+j]
        if K-m <= cnt <= K:
            ans += bisect.bisect_right(ls[K-cnt], R-val) - bisect.bisect_right(ls[K-cnt], L-val-1)
    print(ans)


if __name__ == '__main__':
    main()



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

using namespace std;

int i;

int gcd(int x, int y){
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N), L(N), R(N);
  for (i = 0; i < N; i++){
    cin >> A[i]; 
  }
  for (i = 0; i < N-1; i++){
    L[i+1] = gcd(L[i], A[i]);
  }
  for (i = N-1; i >= 1; i--){
    R[i-1] = gcd(R[i], A[i]);
  }
  int ans = 0;
  for (i = 0; i < N; i++){
    ans = max(ans, gcd(L[i], R[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 305;
const int P = 998244353;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN];
int n, l, m, a[MAXN];
int dp[MAXN][MAXN][MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	scanf("\n%s%d", s + 1, &m);
	int last = 0; l = strlen(s + 1), chkmin(m, l);
	for (int i = 1; i <= l + 1; i++)
		if (s[i] != '1') {
			a[++n] = i - last - 1;
			last = i;
		}
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		static int b[MAXN][MAXN], c[MAXN][MAXN];
		memset(b, 0, sizeof(b));
		memset(c, 0, sizeof(c));
		for (int j = 0; j <= l; j++)
		for (int k = 0; k <= m; k++) {
			int tmp = dp[i - 1][j][k];
			if (tmp == 0) continue;
			update(b[j - min(a[i], j)][k], tmp);
			update(b[j + 1][k], P - tmp);
			update(c[j + 1][k + 1], tmp);
		}
		for (int j = 0; j <= l; j++)
		for (int k = 0; k <= m; k++) {
			if (j != 0) update(b[j][k], b[j - 1][k]);
			update(dp[i][j][k], b[j][k]);
		}
		for (int j = 0; j <= l; j++)
		for (int k = 0; k <= m; k++) {
			if (j != 0 && k != 0) update(c[j][k], c[j - 1][k - 1]);
			update(dp[i][j][k], c[j][k]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= m; i++)
		update(ans, dp[n][0][i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 112316
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
for i in range(m//n,0,-1):
    s,a=divmod(m,i)
    if a%s==0:
        print(i)
        exit()

Measured memory_bytes: 40172
#include <iostream>
#include <vector>
#include <stack>
#include <set>

using namespace std;

vector<vector<int>> E;

vector<int> checked;
vector<int> finished;
stack<int> history;

int loopV = -1;

void dfs(int s, int prev) {
    checked[s] = 1;

    history.push(s);

    for (auto n : E[s]) {
        if (n == prev) continue;

        if (checked[n] && !finished[n]) {
            loopV = n;
            return ;            
        }

        if (checked[n] == 0) {
            dfs(n, s);
            
            if (loopV != -1) return;
        }            
    }

    finished[s] = 1;
    history.pop();    
}



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

    E.resize(N);

    for (int i = 0; i < N; i++) {
        int from, to;
        cin >> from >> to;

        from--, to--;
        
        E[from].emplace_back(to);
        E[to].emplace_back(from);
    }

    checked.resize(N, 0);
    finished.resize(N, 0);

    dfs(0, 0);

    set<int> cycle;
    while (!history.empty()) {
        int v = history.top();
        history.pop();
        cycle.insert(v);

        if (v == loopV) break;
    }

    int Q; cin >> Q;
   
    for (int i = 0; i < Q; i++) {
        int a, b; cin >> a >> b;
        a--, b--;

        if (cycle.count(a) && cycle.count(b)) cout << 2 << endl;
        else cout << 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 18400
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
d = {}
for i in range(n):
    d[i] = abs((t - h[i] * 0.006) - a)

d = sorted(d.items(), key=lambda x:x[1])
print(d[0][0] + 1)

Measured memory_bytes: 3188
#include<queue>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n, q;
	cin >> n >> q;
	pair<string, int> proces;
	int time = 0;
	queue<pair<string, int> > Q;
	for (int i = 0; i < n; i++) {
		cin >> proces.first >> proces.second;
		Q.push(proces);
	}
	while (!Q.empty()) {
		pair<string, int> tmp = Q.front();
		Q.pop();
		if (tmp.second <= q) {
			time += tmp.second;
			cout << tmp.first << " " << time << endl;
		}
		else {
			tmp.second -= q;
			Q.push(tmp);
			time += q;
		}
	}
	cin >> n;
	return 0;
}


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

typedef long long ll;

const int inf = 1000000;

int main() {
    ll N, M;
    ll ans = 0;
    cin >> N >> M;
    vector<pair<ll, ll>>p(N);
    priority_queue<ll>que;
    for (int i = 0; i < N; i++) {
        ll A, B;
        cin >> A >> B;
        p[i] = make_pair(A, B);
    }
    sort(p.begin(), p.end());
    ll a = 1;
    ll i = 0;
    while (a <= M) {
        while (i < N && p[i].first <= a) {
            que.push(p[i].second);
            i++;
        }
        a++;
        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2936
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
	char str_c[1001];
	scanf("%s", str_c);
	string str(str_c);

	int num_q;
	scanf("%d", &num_q);

	int i, j;
	char cmd_c[100];
	string cmd;
	int a, b;
	char repl_c[1001];
	string repl;
	string line;
	i = 0;
	string new_str;
	while(1) {
		getline(cin, line);
		if(line == "") continue;
		else i++;

		sscanf(line.c_str(), "%s", cmd_c);
		cmd = string(cmd_c);
		if(cmd == "replace") {
			sscanf(line.c_str(), "%s %d %d %s", cmd_c, &a, &b, repl_c);
			repl = string(repl_c);
			str.replace(a, b - a + 1, repl);
		} else {
			sscanf(line.c_str(), "%s %d %d", cmd_c, &a, &b);
			if(cmd == "reverse") {
				new_str = string(str);
				for(j = a; j <= b; j++) {
					new_str[j] = str[b + a - j];
				}
				str = string(new_str);
				//printf("-> %s\n", str.c_str());
			} else {
				cout << str.substr(a, b - a + 1) << endl;
			}
		}
		if(i >= num_q) {
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3264
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int Result = 0;
            Result = (N - 2) * 180;
            Console.WriteLine(Result);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
 
using namespace std;
 
int n, k;
int a[200000];
 
int Count(int x) {
	int i;
	
	int ret = 0;
	
	int ok, ng, mid;
	
	rep(i, n) {
		if (a[i] >= 0) {
			ok = -1; ng = n;
			while (ng - ok >= 2) {
				mid = (ok + ng) / 2;
				if (a[i] * a[mid] <= x) { ok = mid; }
				else { ng = mid; }
			}
			if (ok >= i) ret += ok;
			else ret += ok + 1;
			
		}
		else {
			ng = -1; ok = n;
			while (ok - ng >= 2) {
				mid = (ok + ng) / 2;
				if (a[i] * a[mid] <= x) { ok = mid; }
				else { ng = mid; }
			}
			if (ok <= i) ret += n - 1 - ok;
			else ret += n - ok;
		}
	}
	return ret / 2;
}
 
signed main() {
	int i, j;
	
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	
	int INF = 2 * (1e+18);
	int st = -INF, ed = INF, mid;
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (Count(mid) < k) st = mid;
		else ed = mid;
	}
	cout << ed << endl;
	return 0; 
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int ans = 0;
    if(N % 2 == 0){
        ans = N / 2 - 1;
    }
    if(N % 2 == 1){
        ans = N / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int l;
    char s[32],r[32];
    scanf("%s",s);
    l=strlen(s);
    for(int i=0;i<l;i++){
        r[l-i-1]=s[i];
    }
    for(int i=0;i<l;i++){
        printf("%c",r[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 2624
N = int(input())
s = [input() for i in range(N)]
num = 0
d = {}
for i in range(N):
    if ''.join(sorted(s[i])) in d:
        d[''.join(sorted(s[i]))] += 1
        num += d[''.join(sorted(s[i]))]
    else:
        d[''.join(sorted(s[i]))] = 0
print(num)

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

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define int long long

using namespace std;

int32_t main() {
	fast
	int n, a, b;
	cin >> n >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % n == 0) {
			cout << "OK";
			return 0;
		}
	}

	cout << "NG";
}

Measured memory_bytes: 3652
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    vec<ll> dp(1<<a), kek(1<<a);
    vec<vec<ll>> m(a, vec<ll>(a));
    for(int q=0; q<a; q++){
        for(int w=0; w<a; w++) cin>>m[q][w];
    }
    int all = 1<<a, ost;
    for(int msk=1; msk<all; msk++){
        for(int q=0; q<a; q++){
            if(!(msk&(1<<q))) continue;
            for(int w=q+1; w<a; w++){
                if(!(msk&(1<<w))) continue;
                kek[msk] += m[q][w];
            }
        }
        for(int sub=msk; ; sub = (sub-1)&msk){
            ost = msk^sub;
            dp[msk] = max(dp[msk], dp[sub]+kek[ost]);
            if(sub==0) break;
        }
    }
    cout<<dp[all-1];
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FOF(i,a,b) for(int i=a;i< b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=100100,P=998244353;
int n,m,L,o,ans;
int fc[N],vf[N],iv[N],rv[N],W[N],a[N],b[N],f[N];
int qpw(int x,int y){int z=1;for(;y;y>>=1,x=1ll*x*x%P)if(y&1) z=1ll*z*x%P;return z;}
int C(int x,int y){return 1ll*fc[x]*vf[x-y]%P*vf[y]%P;}
void ini(int n){
	for(L=1,o=0;L<=n;L<<=1,o++);
	FOF(i,1,L) rv[i]=rv[i>>1]>>1|(i&1)<<(o-1);
	iv[1]=fc[0]=vf[0]=1;
	FOR(i,2,L) iv[i]=1ll*iv[P%i]*(P-P/i)%P;
	FOR(i,1,L) fc[i]=1ll*fc[i-1]*i%P,vf[i]=1ll*vf[i-1]*iv[i]%P;
	int W1=qpw(3,(P-1)>>o);W[L>>1]=1;
	FOF(i,(L>>1)+1,L) W[i]=1ll*W[i-1]*W1%P;
	ROF(i,(L>>1)-1,0) W[i]=W[i<<1];
}
void DFT(int *A,int L){
	static unsigned long long B[N];
	FOF(i,0,L) B[i]=A[rv[i]];
	for(int i=1,t;i<L;i<<=1)for(int j=0,s=i<<1;j<L;j+=s)FOF(k,0,i)
		t=B[i+j+k]*W[i+k]%P,B[i+j+k]=B[j+k]+P-t,B[j+k]+=t;
	FOF(i,0,L) A[i]=B[i]%P;
}
void IFT(int *A,int L){
	reverse(A+1,A+L);DFT(A,L);
	int nv=P-(P-1)/L;
	FOF(i,0,L) A[i]=1ll*A[i]*nv%P;
}
void work(){
	FOF(i,0,L) a[i]=i<=n?1ll*f[i]*vf[i]%P:0;
	FOF(i,0,L) b[i]=i<=n?vf[i+2]:0;
	DFT(a,L);DFT(b,L);
	FOF(i,0,L) a[i]=1ll*a[i]*b[i]%P;IFT(a,L);
	FOR(i,0,n) f[i]=(1ll*fc[i+2]*a[i]%P-1ll*i*f[i]%P+P)%P;
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	ini(n<<1);f[0]=1;
	FOR(i,1,m) work();
	FOR(i,0,n) (ans+=1ll*C(n,i)*f[i]%P)%=P;
	cout<<ans<<'\n';
}

Measured memory_bytes: 896