akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;
const LL Maxn = 200010;
const LL lg = 20;
const LL Mod = 1e9+7;
LL dep[Maxn];
LL f[Maxn], g[Maxn], size[Maxn], two[Maxn];
LL fa[Maxn][lg];
vector <LL> vec[Maxn], pd[Maxn], po; LL md;
vector <LL> e[Maxn];
LL n, T;
LL sta[Maxn], tp;
void dfs(LL x) {
	pd[dep[x]].push_back(x);
	if(dep[x] > md) md = dep[x];
	for(LL i = 1; i < lg; i++) fa[x][i] = fa[fa[x][i-1]][i-1];
	for(LL i = 0; i < vec[x].size(); i++){
		LL y = vec[x][i];
		dep[y] = dep[x]+1; fa[y][0] = x;
		dfs(y);
	}
}
void dfss(LL x) {
	if(dep[x] == T) size[x] = 1, f[x] = 1, g[x] = 1;
	else size[x] = 0, f[x] = 0, g[x] = 1;
	for(LL i = 0; i < e[x].size(); i++){
		LL y = e[x][i];
		dfss(y);
		f[x] = (f[x]*(two[size[y]]-f[y]+Mod)+g[x]*f[y])%Mod;
		g[x] = g[x]*(two[size[y]]-f[y]+Mod)%Mod;
		size[x] += size[y];
	}
}
LL getlca(LL x, LL y) {
	if(dep[x] < dep[y]) swap(x, y);
	for(LL i = lg-1; i >= 0; i--){
		if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	}
	if(x == y) return x;
	for(LL i = lg-1; i >= 0; i--){
		if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
	}
	return fa[x][0];
}
int main() {
	LL i, j, k;
	scanf("%lld", &n);
	for(i = 1; i <= n; i++){
		LL x;
		scanf("%lld", &x); x++;
		vec[x].push_back(i+1);
	}
	two[0] = 1;
	for(i = 1; i <= n; i++) two[i] = two[i-1]*2%Mod;
	dep[1] = 1;
	dfs(1);
	LL ans = 0;
	for(i = 1; i <= md; i++){
		T = i;
		sta[tp=1] = 1;
		po.clear();
		po.push_back(1);
		for(j = 0; j < pd[i].size(); j++){
			LL x = pd[i][j];
			LL lca = getlca(x, sta[tp]);
			while(dep[sta[tp-1]] >= dep[lca]){
				e[sta[tp-1]].push_back(sta[tp]);
				tp--;
			}
			if(lca != sta[tp]){
				po.push_back(lca);
				e[lca].push_back(sta[tp]);
				tp--;
				sta[++tp] = lca;
			}
			if(x != sta[tp]){
				po.push_back(x);
				sta[++tp] = x;
			}
		}
		while(tp > 1) e[sta[tp-1]].push_back(sta[tp]), tp--;
		dfss(1);
		ans = (ans+f[1]*two[n+1-size[1]])%Mod;
		for(j = 0; j < po.size(); j++) e[po[j]].clear();
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 72064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;

#define   M             (int)1e6+10
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           1e9
#define   rush()        int T;scanf("%d",&T);while(T--)
#define   debug         puts("debug")

typedef   pair<int,int> P;

int cnt[M];
int vis[M];

void slove(int t) {
	
	int tmp = t,stp = 0;
	while(tmp>=0) {
		vis[tmp]++;
		cnt[tmp] += stp;
		stp++;
		tmp--;
	}
	
	stp = 0;
	for(int i=t+2;i<=1e6;i+=2) {
		vis[i]++;
		cnt[i] += ++stp;
	}

}

int main() {
	
	int zero = 0;
	for(int i=0;i<3;i++) {
		int num;
		scanf("%d",&num);
		slove(num);
	}
	
	int ans = inf;

	
	for(int i=0;i<=1e6;i++) {
		if(vis[i] == 3) {
			ans = min(ans,cnt[i]);
		}
	}
	
	printf("%d\n",ans);
}


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

Measured memory_bytes: 8064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

Measured memory_bytes: 31788
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int fairfield(int y,int m,int d)
{
	if(m<=2){
		y--;
		m+=12;
	}
	return 365*y+y/4-y/100+y/400+153*(m+1)/5+d-428;
}

int main()
{
	string weekday[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday", "Saturday"};
	for(int m,d;cin>>m>>d,m|d;)
		cout<<weekday[fairfield(2004,m,d)%7]<<endl;
	
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	N := sc.s()
	for _, r := range N {
		if r == '7' {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1760
package main

import (
	"fmt"
	"math"
)

func main() {
	var a,b,n float64
	fmt.Scan(&a,&b,&n)
	
	x := min(b-1.0,n)
	fmt.Println(math.Floor(a * x / b))
}

func min(a,b float64) float64 {
	if a < b {
		return a
	}
	return b
}

Measured memory_bytes: 1756
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define otc ll t=1;while(t--)
#define ll long long int
#define ld long double
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define ull unsigned long long int
#define memset(arr) memset(arr, 0, sizeof(arr));
bool sortinrev(const pair<ll, ll> &a, const pair<ll, ll> &b)
{return (a.fi > b.fi);}//sort by first in descending order
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b)
{ return (a.se < b.se); }//sort by second in ascending order
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};

int main()
{
    int n;
    cin>>n;
    n=n%10;
    if(n==3)
    cout<<"bon"<<endl;
    else
    if(n==0 || n==1 || n==6 || n==8)
    cout<<"pon"<<endl;
    else
    cout<<"hon"<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int64_t n;
  cin>>n;
  int64_t sum1 =2;
  int64_t  sum2=1;
  int64_t ai;
  if(n==1)
    ai =1;
  else{
    for(int i =2;i<n+1;i++){
      ai = sum1+sum2;
      sum1 = sum2;
      sum2 = ai;  
    }
  }
  cout << ai;
  }
  

Measured memory_bytes: 256
while True:
    s = input().split(" ")
    m = int(s[0])
    f = int(s[1])
    r = int(s[2])
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1 or m + f < 30:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    else:
        if r >= 50:
            print("C")
        else:
            print("D")

Measured memory_bytes: 7676
let () =
    let main () =
        let s = read_line () in
        let t = read_line () in
        let rec loop i acc =
            if i = 3 then acc else
                loop (i + 1) (acc + if s.[i] = t.[i] then 1 else 0)
        in
        let r = loop 0 0 in
        Printf.printf "%d\n" r
    in
    main ()

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>

struct Que{
	int head,tail;
	std::vector<int> time;
	std::vector<std::string> name;
};

int initialize(Que &q,int n){
	int qt;
	std::cin>>qt;
	for(int i=0;i<n;i++){
		int time;
		std::string name;
		std::cin>>name;
		std::cin>>time;
		q.time.push_back(time);
		q.name.push_back(name);
		q.tail++;
	}
	q.time.push_back(0);
	q.name.push_back("end");
	return qt;
}

void enque(int x,std::string str,Que &q,int n){
	q.time[q.tail%(n+1)]=x;
	q.name[q.tail%(n+1)]=str;
	q.tail++;
}

int deque(Que &q,int n){
	q.head++;
	return q.time[(q.head-1)%(n+1)];
}

int main(void){
	Que q;
	q.head=0;
	q.tail=0;
	int time=0,n;
	std::cin>>n;
	int qt=initialize(q,n);
	while(q.head!=q.tail){
		std::string str=q.name[(q.head)%(n+1)];
		int x=deque(q,n);
		x-=qt;
		if(x<=0){
			time+=qt+x;
			std::cout<<q.name[(q.head-1)%(n+1)]<<' '<<time<<'\n';
		}else{
			enque(x,str,q,n);
			time+=qt;
		}
	}
	return 0;
}


Measured memory_bytes: 5556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  
  int A, B;
  cin >> A >> B;
  
  int ans = 0;
  int cnt = 1;
 // cout << A << ", " << B << ", " << cnt << endl;
  while(cnt < B)
  {
//    cout << cnt << endl;
    ans++;
    cnt += A-1;  
  }
  
  cout << ans << endl;
  
  return 0;
}



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


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

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	VL a(n);
	rep(i, n) cin>>a[i];
	
	rep(i, n) a[i] -= (i+1);
	sort(all(a));
	int b=a[n/2];
	ll ans = 0;
	rep(i,n) ans += abs(b- a[i]);
	cout << ans <<"\n";
	return 0;
}



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

int main() {
	int a,b;
	cin >> a >> b;
	string s;
	cin >> s;
	bool check = true;


	for(int i=0;i<a;i++){
		if(isdigit(s[i])==false) check = false; 
	}
	
	if(s[a]!='-') check = false; 

	for(int i=a+1;i<a+b+1;i++){
		if(isdigit(s[i])==false) check = false;
	}
	
	if(check) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void nil()
{
	int n;
	cin>>n;
	string s, c="";
	cin>>s;
	c=c+s[0];
	for(int i=1;i<n;i++)
	{
		if(c.back()!=s[i])
		{
			c=c+s[i];
		}
	}
	cout<<c.size();
}
int main()
{
	#ifndef ONLINE_JUDGE

		freopen("input1.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif	
		nil();

}


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

bool ff(double y1,double x1,double a1,double b1,double y2,double x2,double a2,double b2){
  int ly = max(y1,y2),ry=min(a1,a2);
  int lx = max(x1,x2),rx=min(b1,b2);
  if (lx > rx || ly > ry)return 0;
  return true;
}

bool f(double *left,double *top,double *right,double *bottom){
  if ( left[0]  <=right[1] && top[0] >=bottom[1] &&
      right[0] >=left[1]  && bottom[0] <=top[1])return true;
  else return false;
}

main(){
  double l[2],r[2],t[2],b[2];
  while(cin>>l[0]>>b[0]>>r[0]>>t[0]>>
	l[1]>>b[1]>>r[1]>>t[1]){
    /*    if (f(
	   l[0],b[0],r[0],t[0],
	   l[1],b[1],r[1],t[1]
	  )
	)
    */
    if (f(l,t,r,b))
      cout <<"YES" << endl;
    else cout <<"NO"<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
    int n, a, b;
    cin >> n >> a >> b;
    int MIN = min(a, b);
    int MAX;
    if (n > a+b) MAX = 0;
    else MAX = (a+b)-n;
    cout << MIN << " " << MAX << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
#define MAXSIZE 100

int main(){
    int n, d[MAXSIZE], i;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> d[i];
    }
    sort(d, d + n, greater<int>());
    int ans = 1, comp = d[0];
    for(i = 0; i < n; i++){
        //printf("%d%c", d[i], (i == n-1)? '\n' : ' ');
        //printf("i = %d, ans = %d, comp = %d\n", i, ans, comp);
        if(d[i] < comp){
            ans++;
            comp = d[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N, K, x_i;
  int run_tot=0;
  
  cin >> N >> K;
  
  for (int i=0;i<N;i++){
    cin >> x_i;
    
    if ( x_i < K-x_i )
      run_tot += 2*x_i;
    else
      run_tot += 2*(K-x_i);
  }
  
  cout << run_tot << endl;
}

Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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


fn main() {
    input! {
        n:usize,
        s:chars
    }
    let mut right_white = 0;
    let mut left_black = 0;
    for i in 0..n {
        if s[i] == '.' {
            right_white += 1;
        }
    }
    let mut min_num = right_white;

    for i in 0..n {
        if s[i] == '#' {
            left_black += 1;
        } else if s[i] == '.' {
            right_white -= 1;
        }
        let sum = right_white + left_black;
        if sum < min_num {
            min_num = sum;
        }
    }

    println!("{}", min_num);

}


Measured memory_bytes: 4352
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
for i in range(1,10):
    for j in range(1,10):
        if i * j == n:
            print('Yes')
            quit()
print('No')

Measured memory_bytes: 38764
N = int(input())
A = list(map(int,input().split()))
R = 0
G = 0
B = 0
output = 1
for i in range(N):
    Rf = 0
    Gf = 0
    Bf = 0
    if A[i]==R:
        Rf = 1
    if A[i]==G:
        Gf = 1
    if A[i]==B:
        Bf = 1
    S = Rf+Gf+Bf
    if Rf==1:
        R+=1
    elif Gf ==1:
        G+=1
    elif Bf==1:
        B+=1
    output *= S
    output = output%1000000007
print(output)

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




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


    string s,t;
    cin>>s>>t;
    ll ans = 0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]) ans++;
    }
    cout<<ans<<endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
//typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int h,w,d;
int a;
vector<P> v;
int q;
int l,r;
int imos[90010];

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

	cin>>h>>w>>d;
	v.resize(h*w+1,P(0,0));
	REP(i,h) {
		REP(j,w) {
			cin>>a;
			v[a]=P(i,j);
		}
	}
	FOR(i,1,h*w+1) {
		if(i>d) imos[i]=imos[i-d]+abs(v[i].fi-v[i-d].fi)+abs(v[i].se-v[i-d].se);
		else imos[i]=0;
	}
	cin>>q;
	while(q--) {
		cin>>l>>r;
		cout<<imos[r]-imos[l]<<endl;
	}

	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,ans,chk;
cin>>n>>m;
ans=0;
for(i=n-1;i>=1;i--)
    ans+=i;
    for(i=m-1;i>=1;i--)
    ans+=i;
    cout<<ans<<endl;
return 0;
}


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

int main() {
    int n;
    cin>>n;
    vector<int> mao(n);
    for(int i=0; i<n; i++) {
        cin>>mao.at(i);
    }

    vector<int> ans(n);
    for(int i=0; i<n; i++) {
        int z = mao.at(i);
        ans.at(z-1) = i+1;
    }

    for(int i=0; i<n-1; i++) cout<<ans.at(i)<<" ";

    cout<<ans.at(n-1)<<endl;
}


Measured memory_bytes: 1536
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, t = MAP()
tarr = LIST()
ans = t
for i in range(1, n):
    if tarr[i] - tarr[i - 1] >= t:
        ans += t
    else:
        ans += tarr[i] - tarr[i - 1]
print(ans)

Measured memory_bytes: 27288
N = int(input())
S = input()
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        if S[i] != S[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i + 1][j + 1] + 1
result = 0
for i in range(N):
    for j in range(i + 1, N):
        t = dp[i][j]
        if t > j - i:
            t = j - i
        if t > result:
            result = t
print(result)


Measured memory_bytes: 230024
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
  fast;


   ll n;
   cin>>n;

   string s;
   cin>>s;

   ll ct=1;
   char cur=s[0];
   for(ll i=1;i<n;i++)
   {
    if(s[i]==cur)
        continue;
    else
    {
        ct++;
        cur=s[i];
    }
   }

   cout<<ct<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int main() {
	int m; cin >> m;
	while (m--) {
		string s; cin >> s;
		set<string> uni;
		for (int i = 1; i < s.size(); ++i) {
			string s1 = s.substr(0, i), s2 = s.substr(i, s.size() - i);
			for (int j = 0; j < 2; ++j) {
				for (int k = 0; k < 2; ++k) {
					uni.insert(s1 + s2);
					uni.insert(s2 + s1);
					reverse(s2.begin(), s2.end());
				}
				reverse(s1.begin(), s1.end());
			}
		}
		cout << uni.size() << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
def gcd(a,b)
    if a > b
        c = a
        d = b
    else
        c = b
        d = a
    end
    e = 0
    while c % d != 0
         e = c % d
         c = d
         d = e
    end
    return d
end

str = gets.split
A,B = str[0].to_i, str[1].to_i
answer = A*B/gcd(A,B)
puts answer

Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#include <algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int main(){

	string g,h;
	int i = 0;
	vector<int>ireko;
	bool LeftKakko = false;
	int k = 0;
	while ((std::cin >> g), g != "."){
		REP(l, g.length()){
			char a = g[l];
			if (a == 43){ 
				i++; 
			}else if (a == 45){ 
				i--; 
			}else if (a == 91){ 
				ireko.push_back(k); 
			}else if (a == 93){  
				reverse(h.begin() + ireko.back(), h.end()); 
				ireko.pop_back(); 
			}else if (a == 63){ 
				h += 65;
				i = 0;
				++k; 
			}else{
				int w;
				for (w=a+i; 64 >= w || w >= 91; (w >= 91) ? w -= 26 : w += 26){

				}
				h.push_back(w);
				i = 0;
				++k;
			}
		}
		cout << h<<endl;
		h.erase();
		k = 0;
	}
	return 0;
}

Measured memory_bytes: 1204
judge = ['AC', 'WA', 'TLE', 'RE']
cnt = [0] * 4
N = int(input())
for _ in range(N):
    s = input()
    for i in range(len(judge)):
        if s == judge[i]:
            cnt[i] += 1
for i in range(4):
    print(judge[i] + ' ' + 'x' + ' ' + str(cnt[i]))

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

using namespace std;

int main() {
    int X;
    int result=0;
    cin >> X;
    int num500=0;
    int num5=0;
    num500=(int)(X/500);
    num5=(int)((X%500)/5);
    result=1000*num500+5*num5;
    std::cout << result << std::endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 左からgreedyに
N, D, A = lr()
monsters = []
for _ in range(N):
    x, h = lr()
    monsters.append((x, h))

monsters.sort()
bomb = deque()
answer = 0
attack = 0
for x, h in monsters:
    while bomb:
        if bomb[0][0] + D < x:
            attack -= bomb[0][1]
            bomb.popleft()
        else:
            break
    h -= attack
    if h > 0:
        t = -(-h//A)
        answer += t
        bomb.append((x + D, A * t))
        attack += A * t

print(answer)


Measured memory_bytes: 67932
n,k = input().split()
n = int(n)
k = int(k)
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
min = 10 ** 9
for i in range(n-k+1):
    temp = h[i + k - 1] - h[i]
    if temp < min:
        min = temp
print(min)

Measured memory_bytes: 7384
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
int main(){
    int w[10],k[10];
    rep(i,10)cin>>w[i];
    rep(i,10)cin>>k[i];
    sort(w,w+10);
    sort(k,k+10);
    cout<<w[7]+w[8]+w[9]<<" "<<k[7]+k[8]+k[9]<<endl;
}

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

int main()
{
    string S, T;
    cin >> S >> T;
    int count = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] != T[i]) {
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3904
#include <cstdio>
#include <iostream>

using namespace std;

int main(void)
{
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	if(a[0] + a[1] + a[2] >= 22){
		cout << "bust" << endl;
	}else{
		cout << "win" << endl;
	}

	return 0;
}


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

int main() {
    int n;
    double val = 0;
    cin >> n;
    vector<double> a(n);
    
    for(int i=0; i < n; i++) {
        cin >> a[i]; 
    }
    for(int i = 0; i < n; i++) {
        for(int j = n-1; j >= i+1; j--) {
            if(a[j] < a[j-1]) {
                int tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
            }
        }

    }
//    for(int i=0; i < n; i++) {
//        cout << a[i] << endl; 
//    }
    if(n == 1) {
        val = a[0];
    }
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            val = a[i];
            continue;
        }
        val = (val + a[i]) / 2; 
//        cout << val << endl;
    }
    cout << setprecision(10) << val << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = 0
b = 0
c = 0
for _ in range(N):
    t, x, y = map(int, input().split())
    l = t - c
    m = abs((a + b) - (x + y))
    if l >= m and (l - m) % 2 == 0:
        a = x
        b = y
        c = t
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

l = [a, b, c, d, e]

index = 0
for i in range(1, 5):
    if (l[index] - 1)%10 > (l[i] - 1)%10:
        index = i
        
s = 0
for i in range(5):
    if i == index:
        s += l[i]
    else:
        s += ((l[i]+9) // 10)* 10
        
print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    char ch;
    while (1){
        scanf("%c",&ch);
        if(ch == '\n')break;
        if('a' <= ch && ch <= 'z')printf("%c",ch-32);
        else if('A' <= ch && ch <= 'Z' ) printf("%c", ch+32);
        else printf("%c",ch);
        
    }cout << endl;
    return 0;
    
}


Measured memory_bytes: 3244
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
int n,m;
int st[155][11][2];
int dp[155][11][76];
int num[155];
int main(){
    while(1)
    {
	scanf("%d %d",&n,&m);
	if(!n) return 0;
        for(int i=1;i<=n;i++){
            scanf("%d",&num[i]);
            for(int j=1;j<=num[i];j++){
                scanf("%d %d",&st[i][j][0],&st[i][j][1]);
            }
        }

        for(int i=0;i<155;i++){
            for(int j=0;j<11;j++){
                for(int k=0;k<=m;k++){
                    dp[i][j][k]=INF;
                }
            }
        }

        for(int j=1;j<=num[1];j++){
            for(int k=0;k<=m;k++){
                dp[1][j][k]=0;
            }
        }
        for(int j=1;j<=num[2];j++){
            for(int k=1;k<=m;k++){
                dp[2][j][k]=0;
            }
            for(int y=1;y<=num[1];y++){
                dp[2][j][0]=min(dp[2][j][0],dp[1][y][0]+abs(st[1][y][0]-st[2][j][0])*(st[1][y][1]+st[2][j][1]));
            }
        }

        int ans=INF;

        for(int i=3;i<=n;i++){
            for(int j=1;j<=num[i];j++){
                for(int k=0;k<=m;k++){
                    for(int g=1;g<=num[i-1];g++){
                        dp[i][j][k]=min(dp[i][j][k],dp[i-1][g][k]+abs(st[i][j][0]-st[i-1][g][0])*(st[i][j][1]+st[i-1][g][1]));
                    }
                    if(k!=0){
                        for(int l=1;l<=num[i-2];l++){
                            dp[i][j][k]=min(dp[i][j][k],dp[i-2][l][k-1]+abs(st[i][j][0]-st[i-2][l][0])*(st[i][j][1]+st[i-2][l][1]));
                        }
                    }
                }
            }
        }

        int res=INF;
        for(int j=1;j<=num[n];j++){
            for(int k=0;k<=m;k++){
            res=min(res,dp[n][j][k]);
            }
        }
        for(int j=1;j<=num[n-1];j++){
            for(int k=1;k<m;k++){
            res=min(res,dp[n-1][j][k]);
            }
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 1708
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 998244353;

namespace modexp
{
	const int mod = 998244353;

	constexpr long long p (long long x, long long y)
	{
		long long ans = 1;
		while(y)
		{
			if(y & 1)
				(ans *= x) %= mod;
			(x *= x) %= mod;
			y /= 2;
		}
		return ans;
	}

	constexpr long long inv (const long long x)
	{
		return p (x, mod - 2);
	}
}
using modexp::p;
using modexp::inv;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	ll n, s;
	cin >> n >> s;
	vl v(n);
	cin >> v;
	vl c(3001);
	c[0] = 1;
	rep(i,0,n)
	{
		vl nc = c;
		rep(x,0,3001)
			nc[x] *= 2, nc[x] %= 998244353;
		// rep(i,0,20)
		// 	cerr << nc[i] << ' ';
		// cerr << '\n';
		rep(x,0,3001)
			if(v[i] + x <= 3000)
				(nc[v[i] + x] += c[x]) %= 998244353;
		c = nc;
		// rep(i,0,20)
		// 	cerr << c[i] << ' ';
		// cerr << '\n';
	}
	// rep(i,0,20)
	// 	cerr << c[i] << ' ';
	// cerr << '\n';
	cout << c[s];
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	printf("%lld\n", (b - a) % 2 == 0 ? (b - a) / 2 : min(a + (b - a - 1) / 2, n - b + 1 + (b - a - 1) / 2));
	return 0;
}

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

int A[200005];

int main() {
    int n, k, p;
    cin >> n >> k;
    for (int i= 0; i < n; ++i) {
      cin >> p;
      A[i] = p + 1;
    }
    int s = 0, maxs;
    for (int i= 0; i < k; ++i) s += A[i];
    maxs = s;
    for (int i= 0; i+k < n; ++i) {
      s -= A[i];
      s += A[i+k];
      maxs = max(maxs, s);
    }
    double ans = double(maxs) / 2;
    printf("%.10f\n", ans);
    return 0;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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 put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    set<char> ans;
    rep(i, s.size()) ans.insert(s[i]);

    if( ans.size()%2 != 0 )
    {
        cout << "No" << endl;
    }
    else
    {
        if( ans.find('N') != ans.end() && ans.find('S') != ans.end() )
        {
            cout << "Yes" << endl;
        }
        else if( ans.find('W') != ans.end() && ans.find('E') != ans.end() )
        {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void printTable(vector<vector<char>>);

int main(){
    int H, W;
    cin >> H >> W;
    //まず.と#をvectorへ
    vector<vector<char>> mineTable(H, vector<char>(W)); 
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char a;
            cin >> a;
            mineTable.at(i).at(j) = a;
        }
    }
    //全てのマスについて調べるしかない…？
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int count = 0;
            int row = i - 1;
            int column = j - 1;
            for(int k = 0; k < 3; k++){
                for(int l = 0; l < 3; l++){
                    if(row > -1 && row < H && column > -1 && column < W){
                        
                        if(mineTable.at(row).at(column) == '#'){
                            count++;
                        }
                    }
                    column++;
                }
                row++;
                column -= 3;
            }
            if(mineTable.at(i).at(j) != '#'){
                mineTable.at(i).at(j) = to_string(count).at(0);
            }
        }
    }
    printTable(mineTable);
}

void printTable(vector<vector<char>> mineTable){
    int H = mineTable.size();
    int W = mineTable.at(0).size();
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << mineTable.at(i).at(j);
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
A1 = 1
if 0 in A:
    print(0)
else:    
    for j in range(N):
        A1 *= A[j]
        if A1>10**18:
            print(-1)
            break
    else:
        print(A1)

Measured memory_bytes: 21552
import itertools
def main():
  A, B, C, D, E, F = map(int, input().split())
  water = [100*A*(i)+100*B*(j) for i in range(31) for j in range(31-i)]
  water = set(water)
  sugar_max = int(F*(E/(100+E)))
  sugar = [C*i + D*j for i in range(sugar_max//C+10) for j in range((sugar_max-C*i)//D+10)]
  sugar = set(sugar)
  ans = [0, 0]
  max_den = 0
  for p in itertools.product(water, sugar):
    if p[0] == 0 and p[1] == 0:continue
    if max_den <= p[1]/(p[0]+p[1]) <= E/(100+E) and p[0] + p[1] <= F:
      max_den = p[1]/(p[0]+p[1])
      ans[0] = p[0] + p[1]
      ans[1] = p[1]
  print(*ans)
if __name__ == "__main__":
  main()


Measured memory_bytes: 5296
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

m = {0 => 1}

sum = 0
n.times do |i|
  sum += a[i]
  m[sum] = m[sum].nil? ? 1 : m[sum] + 1
end

res = 0 
m.each do |_k, v|
  next if v < 2 
  # 組み合わせ?
  res += v * (v - 1) / 2
end
puts res


Measured memory_bytes: 31108
#include <stdio.h>
#include <math.h>
#include <unistd.h>
int isprime(int x){
	int i;
	if(x==2){
		return 1;
	}
	if(x<2||x%2==0){
		
		
		return 0;
		
	}
	i=3;
	while(i<=sqrt(x)){
		if(x%i==0){
			
			return 0;
			
		}
		i=i+2;
		
		
		
	}
	return 1;
	
	
	
	
}
int main(void)
{
	int n;
	int x[10000];
	int a=0;
	int i;
	int c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
		
	}
	for(i=0;i<n;i++){
	c=isprime(x[i]);
	if(c==1){
		a++;
		
	}
	}
	printf("%d\n",a);
	
	return 0;
}


Measured memory_bytes: 2076
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> p(n),q(n);

  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  for(int i=0;i<n;i++){
    cin>>q[i];
  }
  vector<int> a(n);
  for(int i=0;i<n;i++){
    a[i]=i+1;
  }
  map<vector<int>, int> mp;
  do{
    mp[a]=mp.size();
  }while(next_permutation(a.begin(),a.end()));
  
  int ans=abs(mp[p]-mp[q]);
  cout<<ans<<endl;
  return 0;
}
    
    
    
  
  
  
  
  
  
  
  
  
  
  


Measured memory_bytes: 5248
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayDeque;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * The Java template file for AtCoder online judge.
 */
public class Main {

  private static FastScanner scanner;
  private static PrintWriter printer;

  public static void solve() {
    int n = scanner.nextInt();
    int k = scanner.nextInt();
    int[] candies = new int[n];
    for (int i = 0; i < n; i++) {
      candies[i] = scanner.nextInt();
    }
    long mod = (long)1e9 + 7;
    long[] dp = new long[k + 1];
    dp[0] = 1L;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= k; j++) {
        dp[j] += dp[j - 1];
        if (dp[j] >= mod) {
          dp[j] -= mod;
        }
      }
      for (int j = k; j >= 0; j--) {
        if (j > candies[i]) {
          dp[j] -= dp[j - candies[i] - 1];
          if (dp[j] < 0) {
            dp[j] += mod;
          }
        }
      }
      // for (int j = k; j >= 0; j--) {
      //   for (int c = 1; c <= candies[i]; c++) {
      //     dp[j] += j - c >= 0 ? dp[j - c] : 0L;
      //   }
      // }
    }
    printer.println(dp[k]);
  }

  public static void main(String[] args) {
    scanner = new FastScanner();
    printer = new PrintWriter(System.out);
    solve();
    printer.flush();
  }

  private static class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(Reader in) {
      br = new BufferedReader(in);
    }

    public FastScanner() {
      this(new InputStreamReader(System.in));
    }

    public String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }

    public int[] readIntArray(int size) {
      int[] ret = new int[size];
      for (int i = 0; i < size; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }
}


Measured memory_bytes: 23380
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int count = 0;
  for (int i = 0; i + 2 < n; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ++count;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
A, B, C = [input() for _ in range(3)]

x = A[0]
cnt_a = 0
cnt_b = 0
cnt_c = 0
for _ in range(len(A)+len(B)+len(C)):
    if x == "a":
        if cnt_a < len(A):
            x = A[cnt_a]
            cnt_a += 1
        else:
            print("A")
            break
    elif x == "b":
        if cnt_b < len(B):
            x = B[cnt_b]
            cnt_b += 1
        else:
            print("B")
            break
    else:
        if cnt_c < len(C):
            x = C[cnt_c]
            cnt_c += 1
        else:
            print("C")
            break


Measured memory_bytes: 3064
while 1:
    N = int(input())
    if N  == 0: break
    ids = [set(list(input().split()[1:])) for _ in range(N)]
    target =set(input().split()[1:])
    ans =[]
    for i in range(N):
        if target <= ids[i]:ans.append(i+1)
    print(ans[0] if len(ans) ==1 else -1)


Measured memory_bytes: 7900
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
  int W, H;
  cin >> W >> H;
  vector<long> p(W), q(H);

  for(int i = 0; i < W; i++) cin >> p[i];
  for(int i = 0; i < H; i++) cin >> q[i];

  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  p.push_back(1000000000);
  q.push_back(1000000000);

  int i = 0, j = 0, p_rest = H+1, q_rest = W+1;
  long long sum = 0;
  while(i != W || j != H) {

    if(p[i] <= q[j]) {
      sum += (long)p[i]*p_rest;
      q_rest--;
      i++;
    } else {
      sum += (long)q[j]*q_rest;
      p_rest--;
      j++;
    }
  }

  cout << sum << endl;


  return 0;
}



Measured memory_bytes: 2688
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(i%2==0)
		{
			if(s[i]!='R' && s[i]!='U' && s[i]!='D')
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else
		{
			if(s[i]!='L' && s[i]!='U' && s[i]!='D')
			{
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";

	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



Measured memory_bytes: 256