akhauriyash/Code-Regression huggingface dataset:
from math import factorial
n = int(input())
s = input()
mod = 10**9+7
t = ""
for i,c in enumerate(s):
	if i%2:
		t += "L" if c=="W" else "R"
	else:
		t += "R" if c=="W" else "L"
if t.count("L")!=t.count("R"):
	print(0)
else:
	ans = 1
	Lcnt = 0
	for i in t:
		if i=="L":
			Lcnt += 1
		else:
			ans *= Lcnt
			Lcnt -= 1
		ans %= mod
	print(ans*factorial(n)%mod)

Measured memory_bytes: 4584
#[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)*}
    };
}

#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn to753(mut n: usize) -> usize {
    let mut ans = 0;
    let mut d = 1;
    let mut ok3 = false;
    let mut ok5 = false;
    let mut ok7 = false;
    loop {
        ans = match n%4 {
            3 => {
                ok7 = true;
                ans + 7 * d
            },
            2 => {
                ok5 = true;
                ans + 5 * d
            },
            1 => {
                ok3 = true;
                ans + 3 * d
            },
            0 => return 0,
            _ => panic!("error")
        };
        if n <= 3 {
            break;
        }
        n /= 4;
        d *= 10;
    }
    if ok3 && ok5 && ok7 {
        ans
    } else {
        0
    }
}

fn main() {
    input!{
      n: usize,
    }
    let mut ans = 0;
    let mut i = 0;
    loop {
        let n753 = to753(i);
        if n753 > n {
            break;
        }
        if to753(i) != 0 {
            ans += 1;
        }
        i += 1;
    }
    println!("{}", ans);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int n;
string s,t;
vector<int> a,b;
vector<int> pa,pb;
int base=5010;

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

  cin>>n>>s>>t;
  int p=(s[0]!=t[0]);
  rep(i,base){
    pa.push_back(-1);
    pb.push_back(-1);
  }
  rep(i,n-1){
    a.push_back(s[i]!=s[i+1]);
    if(s[i]!=s[i+1]){
      pa.push_back(i);
    }
    b.push_back(t[i]!=t[i+1]);
    if(t[i]!=t[i+1]){
      pb.push_back(i);
    }
  }
  rep(i,base){
    pa.push_back(n-1);
    pb.push_back(n-1);
  }
  int m1=pa.size(),m2=pb.size();

  ll res=INF;
  for(int i=0;i<m2;i++){
    if((int)abs(i-base)%2!=p)continue;
    int d=i-base;
    ll sum=0;
    rep(j,m1){
      int k=j+d;
      if(k<0||k>=m2)continue;
      sum+=(ll)abs(pa[j]-pb[k]);
    }
    minch(res,sum);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 512
A,B,C,K=map(int,input().split())
ans=0
if A <= K:
    ans = A
    K=K-A
else:
    ans = K
    print(ans)
    exit()
if B <=K:
    K=K-B
else:
    print(ans)
    exit()
ans = ans - K
print(ans)

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

namespace abc139_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = Convert.ToInt32(input[0]);
            int B = Convert.ToInt32(input[1]);
            int ans = 0;
            int outhole = 1;

            while(outhole < B)
            {
                --outhole;
                outhole += A;
                ++ans;
            }

            Console.WriteLine(ans);
            Console.Read();

        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int main(){
	int n,ans=0,now=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++){
		if(a[i]==now+1){
			now++;
			continue;
		}
		ans++;
	}
	if(ans<n) cout<<ans;
	else cout<<-1;
	return 0;
}

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

int main(){
  int mas[52][52];
  int bw1[52][52],bw2[52][52];
  int H,W,h,w,maxi = -200000000,sum;
  cin >> H >> W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cin >> mas[i][j];
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cin >> bw1[i][j];
  }
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cin >> bw2[i][j];
  }

  for(int i=0;i<H-h+1;i++){
    for(int j=0;j<W-w+1;j++){
      sum = 0;
      for(int k=0;k<h;k++){
	for(int l=0;l<w;l++){
	  if(bw1[i+k][j+l] != bw2[k][l]) goto next;
	  else sum += mas[i+k][j+l];
	}
      }
      maxi = max(maxi,sum);
    next:;
    }
  }
  if(maxi == -200000000) cout << "NA" << endl;
  else cout << maxi << endl;
}
      
      


Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
template <typename Mnd>
struct segment_tree
{
    int sz;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> f;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int _sz, function<Mnd(Mnd, Mnd)> _f, Mnd _e) : f(_f), e(_e)
    {
        sz = 1;
        while (sz < _sz)
            sz <<= 1;
        data.assign(sz * 2, e);
    }
    //参照渡しなので代入とかもできる
    Mnd &operator[](const int &k)
    {
        return data[k + sz];
    }
    //木を構築 O(n)
    void build()
    {
        for (int i = sz - 1; i > 0; i--)
            data[i] = f(data[2 * i], data[2 * i + 1]);
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x)
    {
        data[k += sz] = x;
        while (k >>= 1)
            data[k] = f(data[2 * k], data[2 * k + 1]);
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const
    {
        Mnd l = e, r = e;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
        {
            if (a & 1)
                l = f(l, data[a++]);
            if (b & 1)
                r = f(r, data[--b]);
        }
        return f(l, r);
    }
};
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> r(n + 1, 0), p(n + 1, 0);
    for (size_t i = 0; i < n; i++)
    {
        r[i + 1] = r[i] + a[i];
        p[i + 1] = r[i + 1] - (i + 1) * k; //転倒数(i番目以下でp[i]より小さい要素の数)を求めたい数列
    }
    //座標圧縮,重複要素があることに注意
    vector<ll> b = p;
    map<ll, int> mp;
    sort(all(b));
    for (int i = 0; i < n + 1; i++)
    {
        if (mp.find(b[i]) == mp.end())
            mp[b[i]] = i;
    }
    //セグ木にぶち込む
    ll ans = 0;
    segment_tree<int> seg(n + 10, [](int a, int b) { return a + b; }, 0);
    seg.build();
    for (int i = 0; i < n + 1; i++)
    {
        ans += seg.query(0, mp[p[i]] + 1); //i番目以下でp[i]より小さい要素の数
        seg.update(mp[p[i]], seg[mp[p[i]]] + 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 20992
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    if(S == "ABC"){
        print("ARC");
    }else{
        print("ABC");
    }

    

}

Measured memory_bytes: 3612
import java.util.Scanner;
class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int H,W;
        while(true){
            H=sc.nextInt();
            W=sc.nextInt();
            if(H==0&&W==0)break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                   if(i==0||i==H-1||j==0||j==W-1)
                    System.out.print("#");
                    else System.out.print(".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 35724
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int n;

int Euler_func(int n){
	int ans=n;
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			while(n%i==0) n/=i;
			ans-=ans/i;
		}
	}
	if(n>1) ans-=ans/n;
	return ans;
}

int main(){
	cin>>n;
	cout<<Euler_func(n)<<endl;
}

Measured memory_bytes: 1164
from collections import deque
import sys
input = sys.stdin.buffer.readline

N = int(input())
child = [[] for _ in range(N+1)]
for i in range(2, N+1):
    par = int(input())
    child[par].append(i)

que = deque()
que.append(1)
seq = []
while que:
    v = que.popleft()
    seq.append(v)
    for u in child[v]:
        que.append(u)
seq.reverse()

dp = [0] * (N+1)
for v in seq:
    if child[v]:
        w_child = []
        for u in child[v]:
            w_child.append(dp[u])
        w_child.sort(reverse=True)
        w = [w_child[i] + i + 1 for i in range(len(w_child))]
        dp[v] = max(w)

print(dp[1])


Measured memory_bytes: 60848
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main(){
  int n[4];rep(i,4)cin>>n[i];sort(n,n+4);
  if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }


}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    var (N,M) = readLine()!!.split(" ").map(String::toInt)
    
    var user = (1..N).map{i->
        var (a,b) = readLine()!!.split(" ").map(String::toLong)
        Pair(a,b)
    }.toMutableList()
     var point = (1..M).map{i->
        var (a,b) = readLine()!!.split(" ").map(String::toLong)
        Pair(a,b)
    }.toMutableList()
    
    for(u in user){
        var dis = Math.abs(u.first-point[0].first)+ Math.abs(u.second - point[0].second)
        var min_idx = 0
        for(idx in 1..point.size-1){
            var new_dis = Math.abs(u.first-point[idx].first)+ Math.abs(u.second - point[idx].second)
            if(dis>new_dis) {
                dis = new_dis
                min_idx = idx
            }
        }
        println(min_idx+1)
    }
}


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

int main() {
	string target = "CODEFESTIVAL2016";
	string s;
	
	int ans = 0;
	getline(cin, s);
	for (int i = 0; i < 16; i++) {
		if (s[i] != target[i]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------
int n;

int mod(int a) {  //inlineの有無による実行時間のテスト
    return (a + n) % n;
}

int main() {
    string s;
    cin >> n >> s;

    rep(a, 2) {

        rep(b, 2) {
            bool sheep[n];
            sheep[0] = (a == 0);
            sheep[1] = (b == 0);

            REP(i, 1, n) {
                if ((s[mod(i)] == 'o') == sheep[mod(i)]) sheep[mod(i + 1)] = sheep[mod(i - 1)];
                else sheep[mod(i + 1)] = !sheep[mod(i - 1)];
            }

            bool can = true;

            rep(i, n) {
                if ((sheep[i] == (s[i] == 'o')) != (sheep[mod(i - 1)] == sheep[mod(i + 1)])) {
                    can = false;
                    break;
                }
            }

            if (can) {
                rep(i, n) cout << (sheep[i] ? 'S' : 'W');
                cout << endl;
                return 0;
            }

        }
    }

    cout << -1 << endl;

    return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
};


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	
	VI p(n);
	rep(i, n) cin >>p[i], p[i]--;
	UF ufa(n);
	rep(i, m){
		int x,y; cin >>x >>y;
		ufa.unite(x-1, y-1);
	}

	
	int ans =0;
	rep(i, n){
		if(ufa.same(p[i], i)) ans++;
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace AtCoder.Contest.C
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			long k = cin.NextLong();
			long a = cin.NextLong();
			long b = cin.NextLong();
			long now;
			if (a - 1 >= k) now = k + 1;
			else if (b - a <= 2) now = k + 1;
            else
            {
				now = a;
				now += ((k - (a - 1)) / 2) * (b - a);
				if ((k - (a - 1)) % 2 == 1) now++;
            }
            Console.WriteLine(now);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b >> c >> n;
	A = a - c;
	B = a - b;
	C = b - c;
	if (A < 0) {
		A *= -1;
	}
	if (A <= n) {
		cout << "Yes";
	}
	else {
		if (B < 0) {
			B *= -1;
		}
		if (C < 0) {
			C *= -1;
		}
		if (B <= n && C <= n) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
}

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

int main(){
  string s;
  int x,y;
  cin >> s >> x >> y;

  int i=0;
  for(;i<s.size();i++){
    if(s.at(i)=='T')  break;
  }
  x-=i;

  vector<int> X,Y;
  int now=0;//1=y,0=x
  int count=0;
  for(;i<s.size();i++){
    if(s.at(i)=='T'){
      if(now==1)  Y.push_back(count);
      else  X.push_back(count);
      count=0;
      now^=1;
    }
    else{
      count++;
    }
  }
  if(now==1)  Y.push_back(count);
  else  X.push_back(count);
  //cout << x << "," << y << endl;
  //for(int i=0;i<X.size();i++) cout << X.at(i) << ",";cout << endl;
  //for(int i=0;i<Y.size();i++) cout << Y.at(i) << ",";cout << endl;  

  vector<vector<bool>> dp_X(X.size()+1,vector<bool>(40000,false));
  dp_X.at(0).at(20000)=true;
  for(int i=0;i<X.size();i++){
    for(int j=0;j<40000;j++){
      if(dp_X.at(i).at(j)){
        dp_X.at(i+1).at(j-X.at(i))=true;
        dp_X.at(i+1).at(j+X.at(i))=true;
      }
    }
  }
  vector<vector<bool>> dp_Y(Y.size()+1,vector<bool>(40000,false));
  dp_Y.at(0).at(20000)=true;
  for(int i=0;i<Y.size();i++){
    for(int j=0;j<40000;j++){
      if(dp_Y.at(i).at(j)){
        dp_Y.at(i+1).at(j-Y.at(i))=true;
        dp_Y.at(i+1).at(j+Y.at(i))=true;
      }
    }
  }
  if(dp_X.at(X.size()).at(x+20000) && dp_Y.at(Y.size()).at(y+20000)){
    cout << "Yes" << endl;
  }
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 39424
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
vector<int>v(maxn),adj[maxn];

void solve(){
    // int n;
    // cin >> n;
    // FOR(i,1,n+1)cin >> v[i];
    // FOR(i,1,n){
    //     int u,v;
    //     cin >> u >> v;
    //     adj[u].pb(v);
    //     adj[v].pb(u);
    // }
    int n,m;
    cin >> n >> m;
    vector<int>h(n+5);
    FOR(i,1,n+1){
        cin >> h[i];
    }
    FOR(i,1,m+1){
        int a,b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int ans = 0;
    FOR(i,1,n+1){
        bool fo = 0;
        for(auto &x:adj[i])if(h[x] >= h[i])fo = 1;
            if(!fo)ans++;
    }
    cout << ans;
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n;
    cin >> n;
    printf("%.20lf", 2*n*acos(-1));

    return 0;
}


Measured memory_bytes: 3752
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int ds(int n) {
  int r = 0;
  while (n > 0) {
    r += n % 10;
    n /= 10;
  }
  return r;
}

int main(void) {

  ll n, k, h[200010];
  cin >> n >> k;
  rep(i, n) cin >> h[i];

  sort(h, h + n);

  ll ans = 0;
  rep(i, n - k) {
    ans += h[i];
    h[i] = 0;
  }
  
  cout << ans << endl;
}
  


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair((a),(b))
#define list3(a,b,c) mp((a),mp((b),(c)))
#define list4(a,b,c,d) mp((a),list3((b),(c),(d)))
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int vis[40][40][40];
int n,m;
vector<pair<int,PI > > G[40];

void solve(){
  int s,g;
  cin >> s >> g;
  --s,--g;
  rep(i,n) G[i].clear();
  rep(i,m){
    int x,y,d,c;
    cin >> x >> y >> d >> c;
    --x,--y;
    G[x].pb(mp(y,mp(d,c)));
    G[y].pb(mp(x,mp(d,c)));
  }
  
  priority_queue<pair<double,pair<int,PI > > > q;
  q.push(list4(0.,s,1,s));
  CLR(vis);
  bool fl=true;
  while(!q.empty()){
    double cc=-q.top().F;
    int cv=q.top().S.F;
    int cs=q.top().S.S.F;
    int be=q.top().S.S.S;
    q.pop();

    if(vis[cv][cs][be]) continue;
    //cout << cc << ' ' << cv << ' ' << cs << ' ' << be << endl;
    if(cv==g && cs==1){
      printf("%.8f\n",cc);
      return;
    }    
    vis[cv][cs][be] = true;
    FOR(it,G[cv]){
      if(it->F==be) continue;
      for(int di=-1;di<=1;++di){
	int ns=cs+di;
	if(ns<=0 || ns>it->S.S) continue;
	if(fl && ns!=1) continue;
	q.push(list4(-cc-it->S.F*1./ns,it->F,ns,cv));
      }
    }
    fl=false;
  }
  cout << "unreachable" << endl;
}

int main(){
  while(cin >> n >> m && n) solve();
}

Measured memory_bytes: 20852
N, K = list(map(int, input().split()))
data = [input().split() for _ in range(K*2)]
all_list = list(range(1,N+1))
have = []
for i in range(0,K):

    have.extend(data[1+2*i])

int_have = [int(n) for n in have]
sethave = list(set(int_have))

ans = list(set(all_list) - set(sethave))
print(len(ans))


Measured memory_bytes: 68300
#include <iostream>
using namespace std;
bool check(string);
int main(void){
    // Your code here!
    string str;
    cin >> str;
    if(check(str)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}
bool check(string str){
    for(int i = 0; i < str.length();i+=2){
        if(str[i] == 'L') return false;
    }
    for(int i = 1;i < str.length();i+=2){
        if(str[i] == 'R') return false;
    }
    return true;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, x;
    cin >> n >> x;
    vec a(n);
    rep(i, n) cin >> a[i];

    lint res = 0;

    for (int i = 1; i < n; i++) {
        int tot = a[i] + a[i-1];
        tot -= x;
        if (tot <= 0) continue;
        res += tot;
        if (tot > a[i]) {
            tot -= a[i];
            a[i] = 0;
        }
        else {
            a[i] -= tot;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    int n ;
    cin >> n ;
    string s ;
    cin >> s;
    if(n % 2 == 1) {
        cout << "No" << endl ;
        return 0;
    }
    for(int i = 0;i < n / 2;i++) {
        if(s.at(i) != s.at(n / 2 + i)) {
            cout << "No" << endl ;
            return 0;
        }
    }
    cout << "Yes" << endl ;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int main(){
    string N; cin >> N;
    ll ans = N[0] - '0' + (N.length() -1) * 9;
    FOR(i, 1, N.length()){
        if(N[i] != '9'){
            --ans; break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
  int n, t;
  cin >> n >> t;
  int nin = 1e9;
  for (int i = 0; i < n; i++) {
    int a, tt;
    cin >> a >> tt;
    if (tt <= t) nin = min(nin, a);
  }
  if (nin == 1e9) {
    cout << "TLE" << endl;
  } else {
    cout << nin << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

#include <string.h>
using namespace std;

#define MAXNUM 100000
#define MAXWEIGHT 10000

int n,k;
long long T[MAXNUM];

// P k-tracks,
int check(long long P){
    // cout << "n = " << n << endl;
    int i=0;
    // int value=0;
    long long loadweight = 0;
    for(int j=0; j<k; j++){
        // cout << "j = " << j << "-th track." << endl;
        loadweight = 0;
        while(loadweight + T[i] <= P){
            loadweight += T[i];
            // cout<< "i = " << i << " -th loaded." << endl;
            i++;

            if(i == n){
                // cout << "touched." <<endl; 
                // break;
                return n;
            }
        }
    }
    return i;

}

int solve(){
    long long leftid = 0;
    long long rightid = n*MAXWEIGHT;
    long long midid;

    while (leftid < rightid-1){
        
        // cout << "search between... { " << leftid << " , " << rightid << " }." << endl;

        midid = (leftid+rightid)/2;
        int testvalue = check(midid);
        // cout << "testvalue " << testvalue << endl;
        if(testvalue < n){ leftid = midid; }
        else { rightid = midid; }
    }
    return rightid;
}

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

    
    // cout << "flg1" << endl; 

    int ans = solve();
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll L, R;
    cin >> L >> R;
    if (R - L >= 2019) {
        cout << 0 << endl;
        return 0;
    }
    L %= 2019;
    R %= 2019;
    int ans = 2019;
    for (int i = L; i <= R; i++) {
        for (int j = i + 1; j <= R; j++) {
            ans = min(ans, i * j % 2019);
            if (ans == 0) {
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }


LL N, X;
int main() {
    scanf("%lld%lld", &N, &X);
    LL G = __gcd(N, X);
    N /= G; X /= G;

    printf("%lld\n", (N - 1) * 3 * G);

    return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n) return 0;
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

ll N,K;

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

    Mod mod(1e9+7);
    cin >> N >> K;

    ll m = 1e9+7;

    for (int i = 1;i <= K;i++){
        ll ans = (mod.comb(N-K+1,i)*mod.comb(K-1,i-1))%m;
        cout << ans << endl;
    }

    return 0;

}

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

using namespace std;
int dp[3010][3010];
int main(){
    string s,t;
    cin>>s>>t;
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            
            if(s[i-1]==t[j-1]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                //cout<<"hello";
            }
            dp[i][j]=max(dp[i-1][j],dp[i][j]);
            dp[i][j]=max(dp[i][j-1],dp[i][j]);
        }
    }
    /*
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++)
            cout<<dp[i][j]<<' ';
        cout<<'\n';
    }
    */
    int cur_i=(int)s.size(),cur_j=(int)t.size(),cur=dp[cur_i][cur_j];
    string res="";
    //cout<<res;
    while(cur!=0){
        //cout<<cur_i<<' '<<cur_j<<'\n';
        
        if(dp[cur_i-1][cur_j-1]==dp[cur_i][cur_j-1]&&dp[cur_i-1][cur_j-1]==dp[cur_i-1][cur_j]&&dp[cur_i][cur_j]==cur&&dp[cur_i][cur_j-1]==cur-1)
        {
            res+=t[cur_j-1];
            cur--;
            cur_i--;
            cur_j--;
        }
        else if(dp[cur_i][cur_j-1]==cur)
            cur_j--;
        else
            cur_i--;
    }
    reverse(res.begin(),res.end());
    cout<<res;
}


Measured memory_bytes: 35584
#include <iostream>
using namespace std;
int main(){
	int n;
  	cin >> n;
  	int v[n] ;
  	int c[n] ;
  	for(int i=0; i<n; i++){
    	 cin >> v[i];
    }
  	for(int i=0; i<n; i++){
    	 cin >> c[i];
    }
  	
  	int sum = 0;
  
  	for(int i=0; i<n; i++){
      
    	if(v[i] - c[i] > 0){
         	sum += v[i] - c[i];
        }
    }
  
  	cout << sum << endl;
  
}

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

int main()
{
    int input;
    std::cin >> input;
    for (;; ++input)
    {
        bool check = false;
        int temp = input;
        int a = temp % 10;
        temp /= 10;
        int b = temp % 10;
        temp /= 10;
        int c = temp % 10;
        if (a == b && b == c)
        {
            std::cout << a << b << c << std::endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n = 0, k = 0;
    cin>>n>>k;
    char s[100000+5];
    cin>>s;
    int count=0;
    for (int i=0;i<n-1;i++){
        if(s[i+1]!=s[i]){
            count+=1;
        }
    }
    cout<<(n-1-count+2*k>n-1?n-1:n-1-count+2*k);
}

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

int main() {
    int n;
    cin >> n;
    map<string,int> moji;
    rep(i,n){
        string a;
        cin >> a;
        moji[a] = 1;
    } 
    cout << moji.size() << endl;
    return 0;
}

Measured memory_bytes: 19252
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;

int n,s;
int a[3005],dp[3005];

int quick_power(int x,int y)
{
	int res=1;
	for (;y;y=y>>1,x=(x*x)%mod)
	{
		if (y&1)  res=(res*x)%mod;
	}
	return res;
}

signed main()
{
	cin>>n>>s;
	for (int i=1;i<=n;i++)  cin>>a[i];
	
	dp[0]=quick_power(2,n);
	for (int i=1;i<=n;i++)
	{
		for (int j=s;j>=a[i];j--)  dp[j]=(dp[j]+(dp[j-a[i]]*499122177)%mod)%mod;
	}
	cout<<dp[s]<<endl;
	
	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define fo(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    ll n,i,j,k,t,a[100001];

    cin>>n>>k;

    fo(i,n)
        cin>>a[i];
    sort(a,a+n);

    if(k>a[n-1])
    {
        cout<<"IMPOSSIBLE";
        return 0;
    }

    ll g=a[n-1];
    fo(i,n)
        g=__gcd(g,a[i]);

    if(k%g==0)
        cout<<"POSSIBLE";
    else
        cout<<"IMPOSSIBLE";
    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll pow_mod(ll a, ll n, ll p)
{
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res*a%p;
        a = a*a%p;
        n >>= 1;
    }
    return res;
}

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    const ll MOD = 1e9+7;
    vector<ll> s(n);
    vector<ll> t(m);
    for(i = 0;i < n;++i){
        cin >> s.at(i);
    }
    for(i = 0;i < m;++i){
        cin >> t.at(i);
    }
    vector<vector<ll>> dp(n+1,vector<ll>(m+1,0));
    vector<vector<ll>> sdp(n+1,vector<ll>(m+1,0));
    dp.at(0).at(0) = 1;
    sdp.at(0).at(0) = 1;
    for(i = 0;i <= n;++i){
        for(j = 0;j <= m;++j){
            if(i == 0 && j == 0) continue;
            if(i == 0){
                sdp.at(i).at(j) = sdp.at(i).at(j-1);
                continue;
            }else if(j == 0){
                sdp.at(i).at(j) = sdp.at(i-1).at(j);
                continue;
            }
            if(s.at(i-1) == t.at(j-1)){
                dp.at(i).at(j) = sdp.at(i-1).at(j-1);
            }
            sdp.at(i).at(j) = sdp.at(i).at(j-1) + sdp.at(i-1).at(j) + MOD - sdp.at(i-1).at(j-1) + dp.at(i).at(j);
            sdp.at(i).at(j) %= MOD;
        }
    }
    cout << sdp.at(n).at(m) << endl;
    return 0;
}

Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int NIL=2000000001;
int root=NIL;

struct Node{
    int parent=NIL,sibling=NIL,left=NIL,right=NIL;
};
umap<int,Node> tree;

/*先行順巡回*/
void preParse(int n){
    if(n==NIL){
        return;
    }
    printf(" %d",n);
    preParse(tree[n].left);
    preParse(tree[n].right);
}

/*中間順巡回*/
void inParse(int n){
    if(n==NIL){
        return;
    }
    inParse(tree[n].left);
    printf(" %d",n);
    inParse(tree[n].right);
}

void insert(int x,int z){
    if(root==NIL){
        tree[x];
        root=x;
    }else{
        if(x<z){
            if(tree[z].left==NIL){
                tree[z].left=x;
                tree[x].parent=z;
            }else{
                insert(x,tree[z].left);
            }
        }else{
            if(tree[z].right==NIL){
                tree[z].right=x;
                tree[x].parent=z;
            }else{
                insert(x,tree[z].right);
            }
        }
    }
}

int main(){
    int m;
    in(m);
    string command;
    int x;
    while(m--){
        in(command,x);
        if(command=="insert"){
            insert(x,root);
        }
        if(command=="print"){
            if(root!=NIL){
                inParse(root);putchar('\n');
                preParse(root);putchar('\n');
            }
        }
    }
}


Measured memory_bytes: 30508
//  cd Desktop/Atcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define Rep(i,n) for(i=1;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    int i,n,AC=0,WA=0,TLE=0,RE=0;
    char s[5]={};
    scanf("%d",&n);
    rep(i,n){
        scanf("%s",s);
        switch (s[0]){
        case 'A':AC++;
            break;
        case 'W':WA++;
            break;
        case 'T':TLE++;
            break;
        case 'R':RE++;
            break;
        default:
            break;
        }
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",AC,WA,TLE,RE);
    return 0;
}


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

flag=0
for h in range(1,3501):
  for n in range(h,3501):
    if flag==0:
      val=4*h*n-n*N-h*N
      if val != 0:
        w=N*h*n/val
        if int(w)==w and w > 0:
          print(h,n,int(w))
          flag=1
        
        

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

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        while(true) {
        	int n = sc.nextInt();
        	int m = sc.nextInt();
        	if(n==0 && m==0) break;
        	int [] t = new int[n];
        	int [] h = new int[m];
        	int sumt = 0;
        	int sumh = 0;
        	for(int i=0;i<n;i++) {
        		t[i] = sc.nextInt();
        		sumt += t[i];
        	}
        	for(int i=0;i<m;i++) {
        		h[i] = sc.nextInt();
        		sumh += h[i];
        	}
        	Arrays.sort(t);
        	Arrays.sort(h);
        	/*for(int i=0;i<n;i++) {
        		System.err.println(t[i]);
        	}
        	for(int i=0;i<m;i++) {
        		System.err.println(h[i]);
        	}*/
        	boolean flag = true;
        	int d = sumt - sumh;
        	//System.err.println(d);
        	if(d%2 == 1 || d%2 == -1) {
        		System.out.println("-1");
        		flag = false;
        	}else {
        		loop:for(int i=0;i<n;i++) {
        			for(int j=0;j<m;j++) {
        				if(h[j] == t[i]-(d/2)) {
        					System.out.println(t[i]+" "+h[j]);
        					flag = false;
        					break loop;
        				}
        			}
        		}
        		if(flag) System.out.println("-1");
        	}
        }
    }
}


Measured memory_bytes: 30016
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(long long i=0;i<n;i++)
using namespace std;



int main() {


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

	for (int i = 1; i <= 1250; i++)
	{
		int a = i * 0.08;
		int b = i * 0.1;

		if (a == A && b == B)
		{
			cout << i << endl;
			return 0;

		}
	}

	
	cout << -1 << endl;




	return 0;
}




Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include<numeric>

using namespace std;

int main() {
    int N;
    double x[10],ans=0;
    string u[10];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>x[i]>>u[i];
        if(u[i]=="JPY")ans=ans+x[i];
        else ans=ans+380000.0*x[i];
    } 
    cout<<setprecision(10)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll);  -> a/=b;  result: a = 3
struct ModInt{
	ll val;
	ModInt():val(0ll){}
	ModInt(ll v):val(((v%MOD)+MOD)%MOD){}
	ModInt exp(ll y)const{
		if(!y)return ModInt(1ll);
		ModInt a = exp(y/2ll);
		a *= a;
		if(y&1)a*=(*this);
		return a;
	}
	bool operator==(const ModInt& x)const{return val==x.val;}
	inline bool operator!=(const ModInt& x)const{return !(*this==x);}
	bool operator<(const ModInt& x)const{return val<x.val;}
	bool operator>(const ModInt& x)const{return val>x.val;}
	inline bool operator>=(const ModInt& x)const{return !(*this<x);}
	inline bool operator<=(const ModInt& x)const{return !(*this>x);}
	ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;}
	ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;}
};
istream& operator>>(istream&i,ModInt&x){i>>x.val;return i;}
ostream& operator<<(ostream&o,const ModInt&x){o<<x.val;return o;}
ModInt pow(ModInt a,ll x){
	ModInt res = ModInt(1ll);
	while(x){
		if(x&1)res *= a;
		x >>= 1;
		a = a*a;
	}
	return res;
}
const int SIZE = 200100;
ModInt inv[SIZE+10],fac[SIZE+10],facinv[SIZE+10];
// notice: 0C0 = 1 
ModInt nCr(int n,int r){
	assert(!(n<r));
	assert(!(n<0||r<0));
	return fac[n]*facinv[r]*facinv[n-r];
}
void init(){
	fac[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)fac[i]=fac[i-1]*ModInt(i);
	inv[1]=ModInt(1ll);
	for(int i=2;i<=SIZE;i++)inv[i]=ModInt(0ll)-ModInt(MOD/i)*inv[MOD%i];
	facinv[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)facinv[i]=facinv[i-1]*inv[i];
	return;
}
int N;
string s;
int op[200100];
int main(){
	cin >> N;
	cin >> s;
	init();
	int x = 0;
	int cnt = 0;
	for(int i=0;i<2*N;i++){
		int t = -1;
		if(s[i]=='B')t = 1;
		else t = 0;
		t = (t+x)%2;
		if(t==0){
			op[i] = 0;
			x--;
		}else{
			op[i] = 1;
			x++;
			cnt++;
		}
	}
	if(cnt!=N){
		cout << 0 << endl;
		return 0;
	}
	ModInt ans = ModInt(1ll);
	ll c = 0ll;
	for(int i=2*N-1;i>=0;i--){
		if(op[i]==1){
			if(c<=0ll){
				cout << 0 << endl;
				return 0;
			}
			ans *= ModInt(c);
			c--;
		}else{
			c++;
		}
	}
	cout << ans*fac[N] << endl;
  return 0;
}



Measured memory_bytes: 6020