akhauriyash/Code-Regression huggingface dataset:
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int n=s.length(),m=t.length(),len=0,row=0,col=0;
		int dp[][]=new int[n+1][m+1];
		for(int i=1;i<=n;i++){
		    for(int j=1;j<=m;j++){
		        if(s.charAt(i-1)==t.charAt(j-1)){
		            dp[i][j]=1+dp[i-1][j-1];
		            if(len<dp[i][j]){
		                len=dp[i][j];
		                row=i;col=j;
		            }
		        }
		        else{
		            dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
		        }
		    }
		}
		if(len==0) {System.out.println("");return;}
		int i=n,j=m;
		String ans="";
		while(i>0&&j>0){
		    if(s.charAt(i-1)==t.charAt(j-1)){
		        ans=s.charAt(i-1)+ans;i--;j--;
		    }else if(dp[i-1][j]>dp[i][j-1]) i--;
		    else j--;
		}
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 88468
#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

int main() {
	//input
	int N, M;
	cin >> N >> M;

	dsu d(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
        A--;
        B--;
		d.merge(A, B);
	}

	//calculation
	vector<vector<int>> g = d.groups();
	int out = g.size() - 1;
	cout << out << endl;

	return 0;
}


Measured memory_bytes: 9108
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<time.h>
#include<list>
#include<random>
#include<bitset>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;



int main() {
    int inp;
    cin >> inp;
    int d = inp % 10;
    inp /= 10;
    int c = inp % 10;
    inp /= 10;
    int b = inp % 10;
    inp /= 10;
    int a = inp % 10;

    ull f = 0;
    for (; f < 8; ++f) {
        int sum = a;
        sum += b * (((f & 1) == 1) ? 1 : -1);
        sum += c * ((((f >> 1) & 1) == 1) ? 1 : -1);
        sum += d * ((((f >> 2) & 1) == 1) ? 1 : -1);

        if (sum == 7) break;
    }

    bool pl[3];
    pl[0] = (f & 1) == 1;
    pl[1] = ((f >> 1) & 1) == 1;
    pl[2] = ((f >> 2) & 1) == 1;
    cout << a;
    cout << (pl[0] ? "+" : "-");
    cout << b;
    cout << (pl[1] ? "+" : "-");
    cout << c;
    cout << (pl[2] ? "+" : "-");
    cout << d;
    cout << "=7" << endl;
    return 0;
}

Measured memory_bytes: 256
/* Work 3_2
 * AtCoder ∴
 * cy_an */

#include <stdio.h>

int main(void){
    int n, n1;       // 変数宣言,nの1の位をn1
    scanf("%d", &n); // nを入力
    n1 = n % 10;

    switch(n1){
        case 2 :
        case 4 :
        case 5 :
        case 7 :
        case 9 : printf("hon\n"); break; // 2, 4, 5, 7, 9のとき"hon"を出力
        case 0 :
        case 1 :
        case 6 :
        case 8 : printf("pon\n"); break; // 0, 1, 6, 8のとき"pon"を出力
        case 3 : printf("bon\n"); break; // 3のとき"bon"を出力
    }
    return 0;
}

Measured memory_bytes: 1620
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int ans = K;
    for (int i = 1; i < N; i++) ans *= (K - 1);
    System.out.println(ans);
  }
}


Measured memory_bytes: 21716
h,w=map(int,input().split())
n=int(input())
b=list(map(int,input().split()))
a=[]
for i in range(n):
  for j in range(b[i]):
    a.append(i+1)
g=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
  if i%2==0:
    for j in range(w):
      g[i][j]=a[0]
      a.remove(a[0])
  else:  
    for j in range(w):
      g[i][w-j-1]=a[0]
      a.remove(a[0])
for i in range(h):
  print(*g[i])

Measured memory_bytes: 3920
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

H,W,K = LI()
x1,y1,x2,y2 = LI()
c = [list(map(str,input())) for _ in range(H)]

def grid_bfs(S,s,default=-1):
    dist = [[default]*W for _ in range(H)]
    can_visit_mark = ['.']
    d = [(0,1),(0,-1),(1,0),(-1,0)]
    dist[s[0]][s[1]] = 0
    q = [s]
    counter = 1
    while q:
        q1 = []
        for now in q:
            for delta in d:
                for i in range(1,K+1):
                    new = (now[0]+i*delta[0], now[1]+i*delta[1])
                    if 0 <= new[0] <= H-1 and 0 <= new[1] <= W-1:
                        if S[new[0]][new[1]] in can_visit_mark:  
                            if dist[new[0]][new[1]] == default:
                                dist[new[0]][new[1]] = counter
                                q1.append(new)
                            elif dist[now[0]][now[1]] < dist[new[0]][new[1]]:
                                continue
                            else:
                                break
                        else:
                            break
                    else:
                        break
        if dist[x2-1][y2-1] != default:
            return dist[x2-1][y2-1]
        q = q1
        counter += 1
    return -1

print(grid_bfs(c,(x1-1,y1-1)))

Measured memory_bytes: 153920
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int M = 1e9 + 7;

int add(int a, int b) {
  int c = a + b;
  if (c < 0) c += M;
  if (c >= M) c -= M;
  return c;
}

int mul(int a, int b) {
  return (a * (ll) b) % M;
}

int pw(int a, int n) {
  int res = 1;
  while (n) {
    if (n % 2 == 0) {
      a = mul(a, a);
      n /= 2;
    } else {
      res = mul(res, a);
      n--;
    }
  }
  return res;
}

int inv(int x) {
  return pw(x, M - 2);
}

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> a(n);
  vector <ll> pref;
  ll s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    pref.push_back(s);
  }
  vector <int> cur(n + 1);
  cur[0] = inv(0);
  for (int i= 1; i <= n; i++) {
    cur[i] = inv(i);
    cur[i] = add(cur[i], cur[i - 1]);
  }
  auto sm = [&] (int l, int r) {
    return add(cur[r], -cur[l - 1]);
  };
  int x = 0;
  for (int i = 0; i < n; i++) {
    int ok = add(sm(1, i + 1), sm(1, n - i));
    ok = add(ok, -1);
    x = add(x, mul(ok, a[i]));
  }
  int ret = 1;
  for (int i = 1; i <= n; i++)ret=mul(ret,i);
  cout << mul(x, ret) << endl;
}


Measured memory_bytes: 1784
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int i1 = Character.getNumericValue(s.charAt(0));
        int i2 = Character.getNumericValue(s.charAt(1));

        if(i1 == 9 || i2 == 9){
            System.out.print("Yes");
        }else {
            System.out.print("No");
        }
    }
}

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

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int main() {
    int n,k,q; cin>>n>>k>>q;
    ll a[n];
    rep(i,n)a[i]=0;

    int tmp;
    rep(i,q){
        cin>>tmp;
        --tmp;
        ++a[tmp];
    }
    
    rep(i,n){
        if(q - a[i] <k)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  vector<int> r;
  vector<int> g;
  vector<int> b;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      r.push_back(i);
    }
    if (s[i] == 'G') {
      g.push_back(i);
    }
    if (s[i] == 'B') {
      b.push_back(i);
    }
  }
  ll count = r.size() * g.size() * b.size();
  char j;
  for (int i = 0; i < n-2; i++) {
    char o = s[i];
    for (int j = i+1; j < n-1; j++) {
      char t = s[j];
      if (o != t) {
        if (o == 'R' || t == 'R') {
          if (o == 'G' || t == 'G') {
            //j = 'b';
            auto itr = find(b.begin(), b.end(), (2*j-i));
            if (itr != b.end()) {
              count--;
            }
          }
          else {
            auto itr = find(g.begin(), g.end(), (2*j-i));
            if (itr != g.end()) {
              count--;
            }
          }
        }
        else {
          //j = 'r';
            auto itr = find(r.begin(), r.end(), (2*j-i));
            if (itr != r.end()) {
              count--;
            }
        }
      }
    }
  }
  cout << count << '\n';
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int h, w;
	cin >> h >> w;
	
	int a[h][w], m=0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> a[i][j];
		}
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			int b;
			cin >> b;
			a[i][j]=abs(a[i][j]-b);
			m=max(m, a[i][j]);
		}
	}
	
	const int MAX=(h+w)*m+1;
	bool b[h][w][MAX];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			for(int k=0; k<MAX; k++){
				b[i][j][k]=false;
			}
		}
	}

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(i==0 && j==0) b[i][j][a[i][j]]=true;
			else{
				for(int k=0; k<MAX; k++){
					if(i>0 && b[i-1][j][k]){
						if(k+a[i][j]<MAX) b[i][j][k+a[i][j]]=true;
						b[i][j][abs(k-a[i][j])]=true;
					}
					if(j>0 && b[i][j-1][k]){
						if(k+a[i][j]<MAX) b[i][j][k+a[i][j]]=true;
						b[i][j][abs(k-a[i][j])]=true;
					}
				}
			}
		}
	}

	for(int i=0; i<MAX; i++){
		if(b[h-1][w-1][i]){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
int main() {
  long long N;
  vector <long long> A(5);
  cin >> N;
  long long m = 1e18;
  for (int i = 0; i < 5; i++) {
	  cin >> A[i];
	  m = min(A[i], m);
	}
  cout << (long long) ceil((double) N / m) + 4 << endl;
  return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

count = 0
for i in range(N):
    A = list(map(int, input().split()))
    AB_sum = 0
    for j in range(M):
        AB_sum += A[j] * B[j]
    if AB_sum + C > 0:
        count += 1

print(count)

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;




int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif

    int n , a , b;
    cin >> n >> a >> b;
    if(abs(a-b) % 2 == 0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef vector<Int> vInt;
typedef pair<int,int> pint;
typedef pair<Int,Int> pInt;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef vector<pInt> vpInt;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,1,-1,-1,0};
const int dy[]={0,0,1,-1,1,-1,1,-1,0};

vpInt d;

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

pInt gcd(pInt a, pInt b) {
//cout << a.first << " " << a.second << " " << b.first << " " << b.second << endl;
	if (b.first == 0) return a;
	Int n = (a.first * b.second) / (b.first * a.second);
//cout << (a.first * b.second) << " " << (b.first * a.second) << " " << n << endl;
	pInt p;
	p.first = a.first * b.second - b.first * a.second * n;
	p.second = a.second * b.second;
	Int g = gcd(p.first, p.second);
	p.first /= g;
	p.second /= g;
	return gcd(b, p);
}

int main() {
	int n;
	IL {
		cin >> n;
		if (n == 0) break;
		d.clear();
		rep (i, n) {
			int dd, vv;
			cin >> dd >> vv;
			d.PB(MP(dd, vv));
		}
		pInt g, l = d[0];
		repn (i, 1, n) {
			g = gcd(l, d[i]);
			l.first = l.first * d[i].first * g.second;
			l.second = l.second * d[i].second * g.first;
			Int gg = gcd(l.first, l.second);
			l.first /= gg;
			l.second /= gg;
		}
		rep (i, n) {
			cout << l.first * d[i].second / d[i].first / l.second << endl;
		}
	}
	return 0;
}

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

#define int long long   
#define PB push_back 
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int> 
#define vii vector< ii >
#define F first
#define S second 
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
double pi= 3.14159265358979;
const int N=2e5+5;

void solve()
{   
	string s; cin>>s;
	//string t=s;
	rep(i, 0, sz(s)){
		if(s[i] == '?') cout<<"D";
		else cout<<s[i];
	}
}

signed main() 
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   // cout<<setprecision(6);
    int tc=1; //cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3776
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

const long mod = 1000000000 + 7;

long solve(long n, long k)
{
  long result = 0;
  for (int i = k; i <= n + 1; ++i) {
    auto d = (i * (n - i + 1)) % mod;
    result += d + 1;
    result %= mod;
  }
  return result;
}

int main()
{
  long n, k;
  std::cin >> n >> k;

  std::cout << std::setprecision(20);
  std::cout << solve(n, k) << std::endl;
}


Measured memory_bytes: 3196
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 20;

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

vector<pair<int,int> > v[NMAX];

int countBits(int x)
{
	if(x == 0) return 0;
	return countBits(x>>1) + (x & 1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
		int ai;
		cin >> ai;
		for(int j =0; j < ai; ++j)
		{
			int x,y;
			cin >> x >> y;
			x--;
			v[i].push_back({x,y});
		}
    }
	int sol = 0;
	for(int i = 0; i < (1 << n); ++i)
	{
		vector<int> isTrue(n+1,0);
		bool ok = true;
		for(int j= 0; j < n; ++j)
		{
			if(i & (1 << j))
			{
				for(int k = 0; k < (int) v[j].size(); ++k)
				{
					if(((i >> v[j][k].first) & 1) ^ v[j][k].second)
						ok = false;
					
				}
			}
			if(!ok)
				break;
		}
		if(ok)
			sol = max(sol, countBits(i));
	}
	cout << sol << '\n';



    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val X = sc.next().toInt()
        val Y = sc.next().toInt()
        val b = (Y - 2 * X) / 2
        val a = (4 * X - Y) / 2
        pw.println(if (a >= 0 && b >= 0 && 2 * a + 4 * b == Y) "Yes" else "No")
    }
}


Measured memory_bytes: 36404
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> c(n - 1), s(n - 1), f(n - 1);
    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, n)
    {
        int ans = 0;
        rep(j, i, n - 1)
        {
            if (ans < s[j])
            {
                ans = s[j];
            }
            else
            {
                ans = ((ans + f[j] - 1) / f[j]) * f[j];
            }
            ans += c[j];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   
    string s;
    cin >> s;
    ll ans0 = 0, ans1 = 0;
    char t = '0';
    for(ll i=0;i<s.length();i++){
        if(s[i] != t){
            ans0++;
        }
        if(t == '0'){
            t = '1';
        }else{
            t = '0';
        }
    }
    t = '1';
    for (ll i=0;i<s.length();i++){
        if(s[i] != t){
            ans1++;
        }
        if(t == '0'){
            t = '1';
        }else{
            t = '0';
        }
    }
    cout << min(ans0, ans1) << endl;

}

Measured memory_bytes: 512
/*author:anshumanc007
   created on:08/01/2019
            */
//EMBRACE THE STRUGGLE!!!
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;


//typedef pair<long long int,long long int> pa;
#define MAX 100005
long long int MOD=1e9+7;
long long int INF=1e18;
stack<long long int> st;
bool visited[MAX];
long long int dp[MAX];
void dfs(vector<long long int >adj[],long long int i)
{
    visited[i]=true;
    long long int j;
    for(auto j:adj[i])
    {
        if(!visited[j])
        dfs(adj,j);
    }
    st.push(i);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,q,r,x,y,a,b,mini=INF,maxi=0,cnt=0,W,ans;
    cin>>n>>m;
    vector<long long int>adj[n];
    vector<long long int>adj1[n];
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        x--;
        y--;
        adj[x].push_back(y);
        adj1[y].push_back(x);
    }
    for(i=0;i<n;i++)
    {
        visited[i]=false;
        dp[i]=0;
    }
    for(i=0;i<n;i++)
    {
        if(!visited[i])
        {
            dfs(adj,i);
        }
    }
    vector<long long int>V;
    while(!st.empty())
    {
        j=st.top();
        st.pop();
        V.push_back(j);
    }
    
  for(j=V.size()-1;j>=0;j--)
{
      i=V[j];
    //  st.pop();
      for(auto k:adj1[i])
      {
          dp[k]=max(dp[k],dp[i]+1);
          if(dp[k]>maxi)
          {
              maxi=dp[k];
          }
      }
  }
    cout<<maxi;
    
    

    
}

Measured memory_bytes: 15928
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(void)
{
    int x,y;
    int group[12] = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0}; 
    cin >> x >> y;

    if(group[x-1] == group[y-1])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int n, a[100005], cnt1[100005], cnt2[100005];
struct node {
	int v, tot;
	bool operator < (const node rhs) {
		return tot > rhs.tot;
	}
} q1[100005], q2[100005];
int main() {
	std::scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		std::scanf("%d", &a[i]);
		if (i & 1) cnt1[a[i]]++; else cnt2[a[i]]++;
	}
	for (int i = 1; i <= 100000; i++) q1[i] = (node) { i, cnt1[i] }, q2[i] = (node) { i, cnt2[i]};
	std::sort(q1 + 1, q1 + 100001); std::sort(q2 + 1, q2 + 100001);
	if (q1[1].v != q2[1].v) std::printf("%d\n", n - q1[1].tot - q2[1].tot);
	else std::printf("%d\n", n - std::max(q1[1].tot + q2[2].tot, q1[2].tot + q2[1].tot));
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,l;
    char a[1000];
    cin>>a;
    l=strlen(a);
    if(a[2]==a[3]&&a[4]==a[5])
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
int a[200100],nx[1000100],q[1001000],qt[1001000],v[1001000];
bool is[1001000];
#define nw(xx) (x+(xx-l)*inv)
int main()
{
	for(re int i=1;i<=1e6;i++)q[i]=qt[i]=i;
	re int n,Q,l=1,r=1e6,inv=1,x=1,x1=1e6,a0=0,p0=1;
	scanf("%d",&n);
	for(re int i=1;i<n;i++)scanf("%d",&a[i]);
	for(re int i=n-1;i>=3;i--)
	{
		a0-=a[i];
		if(a0<0)a0=-a0,p0=-p0;
		else if(a0==0&&p0<0)p0=-p0;
		if(l>a[i])l-=a[i],r-=a[i];
		else
		{
			if(r<a[i])std::swap(x,x1),inv=-inv,l=a[i]-l,r=a[i]-r,std::swap(l,r);
			else
			{
				re int qw=nw(a[i]),qw1;
				for(re int i1=q[qw];i1;i1=nx[i1])is[i1]=1;
				q[qw]=qt[qw]=0;
				if(a[i]*2<=l+r)
				{
					for(re int i1=l;i1<a[i];i1++)
					{
						qw=nw(i1),qw1=nw(a[i]*2-i1);
						nx[qt[qw1]]=q[qw];qt[qw1]=qt[qw];
						q[qw]=qt[qw]=0;
					}
					x=nw(a[i]+1);x1=nw(r);
				}else
				{
					for(re int i1=r;i1>a[i];i1--)
					{
						qw=nw(i1),qw1=nw(a[i]*2-i1);
						nx[qt[qw1]]=q[qw];qt[qw1]=qt[qw];
						q[qw]=qt[qw]=0;
					}
					x=nw(a[i]-1);x1=nw(l);inv=-inv;
				}
				r=std::max(a[i]-l,r-a[i]);l=1;
			}
		}
	}
	scanf("%d",&Q);
	v[0]=a0+a[1]-a[2];
	for(re int i=1;i<=1e6;i++){v[i]=v[i-1]+p0;if(is[i])p0=-p0;}
	for(;Q--;)
	{
		scanf("%d",&x);
		if(x>1e6)printf("%d\n",(x-(int)1e6)+v[(int)1e6]);
		else printf("%d\n",v[x]);
	}
}

Measured memory_bytes: 19584
#include<bits/stdc++.h>
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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int n; cin >> n;
  pair<pair<string, int>, int> p[n];
  for (int i = 0; i < n; i++)
  {
    string s;
    int num;
    cin >> s >> num;
    p[i] = make_pair(make_pair(s, -num), i);
  }
  
  sort(p, p + n);
  for (int i = 0; i < n; i++) cout << p[i].second + 1 << endl;
}


Measured memory_bytes: 256
n=int(input())
d={}
for i in range(n):
    tmp = input()
    if tmp in d:
        d[tmp]+=1
    else:
        d[tmp]=1
max_k_list=[]
max_d = max(d.values())
for k,v in d.items():
    if v == max_d:
        max_k_list.append(k)
max_k_list.sort()
for i in max_k_list:
    print(i)
    

Measured memory_bytes: 92760
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

const int N = 111111;
vector<int> tree[N];
int n;

int dfs(int node, int p = 0) {
    int ans = 0;
    for(nnode : tree[node]) {
        if(nnode != p) {
            ans ^= dfs(nnode, node);
        }
    }
    return ans + 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    cout << (dfs(1) - 1 ? "Alice" : "Bob") << endl;
    return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
using P = pair<int, int>;

template< typename Monoid >
struct SegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree() {}
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }

  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const
  {
    return seg[k];
  }
};

P INF = P(1e9, 1e9);
int N;
vector<int> A;
SegmentTree< P > odd(300000, [](P a, P b) { return min(a, b); }, INF);
SegmentTree< P > evn(300000, [](P a, P b) { return min(a, b); }, INF);

set<P> ans;

map<P, vector<P> > graph;
map<P, P> val;
void dfs(int l, int r) {
  if ( r - l <= 1 ) return;
  if ( l%2 ) {
    P p = odd.query(l, r);
    P q = evn.query(p.second+1, r);
    int ll = p.second, rr = q.second;
    graph[P(l, r)].push_back(P(l, ll));
    graph[P(l, r)].push_back(P(ll+1, rr));
    graph[P(l, r)].push_back(P(rr+1, r));
    val[P(l, r)] = P(p.first, q.first);
    dfs(l, ll);
    dfs(ll+1, rr);
    dfs(rr+1, r);    
  } else {
    P p = evn.query(l, r);
    P q = odd.query(p.second+1, r);
    int ll = p.second, rr = q.second;
    graph[P(l, r)].push_back(P(l, ll));
    graph[P(l, r)].push_back(P(ll+1, rr));
    graph[P(l, r)].push_back(P(rr+1, r));
    val[P(l, r)] = P(p.first, q.first);
    dfs(l, ll);
    dfs(ll+1, rr);
    dfs(rr+1, r);    
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N;
  A.resize(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
    if ( i%2 ) odd.update(i, P(A[i], i));
    else evn.update(i, P(A[i], i));
  }

  dfs(0, N);
  using Pp = pair<P, P>;  
  priority_queue<Pp, vector<Pp>, greater<Pp> > Q;
  Q.push(Pp(val[P(0, N)], P(0, N)));
  while ( !Q.empty() ) {
    P v = Q.top().first;
    P p = Q.top().second;
    Q.pop();

    if ( p.second-p.first <= 1 ) continue;

    cout << v.first << " " << v.second << " ";
    for ( P nxt: graph[p] ) {
      P pval = val[nxt];      
      Q.push(Pp(pval, nxt));
    }
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 101632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rep1(i,n) for(int i=1; (i)<(n); ++(i))
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; }
const long long llINF = 1LL<<60;
const int INF = 1e9;
int main(){
    int n,ans=0;  cin >> n;
    
    rep1(i,n+1) if(i%2==1)ans++;
    cout << (double)ans/(double)n;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree = 
//  tree<key, val, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;

int n, m, k;
int a[N], b[N];

void solve(int test)
{
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  priority_queue<int64> q;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    if (a[i] - b[i] > 0)
      q.push(a[i] - b[i]);
  }
  int ans = 0;
  int c = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] - b[i] < 0) {
      ++ans;
      while (b[i] - a[i] > c) {
        if (q.empty()) {
          cout << "-1\n";
          return;
        }
        c += q.top();
        q.pop();
        ++ans;
      }
      c -= b[i] - a[i];
    }
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
      solve(i);
  //cerr << endl << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count();
  return 0;
}


Measured memory_bytes: 1532
import java.util.Scanner;

//Goofy Converter
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			int[] a = new int[n];
			for(int i=0;i<n;i++)a[i]=sc.nextInt();
			String res = "Goofy";
			for(int S=0;S<1<<m;S++){
				StringBuilder sb = new StringBuilder();
				int s = 0, h = 0;
				boolean f = true;
				for(int k=0;k<m;k++){
					sb.append((S>>k)&1);
					if(((S>>k)&1)>0)s++;
				}
				if(s!=a[0])continue;
				for(int i=1;i<n&&f;i++){
					if(sb.charAt(h++)=='1')s--;
					if(a[i]==s)sb.append("0");
					else if(s+1==a[i]){
						sb.append("1"); s++;
					}
					else f=false;
				}
				if(f){
					res = sb.toString(); break;
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using LL=long long;
using Point=pair<int,int>;
const int MX=4005,mod=1000000007;
#define st first
#define nd second

int N,ans,fac[MX<<1],inv[MX<<1];
int Pool[MX][MX],*f[MX],**dp;
Point P[200005];

inline int read()
{
    int x=0,c=getchar();
    while(!isdigit(c))c=getchar();
    while(isdigit(c))x=x*10+c-'0',c=getchar();
    return x;
}
inline void update(int& a,int b){((a+=b)>=mod)&&(a-=mod);}
int Inv(int u){return u==1?1:LL(mod-mod/u)*Inv(mod%u)%mod;}
inline int C(int n,int m){return (LL)fac[n]*inv[m]%mod*inv[n-m]%mod;}

int main()
{
    N=read();
    for(int i=0;i<MX;i++)f[i]=Pool[i]+2002;
    dp=f+2002;
    fac[0]=1;
    for(int i=1;i<=8000;i++)fac[i]=(LL)fac[i-1]*i%mod;
    inv[8000]=Inv(fac[8000]);
    for(int i=8000;i;i--)inv[i-1]=(LL)inv[i]*i%mod;
    for(int i=1,x,y;i<=N;i++)
        x=read(),y=read(),dp[-x][-y]+=1,P[i]=make_pair(x,y);
    for(int i=-1999;i<=2000;i++)update(dp[-2000][i],dp[-2000][i-1]);
    for(int i=-1999;i<=2000;i++)update(dp[i][-2000],dp[i-1][-2000]);
    for(int i=-1999;i<=2000;i++)for(int j=-1999;j<=2000;j++)
        update(dp[i][j],dp[i-1][j]),update(dp[i][j],dp[i][j-1]);
    for(int i=1;i<=N;i++)update(ans,dp[P[i].st][P[i].nd]);
    for(int i=1;i<=N;i++)update(ans,mod-C((P[i].st+P[i].nd)*2,P[i].st*2));
    printf("%lld\n",(LL)ans*Inv(2)%mod);
    return 0;
}


Measured memory_bytes: 64512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n)
    cin >> a.at(i);
  sort(all(a));
  int ans=0;
  rep(i,k)
    ans+=a.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3568
integer N
integer,allocatable,dimension(:)::C,S,F
integer T
read*,N
allocate(C(N),S(N),F(N))
do i=1,N-1
  read*,C(i),S(i),F(i)
end do

do i=1,N
  T=0
  do j=i,N-1
    if(T<=S(j))then
      T=S(j)
    else if(mod(T,F(j))/=0)then
      T=T+F(j)-mod(T,F(j))
    endif
    T=T+C(j)
  end do
  print"(i0)",T
end do
end

Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True
#for i in range(n):

ans=0

n,t,a=LI_()
n+=1
g,c=GI(n,n-1)

#for i in range(1,30):


#vにはdepthをセット & -1 で未訪問フラグ



def bfs(x):  # x スタート
    v=[-1]*(n)
    p=deque()
    p.append(x)
    v[x]=0
    while p:
        c=p.popleft()
        for i in g[c]:
            if v[i]==-1:
                p.append(i)
                v[i]=v[c]+1
    return v



v=bfs(a)
w=bfs(t)
ans=0
for i in range(n):
    if v[i]>=w[i] and max([v[j] for j in g[i]])>v[i]:
        ans=max(ans,v[i])
#print(max(0,ans-1))
print(ans)

Measured memory_bytes: 81084
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;
using vi = vector<int>;

int const MAXN=110000;

vi pneg(const vi &p) {
	vi P(sz(p));
	rep(i,0,sz(p)) P[p[i]]=i;
	return P;
}

void pmul(const vi &p,const vi &q,vi &res) {
	static int tmp[MAXN];
	rep(i,0,sz(p)) tmp[i]=p[q[i]];
	rep(i,0,sz(p)) res[i]=tmp[i];
}

vi ppow(vi p,int n) {
	vi res(sz(p));
	rep(i,0,sz(p)) res[i]=i;
	while (n>0) {
		if (n%2) pmul(res,p,res);
		pmul(p,p,p);
		n/=2;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,K;
	cin>>N>>K;
	K--;
	
	vi p(N),q(N);
	rep(i,0,N) {
		cin>>p[i];
		p[i]--;
	}
	rep(i,0,N) {
		cin>>q[i];
		q[i]--;
	}
	
	vi P=pneg(p);
	vi Q=pneg(q);
	
	// a=qPQp
	vi a(N);
	pmul(q,P,a);
	pmul(a,Q,a);
	pmul(a,p,a);
	
	// a=a^(K/6)
	a=ppow(a,K/6);
	
	vi b(N);
	switch (K%6) {
		case 0:
			b=p;
			break;
		case 1:
			b=q;
			break;
		case 2:
			// b=qP
			pmul(q,P,b);
			break;
		case 3:
			// b=qPQ
			pmul(q,P,b);
			pmul(b,Q,b);
			break;
		case 4:
			// b=qPQpQ
			pmul(q,P,b);
			pmul(b,Q,b);
			pmul(b,p,b);
			pmul(b,Q,b);
			break;
		case 5:
			// b=qPQppQ
			pmul(q,P,b);
			pmul(b,Q,b);
			pmul(b,p,b);
			pmul(b,p,b);
			pmul(b,Q,b);
			break;
		default:
			assert(false);
	}
	
	vi res(N);
	pmul(a,b,res);
	pmul(res,pneg(a),res);
	
	rep(i,0,N) cout<<res[i]+1<<" \n"[i+1==N];
}


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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

// fn dfs(unused: &[usize], used: &[usize], target: &[usize], count: usize) -> usize {
//     if target == used {
//         return count;
//     }
//     for i in 0..unused.len() {
//         dfs(unused.iter().enumerate().filter(|&(j,v)| j != i).map(|&(j,v) v).collect(), )
//     }

// }

fn next_permutation<T: Ord>(v: &mut [T]) -> bool {
    let mut i = v.len() - 1;
    while i > 0 && v[i-1] > v[i] {
        i -= 1;
    }

    if i == 0 {
        v.reverse();
        return false;
    }
    i -= 1;
    let mut j = v.len() - 1;
    while j > i && v[i] > v[j] {
        j -= 1;
    }
    v.swap(i,j);
    v[i + 1..].reverse();
    true
}

fn main() {
    let n = read::<usize>();
    let p = read_vec::<usize>();
    let q = read_vec::<usize>();

    let mut v = vec![];
    for i in 1..n+1 {
        v.push(i);
    }
    let mut p_count: i64 = 0;
    let mut q_count: i64 = 0;

    let mut count: i64 = 1;
    loop {
        if p == v {
            p_count = count;
        }
        if q == v {
            q_count = count;
        }

        count += 1;
        if !next_permutation(&mut v) {
            break;
        }
    }

    println!("{}", (p_count- q_count).abs());

}

Measured memory_bytes: 4352
using System;
using System.Linq;

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var aM = a.Max();
		if (aM == 1) { Console.WriteLine(n); return; }

		var ps = PrimesF(2, aM);
		var cs = new int[aM + 1];
		var a2 = (int[])a.Clone();

		for (int i = 0; i < n; i++)
		{
			foreach (var p in ps)
			{
				if (p > 1000) break;
				if (a2[i] == 1) break;
				var c = 0;
				for (; a2[i] % p == 0; c++) a2[i] /= p;
				if (c > cs[p]) cs[p] = c;
			}
			if (a2[i] > 1) cs[a2[i]] = 1;
		}

		var lcm = ps.Where(p => cs[p] > 0).Select(p => ((MInt)p).Pow(cs[p])).Aggregate((x, y) => x * y);
		Console.WriteLine(a.Select(x => lcm / x).Aggregate((x, y) => x + y).V);
	}

	static int[] PrimesF(int m, int M)
	{
		var b = PrimeFlags(M);
		return Enumerable.Range(m, M - m + 1).Where(i => b[i]).ToArray();
	}
	static bool[] PrimeFlags(int M)
	{
		var rM = (int)Math.Sqrt(M);
		var b = new bool[M + 1]; b[2] = true;
		for (int i = 3; i <= M; i += 2) b[i] = true;
		for (int p = 3; p <= rM; p++) if (b[p]) for (var i = p * p; i <= M; i += 2 * p) b[i] = false;
		return b;
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 20064
#include <bits/stdc++.h>
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R) >> 1)
using namespace std;
typedef long long LL;
const int N = 100500;
const int mod = 1e9 + 7;
int a[N], b[N], n;
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int m = 1;
	b[m - 1] = 1;
	for (int i = 1; i < n; ++i) {
		if (a[i] != a[i - 1]) {
			if (b[m - 1] == 1) {
				a[m - 1] = a[i];
				b[m - 1] = 0;
			} else {
				a[m++] = a[i];
			}
		}
		b[m - 1]++;
	}
	if (b[m - 1] == 1) m--;
	long long ans = 0;
	for (int i = m - 1; i >= 0; --i) {
		if (b[i] > 4) {
			ans = max(ans, 1LL * a[i] * a[i]);
		}
	}
	if (m > 1) {
		ans = max(ans, 1LL * a[m - 1] * a[m - 2]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main{
    public static void main (String[] args){
        Scanner sc = new Scanner (System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int z = 0;
        if(a<b){
            if(b<c){
                System.out.printf("%d %d %d\n",a,b,c);
            }
            else if(a<c){
                z=a;a=b;b=z;
                System.out.printf("%d %d %d\n",a,b,c);
            }
            else{
                z=b;b=c;c=z;
                System.out.printf("%d %d %d\n",a,b,c);
            }
            
        }else{
            z=a;a=c;c=z;
            if(a>b){
            z=a;a=b;b=z;
            }
            System.out.printf("%d %d %d\n",a,b,c);
        }
            
        sc.close();
    }
    }


Measured memory_bytes: 26220
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int s,w;
	cin>>s>>w;
	if(w>=s) cout<<"unsafe";
	else cout<<"safe";
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

int main(){
  string A,B,C ;
  cin >> A >> B >> C;

  if (A[A.length() - 1] == B[0] &&
      B[B.length() - 1] == C[0]){
        cout << "YES" << endl;
    }else{
      cout << "NO" <<endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, H):
    return len(list(filter(lambda x: x >= K, H)))


def main():
    N, K = read_int_n()
    H = read_int_n()
    print(slv(N, K, H))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14320
let s = read_line ()
let n, ans = String.length s, ref max_int
let _ = Char.(for i = code 'a' to code 'z' do let d, b, c, l, cs = chr i, ref false, ref 0, ref n, Array.init n @@ fun i -> s.[i] in
  while not !b do let b2 = ref true in for i = 0 to !l - 1 do if cs.(i) <> d then b2 := false else if i > 0 then cs.(i - 1) <- cs.(i) done; decr l; b := !b2; if not !b then incr c done; ans := min !ans !c done); Printf.printf "%d\n" !ans

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

const int N = 2e5 + 5;
int n, a[N], b;
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}

int main() {
	n = read();
	for (int i = 2; i <= n; ++i) {
		b = read();
		a[b]++;
	}
	for (int i = 1; i <= n; ++i)
		printf("%d\n", a[i]);
	return 0;
}

Measured memory_bytes: 4416
#include<stdio.h>
int main()
{
	int n,r,i,f;
	for(i=0;i<5;i++){
		r=0;
		scanf("%d",&f);
		if(f==0){
			break;
		}
		n=1000-f;
		if(n>=500){
			r++;
			n-=500;
		}
		while(n>=100){
			r++;
			n-=100;
		}
		if(n>=50){
			r++;
			n-=50;
		}
		while(n>=10){
			r++;
			n-=10;
		}
		if(n>=5){
			r++;
			n-=5;
		}
		while(n>0){
			r++;
			n-=1;
		}
		printf("%d\n",r);
	}

	return 0;
}

Measured memory_bytes: 2728