akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length();
    int num=0,ans=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A' ||s[i]=='C' ||s[i]=='G'||s[i]=='T'){
            num++;
        }
        else{
            ans=max(ans,num);
            num=0;
        }
    }
    ans=max(ans,num);
    cout << ans<<endl;

    return 0;
}





Measured memory_bytes: 256
def solve_el(from, to, max, set)
  return true if from == to
  return false if from < to

  set.each do |i|
    next if i > from
    return true if solve_el(from % i, to, max, set)
  end

  max.downto(1).each do |i|
    next if i > from
    return true if solve_el(from % i, to, max, set)
  end

  return false
end

def solve_part(from, to, max, set)
  from.length.times do |i|
    return false if !solve_el(from[i], to[i], max, set)
  end
end

length = gets.chomp.to_i
from = gets.split.map(&:to_i)
to = gets.split.map(&:to_i)

if solve_part(from, to, 50, [])
  res = []

  50.downto(1) do |i|
    if !solve_part(from, to, i - 1, res)
      res.push(i)
    end
  end

  puts res.map{|i|2**i}.reduce(&:+) || 0
else
  puts -1
end


Measured memory_bytes: 1916
#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;

  vector<ll> a(n);

  priority_queue<ll, vector<ll>, less<ll>> que;

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

  sort(a.rbegin(), a.rend());

  ll ans = 0;

  for (int i = 0; i < n; i++) {
    if (i == 0) {
      que.push(a[i]);
    } else {
      que.push(a[i]);
      que.push(a[i]);
    }
  }

  for (int i = 0; i < n - 1; i++) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 9020
#include <cstdio>
using namespace std;

const int MAXN = 105;

int N, M, K;
int sol[MAXN][MAXN];

int main() {
	scanf("%d%d%d", &N, &M, &K);
	int x = 0, y = 0;
	for (int i = 1; i <= K; i++) {
		int cnt;
		scanf("%d", &cnt);
		while (cnt--) {
			sol[x][y] = i;
			if (x % 2) {
				if (y)
					y--;
				else
					x++;
			}
			else {
				if (y < M - 1)
					y++;
				else
					x++;
			}
		}
	}
	
	for (int i = 0; i < N; i++, puts(""))
		for (int j = 0; j < M; j++)
			printf("%d ", sol[i][j]);
			
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(void){
    string s;
    int ans = 0;
    cin >> s;
    for (int i = 0; i < 6; i++) if (s[i] == '1') ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    bool flag=false;
    while(a>0)
    {
        int temp=a%10;
        if(temp==7)
        {
            flag=true;
        }
        a=a/10;
    }
    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ab = sc.nextInt();
    
    int x = sc.nextInt();
    int y = sc.nextInt();
    
    int min = (x < y ? x : y);
    int sub = Math.abs(x - y);
    
    int buyA = 0;
    int buyB = 0;
    int buyAB = 0;
    
    
    if(a + b > ab * 2){
      buyAB += min * 2;
      x -= min;
      y -= min;
    }
    
    if(a > ab * 2){
      buyAB += x * 2;
    }else{
      buyA += x;
    }
    
    if(b > ab * 2){
      buyAB += y * 2;
    }else{
      buyB += y;
    }
    
    System.out.println(buyA * a + buyB * b + buyAB * ab);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int max(int a, int b)
{
  if(a<b){
    return b;
  } else {
    return a;
  }
}

int main()
{
  int p,q,r,tmp;
  cin >> p >> q >> r;
  tmp = max(p,q);
  tmp = max(tmp,r);
  tmp = p + q + r -tmp;
  cout << tmp << endl;
  return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
const int MAX=1000000;
int fact[MAX],inv[MAX];
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}

int C(int n,int k){
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}

int pow3[MAX];
signed main(){
    fact[0]=1;
    for(int i=1;i<MAX;i++)fact[i]=fact[i-1]*i%mod;
    inv[MAX-1]=mpow(fact[MAX-1],mod-2);
    for(int i=MAX-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    pow3[0]=1;
    for(int i=1;i<MAX;i++)pow3[i]=pow3[i-1]*3%mod;

    int N,M,K;
    cin>>N>>M>>K;
    int ans=0;

    int curL=0,curR=1;

    for(int i=0;i<=M+K;i++){
        ans=(ans+(curR-curL+mod)*C(N-1+i,i)%mod*pow3[M+K-i])%mod;
        curL=curL*2%mod;
        curR=curR*2%mod;
        if(i>=M)curR=(curR-C(i,M)+mod)%mod;
        if(i>=K)curL=(curL+C(i,i-K))%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 23680
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int main() {
	std::string s,t;
	std::cin>>s>>t;
	int cnt=0;
	rep(i,s.size()){
		if(s[i]!=t[i])cnt++;
	}
	std::cout<<cnt<<std::endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#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)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int N; cin >> N;
    VL A(N); REP(i,N) cin >> A[i];
    VL S(N+1,0); REP(i,N) S[i+1] = (S[i]+A[i])%MOD;

    ll ans = 0;
    REP(i,N-1){
        (ans += A[i+1]*S[i+1]) %= MOD;
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 6364
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int ret = k;
  while(n-- > 1) {
    ret *= k-1;
  }
  printf("%d\n", ret);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<pair<ll, ll>> xy(n);
    rep(i, n) cin >> xy[i].first >> xy[i].second;
    sort(all(xy));
    double sum = 0;
    do {
        rep(i, n - 1) {
            ll dx = (xy[i].first - xy[i + 1].first);
            ll dy = (xy[i].second - xy[i + 1].second);
            sum += sqrt(dx * dx + dy * dy);
        }
    }
    while(next_permutation(all(xy)));
    ll p = 1;
    reps(i, 1, n + 1) p *= i;
    printf("%.10f\n", sum / p);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
h,w,k = map(int, input().split())
k -= 1
mod = 1000000007

if w==1:
    print(1)
    exit()

dp = [[0 for _ in range(w)] for _ in range(h+1)]
dp[0][0] = 1

for hi in range(1,h+1):
    for b in range(2**(w-1)):
        judge = False
        for i in range(w-2):
            if (b>>i)&3 == 3:
                judge = True
                break
        if judge:
            continue

        perm = [i for i in range(w)]
        for i in range(w-1):
            if (b>>i)&1==1:
                perm[i],perm[i+1] = perm[i+1],perm[i]
        for i in range(w):
            dp[hi][perm[i]]  = (dp[hi][perm[i]]+dp[hi-1][i])%mod

print(dp[h][k])


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
			b[i] = stdIn.nextInt();
			c[i] = stdIn.nextInt();
		}
			
			long[][]dp = new long[n+1][3];
			
			
			//DPするぞ
			
			for(int i = 0; i < n; i++) {
				
				for(int j = 0; j < 3; j++) {
					
					if(j == 0) { //Aの選択肢
						
						dp[i+1][j+1] = dp[i][j] + b[i];
								
						dp[i+1][j+2] = dp[i][j] + c[i];
						
						
					}else if(j == 1) { //Bの選択肢
						
						dp[i+1][j-1] = Math.max(dp[i+1][j-1],dp[i][j]+a[i] );
						dp[i+1][j+1] = Math.max(dp[i+1][j+1],dp[i][j]+c[i] );
						
						
						
						
					}else { //Cの選択肢
						dp[i+1][j-2] = Math.max(dp[i+1][j-2],dp[i][j]+a[i] );
						
						dp[i+1][j-1] = Math.max(dp[i+1][j-1],dp[i][j]+b[i] );
						
						
					}
					
					
				}
				
			}
			
		long max = 0;
		
		for(int i = 0; i < 3; i++) {
			if(max < dp[n][i]) {
				max = dp[n][i];
			}
		}
		
		System.out.println(max);
		
		
		
	}

}


Measured memory_bytes: 93720
#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    io
    string s;
    long i,n,mp[26]={0},w=0,ss=0;
    cin>>s;
    n=s.length();
    for(i=0;i<n;++i)
    mp[s[i]-'a']++;
    for(i=0;i<26;++i)
    {
        w+=mp[i];
        ss+=mp[i]*mp[i];
    }
    cout<<(w*w-ss)/2+1  ;
    return 0;
}


Measured memory_bytes: 720
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()

dp = [99999999] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
    dp[i] = dp[i - 1] + 1
    k = 6
    while i - k >= 0:
        dp[i] = min(dp[i], dp[i - k] + 1)
        k *= 6
    k = 9
    while i - k >= 0:
        dp[i] = min(dp[i], dp[i - k] + 1)
        k *= 9
print(dp[n])

Measured memory_bytes: 3828
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<v)v=rest[i];return v}
function max(){var rest=arguments,v=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>v)v=rest[i];return v}
function gcd(){var rest=arguments,v=rest[0],temp=(a,b)=>b?temp(b,a%b):a;for(var i=1;i<rest.length;i++)v=temp(v,rest[i]);return v}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var nm = toIntArr(input[0].split(' '));
	var n = nm[0];
	var m = nm[1];
	var s = input[1];
	var t = input[2];

	var g = gcd(n,m);
	var n1 = n/g;
	var m1 = m/g;

	var k = n1 * m;
	var l = n1 * m1;

	for(var i = 0; i < g; i++){
		if(s[n1*i] !== t[m1*i]){
			console.log(-1);
			return 0;
		}
	}

	var ans;

	console.log(k);

	return 0;
}



Measured memory_bytes: 21192
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(usize, usize); n],
    }
    let mut ans = 0;
    for (a, k) in p.into_iter() {
        let mut x = a;
        while x % k != 0 {
            let v = (x + k - 1) / k;
            let u = (x - k * (v - 1)) / v;
            x -= u * v;
            while (x + k - 1) / k == v {
                x -= v;
            }
        }
        ans ^= x / k;
    }
    let s = if ans != 0 {"Takahashi"} else {"Aoki"};
    println!("{}", s);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
import math
n, m, k = map(int, input().split())

def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

MOD = 998244353
N = 3*10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod MOD)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod MOD)
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

ans = 0
for kk in range(k+1):
    ans_kk = m*cmb(n-1,kk,MOD)* pow(m-1, n-kk-1, MOD)
    ans = (ans + ans_kk)%MOD

print(ans)

Measured memory_bytes: 44844
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int min = sc.nextInt();
		int max = sc.nextInt();
		int count = sc.nextInt();
		sc.close();
		ArrayList<Integer> numList = new ArrayList<>();
		for(int i=0;i<count;i++) {
			if(min+i>max && max-i<min) {
				break;
			}
			if(!numList.contains(min+i) && min+i<=max) {
				numList.add(min+i);
			}
			if(!numList.contains(max-i) && max-i>=min) {
				numList.add(max-i);
			}
		}
		Collections.sort(numList);
		for(Integer i : numList) {System.out.println(i); }
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 200005;
const int mod = 1e9 + 7;

struct Edge { int p, v, w; } e[MAXN << 1];
int n, V, E, ans, e_cnt = 1, f[MAXN], hed[MAXN], siz[MAXN], par[MAXN], fac[MAXN], inv[MAXN], vis[MAXN];

inline void Addedge(int x, int y, int w)
{
	e[++ e_cnt] = {y, hed[x], w}; hed[x] = e_cnt;
	e[++ e_cnt] = {x, hed[y], w}; hed[y] = e_cnt;
}

inline int C(int x, int y)
{
	return 1LL * fac[x] * inv[y] % mod * inv[x - y] % mod;
}

inline void Dfs(int x)
{
	vis[x] = 1, V ++;
	for (int i = hed[x]; i; i = e[i].v, E ++)
		if (!vis[e[i].p])
			Dfs(e[i].p);
}

inline void Dfs(int x, int p)
{
	vis[x] = -1;
	for (int i = hed[x]; i; i = e[i].v)
		if (i ^ p ^ 1)
			if (~vis[e[i].p])
				par[e[i].p] = i, Dfs(e[i].p, i);
			else if (!E)
			{
				E = i;
				for (int cur = x; cur ^ e[i].p; cur = e[par[cur] ^ 1].p)
					if (e[par[cur]].w > e[E].w)
						E = par[cur];
			}
}

inline void Dp(int x, int p)
{
	siz[x] = f[x] = 1;
	for (int i = hed[x]; i; i = e[i].v)
		if ((i ^ p ^ 1) && (i ^ E) && (i ^ E ^ 1))
		{
			int y = e[i].p;
			Dp(y, i);
			if (e[i].w > e[p].w)
				ans = 1LL * f[y] * inv[siz[y]] % mod * ans % mod;
			else
				siz[x] += siz[y], f[x] = 1LL * f[x] * f[y] % mod * C(siz[x] - 1, siz[y]) % mod;
		}
	if (p == E)
		ans = 1LL * f[x] * inv[siz[x]] % mod * ans % mod;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read() << 1, fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; i ++)
		fac[i] = 1LL * fac[i - 1] * i % mod, inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (int i = 2; i <= n; i ++)
		inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
	for (int i = 1, x, y; i <= n; i ++)
		x = Read(), y = Read(), Addedge(x, y + (n >> 1), x + y);
	int ret = fac[n], cur = 0;
	for (int i = 1; i <= n; i ++)
		if (!vis[i])
		{
			V = E = 0;
			Dfs(i);
			if (V << 1 ^ E)
				return puts("0"), 0;
			E = 0;
			Dfs(i, 0);
			ans = 1;
			Dp(e[E].p, E);
			cur = ans;
			ans = 1;
			Dp(e[E ^ 1].p, E);
			ret = 1LL * ret * (cur + ans) % mod;
		}
	return printf("%d\n", ret), 0;
}


Measured memory_bytes: 12160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> used(n);
    vector<int>h(n);
    rep(i,n)cin >> h[i];
    vector<vector<int>> g(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    rep(i,n){
        int cnt = 0;
        int ma = h[i];
        for(int x: g[i]){
            ma = max(ma, h[x]);
            if(ma==h[x])cnt++;
        }
        if(ma == h[i] and cnt==0)ans++;
    }
    cout << ans << endl;
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

bool is_kai(std::string s) {
	std::string t = s;
	std::reverse(t.begin(), t.end());
	return s == t;
}

int main() {
	double n;
	std::cin >> n;
	printf("%.11f\n", (n / 3) * (n / 3) * (n / 3));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<int> s;int n;
int proc(int x,bool ff){
	while(1){
		if(ff)s.insert(x);else{
			if(s.count(x))return x;
		}
		if(x == 1)break;
		x = (x + n - 2)/n;
	}
	return -1;
}
int main(){
	int q,x,y;
	scanf("%d%d",&n,&q);
	while(q--){
		scanf("%d%d",&x,&y);
		if(n == 1){
			printf("%d\n",min(x,y));
			continue;
		}
		s.clear();
		proc(x, true);
		printf("%d\n",proc(y, false));
	}
	return 0;
}


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


int main(){
	
	
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	map<long long ,int> mapa;
	for(int i=0;i<n;i++){
		mapa[i+arr[i]+1] += 1;
	}
	long long ans = 0;
	for(int i=0;i<n;i++){
		ans += mapa[i - arr[i] + 1];
	}
	cout<<ans<<endl;
	
	
	
	
	return 0;
 
}

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

vector<vector<int> > B;

int revNum(int num) {
  return 7 - num;
}

int isHeavy(int num) {
  return num > 3;
}

int heavyNum(int num) {
  return isHeavy(num) ? num : revNum(num);
}

int sideHeavyNum(int t, int f) {
  return 15 - heavyNum(t) - heavyNum(f);
}

int check(int t, int f) {
  int ht = heavyNum(t);
  int hf = heavyNum(f);
  return (ht - hf + 2) % 3;
}

int leftNum(int t, int f) {
  int s = sideHeavyNum(t, f);
  return (isHeavy(t) + isHeavy(f) + check(t, f)) % 2 ? revNum(s) : s;
}

int canDrop(int x, int y, int h) {
  return B[x][y] >> 3 < h;
}

void dropDice(int t, int f, int x, int y) {
  int l = leftNum(t, f);
  int h = B[x][y] >> 3;

  int xx = x - (isHeavy(l) ? 1 : -1);
  int xy = y;
  int yx = x;
  int yy = y - (isHeavy(f) ? 1 : -1);

  if (!canDrop(xx, xy, h) && !canDrop(yx, yy, h)) {
    B[x][y] &= ~7;
    B[x][y] |= t;
    B[x][y] += 8;
    return;
  }

  int hf = heavyNum(f);
  int hl = heavyNum(l);

  if (hl > hf) {
    if (canDrop(xx, xy, h)) {
      dropDice(revNum(hl), f, xx, xy);
    } else {
      dropDice(revNum(hf), isHeavy(f) ? t : revNum(t), yx, yy);
    }
  } else {
    if (canDrop(yx, yy, h)) {
      dropDice(revNum(hf), isHeavy(f) ? t : revNum(t), yx, yy);
    } else {
      dropDice(revNum(hl), f, xx, xy);
    }
  }
}

int main() {
  while (true) {
    int n;
    cin >> n;

    if (n == 0) {
      break;
    }

    int l = 2 * n + 1;
    B.resize(l);
    for (int i = 0; i < l; i++) {
      B[i].resize(l);
      fill(B[i].begin(), B[i].end(), 0);
    }

    for (int i = 0; i < n; i++) {
      int t, f;
      cin >> t >> f;

      dropDice(t, f, n, n);
    }

    vector<int> cnt(7);
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 0; i < l; i++) {
      for (int j = 0; j < l; j++) {
	cnt[B[i][j] & 7]++;
      }
    }

    for (int i = 1; i < 7; i++) {
      cout << cnt[i];
      if (i != 6) {
	cout << ' ';
      }
    }
    cout << endl;
  }

  return 0;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;

int main(){
    int ans=0;
    string S;
    cin >> S;
    
    char c = S[0];
    rep(i,S.size()){
        if(S[i] != c){
            ans++;
            c = S[i];
        }
    }
    
    cout << ans;
    //printf("%.15lf",ans);
    cout << endl;
    return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#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 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 ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
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;

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(){
    int n; cin >> n;
    VI a(n);
    REP(i, n)  cin >> a[i];
    int m; cin >> m;
    REP(i, m){
        int b; cin >> b;
        if(!binary_search(ALL(a), b)){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}



Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    string s; cin>>s;
    int n=s.size();
    int ans=1e9;
    for(int p=0; p<2; p++){
        for(int q=0; q<2; q++){
            int l=0, r=0, sl=-1e9, sr=1e9;
            int d=0, L=-p, R=q;
            for(int i=0; i<n; i++){
                if(s[i]=='0'){
                    l--; r--;
                    sl--; sr--;
                    if(~(i+p)&1){
                        sl=max(sl, 1);
                    }
                }else if(s[i]=='1'){
                    l++; r++;
                    sl++; sr++;
                    if(~(i+q)&1){
                        sr=min(sr, -1);
                    }
                }else{
                    l--; r++;
                    sl--; sr++;
                    if(~(i+p)&1){
                        sl=max(sl, 1);
                    }
                    if(~(i+q)&1){
                        sr=min(sr, -1);
                    }
                }
                d=max(d, sl-sr);
                L=min(L, r-sl);
                R=max(R, l-sr);
            }
            ans=min(ans, max(d, R-L));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5288
// 解答AC
#include <bits/stdc++.h>
using namespace std;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;
    vector<vector<bool>> avail(H);
    for(int i=0; i<H; i++){
        string s;
        cin >> s;
        avail[i].resize(W);
        for(int j=0; j<W; j++) avail[i][j] = (s[j] == '.');
    }

    int dx[] = {-1, 1, 0, 0};
    int dy[] = {0, 0, -1, 1};
    auto inside = [&](int i, int j){ return i>=0 && i<H && j>=0 && j<W && avail[i][j]; };

    vector<vector<int>> dist(H, vector<int>(W, 1e9));
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    dist[sx][sy] = 0;

    while(que.size()){
        auto [i, j] = que.front(); que.pop();
        for(int k=0; k<4; k++) for(int d=1; d<=K; d++){
            int x = i+d*dx[k], y = j+d*dy[k];
            if(!inside(x, y) || dist[x][y] <= dist[i][j]) break;
            if(dist[x][y] == 1e9){
                dist[x][y] = dist[i][j] + 1;
                que.emplace(x, y);
            }
        }
    }

    int ans = dist[gx][gy];
    if(ans == 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}


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

int main(int argc, const char * argv[]) {
    int D;
    
    cin >> D;
    
    cout << "Christmas";
    for (int i = 0; i < 25 - D; i++) {
        cout << " Eve";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define foru(i,a,n) for(int i=(a); i<=(n); i++)
using namespace std;
const int N = 202020;
int n, k, a[N], d[N], ans = 0;
int main()
{
    cin >>n >>k;
    foru(i,1,n) cin >>a[i];
    foru(i,1,n) d[a[i]]++;
    sort(d+1, d+1+n, greater<int>());
    foru(i,k+1,n) ans+=d[i];
    cout <<ans;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        if(h>=k) ans++;
    }
    cout << ans;
}

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

int main(){
    int n;
    cin >> n;
    int impare;

    if(n%2 == 0)
        impare = n/2;
    else
        impare = n/2 + 1;

    float rezultat = (float)impare / n;
    cout << rezultat << endl;
}

Measured memory_bytes: 256
D = gets.to_i
C = gets.split.map(&:to_i)
S = []
D.times{
	S << gets.split.map(&:to_i)
}
warn C.inspect
warn S.inspect

T = Array.new(D){rand(26)}

def last(d, i)
	r = d
	while r >= 0
		break if T[r] == i
		r -= 1
	end
	r
end

def full_score
	r = 0
	D.times{|d|
		r += S[d][T[d]]
		26.times{|l|
			r -= C[l] * (d - last(d, l))
		}
	}
	r
end

def diff(d, q)
	r = 0
	r -= S[d][T[d]]
	r += S[d][q]
	nd = d + 1
	while nd < D && T[nd] != T[d]
		nd += 1
	end
	r -= C[T[d]] * (d - last(d - 1, T[d])) * (nd - d)
	nd = d + 1
	while nd < D && T[nd] != q
		nd += 1
	end
	r += C[q] * (d - last(d, q)) * (nd - d)
	r
end

s = full_score
warn "score:#{s}"
st = Time.now
c = 0
loop{
	d = rand(D)
	q = rand(26)
	dif = diff(d, q)
	if dif > 0
		s += dif
		T[d] = q
	end
	c += 1
	t = Time.now
	if  t - st > 1.9
		break
	end
}
warn "score:#{s}"
warn "loop:#{c}"
puts T.map{|i|i + 1}



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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	int M = min(a,b);
	int mm = max(0,a + b - n);
	cout << M << endl;
	cout << mm << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[3][3];
  int i,j;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
     cin >> s[i][j];
    }
  }
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(i==j){
        cout<< s[i][j];
      }
    }
  }
}
  

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        String[] s = S.split("");
        String[] t = T.split("");
        Arrays.sort(s);
        Arrays.sort(t, Collections.reverseOrder());
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<s.length; i++) { 
            sb.append(s[i]);
        }
        S = String.valueOf(sb);
        sb = new StringBuilder();
        for(int i=0; i<t.length; i++) { 
            sb.append(t[i]);
        }
        T = String.valueOf(sb);
        if(S.compareTo(T) < 0) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)

using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n)cin>>a.at(i);
  rep(i,n)cin>>b.at(i);
  rep(i,n){
    if(i==0)continue;
    else a.at(i) += a.at(i-1);
  }
  rep(i,n){
    if(i==0)continue;
    else b.at(n-i-1) += b.at(n-i);
  }
  int ans = a.at(0)+b.at(0);
  rep1(i,n)ans = max(ans,a.at(i)+b.at(i));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
H,W,N = map(int,input().split())
sr,sc = map(int,input().split())

S = input()
T = input()
nowh = sr-1
noww = sc-1
flag = False
FLAG = False
for i in range(N):
    if S[i] == 'U':
        nowh -= 1
    if nowh < 0 or nowh >= H:
        flag = True
        break
    if T[i] == 'D' and nowh < H-1:
        nowh += 1
if flag:
    FLAG = True

nowh = sr-1
noww = sc-1
flag = False
for i in range(N):
    if S[i] == 'D':
        nowh += 1
    if nowh < 0 or nowh >= H:
        flag = True
        break
    if T[i] == 'U' and nowh > 0:
        nowh -= 1
if flag:
    FLAG = True

nowh = sr-1
noww = sc-1
flag = False
for i in range(N):
    if S[i] == 'R':
        noww += 1
    if noww < 0 or noww >= W:
        flag = True
        break
    if T[i] == 'L' and noww > 0:
        noww -= 1
if flag:
    FLAG = True

nowh = sr-1
noww = sc-1
flag = False
for i in range(N):
    if S[i] == 'L':
        noww -= 1
    if noww < 0 or noww >= W:
        flag = True
        break
    if T[i] == 'R' and noww < W-1:
        noww += 1
if flag:
    FLAG = True

if FLAG:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 43344
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, typ = 0, ct = 0;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a)
		cin >> i;
	for (int i = 0; i < n; ++i)
	{
		if (i == 0)
			++ct;
		else if (!typ)
		{
			if (a[i] > a[i - 1])
				typ = 1;
			else if (a[i] < a[i - 1])
				typ = -1;
		}
		else
		{
			if (typ == 1)
			{
				if (a[i] < a[i - 1])
				{
					typ = 0; ++ct;
				}
			}
			else
			{
				if (a[i] > a[i - 1])
				{
					typ = 0; ++ct;
				}
			}
		}
	}
	cout << ct << endl;
}

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

using namespace std;

int main(){

   int n;
   cin >> n;

   int t_p = 0, h_p = 0;

   for(int i = 0; i < n; i++){
      string t_c, h_c;
      cin >> t_c >> h_c;

      if(t_c < h_c){
         h_p += 3;
      }
      else if(t_c == h_c){
         t_p++;
         h_p++; 
      }
      else{
         t_p += 3;
      }
   }

   cout << t_p << " " << h_p << endl;

   return 0;
}


Measured memory_bytes: 3152
# -*- coding: utf-8 -*-
# abc141/abc141_d
import sys
import heapq

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    h = [-int(s) for s in sys.stdin.readline().rstrip().split()]
    heapq.heapify(h)
    for _ in range(M):
        heapq.heapreplace(h, -(-h[0] // 2))
    print(-sum(h))

main()


Measured memory_bytes: 14380
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



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

   int N;
   cin >> N;
   VI H(N);
   REP(i, N)
      cin >> H[i];

   VI DP(N);
   for (int i = N-2; i >= 0; --i) {
      if (H[i] >= H[i+1])
         DP[i] = DP[i+1] + 1;
      else
         DP[i] = 0;
   }

   int res = *max_element(DP.begin(), DP.end());
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 1024
class SegmentTreeMax():
  def __init__(self,n,init):
    self.offset=2**((n-1).bit_length())
    self.tree=[init]*(2*self.offset)
    self.init=init
  def update(self,pos,val):
    pos+=self.offset
    self.tree[pos]=val
    while pos>1:
      pos=pos//2
      self.tree[pos]=max(self.tree[2*pos],self.tree[2*pos+1])
  def query(self,l,r):
    l+=self.offset
    r+=self.offset
    ret=self.init
    while l<=r:
      ret=max(ret,self.tree[r])
      r=(r-1)//2
      ret=max(ret,self.tree[l])
      l=(l+1)//2
    return ret

mod=998244353
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
st=SegmentTreeMax(n,0)
ranges=[]
for i in range(n):
  x=arr[i][0]+arr[i][1]
  l=-1
  r=n
  while r-l!=1:
    mid=(l+r)//2
    if arr[mid][0]>=x:
      r=mid
    else:
      l=mid
  ranges.append(l)
  st.update(i,r)
for i in range(n-1,-1,-1):
  ranges[i]=st.query(i,ranges[i])
  st.update(i,ranges[i])
dp=[0]*(n+1)
dp[-1]=1
for i in range(n-1,-1,-1):
  j=ranges[i]
  dp[i]=dp[i+1]+dp[j]
  dp[i]%=mod
print(dp[0])

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

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

	cout<<fixed<<setprecision(12);
	int n;
	cin>>n;
	ld p[n+1];
	for(int i=1;i<=n;i++)
		cin>>p[i];
	ld dp[n+1][n+1];
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		dp[i][0] = dp[i-1][0]*(1-p[i]);
		dp[i][i] = dp[i-1][i-1]*p[i];
		for(int j=1;j<i;j++)
			dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
	}

	ld ans = 0.0;
	for(int i=n;2*i>n;i--)
		ans += dp[n][i];
	cout<<ans<<endl;
}

Measured memory_bytes: 140928
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(K, i, N) for (ll i = K; i < (ll)(N); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())  // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
  long long N, K;
  cin >> N >> K;
  cout << min(N % K, K - N % K) << endl;}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  int n,i,c,min;
  cin >> n;
  int p[n];
  cin >> p[0];
  min = p[0];
  c = 1;
  for(i = 1; i < n; i++){
    cin >> p[i];
    if(p[i] <= min){
      c += 1;
      min = p[i];
    }
  }
  cout << c;
}



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

using namespace std;

#define ll long long
typedef complex<double> P;

int partition(int* A, int p, int r) {
  int x = A[r];
  int i = p-1;
  for (int j = p; j < r; j++) {
    if(A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i+1;
}

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

  int ix = partition(a, 0, n-1);
  for (int i = 0; i < n; i++) {
    if(i == ix) cout << '[' << a[i] << ']' << (i != n-1 ? ' ' : '\n');
    else cout << a[i] << (i != n-1 ? ' ' : '\n');
  }
}

Measured memory_bytes: 3456
def input_space():
    return list(map(int,input().split(" ")))

K,A,B=input_space()

if B-A<=2:
    res=K+1
else:
    c=B-A
    k=c-1
    t=max(0,(K-A+1)//2)
    mod=(K-A+1)%2
    res=A+t*c+mod



print(res)




'''
Solve[{c=B/A, k=c-1,  t=(K-A+1)/2,r=A+t*k*A},{r}]
'''

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
///                    BISMILLAHIR RAHMANIR RAHIM
int main()
{
    int a;
    cin>> a;
    ll ans=0;
    ans=ans+a;
    int temp=a;
    a=a*a;
    ans=ans+a;
    a=a*temp;
    ans=ans+a;
    cout<<ans<<endl;
}

/// A L H A M D U L I L L A H


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::vector;
using std::cin;
using std::map;
using std::multimap;
using std::set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

int main() {
	int n;
	cin >> n;
	VL v(n);
	REP(i, n) { cin >> v[i]; }

	ll t = v[0];
	ll c = 1;
	ll ans = 0;
	FOR(i, 1, n) {
		if (v[i] == t) {
			++c;
		} else {
			ans += c / 2;
			c = 1;
			t = v[i];
		}
	}
	ans += c / 2;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Stack;


class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		while(in.hasNext()){
			int l = in.nextInt();
			if(l == 0) return;
			int a = 0;
			boolean f = true;
			for(int i = 0; i < 12; i++){
				int m = in.nextInt(), n = in.nextInt();
				a += m - n;
				if(a >= l && f){
					System.out.println(i + 1);
					f =false;
				}
				if(i == 11 && f) System.out.println("NA");
			}
		}
	}

	

}

Measured memory_bytes: 44464