akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define it pair<int, pair<int, int>>
#define F first
#define S second
#define fori(p, n) for(int i = p; i < n; i++)
#define forj(q, m) for(int j = q; j < m; j++)
#define fork(r, l) for(int k = r; k < l; k++)
#define revi(h) for(int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout<<"DEBUGGING --- "<<x<<endl;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);
signed main(){
    fastio;
    //input_from_file; 
    //output_to_file;
    int n, k; cin>>n>>k;
    vector<int>A(n);
    fori(0, n) cin>>A[i];
    sort(all(A));
    vector<vector<int>>dp(k + 1, vector<int>(2));
    dp[0][1] = 0;
    dp[0][0] = 1;
    fori(1, k + 1){
        dp[i][0] = 1;
        dp[i][1] = 0;
        for(int j = 0; j < n && A[j] <= i; j++){
            dp[i][0] = min(dp[i - A[j]][1], dp[i][0]);
            dp[i][1] = max(dp[i - A[j]][0], dp[i][1]);}
    }
    //fori(0, k + 1) cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    if(dp[k][0] == 0) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 5760
fn main() {
    let a:u32 = read();
    let b:u32 = read();
    let h:u32 = read();
    println!("{}",(a+b)*h/2);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 4352
N = int(input())
S = list(input())
e = w = 0
m = 0
t = 0
for i in range(N):
    if S[i] == "W":
        w += 1
    else:
        e += 1
for i in range(N):
    if t == 1:
        w += 1
        t = 0
    if S[i] == "W":
        w -= 1
    else:
        t = 1
    if m < w:
        m = w
print(N-m-1)



Measured memory_bytes: 5920
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
vector<vector<LL>> dp;
vector<vector<LL>> fl;
vector<LL> aa;

LL f(int l,int r,int v){
	if(fl[l][r]==1)return dp[l][r];
	if(l==r){
		fl[l][r]=1;
		if(v==0){
			dp[l][r]=aa[l];
		}else{
			dp[l][r]=-aa[l];
		}
		return dp[l][r];
	}
	if(v==0){
		dp[l][r]=max(f(l+1,r,v^1)+aa[l],f(l,r-1,v^1)+aa[r]);
	}else{
		dp[l][r]=min(f(l+1,r,v^1)-aa[l],f(l,r-1,v^1)-aa[r]);
	}
	fl[l][r]=1;
	return dp[l][r];
}

int main(){
	int n;
	cin>>n;
	vector<LL> a(n);
	FOR(i,0,n)cin>>a[i];
	aa=a;
	vector<vector<LL>> dp2=vector<vector<LL>>(n+1,vector<LL>(n+1,0));
	vector<vector<LL>> fl2=vector<vector<LL>>(n+1,vector<LL>(n+1,0));
	dp=dp2;
	fl=fl2;
	cout<<f(0,n-1,0);

    return 0;
}


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

dictS={}
dictT={}

passed = True
for i in range((len(S))):
  s = S[i]
  t = T[i]
  if( not s in dictS.keys() ):
    dictS[s]=len(dictS)
  if( not t in dictT.keys() ):
    dictT[t]=len(dictT)

  if(dictS[s] != dictT[t]):
    print("No")
    passed=False
    break
    
if(passed):
  print("Yes")

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String value = sc.next();
		
		int index = 0;
		
		for(int i=0; i<value.length(); i++) {
			if(value.charAt(i)=='2') {
				index++;
			}
		}
		System.out.println(index);
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <iostream>
typedef long long ll;

#include <set>

using namespace std;

ll cnt(ll n, ll c, ll d){
  return n / c + n / d - n / ((c * d) / __gcd(c, d));
}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  const ll ans = b - a + 1 - (cnt(b, c, d) - cnt(a - 1, c, d));
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int N, R;
    cin >> N >> R;
    if (N >= 10)
    {
        cout << R << endl;
    }
    else
    {
        cout << R + 100 * (10 - N) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

char toLowerCase(char c){
  if(isLowerCase(c)){
    return c;
  }else{
    return c+'a'-'A';
  }
}
char toUpperCase(char c){
  if(isLowerCase(c)){
    return c-('a'-'A');
  }else{
    return c;
  }
}
ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b;cin>>a>>b;
  string ans;
  if(a+b==15){
    ans="+";
  }else if(a*b==15){
    ans="*";
  }else{
    ans="x";
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

map<int, bool> a;

bool ok(int m) {
  while(m > 0) {
    if(a[m%10]) {
      return false;
    }
    m /= 10;
  }
  return true;
}

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, k; cin >> n >> k;
  int tmp = 0;
  REP(i, k) {
    cin >> tmp;
    a[tmp] = true;
  }

  FOR(i, n, 100000) {
    if(ok(i)) {
      cout << i << endl;
      break;
    }
  }
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int is_odd(int x)
{
    return x%2;
}


int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(is_odd(i)==1&&is_odd(x)==1)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	if(n < 1000) puts("ABC");
	else puts("ABD");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int N;

int main() {
  cin >> N;
  string S[N];
  rep(i, N) {
    cin >> S[i];
  }

  map<string, int> mp;
  rep(i, N) {
    mp[S[i]]++;
  }
  
  int max_ = 1;
  for (auto p : mp) {
    max_ = max(p.second, max_);
  }

  for (auto p : mp) {
    if (p.second == max_) {
      cout << p.first << endl;
    }
  }
  
  
  /*
  for(auto itr = t.begin(); itr != t.end(); itr++) {
    u[*itr] = 0;
    cout << *itr << endl;
  }
  */
}


Measured memory_bytes: 26752
N,A,B=map(int,input().split())
S=input()
k_a=0
k_b=0
for i in S:
    if k_a+k_b<A+B and i=="a":
        k_a+=1
        print("Yes")
    elif k_a+k_b<A+B and k_b<B and i=="b":
        k_b+=1
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4016
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let mut s = sc.chars();
    let n = s.len();
    let k: usize = sc.read();

    if s[0] != s[n - 1] {
        let ans = calc(&mut s);
        println!("{}", ans * k);
        return;
    }

    let mut s1 = s.clone();
    let ans1 = calc(&mut s1);
    if s1[n - 1] == '.' {
        println!("{}", ans1 * k);
        return;
    }

    let ans_t = ans1 * k + k - 1;

    let mut s2 = s.clone();
    s2[0] = '.';
    let ans2 = calc(&mut s2);
    if s2[n - 1] == '.' {
        let ans = (k + 1) / 2 * ans1 + k / 2 * (ans2 + 1);
        println!("{}", cmp::min(ans, ans_t));
        return;
    }
    // s1: a.xa 1
    // s2: .axa 1
    // a.xa .axa .axa

    let edge = (k - 1) / 2;
    let ans = (k + 1) / 2 * ans1 + k / 2 * (ans2 + 1) + edge;
    let ans_s = ans1 + (ans2 + 1) * (k - 1);
    println!("{}", cmp::min(ans, cmp::min(ans_s, ans_t)));
}

fn calc(s: &mut Vec<char>) -> usize {
    let n = s.len();
    let mut ans = 0;
    for i in 0..(n - 1) {
        if s[i] == s[i + 1] {
            s[i + 1] = '.';
            ans += 1;
        }
    }
    ans
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
# 解説を見た
# UnionFindを使ったの初めて

class UnionFind
  def initialize size
    @parents = []
    size.times do |i|
      @parents[i] = i
    end
    @sizes = [1] * size
  end

  def find a
    a == @parents[a] ? a : find(@parents[a])
  end

  def union a, b
    ra = find a
    rb = find b
    return if ra == rb

    if @sizes[ra] > @sizes[rb]
      @parents[rb] = @parents[ra]
      @sizes[ra] += @sizes[rb]
    else
      @parents[ra] = @parents[rb]
      @sizes[rb] += @sizes[ra]
    end
  end
end

n = gets.to_i
cs = []
n.times { |i| cs << gets.split.map(&:to_i) + [i] }

road = []
cs.sort_by { |x, y, i| x }.each_cons(2) do |(x1, _, i1), (x2, _, i2)|
  road << [x2 - x1, i1, i2]
end
cs.sort_by { |x, y| y }.each_cons(2) do |(_, y1, i1), (_, y2, i2)|
  road << [y2 - y1, i1, i2]
end

uf = UnionFind.new 100001
ans = 0
road.sort.each do |(cost, i1, i2)|
  ra = uf.find i1
  rb = uf.find i2
  if ra != rb
    ans += cost
    uf.union i1, i2
  end
end

puts ans


Measured memory_bytes: 24656
#include<cstring>
#include<algorithm>
#include<cstdio>
#define N 10005
#define INF 0x3f3f3f3f
using namespace std;
long long int d[N];
long long int a[1005];
int v[15];
int s[10005];
int b[1005];
int c[15];
int n;
int m;
int tar;
long long int ans=INF;
int main(){
scanf("%d%d",&n,&m);
//for(int i=1;i<=n;i++){
//l[i][0]=0;
//}
memset(d,0x3f,sizeof(d));
memset(v,0,sizeof(v));
memset(s,0,sizeof(s));

for(int i=1;i<=m;i++){
int x,y;
scanf("%lld%d",&a[i],&y);
int st=0;
for(int j=1;j<=y;j++){
scanf("%d",&c[j]);
v[c[j]]++;
st+=(1<<(c[j]-1));
}
b[i]=st;
}
tar=0;
for(int i=1;i<=n;i++){
tar+=(1<<(i-1));
if(v[i]==0){
printf("-1");
return 0;
}
}
d[0]=0;
for(int i=0;i<=tar;i++){
for(int j=1;j<=m;j++){
if(d[i|b[j]]>d[i]+a[j]){
d[i|b[j]]=d[i]+a[j];
}
}

}
printf("%lld",d[tar]);
}

Measured memory_bytes: 1856
#include<cstdio>

using namespace std;

bool isans(int x){
    int a[5];
    int num = x;
    for(int i = 0; i < 5; i++){
        a[i] = num % 10;
        num /= 10;
    }
    if (a[0] == a[4] && a[1] == a[3]) return true;
    else return false;
    
}

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    int ans = 0;
    for(int i = a; i <= b; i++){
        if (isans(i)) ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
const MOD: u64 = 1000000007;

fn main() {
    let nab = read_vec::<u64>();
    let n = nab[0];
    let a = nab[1];
    let b = nab[2];

    let sum = (exp(2, n) + 2 * MOD - comb(n, a) - comb(n, b) - 1) % MOD;

    println!("{}", sum);
}

fn exp(b: u64, n: u64) -> u64 {
    if n == 0 {
        return 1
    }

    if n % 2 == 0 {
        let tmp = exp(b, n/2);
        tmp * tmp % MOD
    } else {
        b * exp(b, n-1) % MOD
    }
}

fn comb(a: u64, b: u64) -> u64 {
    let b = {
        let tmp = a - b;
        if tmp < b { tmp } else { b }
    };

    let mut ch = 1;
    for i in 0..b {
        ch *= a - i;
        if ch > MOD {
            ch %= MOD;
        }
    }

    let mut mo = 1;
    let mut x = b;
    while x > 0 {
        mo *= x;
        if mo > MOD {
            mo %= MOD;
        }
        x -= 1;
    }

    ch * exp(mo, MOD-2) % MOD
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n = get_int()
    A, B = get_data(n, [int, int])
    sum = 0
    for a, b in sorted(zip(A, B), key=op.itemgetter(1)):
        sum += a
        if sum > b:
            print("No")
            return
    print("Yes")
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


Measured memory_bytes: 123168
using System;
using System.Linq;
class S
{
static void Main()
{
int []a=Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(a);
int y=3;
if(a[0]==a[1]&&a[2]==a[1]){y=1;}
else if(a[0]==a[1]){y=2;}
else if(a[1]==a[2]){y=2;}//:}
Console.WriteLine(y);
}
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);
const ll MOD = (ll)(1e9 + 7);

int n;
int a[MAX_N];

int duplicate;
int duplicate_ind_fst;
int duplicate_ind_snd;

/////////////////////////////////////////////////////////////
class CombinationModulo {
public:
  static const int MAX_N_LIB = (int)(1e5 + 100);
  static const ll MOD_LIB = (ll)(1e9 + 7);

  ll fact[MAX_N_LIB];
  ll inv[MAX_N_LIB];
  ll fact_inv[MAX_N_LIB];

  CombinationModulo(int n) {
    init(n);
  }

  void init(int n) {
    inv[1] = fact[0] = fact_inv[0] = 1;
    for (int i = 2; i <= n; i++) {
      inv[i] = (MOD_LIB - (MOD_LIB / i) * inv[MOD_LIB % i] % MOD_LIB) % MOD_LIB;
    }
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i % MOD_LIB;
    }
    for (int i = 1; i <= n; i++) {
      fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD_LIB;
    }
  }

  ll comb(int n, int r) {
    if (r > n) return 0;
  	return fact[n] * fact_inv[r] % MOD_LIB * fact_inv[n - r] % MOD_LIB;
  }
};
/////////////////////////////////////////////////////////////

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n + 1; ++i) {
    scanf("%d", &(a[i]));
  }

  set<int> visited;

  visited.insert(a[0]);

  for (int i = 1; i < n + 1; ++i) {
    if (visited.find(a[i]) != visited.end()) {
      duplicate = a[i];
      duplicate_ind_snd = i;
      break;
    }
    visited.insert(a[i]);
  }

  for (int i = 0; i < n + 1; ++i) {
    if (a[i] == duplicate) {
      duplicate_ind_fst = i;
      break;
    }
  }

  CombinationModulo comb_mod(n + 5);

  int available = (n + 1 - duplicate_ind_snd) + (duplicate_ind_fst + 1) - 1;

  for (int i = 1; i <= n + 1; ++i) {
    if (i == 1) {
      printf("%lld\n", n);
    }
    else {
      ll whole = comb_mod.comb(n + 1, i);

      if (i <= available) { // duplicate case
        ll minus = comb_mod.comb(available - 1, i - 1);

        whole -= minus;
        whole %= MOD;
        if (whole < 0) whole += MOD;
      }

      printf("%lld\n", whole);
    }
  }

  return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
constexpr lint mod=1'000'000'007;
lint inverse(lint a){
    lint m=mod;
    lint u=0,v=1;
    while(a!=0){
        lint t=m/a;
        m-=t*a;std::swap(a,m);
        u-=t*v;std::swap(u,v);
    }
    assert(m==1);
    if(u<0)u+=mod;
    return u;
}
void mul_assign(lint&x,lint y){x=x*y%mod;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<std::vector<lint>>g(n);
    for(lint i=0;i<n-1;i++){
        lint u,v;std::cin>>u>>v;u--,v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }
    std::vector<lint>p(n,-1),ord;
    std::queue<lint>que;
    que.push(0);
    p.at(0)=0;
    while(!que.empty()){
        lint x=que.front();que.pop();
        ord.push_back(x);
        auto&&v=g.at(x);
        for(lint y:v){
            if(p.at(y)!=-1)continue;
            p.at(y)=x;
            que.push(y);
        }
        if(x)v.erase(std::find(v.begin(),v.end(),p.at(x)));
    }
    auto rord=std::vector<lint>(ord.rbegin(),ord.rend());
    std::vector<lint>sz(n,1);
    for(lint x:rord){
        for(lint y:g.at(x))sz.at(x)+=sz.at(y);
    }
    std::vector<lint>fact(n+1,1);
    for(lint i=1;i<=n;i++)fact.at(i)=fact.at(i-1)*i%mod;
    std::vector<lint>dp(n),ep(n,1);
    for(lint x:rord){
        dp.at(x)=fact.at(sz.at(x)-1);
        for(lint y:g.at(x)){
            mul_assign(dp.at(x),dp.at(y));
            mul_assign(dp.at(x),inverse(fact.at(sz.at(y))));
        }
    }
    for(lint x:ord){
        for(lint y:g.at(x)){
            lint&e=ep.at(y);
            e=dp.at(x);
            mul_assign(e,ep.at(x));
            mul_assign(e,inverse(dp.at(y)));
            mul_assign(e,fact.at(n-sz.at(y)-1));
            mul_assign(e,inverse(fact.at(sz.at(x)-1)));
            mul_assign(e,fact.at(sz.at(y)));
            mul_assign(e,inverse(fact.at(n-sz.at(x))));
        }
    }
    for(lint i=0;i<n;i++){
        lint x=dp.at(i)*ep.at(i)%mod;
        mul_assign(x,fact.at(n-1));
        mul_assign(x,inverse(fact.at(sz.at(i)-1)));
        mul_assign(x,inverse(fact.at(n-sz.at(i))));
        std::cout<<x<<'\n';
    }
}


Measured memory_bytes: 27504
using System;

class Program
{
    static void Main()
    {

		while(true)
		{
		string[] input = Console.ReadLine().Split(' ');

		int x = int.Parse(input[0]);
		int y = int.Parse(input[1]);

		if ( x > y)
		{
		int tmp = x;
		x = y;
		y = tmp;
		}

		if (x == 0 && y == 0) break;
		Console.WriteLine("{0} {1}" ,x ,y);
		}
	}
}


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


using namespace std;


int main(void)
{
    vector<int> arr;
    int N;

    cin >> N;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        arr.push_back(tmp);
    }

    sort(arr.begin(), arr.end());
    double ans = 0;
    for (auto it = arr.begin(); it != arr.end(); ++it) {
        if (it == arr.begin()) {
            ans = (double)*it;
            continue;
        }

        ans = (ans + *it) / 2.;
    }

    cout << ans << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

bool used[2510][2510];
int roomL[51][51], roomR[51][51];

inline int s_to_i(char c) {
  switch (c) {
  case '#':
    return -1;
  case '.':
    return 0;
  case 'L':
  case 'R':
    return 1;
  case '%':
    return 2;
  }
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int R, C;
    cin >> C >> R;
    if (R == 0 && C == 0) break;
    int sl = 0, sr = 0;
    REP(i, R) {
      string rowL, rowR;
      cin >> rowL >> rowR;
      REP(j, C) {
	roomL[i][j] = s_to_i(rowL[j]);
	if (roomL[i][j] == 1) sl = i * C + j;
	roomR[i][j] = s_to_i(rowR[j]);
	if (roomR[i][j] == 1) sr = i * C + j;
      }
    }	  

    //cout << slr << ' ' << slc << ' ' << elr << ' ' << elc << ' ' << srr << ' ' << src << ' ' << err << ' ' << erc << endl;
    REP(i, R*C) REP(j, R*C) used[i][j] = false;
    
    queue<P> que;
    que.push(P(sl, sr));

    bool flag = false;
    while (!que.empty()) {
      P p = que.front(); que.pop();
      int l = p.first, r = p.second, lr = p.first / C, lc = p.first % C, rr = p.second / C, rc = p.second % C;
      //cout << lr << ' ' << lc << ' ' << rr << ' ' << rc << endl;
      if (roomL[lr][lc] == 2 && roomR[rr][rc] == 2) {
	flag = true;
	break;
      } else if (used[l][r] || roomL[lr][lc] == 2 || roomR[rr][rc] == 2) {
	continue;
      }

      used[l][r] = true;
      REP(i, 4) {
	int nlr = lr + dr[i], nlc = lc + dc[i], nrr = rr + dr[(i+2*(i&1))%4], nrc = rc + dc[(i+2*(i&1))%4];
	if (nlr < 0 || nlr >= R || nlc < 0 || nlc >= C || roomL[nlr][nlc] == -1) nlr = lr, nlc = lc;
	if (nrr < 0 || nrr >= R || nrc < 0 || nrc >= C || roomR[nrr][nrc] == -1) nrr = rr, nrc = rc;
	if (!used[nlr * C + nlc][nrr * C + nrc]) que.push(P(nlr * C + nlc, nrr * C + nrc));
      }
    }
    cout << (flag ? "Yes" : "No") << endl;    
  }
  return 0;
}

Measured memory_bytes: 9960
function Main(input) {
    var N = parseInt(input[0], 10);
    var TXY = input.slice(1).map(txy => {
        var list = txy.split(/\s/)
        return {
            t: list[0],
            x: list[1],
            y: list[2]
        };
    });

    var time = 0;
    var isTimeEven = false;
    var dist = 0;

    for (var i = 0; i < N; i++) {
        if (i === 0) {
            time = TXY[i].t;
            isTimeEven = time % 2 === 0;
            dist = Math.abs(TXY[i].x) + Math.abs(TXY[i].y);
            if (dist > time) {
                return console.log('No');
            } else {
                if (isTimeEven) {
                    if (dist % 2 !== 0) {
                        return console.log('No');
                    }
                } else {
                    if (dist % 2 !== 1) {
                        return console.log('No');
                    }
                }
            }
        } else {
            time = TXY[i].t - TXY[i - 1].t;
            isTimeEven = time % 2 === 0;
            dist = Math.abs(TXY[i].x - TXY[i - 1].x) + Math.abs(TXY[i].y - TXY[i -1].y);
            if (dist > time) {
                return console.log('No');
            } else {
                if (isTimeEven) {
                    if (dist % 2 !== 0) {
                        return console.log('No');
                    }
                } else {
                    if (dist % 2 !== 1) {
                        return console.log('No');
                    }
                }
            }
        }
    }

    console.log('Yes');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

Measured memory_bytes: 53044
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll x, y;
    cin >> x >> y;
 
    ll i;  
    for (i=0; x<=y; ++i)
        x *= 2;

    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
// URL: https://atcoder.jp/contests/abc132/tasks/abc132_b

import std.algorithm, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  int n; io.getV(n);
  int[] p; io.getA(n, p);

  int r = 0;
  foreach (i; 0..n-2)
    if (p[i] < p[i+1] && p[i+1] < p[i+2] || p[i] > p[i+1] && p[i+1] > p[i+2])
      ++r;

  io.put(r);
}

auto io = IO();

struct IO
{
  import std.algorithm, std.conv, std.format, std.range, std.stdio, std.traits;

  dchar[] buf;
  auto sp = (new dchar[](0)).splitter;
  int precision = 10;
  string delimiter = " ";

  void nextLine()
  {
    stdin.readln(buf);
    sp = buf.splitter;
  }

  auto get(T)(ref T v)
  {
    if (sp.empty) nextLine();
    v = sp.front.to!T;
    sp.popFront();
  }

  auto getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }

  auto getA(T)(size_t n, ref T v)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }

  auto getC(T...)(size_t n, ref T v)
  {
    foreach (ref w; v)
      w = new typeof(w)(n);
    foreach (i; 0..n)
      foreach (ref w; v) get(w[i]);
  }

  auto getM(T)(size_t r, size_t c, T v)
  {
    v = new T(r, c);
    foreach (ref w; v) getA(c, w);
  }

  auto putA(T)(T v)
  {
    static if (isInputRange!T && hasLength!T && !isSomeString!T) {
      foreach (i, w; v) {
	putA(w);
	if (i < v.length - 1) write(delimiter);
      }
    } else if (isFloatingPoint!T) {
      writef(format("%%.%df", precision), v);
    } else {
      write(v);
    }
  }

  auto put(T...)(T v)
  {
    foreach (i, w; v) {
      putA(w);
      if (i < v.length - 1) write(delimiter);
    }
    writeln;
  }

  auto putB(S, T)(bool c, S t, T f)
  {
    if (c)
      put(t);
    else
      put(f);
  }

  auto dbg(T...)(T v)
  {
    stderr.writeln(v);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    while(true){
        string s;
        cin >> s;
        if (s == "0") break;

        ll ans = 0;
        rep(i,s.size()){
            ans += s[i] - '0';
        }
        cout << ans << endl;
        
    }
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
using namespace std;
const int MAX_N = 100002;
int par[MAX_N];//親
int pank[MAX_N];//木の深さ

//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        pank[i]=0;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(pank[x]<pank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(pank[x]==pank[y])pank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}

int main(void){
    int n,m;cin>>n>>m;
    init(n);
    map<int,int> mp;
    rep(i,n){
        int x;cin>>x;x--;
        mp[i]=x;
    }
    rep(i,m){
        int a,b;cin>>a>>b;a--;b--;
        unite(a,b);
    }
    vector<bool> sol(n,false);
    int res=0;
    rep(i,n){
        int x=i,y=mp[i];
        if(same(x,y)){
            if(!sol[x]){
                sol[x]=true;
                res++;
                //cout<<1<<endl;
            }
        }
    }
    cout<<res<<endl;
}

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

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
		
	int n; cin >> n;
	string s; cin >> s;

	// RRRRRRRRWWWWWWWWW
	int i = 0, j = n-1, ans = 0;
	while (1) {
		while (i < n && s[i] == 'R') i++;
		while (j >= 0 && s[j] == 'W') j--;

		if (i > j) break;
		swap(s[i], s[j]); ans++;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define ll long long



int main()
{
    string a,b;ll x=0;
    cin>>a;
    cin>>b;
    if(a.size()>b.size())cout<<"GREATER";
    else if(a.size()<b.size())cout<<"LESS";
    else{
        for(int i=0;i<a.size();i++){
            if(a[i]>b[i]){
                cout<<"GREATER";x=2;break;
            }
            else if(a[i]<b[i]){
                cout<<"LESS";x=2;break;
            }
        }
        if(x!=2)cout<<"EQUAL";
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int Q = sc.nextInt();

		StringBuffer sbNormal = new StringBuffer(S);
		StringBuffer sbReverse = new StringBuffer();
		boolean reverse = false;

		for (int i=0; i<Q; i++){
			int T = sc.nextInt();
			if (T == 1){
				reverse = !reverse;
			} else {
				int F = sc.nextInt();
				char C = sc.next().charAt(0);
				if ((F == 1 && !reverse) || (F == 2 && reverse)) {
					sbReverse.append(C);
				} else {
					sbNormal.append(C);
				}
			}
		}
		if (reverse) {
			System.out.println(sbNormal.reverse().append(sbReverse).toString()
					);
		} else {
			System.out.println(sbReverse.reverse().append(sbNormal).toString());
		}

	}
}

Measured memory_bytes: 121796
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
#define TAU (2.0*PI)
#define N 7500000

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,i,j,cnt[123],t;
	double x[123],y[123],cs,sn,mx;
	fill(cnt,cnt+123,0);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x[i] >> y[i];
	}
	for(i=0; i<N; ++i){
		cs = cos(TAU*i/N);
		sn = sin(TAU*i/N);
		mx = -INFLL;
		for(j=0; j<n; ++j){
			if(mx < (cs*x[j]+sn*y[j])){
				t = j;
				mx = (cs*x[j]+sn*y[j]);
			}
		}
		++cnt[t];
	}
	for(i=0; i<n; ++i){
		printf("%.10lf\n",((double)(cnt[i])/N));
	}
	return 0;
}



Measured memory_bytes: 768
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

const int maxn=5e5+5;

int n,m;
ll f[maxn];
int pos[maxn],d[maxn];

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

int main() {
	n=read(),pos[0]=read();
	for(int i=1;i<=n;i++) {
		d[i]=read();
		pos[i]=min(pos[i-1],abs(pos[i-1]-d[i]));
	}
	f[n+1]=1;
	for(int i=n;i;i--) {
		f[i]=f[i+1];
		if(d[i]<f[i]*2)f[i]+=d[i];
	}
	m=read();
	for(int i=1;i<=m;i++) {
		int id=read();
		if(pos[id-1]>=f[id+1])puts("YES");
		else puts("NO");
	}
	return 0;
}


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

int main (){
  
  int a,b;
  cin >> a >> b;
  int A =( a + b )%2;
  if (A == 1){
    cout << (a + b)/2+1 << endl;
  }
  else {
    cout << (a + b)/2 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int w,h,n;
	cin>>w>>h>>n;
	int lx=0,rx=w,ly=0,ry=h;
	for(int i=0;i<n;i++){
		int x,y,a;
		cin>>x>>y>>a;
		if(a == 1){
			lx = max(x,lx);
		}
		if(a == 2){
			rx = min(x,rx);
		}
		if(a == 3){
			ly = max(y,ly);
		}
		if(a == 4){
			ry = min(y,ry);
		}
	}
	if(rx < lx || ry < ly){
		cout<<0<<endl;
		return;
	}
	// cout<<lx<<" "<<rx<<" "<<ly<<" "<<ry<<endl;;
	int ans = (rx-lx)*(ry-ly);
	cout<<ans<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
n=[int(x) for x in input()]
k=len(n)-1#間に入れるから-1
ans=0
for i in range(2**k):#+ or - の2択
    op=[""]*k
    for j in range(k):
        if (i>>j)&1:
            op[k-j-1]="+"
    formula=""
    for p_y,p_n in zip(n,op+[""]):
        formula+=(str(p_y)+p_n)
    ans+=eval(formula)
print(ans)

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



int main() {
  int n, count = 0;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  for(int i = 0; i < n; i++) {
    cin >> A[i];
    cin >> B[i];
    if(A[i] == B[i]){
      count++;
      if(count == 3) break;
    }else{
      count = 0;
    }
  }
  if(count == 3){
    puts("Yes"); 
  }else{
    puts("No");
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
    ll N,M; cin >> N >> M;
    if (abs(M-N) >= 2){
        cout << 0 << endl;
        return 0;
    }
    init();
    if (abs(N-M) == 1){
        cout << fac[N]*fac[M]%MOD << endl;
        return 0;
    }
    cout << (fac[N]*fac[M]*2)%MOD << endl;
}

Measured memory_bytes: 12032
package main

import "fmt"

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}
func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if abs(a-c) <= d {
		fmt.Println("Yes")
		return
	}
	if abs(a-b) <= d && abs(b-c) <= d {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    array<int, 3> C = {};
    if (A[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    const int64_t p = 1e9 + 7;
    int64_t ans = 1;
    for (int i = 0; i < n; i++){
        int cnt = 0;
        bool flag = false;
        for (auto &c: C){
            if (A[i] == c){
                cnt++;
                if (!flag){
                    flag = true;
                    c++;
                }
            }
        }

        ans *= cnt;
        ans %= p;
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			char c[]=in.next().toCharArray();
			if(c[0]=='0')
				return;
			int sa=0;
			int sb=0;
			for(int i=1;i<c.length;i++)
			{
				if(c[i]=='A')
					sa++;
				else 
					sb++;
				if(i==c.length-1)
				{
					if((sa+1-sb)>=2)
						sa++;
					else if(sb+1-sa>=2)
						sb++;
					else if((sa+1)==11)
						sa++;
					else if((sb+1)==11)
						sb++;
				}
			}
			System.out.println(sa+" "+sb);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<algorithm>
using namespace std;
struct data {
	long long int x, y, z;
	inline bool operator<(const data& temp)const {
		return x < temp.x || (x == temp.x && y < temp.y) || (x == temp.x && y == temp.y && z < temp.z);
	}
}b[300000];
long long int n, m, k;
long long int find(long long int x) {
	if (x >= 0) return x % k;
	long long int y = (-x) / k+10;
	x += y * k;
	return x % k;
}
int main() {
	long long int s,e,i;
	scanf("%lld %lld %lld", &n, &m, &k);
	if (k < 0) {
		m = m + k * (n - 1);
		k = k *= -1;
	}
	if (k == 0) {
		if (m == 0) printf("1"); else printf("%lld", n + 1);
		return 0;
	}
	s = n * m + (n - 1) * n / 2 * k;
	e = n * m + (n - 1) * n / 2 * k;
	long long int cnt = 1;
	b[cnt].x = find(s);
	b[cnt].y = (s - find(s)) / k;
	b[cnt].z = (e - find(s)) / k;
	for (i = 1; i <= n; i++) {
		s -= m + (i - 1) * k;
		e -= m + (n - i) * k;
		cnt++;
		b[cnt].x = find(s);
		b[cnt].z = (s - find(s)) / k;
		b[cnt].y = (e - find(s)) / k;
	}
	long long int ccnt = cnt;
	sort(b + 1, b + cnt + 1);
	cnt = 0;
	s = b[1].y, e = b[1].z;
	cnt = e - s + 1;
	for (i = 2; i <= ccnt; i++) {
		if (b[i].x != b[i - 1].x) {
			s = b[i].y, e = b[i].z;
			cnt += e - s + 1;
			continue;
		}
		if (b[i].z <= e) continue;
		if (b[i].y > e) {
			s = b[i].y, e = b[i].z;
			cnt += e - s + 1;
			continue;
		}
		cnt += (b[i].z - e);
		e = b[i].z;
	}
	printf("%lld", cnt);
	return 0;
}

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

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

int main() {
  int N; cin >> N;
  unordered_map<int, int> p;
  for(int i = 0; i < N; i++) {
    int a; cin >> a;
    if(p.count(a) > 0) {
      p.at(a)++;
    } else {
      p.emplace(a, 1);
    }
  }

  int M; cin >> M;
  if(M > N) {
    cout << "NO"<< endl;
    return 0;
  }

  for(int i = 0; i < M; i++) {
    int a; cin >> a;
    if(p.count(a) == 0) {
      cout << "NO"<< endl;
      return 0;
    } else {
      p.at(a)--;
      if(p.at(a) < 0) {
        cout << "NO"<< endl;
        return 0;
      }
    }
  }


  cout << "YES" << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> sw(m, vector<int>(n));
  rep(i, m) {
    int k;
    cin >> k;

    rep(j, k) {
      int s;
      cin >> s;
      sw[i][--s] = 1;
    }
  }

  vector<int> p(m);
  rep(i, m) cin >> p[i];

  int ans = 0;

  rep(i, 1 << n) {
    vector<int> cnt(m);
    bool ok = true;
    rep(j, m) {
      int on = 0;
      rep(k, n) {
        if ((i >> k & 1) && sw[j][k]) {
          on++;
        }
      }
      if (on % 2 != p[j]) {
        ok = false;
      }
    }
    if (ok) ans++;
  }

  cout << ans << endl;
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		String x = "";
		try {
			x = in.readLine();
			int n = Integer.parseInt(x);

			String[] xs = in.readLine().split(" ");
			String[] ys = in.readLine().split(" ");

			int[] px = new int[xs.length];
			int[] py = new int[ys.length];
			for (int i = 0; i < px.length; i++) {
				px[i] = Integer.parseInt(xs[i]);
				py[i] = Integer.parseInt(ys[i]);
			}

			double ans = 0.0;
			for (int i = 0; i < px.length; i++) {
				ans = ans + Math.abs(px[i] - py[i]);
			}
			System.out.println(ans);

			ans = 0.0;
			for (int i = 0; i < px.length; i++) {
				ans = ans + (px[i] - py[i]) * (px[i] - py[i]);
			}
			System.out.println(Math.sqrt(ans));

			ans = 0.0;
			for (int i = 0; i < px.length; i++) {
				ans = ans + Math.abs((px[i] - py[i]) * (px[i] - py[i]) * (px[i] - py[i]));
			}
			System.out.println(Math.cbrt(ans));

			ans = 0.0;
			for (int i = 0; i < px.length; i++) {
				double d = Math.abs(px[i] - py[i]);
				if (ans < d) ans = d;
			}
			System.out.println(ans);
			
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 24392
#include <stdio.h>

int main(void)
{
	int i;
	char s1[15],s2[15],s3[15];
	scanf("%s %s %s",s1,s2,s3);
	
	s1[0]=s1[0]-32;
	s2[0]=s2[0]-32;
	s3[0]=s3[0]-32;
	
	printf("%c%c%c\n",s1[0],s2[0],s3[0]);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi d(n);
	rep(i, n) cin >> d[i];
	sort(all(d));
	cout << d[n / 2] - d[n / 2 - 1] << endl;	
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 640
#include<stdio.h>

int gcd(int a,int b){
  if(a==b) return a;
  else if(a>b) return gcd(a-b,b);
  else return gcd(a,b-a);
  return 0;
}

int main(void){
  int x,y;
  scanf("%d %d",&x,&y);
  printf("%d\n",gcd(x,y));
  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int min, cnt=0;
	for(int i=0; i<n; i++)
	{
		int a;
		cin>>a;
		if(i==0) min=a, cnt++;
		else if(a>min) continue;
		else if(a<min) cnt++, min=a;
		if(a==1) break;
	}
	cout<<cnt;
}

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

int main() {
	int q;
	cin >> q;
	set<int> S;
	for (int i = 0; i < q; ++i) {
		int query;
		cin >> query;
		if (query == 0) {
			int x;
			cin >> x;
			S.insert(x);
			cout << S.size() << endl;
		}
		else if (query == 1) {
			int x;
			cin >> x;
			cout << S.count(x) << endl;
		}
		else if (query == 2) {
			int x;
			cin >> x;
			S.erase(x);
		}
		else {
			int L, R;
			cin >> L >> R;
			for (auto i = S.lower_bound(L); i != S.upper_bound(R); ++i) cout << *i << endl;
		}
	}
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) {
    if (s.substr(i) == t.substr(0, n - i)) {
      cout << n + i << '\n';
      return 0;
    }
  }
  cout << n * 2 << '\n';
  return 0;
}

Measured memory_bytes: 256