akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        c: isize,
        b: [isize; m],
        a: [[isize; m]; n],
    }

    let mut ans = 0;
    for i in 0..n {
        let mut x = c;
        for j in 0..m {
            x += a[i][j] * b[j];
        }
        if x > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main()
{	
	int cnt=0;
	double a=100,n;
	cin>>n;
	while(a<n)
	{
		a=floor(a*1.01);
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main() {

  int i1, i2, n, m, c;
  int A[101][101];
  int b[101];

  cin >> n >> m;

  for(i1 = 1; i1 <= n; i1++){
    for(i2 = 1; i2 <= m; i2++){
      cin >> A[i1][i2];
    }
  }

  for(i1 = 1; i1 <= m; i1++){
    cin >> b[i1];
  }

  for(i1 = 1; i1 <= n; i1++){
    for(i2 = 1; i2 <= m; i2++){
      c += A[i1][i2] * b[i2];
    }
    cout << c << endl;
    c = 0;
  }
  
  return 0;
  
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll switches[15];
void convert(int n,int m)
{	int i=1;
	while(n!=0)
	{
		if(n%2==0)
		{
			switches[i]=0;
		}
		else
		{
			switches[i]=1;
		}
		i++;
		n=n/2;
	}
}
int main()
{
	ll n,m,k,s;
	vector<int>v[11],p;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>k;
		v[i].push_back(k);
		for(int j=0;j<k;j++)
		{
			cin>>s;
			v[i].push_back(s);
		}
	}
	for(int i=0;i<m;i++)
	{
		cin>>s;
		p.push_back(s);
	}
	ll ans=0,indi=0,count=0;
	for(int i=0;i<pow(2,n);i++)
	{
		memset(switches,0,sizeof(switches));
		convert(i,n);
		indi=0;
		for(int j=0;j<m;j++)
		{	count=0;
			for(int x=1;x<=v[j][0];x++)
			{
				if(switches[v[j][x]]==1)
				{
					count+=1;
				}
			}
		//	cout<<count<<' '<<i;
			if(p[j]!=count%2)
			{
				indi=1;
				break;
			}
		}
		if(indi==0)
		{
			ans+=1;
			//cout<<i<<"anu";
		}
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

const int MAXN = 1000;
int main(){
    int N,K;
    cin >> N >> K;
    int p[MAXN];
    rep(i,N)cin >> p[i];
    sort(p,p+N);

    int sum = 0;
    rep(i,K)sum+=p[i];
    cout << sum << endl;;
    return 0;
}

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

namespace ProconLib{
    
    template<class Monoid>
    class SegmentTree{
        public: 
        using value_t= typename Monoid::value_t;
        private:
        int N;
        std::vector<value_t> dat;
        static int calcN(int n){int res=1; while(res<n) res*=2; return res;}
        value_t queryImpl(int a,int b,int k,int l,int r);

        public:
        SegmentTree(int N);
        void update(int pos,value_t val);        
        void updateALL(std::vector<value_t> x);
        value_t query(int a,int b);
    };

    // struct MonoidExample{
    //     using value_t=int;
    //     static constexpr value_t E(){return 0;}
    //     static value_t op(value_t lhs,value_t rhs){return lhs+rhs;}
    // };
    
    template<typename Monoid>
    SegmentTree<Monoid>::SegmentTree(int n):N(calcN(n)),dat(2*N-1,Monoid::E()){}

    template<typename Monoid>
    void SegmentTree<Monoid>::update(int pos,value_t val){
        pos+=N-1;
        dat[pos]=val;
        while(pos!=0){
            int par=(pos-1)/2;
            dat[par]=Monoid::op(dat[par*2+1],dat[par*2+2]);
            pos=par;
        }
    }

    template<typename Monoid>
    void SegmentTree<Monoid>::updateALL(std::vector<value_t> x){
        for(int i=0;i<x.size();i++) dat[N-1+i]=x[i];
        for(int i=N-2;i>=0;i--) dat[i]=Monoid::op(dat[i*2+1],dat[i*2+2]);
    }

    template<typename Monoid>
    typename SegmentTree<Monoid>::value_t SegmentTree<Monoid>::query(int a,int b){
        return queryImpl(a,b,0,0,N);
    }

    template<typename Monoid>
    typename SegmentTree<Monoid>::value_t SegmentTree<Monoid>::queryImpl(int a,int b,int k,int l,int r){
        if(a<=l && r<=b) return dat[k];
        if(r<=a || b<=l) return Monoid::E();
        int mid=(l+r)/2;
        value_t c1v=queryImpl(a,b,k*2+1,l,mid);
        value_t c2v=queryImpl(a,b,k*2+2,mid,r);
        return Monoid::op(c1v,c2v);
    }
}

using namespace std;

using ll=long long;
const ll INF=1e15;

using namespace ProconLib;

 struct MonoidExample{
         using value_t=ll;
         static constexpr value_t E(){return INF;}
         static value_t op(value_t lhs,value_t rhs){return min(lhs,rhs);}
     };

int main(){
    int N,M;
    cin>>N>>M;
    vector<vector<pair<int,ll>>> RC(N);
    for(int i=0;i<M;i++){
        int l,r;
        ll c;
        cin>>l>>r>>c;
        l--,r--;
        RC[r].push_back({l,c});
    }

    SegmentTree<MonoidExample> seg(N);
    vector<ll> dp(N,INF);
    dp[0]=0;
    seg.update(0,dp[0]);
    for(int i=0;i<N;i++){
        for(auto p:RC[i]){
            dp[i]=min(dp[i],seg.query(p.first,i)+p.second);
        }
        seg.update(i,dp[i]);
    }
    cout<<(dp[N-1]>=INF ? -1LL :dp[N-1])<<endl;
    return 0;
}


Measured memory_bytes: 8448
finish = gets.chomp
i = 0
answer = []
while i < finish.to_i
 array = gets.split
 
 if array[0].to_i > array[1].to_i
  array[0],array[1] = array[1],array[0]
 end

 if array[1].to_i > array[2].to_i
  array[1],array[2] = array[2],array[1]
 end

 if array[0].to_i > array[1].to_i
  array[0],array[1] = array[1],array[0]
 end

 if array[2].to_i**2 == array[0].to_i**2 + array[1].to_i**2
  answer[i] = "YES"
 else
  answer[i] = "NO"
 end

 i = i+1
end

puts answer

Measured memory_bytes: 6112
from sys import exit
import math
n=int(input())
l=math.floor(math.sqrt(n))

for i in range(l+1,0,-1):
    if n%i==0:
        a,b=i,n//i
        h=max(a,b)
        k=math.floor(math.log10(h))+1
        print(k)
        exit()


Measured memory_bytes: 3060
n, m = map(int, input().split())
A = []
for i in range(n):
    a = input().split()
    A.extend(a[1:])
words = list(set(A))
result = 0
for j in range(len(words)):
    if A.count(words[j]) == n:
        result += 1
print(result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define vl vector
#define pb push_back
#define ff first
#define ss second
using namespace std;

int main()
{
    ll n,m,i,a=0,b=0,k,t,j;
    cin>>a;
    ll ans=0;
    ans+=a;
    ans+=a*a;
    ans+=(a*a)*a;
    cout<<ans;
}

Measured memory_bytes: 3624
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		int ans = B;
		if(A>=6 && A<=12) {
			ans = B/2;
		}else if(A<=5) {
			ans = 0;
		}
		
		out.println(ans);
		
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int w = sc.nextInt();

        String ans = "";
        if (s > w) {
            ans = "safe";
        }
        else {
            ans = "unsafe";
        }
        System.out.println(ans);
    }
}

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

#include <set>
#include <cmath>
#include <algorithm>

using namespace std;
int mainA()
{
	string str1, str2;
	cin >> str1 >> str2;
	int a = stoi(str1);
	int b = stoi(str2);
	int plus = a + b;
	int minus = a - b;
	int mult = a * b;
	int maxval = max(plus, max(minus, mult));

	cout << maxval << endl;

	return 0;
}

int main()
{
	return mainA();
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	string S;

	cin >> S;

	if ((S[0] == S[1] && S[1] == S[2]) || (S[1] == S[2] && S[2] == S[3]))cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
def solve(sy,sx,ty,tx)
	cy=sy; cx=sx
	while cy<ty
		cy+=1
		print("U")
	end
	while cx<tx
		cx+=1
		print("R")
	end
	while cy>sy
		cy-=1
		print("D")
	end
	while cx>sx
		cx-=1
		print("L")
	end
	cx-=1
	print("L")
	while cy<ty+1
		cy+=1
		print("U")
	end
	while cx<tx
		cx+=1
		print("R")
	end
	cy-=1
	print("D")
	cx+=1
	print("R")
	while cy>sy-1
		cy-=1
		print("D")
	end
	while cx>sx
		cx-=1
		print("L")
	end
	print("U\n")
end

if __FILE__==$0
	
	reads_i=lambda{|s,d|s.strip.split(d).map(&:to_i)}
	d=reads_i[gets," "]
	solve(d[1],d[0],d[3],d[2])
end

Measured memory_bytes: 1916
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
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; }


using namespace std;



bool dp[81][81][12810], visited[81][81];

/*
dp[h][w][ab] := マスh, wに到達するまでに差の絶対値がab なる パスが存在すればtrue を用意して,80^3
(全ての絶対値範囲を網羅して80^4にしてもよい、余裕があるので)
というかしないとダメか、80までしかためておけない場合ゴールの周辺2マスが0, 80で囲まれていた場合詰んでしまう
パスの長さは80*2なので、(80^4)*2 ≒8*10^7 くらいのdpテーブルがひつようになる

この考察の元には、差の絶対値さえ保持しておけば、大きくするには大きいほうに大きいほうを足せばよいし、小さくするには大きいほうに小さいほうを足せばよい というのがある
1マスの更新コストには、12800*2の更新コスト(遷移元のコストを全部見る)がかかるので、
80*80*12800*2 = 1.6*10^8 でC++ならギリギリ間に合いそう、とかいいつつdpは軽いので余裕で間に合いそう
*/

signed main() {
    int H, W;
    cin >> H >> W;
    int A[81][81], B[81][81];
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
        }
    }
    rep(i, H) {
        rep(j, W) {
            cin >> B[i][j];
        }
    }

    dp[0][0][abs(A[0][0] - B[0][0])] = true;
    visited[0][0] = true;

    function<void(int, int)> rec = [&](int x, int y) {
        if (x < 0 || y < 0) {
            return;
        }
        if (visited[y][x]) {
            return;
        }
        rec(x - 1, y);
        rec(x, y - 1);

        int diff = abs(A[y][x] - B[y][x]);
        rep(i, 12810) {
            if (y-1 >= 0 && dp[y-1][x][i]) {
                if (i + diff < 12810) {
                    dp[y][x][i + diff] = true;
                }
                if (abs(i - diff) < 12810) {
                    dp[y][x][abs(i - diff)] = true;
                }
            }

            if (x - 1 >= 0 && dp[y][x-1][i]) {
                if (i + diff < 12810) {
                    dp[y][x][i + diff] = true;
                }
                if (abs(i - diff) < 12810) {
                    dp[y][x][abs(i - diff)] = true;
                }
            }
        }
        visited[y][x] = true;
    };

    rec(W - 1, H - 1);
    int ans = -1;

    rep(i, 12810) {
        if (dp[H - 1][W - 1][i]) {
            ans = i;
            break;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 81408
from collections import defaultdict
d = defaultdict(int)
n = int(input())
l = sorted(list(map(int,input().split())))
for i in l:
    d[i] += 1

ans = 0
for i in range(n-1,-1,-1):
    if d[l[i]] == 0:
        continue
    x = 2**(l[i].bit_length())
    y = x-l[i]
    if y == l[i]:
        if d[y] >= 2:
            d[y] -= 2
            ans += 1
    else:
        if d[y] > 0:
            d[y] -= 1
            d[l[i]] -= 1
            ans += 1
            
print(ans)

Measured memory_bytes: 56944
#include <stdio.h>

int main()
{
  char w[3][10] = {"Sunny", "Cloudy", "Rainy"};
  char s[10];
  scanf("%s", s);
  for(int i = 0; i < 3; i++) {
    if(s[0] == w[i][0]) {
      printf("%s\n", w[(i + 1) % 3]);
    }
  }
  return 0;
}


Measured memory_bytes: 1624
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
    //int nax = max_element(p.begin(),p.end())-p.begin();
    //int nin = max_element(p.begin(),p.end())-p.begin();
     //sort(l.begin(),l.end(),greater<int>());
     //stringは",charは'
     //ちょっとあやしかったら立ち止まって考える
     //例外処理はreturn忘れずに

 int main(){
     vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
     int k;
     cin >> k;
     rep(i,k){
         if(i==k-1){
         cout << a[i] << endl;;
         break;
         }
     }
     return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)

template<class Iterator, class Compare>
int inversion_number(Iterator l, Iterator r, Compare comp){
	if(r - l <= 1) return 0;
	Iterator i, j, k, h = l + (r - l) / 2;
	int ans = inversion_number(l, h, comp) + inversion_number(h, r, comp);
	auto x = *l;
	vector<decltype(x)> tmp(l, r);
	for(i = l, j = l, k = h; i < r; i++){
		if(k == r || (j < h && !comp(tmp[k - l], tmp[j - l]))){
			*i = tmp[j - l];
			j++;
		}
		else{
			*i = tmp[k - l];
			ans += k - i;
			k++;
		}
	}
	return ans;
}

int main(){
	int N, i, j, k, S;
	scanf("%d", &N);
	vector<int> A(N), B(N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	for(i = 0; i < N; i++){
		scanf("%d", &B[i]);
	}
	int ans = inf;
	for(S = 0; S < (1 << N); S++){
		vector<pair<int, int>> V_eo(N);
		for(i = 0; i < N; i++){
			if((S | (1 << i)) == S){
				V_eo[i].first = B[i];
				V_eo[i].second = (i + 1) % 2;
			}
			else{
				V_eo[i].first = A[i];
				V_eo[i].second = i % 2;
			}
		}
		int f = 1;
		int now = inversion_number(V_eo.begin(), V_eo.end(), [](auto a, auto b){return a.first < b.first;});
		for(i = 0; i < N; i = j){
			for(j = i + 1; j < N && V_eo[j].first == V_eo[i].first; j++);
			int Ol[2] = {0, 0};
			vector<int> sub(j - i);
			for(k = i; k < j; k++){
				V_eo[k].second ^= (i % 2);
				sub[k - i] = 2 * Ol[V_eo[k].second] + V_eo[k].second;
				Ol[V_eo[k].second]++;
			}
			if(Ol[0] != (j - i + 1) / 2 || Ol[1] != (j - i) / 2){
				f = 0;
				break;
			}
			now += inversion_number(sub.begin(), sub.end(), [](auto a, auto b){return a < b;});
		}
		if(f == 1){
//			printf("now[%d] = %d\n", S, now);
			ans = min(ans, now);
		}
	}
	if(ans >= inf){
		printf("-1\n");
	}
	else{
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/abc116/tasks/abc116_c
// ---------------------------------------------
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	hs := make([]int, n, n+2)
	for i := 0; i < n; i++ {
		fmt.Scan(&hs[i])
	}
	hs = append(append([]int{0}, hs...), 0)
	cost := 0
	for i := 1; i <= len(hs)-1; i++ {
		if hs[i] > hs[i-1] {
			cost += hs[i] - hs[i-1]
		}
	}
	fmt.Println(cost)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int a[3007];
int n,u,v,par[3007];
vector <int> edge[3007];
int dfs(int u){
	for(int i=0;i<(int)edge[u].size();i++){
		int v=edge[u][i];
		if(v==par[u]) continue;
		par[v]=u;
		if(a[v]<a[u] && dfs(v)==0) return 1;
	}
	return 0;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		cin>>u>>v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	for(int i=1;i<=n;i++){
		for(int i=1;i<=n;i++) par[i]=0;
		if(dfs(i)==1) cout<<i<<" ";
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <queue>
#include <list>
#include <set>

#define llong long long int

using namespace std;

int num_of_bits(long bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S; cin >> S;
    int n = S.size();
    int s[41];
    for (int i = 0; i < n; ++i) {
        s[i] = S[i] - '0';
        //cout << s[i] << endl;
    }

    int dif = 100000;
    for (int i = 0; i <= n - 3; ++i) {
        int tmp = 100 * s[i] + 10 * s[i + 1] + s[i + 2];
        //cout << tmp << endl;
        if (abs(753 - tmp) <= dif) {
            dif = abs(753 - tmp);
        }
    }

    cout << dif << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#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 REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{   
    ll n,x,m;
    cin>>n>>x>>m;
    map<ll,ll> mp;
    ll ans = 0;

    ll x1 = x;
    mp[x] = 1;
    ll curr = 2;
    ll start = 0,end = 0;

    while(1){
        x = (x*x) % m;
        if(mp.count(x)){
            start = mp[x] - 1;
            end = curr-1;
            break;
        }
        else {
            mp[x] = curr;
            curr++;
        }
    }

    ll p = min(n,start);
    REP(i,1,p+1){
        ans += x1;
        x1 = (x1*x1) % m;
    }
    n -= p;

    ll temp = 0;
    ll x2 = x1;
    REP(i,start+1,end+1){
        temp += x1;
        x1 = (x1*x1) % m;
    }

    if(end-start > 0){
        ans += (n/(end-start))*temp;
        n %= (end-start);
        REP(i,1,n+1){
            ans += x2;
            x2 = (x2*x2) % m;
        }
    }
    cout<<ans<<endl;
    return 0;
}   
    

Measured memory_bytes: 6668
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <list>
#include <vector>
#include <unistd.h>
#include <algorithm>
#define ll long long
using namespace std;
ll N;
ll m[301][301]; 
int main(){
	cin >> N;
	memset(m, -1, sizeof(m));
	for ( ll i = 0 ; i < N ; i ++ ){
		for ( ll j = 0 ; j < N ; j ++ ){
			cin >> m[i][j];
		}
	}
	ll tot = 0;
	for ( ll i = 0 ; i < N ; i ++ ){
		for ( ll j = 0 ; j < N ; j ++ ){
			if ( i == j ) continue;
			bool flag = true;
			for ( ll k = 0 ; k < N ; k ++ ){
				if ( k == i || k == j ) continue;
				if ( m[i][k] + m[k][j] < m[i][j] )  {
					cout << -1 << endl;
					return 0;
				}
				if ( m[i][k] + m[k][j] == m[i][j] ) flag = false;
			}
			if ( flag ){
					tot += m[i][j];
			}                
		}
	}
	cout << tot / 2 << endl;
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
vector<int> MakeKMPFailureLink(string& S){
	int N = S.length();
	vector<int> kmp_failure_link(N+1);
	int p = -1;
	kmp_failure_link[0] = p;
	for(int i=1;i<=N;i++){
		while(p >= 0 && S[i-1] != S[p]){
			p = kmp_failure_link[p];
		}
		p++;
		kmp_failure_link[i] = p;
	}
	return kmp_failure_link;
}
bool OK[500000];
int n;
//kmp_failure_linkにはSのkmp_failure_linkを入れる
void KMPCount(string& T,string &S,vector<int>& kmp_failure_link){
	int N = S.length();
	int p = 0;
	for(int i=0;i<T.length();i++){
		while(p >= 0 && T[i] != S[p]){
			p = kmp_failure_link[p];
		}
		p++;
		if(p == N){
			OK[i%n] = true;
			p = kmp_failure_link[N];
		}
	}
}
bool finished[500000];
bool in[500000];
void Calc(){
	string S0 = res();
	string T = res();
	n = S0.length();
	string S;
	while(S.length() < T.length()){
		S += S0;
	}
	S += S0;
	vector<int> failurelink = MakeKMPFailureLink(T);
	KMPCount(S,T,failurelink);
	int ans = 0;
	for(int i=0;i<n;i++){
		if(OK[i]){
			in[(i+T.length()) % S0.length()] = true;
		}
	}
	for(int i=0;i<n;i++){
		if(!in[i]){
			int p = i;
			int c = 0;
			while(OK[p]){
				c++;
				p = (p+T.length()) % S0.length();
			}
			ans = max(ans,c);
		}
	}
	for(int i=0;i<n;i++){
		if(OK[i] && !finished[i]){
			finished[i] = true;
			int p = (i+T.length()) % S0.length();
			while(OK[p]){
				if(i == p){
					cout << -1 << endl;
					return;
				}
				if(finished[p]){
					break;
				}
				finished[p] = true;
				p = (p+T.length()) % S0.length();
			}
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n, c, k, tstart, counter, waiting;
	cin >> n >> c >> k;
	vector<int> t(n);
	rep(i, 0, n - 1) cin >> t[i];
	sort(t.begin(), t.end());
	tstart = t[0];
	counter = waiting = 0;
	rep(i, 0, n - 1)
	{
		++waiting;
		if (t[i] - tstart > k)
		{
			++counter;
			tstart = t[i];
			waiting = 1;
		}
		else if (waiting > c)
		{
			++counter;
			tstart = t[i];
			waiting = 1;
		}
		if (i == n - 1)
		{
			++counter;
		}
	}
	cout << counter << endl;
}


Measured memory_bytes: 640
n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
ans=0
for i in range(n):
  if B[i]>=A[i]:
    ans+=A[i]
    if B[i]-A[i]>A[i+1]:
      ans+=A[i+1]
      A[i+1]=0
    else:
      ans+=B[i]-A[i]
      A[i+1]-=B[i]-A[i]
  else:
    ans+=B[i]
print(ans) 

Measured memory_bytes: 18436
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>
#include <algorithm>
using namespace std;
int mygcd2(int a,int b);
int mygcd3(int a,int b,int c);
int main(void){
	int K;
	cin >> K;
	long ans=0;
	int anstmp = 0;
	for(int i=1;i<=K;i++){
		for(int j=i;j<=K;j++){
			for(int k=j;k<=K;k++){
				if(i != j && j != k)anstmp= 6*mygcd3(i,j,k);
				else if(i!= j || j!=k) anstmp =3*mygcd3(i,j,k);
				else anstmp=mygcd3(i,j,k);
				ans += anstmp;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

int mygcd2(int a,int b){
	if(b==0)return a;
	return mygcd2(b,a%b);
}

int mygcd3(int a,int b,int c){
	return mygcd2(mygcd2(a,b),c);
}



Measured memory_bytes: 3636
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

T1,T2 = MI()
A1,A2 = MI()
B1,B2 = MI()

if A1*T1 + A2*T2 == B1*T1 + B2*T2:
    print('infinity')
    exit()

if A1*T1 + A2*T2 > B1*T1 + B2*T2:
    A1,B1 = B1,A1
    A2,B2 = B2,A2

if A1 < B1:
    print(0)
    exit()

if ((A1-B1)*T1) % (B1*T1+B2*T2-A1*T1-A2*T2) != 0:
    print(((A1-B1)*T1)//(B1*T1+B2*T2-A1*T1-A2*T2)*2+1)
else:
    print(((A1-B1)*T1)//(B1*T1+B2*T2-A1*T1-A2*T2)*2)


Measured memory_bytes: 61968
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n;
int h[100010];
int dp[100010];

void chmin(int a, int *b)
{
	if (*b > a)
		*b = a;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0; i < n + 2; i++)
	{
		dp[i] = INT_MAX; 
		scanf("%d", h+i);
	}
	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		if(i+1 < n) chmin(dp[i] + abs(h[i + 1] - h[i]), &dp[i + 1]);
		if(i+2 < n) chmin(dp[i] + abs(h[i + 2] - h[i]), &dp[i + 2]);
	}

	printf("%d", dp[n - 1]);
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int solver(const int N, const int M, vector<int> &S, vector<int> &L, vector<int> &P){
  vector<vl> dp(N+1, vl((M+1),0));

  rep(i,N){
    rep(j,M+1){
      if(j<S[i]){
        dp[i+1][j] = max(dp[i][j],dp[i+1][j]);
        continue;
      }else{
        dp[i+1][j] = max({dp[i][j],dp[i+1][j-S[i]]+P[i],dp[i+1][max(0,j-L[i])]+P[i]});
      } 
    } 
  }
  return dp[N][M];
}
  


int main(){
  int N;
  cin >> N;
  vector<int> S(N), L(N), P(N);
  rep(i, N) cin >> S[i] >> L[i] >> P[i];
  int M;
  cin >> M;
  bool check=false;
  vector<int> ans(M);
  rep(i,M){
    int m;
    cin >> m;
    int a = solver(N,m,S,L,P);
    if(a<=0){
      cout << -1 << endl;
      return 0;
    }else ans[i]=a;
  }
  rep(i,M){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4124
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

int vs[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  multiset<int> ss;
  for(int i = n-1; i >= 0; --i) {
    auto it = ss.upper_bound(vs[i]);
    if(it == ss.end()) {
      ss.insert(vs[i]);
    } else {
      ss.erase(it);
      ss.insert(vs[i]);
    }
  }
  cout << ss.size() << endl;
  
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

#define ass(x) ({if(!(x)) return false;})

const int mxn = 206;

int n, h;
unordered_map<int,int> deg;
unordered_map<int,bool> v;

struct DSU {
	unordered_map<int,int> p;
	void clear() {
		for (int i = -200; i <= 200; ++i)
			p[i] = i;
	}
	int root(int x) {
		return p[x] == x ? x : p[x] = root(p[x]);
	}
	void merge(int x, int y) {
		p[root(x)] = root(y);
	}
	int operator[](int x) { return root(x); }
} U;

unordered_map<int,int> f;

bool connected() {
	for (int i = -200; i <= 200; ++i)
		f[U[i]] |= deg[i] < 0 ? 1 : deg[i] > 0 ? 2 : 0;
	for (int i = -200; i <= 200; ++i) if (v[i])
		ass(f[U[i]] == 3);
	return true;
}

bool check() {
	for (int i = -200; i <= 200; ++i)
		ass(deg[i] * i >= 0);
	return true;
}

int main() {
	cin >> n >> h;
	
	U.clear();
	
	for (int i = 1; i <= n; ++i) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int x, y;
		x = c ? -c : a;
		y = d ? -d : b;
		y = -y;
		++deg[x];
		--deg[y];
		v[x] = v[y] = true;
		U.merge(x, y);
		//cout << x << ' ' << y << endl;
	}
	
	puts(check() && connected() ? "YES" : "NO");
	
	return 0;
}


Measured memory_bytes: 256
use std::io;

fn main(){
    let mut line=String::new();
    io::stdin().read_line(&mut line).ok();
    let nums:Vec<&str>=line.split_whitespace().collect();
    let x:i32=nums[0].parse().unwrap();
    let y:i32=nums[1].parse().unwrap();
    let z:i32=nums[2].parse().unwrap();
    println!("{} {} {}",z,x,y);
    
}

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

using namespace std;

int main()
{
	int N;
	cin>>N;
	long long sum=0;
	for(int i=1 ; i<=N ; i++)
	{
		if(i%3!=0 && i%5!=0)
		{
			sum+=i;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int pre = sc.nextInt();;
        boolean end = false;
        for(int i=1; i<N; i++) {
            int H = sc.nextInt();
            if(pre > H) {
                System.out.println("No");
                end = true;
                break;
            }
            if (pre < H) {
                pre = H-1;
            } else {
                pre = H;
            }
        }
        if (!end) {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 45208
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define MOD 1000000009
using namespace std;
typedef long long ll;
int main()
{
  int a;
  cin >> a ;
  for(int i = 1; i <= 9; i ++){
    if(a%i == 0){
      if(a/i >= 1 && a/i <=9){
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
a, b = map(int,input().split())
cnt = 0
for i in range(a, b+1):
    i_s = str(i)
    i_r = 0
    for j in range(len(i_s)):
        i_r *= 10
        i_r += int(i_s[-j-1])
    if i == i_r:
        cnt += 1
print(cnt)

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define Task "B"

using namespace std;
int n, a[105];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i<=n; ++i) cin >> a[i];

    double res = 0;
    for(int i = 1; i<=n; ++i) res += 1.0 / a[i];

    res = 1.0/res;
    cout << fixed << setprecision(5) << res;

    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	string a;
	cin >> a;
	int x = 0, y = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] == 'R')
		{
			x++;
		}
	}
	for (int i = x; i < n; i++)
	{
		if (a[i] == 'R')
		{
			y++;
		}
	}
	cout << y;
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

#define T0(T) T
#define T1(T) vector<T0(T)>
#define T2(T) vector<T1(T)>
#define V0(v, T,    ...) v
#define V1(v, T, n, ...) T1(T)(n, V0(v, T, __VA_ARGS__))
#define V2(v, T, n, ...) T2(T)(n, V1(v, T, __VA_ARGS__))

#define PC __builtin_popcountll
#define BL(a) (a ? 64 - __builtin_clzll(a) : 0)

template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "["; inc(i, SI(v)) { os << (i == 0 ? "" : ", ") << v[i]; } os << "]";
	return os;
}

int main() {
	int n;
	cin >> n;
	auto v = V2(-1, int, n, n);
	inc(i, n) {
		int a; cin >> a;
		inc(j, a) {
			int x, y;
			cin >> x >> y;
			x--;
			v[i][x] = y;
		}
	}
	
	int ans = 0;
	inc(b, 1 << n) {
		bool f = true;
		inc(i, n) {
		inc(j, n) {
			if(bit(b, i) == 1 && v[i][j] != -1) { f &= (bit(b, j) == v[i][j]); }
		}
		}
		if(f) { setmax(ans, PC(b)); }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N;
vector<int> G[5050];
int siz[5050];
vector<int> cent;

void solve(int v,int p){
  siz[v]=1;
  bool flag=1;
  for(int u:G[v]) if(u!=p){
    solve(u,v);
    if(siz[u]>N/2) flag=0;
    siz[v]+=siz[u];
  }
  if(N-siz[v]>N/2) flag=0;
  if(flag) cent.push_back(v);
}


const int MAX_N=5050;
ll inv[MAX_N+1], fact[MAX_N+1], ifact[MAX_N+1];

ll comb(int n, int k){
  if(n<k) return 0;
  return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}

void prepare(){
  inv[1]=fact[0]=fact[1]=ifact[0]=ifact[1]=1LL;
  for(int i=2;i<=MAX_N;i++){
    inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    fact[i]=fact[i-1]*i%MOD;
    ifact[i]=ifact[i-1]*inv[i]%MOD;
  }
}


// dp[i][x]:i番目までにx個選んだ場合の選び方
ll to[5050], from[5050];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  cin>>N;
  rep(i,N-1){
    int x,y; cin>>x>>y; x--,y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  solve(0,-1);
  prepare();
  if(cent.size()==2){
    cout<<fact[N/2]*fact[N/2]%MOD<<endl;
    return 0;
  }
  from[0]=1;
  int c=cent[0], n=G[c].size();
  solve(c,-1);
  for(int v:G[c]){
    int s=siz[v];
    fill(to,to+5050,0);
    rep(j,N+1) if(from[j]){
      for(int k=0;k<=s;k++){
      (to[j+k]+=from[j]*comb(s,k)%MOD*comb(s,k)%MOD*fact[k])%=MOD;
      } 
    }
    swap(to,from);
  }
  ll ans=0;
  int sig=1;
  rep(i,N+1){
    (ans+=sig*fact[N-i]*from[i])%=MOD;
    ans=(ans+MOD)%MOD;
    sig*=-1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct point{double x;double y;};
int i,j,k,count1=0,count2=0;

int main(void){
    int ans=0;
    string s,t="CODEFESTIVAL2016";
    cin>>s;
    for(i=0;i<s.length();i++){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
}

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

int main()
{
	int A, B, H, M;
	scanf("%d %d %d %d", &A, &B, &H, &M);
	
	long double h = M_PI * (H + M / 60.0) / 6.0, m = M_PI * M / 30.0;
	printf("%.10Lf\n", sqrtl((long double)A * A + (long double)B * B - 2.0 * A * B * cosl(h - m)));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>

using namespace std;

int main(){
  string S; cin >> S;
  sort(S.begin(), S.end());
  if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

//ll mod = 1000000007;
ll mod = 998244353;

signed main()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>> vp(n);
    rep(i, n)
    {
        ll x, l;
        cin >> x >> l;
        vp[i] = {x + l, x - l};
    }
    sort(all(vp));
    ll l = -INT_MAX;
    ll ans = 0;
    rep(i, n)
    {
        if (vp[i].second >= l)
        {
            l = vp[i].first;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    long long int K, N;
    cin >> K >> N;
    long long int A[N];
    long long int distance = 0;
    for(long long int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long int max_section_value = A[1] - A[0];
    for(long long int i = 1; i < N - 1; i++) {
        max_section_value = max(max_section_value, A[i+1] - A[i]);
    }
    max_section_value = max(max_section_value, K + A[0] - A[N-1]);
    distance = K - max_section_value;
    cout << distance << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long long all = 0;
    for (int i = 0; i < n; i++) all += a[i];
    long long remain = 0;
    for (int i = 1; i < n - 1; i += 2) remain += a[i] * 2;
    vector<int> ans(n);
    ans[0] = all - remain;
    for (int i = 0; i < n - 1; i++) ans[i + 1] = a[i] * 2 - ans[i];
    for (int i = 0; i < n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int d, n;
    cin >> d >> n;

    int out = 0;
    if (d == 0) {
        out = n;
    } else if (d == 1) {
        out = 100 * n;
    } else {
        // d == 2
        out = 10000 * n;
    }

    if ( n == 100) {
        out += pow(100,d);
    }

    cout << out << endl;
    
    return 0;
}

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

typedef struct node {
	int key;
	struct node *p_left;
	struct node *p_right;
	struct node *p_parent;
}NODE;

void insert(int value);	/* ?????\ */
void inorder(NODE *p_node);	/* ??????????????? */
void preorder(NODE *p_node); /* ??????????????? */
int find(int value);

NODE *p_root;

int main(void) {

	char command[20];
	int value;
	int n;
	int i;
	int result_find;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s", &command);
		if (command[0] == 'i') {
			scanf("%d", &value);
			insert(value);
		}
		else if (command[0] == 'p') {
			inorder(p_root);
			printf("\n");
			preorder(p_root);
			printf("\n");
		}
		else if (command[0] == 'f') {
			scanf("%d", &value);
			result_find =find(value);
			if (result_find == 0) {
				printf("no\n");
			}
			else {
				printf("yes\n");
			}
		}
	}
	return 0;
}

void insert(int value) {
	NODE *x = p_root;	/* ??? */
	NODE *y = NULL;	/* x?????? */

	NODE *z = (NODE *)malloc(sizeof(NODE));
	z->key = value;
	z->p_left = NULL;
	z->p_right = NULL;

	while (x != NULL) {
		y = x;
		if (z->key < x->key) {
			x = x->p_left;		/* ?????????????§???? */
		}
		else {
			x = x->p_right;	/* ?????????????§???? */
		}
	}
	z->p_parent = y;

	if (y == NULL) {	/* ??¨???????????´??? */
		p_root = z;
	}
	else if (z->key < y->key) {
		y->p_left = z;	//z?????????????????????
	}
	else {
		y->p_right = z;	//z?????????????????????
	}
}

//?????????????????§??¨???
void inorder(NODE *p_node) {

	if (p_node == NULL) {
		return;
	}
	inorder(p_node->p_left);
	printf(" %d", p_node->key);
	inorder(p_node->p_right);
}

//?????????????????§??¨???
void preorder(NODE *p_node) {

	if (p_node == NULL) {
		return;
	}
	printf(" %d", p_node->key);
	preorder(p_node->p_left);
	preorder(p_node->p_right);
}

int find(int value) {
	
	NODE *p_node;
	p_node = p_root;

	while (1) {
		if (p_node->key > value) {
			if (p_node->p_left != NULL) {
				p_node = p_node->p_left;
			}
			else {
				return 0;
			}
		}
		else if (p_node->key < value) {
			if (p_node->p_right != NULL) {
				p_node = p_node->p_right;
			}
			else {
				return 0;
			}
		}
		else {
			return 1;
		}
	}
}

Measured memory_bytes: 19364
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut l: [i32; n],  // Vec<(i32, i32, i32)>
    }

    let mut ans = 0;
    if n <= 1 {
        println!("0");
        return;
    }
    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            for k in j + 1..n {
                if l[i] != l[j]
                    && l[j] != l[k]
                    && l[k] != l[i]
                    && l[i] + l[j] > l[k]
                    && l[j] + l[k] > l[i]
                    && l[k] + l[i] > l[j]
                {
                    ans += 1;
                }
            }
        }
    }
    print!("{}", ans);
}


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

int main () {
	string c[3];
	cin >> c[0] >> c[1] >> c[2];
	if (c[0] != c[1]){
        if (c[1] != c[2] && c[0] != c[2]){
            cout << "3"; //\n\nThree different colors: " << c[0] << c[1] << c[2];
        }
        else{
            cout << "2"; //\n\nTwo different colors: " << c[0] << c[1];
        }
        return 0;
	}
	if (c[0] != c[2]){
        cout << "2"; // \n\nTwo different colors: " << c[0] << c[1];
        return 0;
    }
    cout << "1";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  ll ans = 0;
  vector<ll> v(n, 0);
  for (int i = 0; i < n-1; i++) {
    cin >> v[i];
  }
  ans += v[0];
  for (int i =1; i < n-1; i++) {
    ans += min(v[i], v[i-1]);
  }
  ans += v[n-2];
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
def check(s, n, x, y)
	if x == 1
		return s[0] == 'Y' if y == 0
		return s[2*n] == 'Y' if y == 1
	elsif x == n + 1
		return s[2*n-1] == 'Y' if y == 0
		return s[4*n-1] == 'Y' if y == 1
	else
		a, b = 2*x - 2, 2*x - 1
		a += 2*n if y == 1
		b += 2*n if y == 1
		return s[a-1] == 'Y' || s[b-1] == 'Y'
	end
end

def calc(n, s)
	cnt0, cnt1 = 0, 0
	lst0, lst1 = -1, -1
	fst0, fst1 = n+2, n+2
	for i in (1..n+1) do 
		cnt0, lst0, fst0 = cnt0+1, i, [fst0, i].min if check(s, n, i, 0)
		cnt1, lst1, fst1 = cnt1+1, i, [fst1, i].min if check(s, n, i, 1)
	end
	# p [cnt0, cnt1, fst0, fst1, lst0, lst1]
	return n + cnt0 + cnt1 if cnt1 == 0
	ans = n + cnt0 + cnt1 + 2
	if cnt0 != 0
		ans -= 1 if fst0 <= fst1
		ans -= 1 if lst0 >= lst1
	end
	return ans
end

gets.to_i.times do
	n = gets.to_i
	s = gets
	puts calc(n, s)
end

Measured memory_bytes: 6988
using System;

namespace ABC122
{
    class Program
    {
        static void Main(string[] args)
        {
            var b = Console.ReadLine();

            switch (b)
            {
                case "A":
                    Console.WriteLine("T");
                    break;
                case "C":
                    Console.WriteLine("G");
                    break;
                case "G":
                    Console.WriteLine("C");
                    break;
                case "T":
                    Console.WriteLine("A");
                    break;
            }
        }
    }
}


Measured memory_bytes: 9044