akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int N,M;
		int sum=0;
		N=cin.nextInt();
		M=cin.nextInt();
		sum=N*(N-1)/2+M*(M-1)/2;
		System.out.println(sum);
	}

}


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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))

static long int heap[100010];
int sz=-1;

void push(long int x){
	//自分のノード番号
	int i;
	int p;
	sz++;
	i=sz;
	
	while(i>0){
		//親のノード番号
		p=(i-1)/2;
		//もう逆転していないなら抜ける
		if(heap[p]<=x) break;
		//親のノードの数字を下ろして、自分は上に
		heap[i]=heap[p];
		i=p;
	}
	heap[i]=x;
}

int pop(){
	long int ret;
	int a,b;
	long int x;
	int i;
	//最小値
	ret=heap[0];
	//根に持ってくる値
	x=heap[sz];
	sz=sz-1;
	//根からおろしていく
	i=0;
	while(i*2+1<=sz){
		a=i*2+1;
		b=i*2+2;
		if(b<=sz&&heap[b]<heap[a]) a=b;
		//もう逆転していないなら終わり
		if(heap[a]>=x) break;
		//子の数字を持ち上げる
		heap[i]=heap[a];
		i=a;
	}
	heap[i]=x;
	
	return ret;
}

static long int heapup[100010];
int szup=-1;

void pushup(llong int x){
	//自分のノード番号
	int i;
	int p;
	szup++;
	i=szup;
	
	while(i>0){
		//親のノード番号
		p=(i-1)/2;
		//もう逆転していないなら抜ける
		if(heapup[p]>=x) break;
		//親のノードの数字を下ろして、自分は上に
		heapup[i]=heapup[p];
		i=p;
	}
	heapup[i]=x;
}

int popup(){
	llong int ret;
	int a,b;
	llong int x;
	int i;
	//最小値
	ret=heapup[0];
	//根に持ってくる値
	x=heapup[szup];
	szup=szup-1;
	//根からおろしていく
	i=0;
	while(i*2+1<=szup){
		a=i*2+1;
		b=i*2+2;
		if(b<=szup&&heapup[b]>heapup[a]) a=b;
		//もう逆転していないなら終わり
		if(heapup[a]<=x) {
			break;
		}
		//子の数字を持ち上げる
		heapup[i]=heapup[a];
		i=a;
	}
	heapup[i]=x;
	
	return ret;
}



int main(void)
{
	//変数の宣言
	int n;
	static llong int a[300010];
	static llong int lsum[100010];
	static llong int ldec[100010];
	static llong int rsum[100010];
	static llong int rdec[100010];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	llong int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	for(i=0;i<3*n;i++){
		scanf("%lld",&a[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	lsum[0]=a[n];
	for(i=n+1;i<2*n;i++){
		lsum[i-n]=lsum[i-n-1]+a[i];
	}
	
	rsum[n-1]=a[2*n-1];
	for(i=2*n-2;i>=n;i--){
		rsum[i-n]=rsum[i-n+1]+a[i];
	}
	
	for(i=0;i<n;i++){
		push(a[i]);
	}
	
	
	for(i=n;i<2*n;i++){
		push(a[i]);
		if(i==n){
			ldec[i-n]=heap[0];
		}else{
			ldec[i-n]=ldec[i-n-1]+heap[0];
		}
		pop();
	}
	
	for(i=2*n;i<3*n;i++){
		pushup(a[i]);
	}
	
	for(i=2*n-1;i>=n;i--){
		pushup(a[i]);
		if(i==2*n-1){
			rdec[i-n]=heapup[0];
		}else{
			rdec[i-n]=rdec[i-n+1]+heapup[0];
		}
		popup();
	}
	
	for(i=0;i<=n;i++){
		if(i==0){
			ans=rdec[0]-rsum[0];
			temp=ans;
		}else if(i==n){
			temp=lsum[n-1]-ldec[n-1];
			if(temp>ans) ans=temp;
		}else{
			temp=lsum[i-1]-ldec[i-1]+rdec[i]-rsum[i];
			if(temp>ans) ans=temp;
		}
	}
	
	
	for(i=0;i<n;i++){
		ans=ans+a[i];
	}
	for(i=2*n;i<3*n;i++){
		ans=ans-a[i];
	}
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%lld\n",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 7168
def pow(n,k,m):#n^k mod m
    ans = 1
    while k>0:
        if(k & 1):ans = (ans*n) % m
        n = (n*n)%m
        k >>= 1
    return ans

MOD = 10**9 + 7

n = int(input())

a = list(map(int,input().split()))

for i in range(1,n):
    a[i] = a[i]^a[i-1] #累積和

zero = [0 for i in range(n)] #zero[i] = i番目までの0の個数

if a[0] == 0: zero[0] = 1

for i in range(1,n):
    if a[i] == 0:zero[i] = zero[i-1]+1
    else : zero[i] = zero[i-1]

dp = [0 for i in range(n)]

pre,dpsum = {},{}

for i in range(n):
    if a[i] == 0:continue
    if pre.get(a[i]) is None:
        dp[i] = 1
        pre[a[i]] = i
        dpsum[a[i]] = 1
    else:
        j = pre[a[i]]
        z = zero[i]-zero[j]
        dp[i] = (dpsum[a[i]]*z + dp[j]) % MOD
        pre[a[i]] = i
        dpsum[a[i]] = (dp[i]+dpsum[a[i]]) % MOD

if a[-1] != 0:
    print(dp[-1])
else:
    print((pow(2,zero[-1]-1,MOD)+sum(dp)) % MOD)

Measured memory_bytes: 136492
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int W,H,x,y,r;
  int flag = 0;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if ((x < r) || (y < r)) flag = 1;
  if ((x + r > W) || (y + r > H)) flag = 1;

  if (flag) {
    printf("No\n");
  }
  else {
    printf("Yes\n");
  }
  return (0);
}



Measured memory_bytes: 2120
'use strict'
function main(inp) {
  let info = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
  console.log(info[inp-1]);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import sys
input = sys.stdin.readline
from math import factorial 
mod = 10 ** 9 + 7

N, M = [int(x) for x in input().split()]
if abs(N - M) >= 2: ans = 0
else: ans = (factorial(N) % mod * factorial(M) % mod) % mod
if N == M: ans *= 2
print(ans % mod)

Measured memory_bytes: 4084
n,m = map(int,input().split())
X = list(map(int,input().split()))
mod = [[0,0] for _ in range(m)]
d = {}
for x in X:
    if x not in d.keys():d[x] = 0
    d[x] += 1
for k,v in d.items():
    mod[k%m][0] += v//2
    mod[k%m][1] += v%2
ans = 0
for i in range(m//2+1):
    if i == 0 or i == m-i:
        ans += mod[i][1]//2 + mod[i][0]
    else:
        if mod[i][1] < mod[m-i][1]:
            ans += min(mod[m-i][1], mod[i][0]*2 + mod[i][1])
            ans += mod[m-i][0]
            ans += max(0,(mod[i][0]*2 + mod[i][1] - mod[m-i][1]))//2
        elif mod[i][1] == mod[m-i][1]:
            ans += mod[i][0] + mod[m-i][0] + mod[i][1]
        else:
            ans += min(mod[i][1], mod[m-i][0]*2 + mod[m-i][1])
            ans += mod[i][0]
            ans += max(0,(mod[m-i][0]*2 + mod[m-i][1] - mod[i][1]))//2
print(ans)


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

const int MAXN = 300005;

int a[MAXN], b[MAXN];
long long c[MAXN];
int n;
int pre[MAXN];

int main()
{
	scanf("%d", &n);
	int last = 0, c = 0;
	for (int i = 1; i <= n; i++) {
		pre[i] = last;
		scanf("%d", &a[i]);
		if (a[i]) last = i;
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		long long sum = a[i];
		int x = a[i];
		for (int j = i; j > 0; ) {
			if (sum == x) {
				ans += j-pre[j];
				j = pre[j];
				sum += a[j], x ^= a[j];
			} else break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
S = input()

open_left=0
open_right=0
for c in S:
    if c == ')':
        if open_left > 0:
            open_left -= 1
        else:
            open_right += 1
    else:
        open_left += 1
#print('(', open_left, ')', open_right)

ans = '('*open_right + S + ')' * open_left
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second


signed main(){
  string s;
  cin>>s;
  int A=0;
  r(i,s.size()){
    if(i%2==0 && s[i]=='L')A=1;
    if(i%2==1 && s[i]=='R')A=1;
  }
  cout<<(A?"No":"Yes")<<endl;
}


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

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

    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    cout << vec.at(n-1)-vec.at(0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second 
//#define int   long long
#define ll   long long
#define pii pair<int, int>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main(){
    FAST
    string str;
    cin>>str;
    if(str[2] == str[3] && str[4] == str[5]){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  string s;cin >> s;
  vector<vector<int>> lis(s.size(),vector<int>(26,0));
  for(int i = s.size()-1;i>=0;i--){
    if(i != s.size()-1) rep(j,26) lis[i][j] = lis[i+1][j];
    lis[i][s[i]-'a']++;
  }
  ll ans = 0;
  rep(i,s.size()-1){
    rep(j,26){
      if(j != (s[i]-'a')) ans+=lis[i+1][j];
    }
  }

  cout << ans+1 << endl;
}

Measured memory_bytes: 30040
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }
const long long INF = 1LL << 60;

int main()
{
    ll n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    sort(a.begin(),a.end());

    bool ans = true;

    rep(i,n-1){
        if(a[i] == a[i+1]) {
            ans = false;
            break;
        }
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

void solve() {
  int n;
  cin >> n;
  cout << setprecision(10) << ((n + 1) / 2) / (double) n << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

import functools
@functools.lru_cache(maxsize=None)
def factrial_memo(n):
  fact = [1, 1]
  for i in range(2, n + 1):
    fact.append((fact[-1] * i) % mod)
  return fact

def permutation(n,r): #nPr
  return fact[n]*pow(fact[n-r],mod-2,mod)%mod
  
def combination(n,r): #nCr
  return permutation(n,r)*pow(fact[r],mod-2,mod)%mod

def homogeneous(n,r): #nHr
  return combination(n+r-1,r)%mod

N,M = IL()

fact = factrial_memo(10**6)

s = 0
for k in range(1,N+1):
  s += combination(N, k) * permutation(M-k, N-k) * (-1)**(k-1)
ans = (permutation(M, N)**2 - s*permutation(M, N)) %mod
print(ans)

Measured memory_bytes: 162744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(ll i = a ; i <=n;++i)
#define sf(n) scanf("%lld",&n)
#define pf(n) printf("%lld\n",n)
#define bug printf("bug\n")
#define pi 3.14159265

int main(){
string s ;
cin >> s;
ll ans = 0;
rep(i,0 ,2) {if(s[i]=='o') ans++;}

ans = 700 + ans * 100;
cout << ans <<endl;
return 0;
}


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

int main(){
    pair<long long,int> order[2020];
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        long long temp;
        cin>>temp;
        order[i]=make_pair(temp,i+1);
    }
    sort(order,order+n);
    reverse(order,order+n);
    long long dp[2020][2020];
    for(int x=0;x<=n;x++){
        for(int y=0;y<=n;y++){
            dp[x][y]=-1;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        long long k=order[i].first;
        int bef=order[i].second;
        for(int x=0;x<=i;x++){
            int y=i-x;
            dp[x+1][y]=max(dp[x+1][y],dp[x][y]+abs(bef-(x+1))*k);
			dp[x][y+1]=max(dp[x][y+1],dp[x][y]+abs(bef-(n-y))*k);
        }
    }
    long long sum=0;
    for(int i=0;i<=n;i++){
        sum=max(sum,dp[i][n-i]);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 35260
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AWannaGoBackHome solver = new AWannaGoBackHome();
        solver.solve(1, in, out);
        out.close();
    }

    static class AWannaGoBackHome {
        private static final String YES = "Yes";
        private static final String NO = "No";

        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String s = in.string();
            int mask = 0;
            for (char c : s.toCharArray()) {
                switch (c) {
                    case 'N':
                        mask |= 0b0001;
                        break;
                    case 'S':
                        mask |= 0b0010;
                        break;
                    case 'E':
                        mask |= 0b0100;
                        break;
                    case 'W':
                        mask |= 0b1000;
                        break;
                }
            }
            if (mask == 3 || mask == 12 || mask == 15) {
                out.println(YES);
            } else {
                out.println(NO);
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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

#define int long long

using namespace std;

int n;
int f[5000][100];
int g[5000][100];
int a[1001];
int sum;
int dem;
int B;
int res;

void input(){
	cin>>n>>B;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
}

void solve(){
	res = 0;
	g[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int tong=0;tong<=n*50;tong++){
			for(int sl=0;sl<=n;sl++){
				f[tong+a[i]][sl+1]+=g[tong][sl];
				f[tong][sl] += g[tong][sl];
			}
		}
		for(int tong=0;tong<=n*50;tong++){
			for(int sl=0;sl<=n;sl++){
				g[tong][sl] = f[tong][sl];
				f[tong][sl] = 0;
			}
		}
	}
	
	for(int tong=B,sl=1;tong<=n*50;tong+=B,++sl){
		res += g[tong][sl];
	}
}

void output(){
	cout<<res;
}

signed main(){
//	freopen("","r",stdin);

//	int ntest;
//	scanf("%d",&ntest);
//
//	for(int itest=0;itest<ntest;itest++){

		input();
		solve();
		output();

//		printf("\n");

//	}

	return 0;
}




Measured memory_bytes: 6272
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
	    int a = in.readInt();
	    int b = in.readInt();
	    int c = in.readInt();
	    int x = in.readInt(); 
	    int ans = 0; 
	    for(int i = 0; i<=a; i++) {
	    	for(int j = 0; j<=b; j++) {
	    		for(int k = 0; k<=c; k++) {
	    			int temp = 500*i + 100 * j + 50 * k; 
	    			
	    			if(temp == x) ans++; 
	    		}
	    	}
	    }
	    System.out.println(ans); 
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 23124
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

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


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main() {
  int n, k;
  cin >> n >> k;
  int mx = (n-1)*(n-2)/2;
  if (mx < k) {
    puts("-1");
    return 0;
  }
  vector<P> ans;
  rep(i,n-1) {
    ans.push_back(P(i+1,n));
  }
  int add = mx-k;
  vector<P> edge;
  rep(i,n-1)rep(j,i) edge.push_back(P(i+1,j+1));
  rep(i,add) ans.push_back(edge[i]);
  cout << ans.size() << endl;
  rep(i,ans.size()) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 3684
s=input()

for i in range(len(s)):
  if i>0:
    if s[i]==s[i-1]:
      print(i-1+1,i+1)
      exit()
  if i>1:
    if s[i]==s[i-2]:
      print(i-2+1,i+1)
      exit()
      
print(-1,-1)

Measured memory_bytes: 9160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

struct process{
	char name[11];
	int time;
};

const long LEN=510029;

class queue {
	process data[LEN];
	int head, tail;
public:
	queue(): head(0), tail(0) {}  

	void enqueue(const process& p){
		data[tail+1]=p;
		tail= (tail+1) % LEN;
	}
	process& dequeue(){
		head= (head+1) % LEN;
		return data[head];
	}

	bool isEmpty(){ return head == tail;  }
	bool isFull(){  return (tail+1) % LEN == head;  }
};


int main()
{
	queue q;


	int n;
	short quan;
	cin>>n>>quan;

	process p;



	int passTime=0;

	for( int i=0; !q.isEmpty() || i<n; i++ ) {

		if( i<n ){
			scanf("%s %d", &p.name, &p.time);
		}
		else
			p=q.dequeue();
			


		if( p.time - quan <=0 ){
			passTime+=p.time;
			printf("%s %d\n", p.name, passTime);

		}else{
			passTime+=quan;
			p.time-=quan;
			q.enqueue(p);
		}


	}

}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

void solve() {
  string s, t;
  cin >> s >> t;
  s += s;
  vector<vector<int> > v(26);
  rep(i, sz(s)) v[s[i] - 'a'].eb(i);
  // rep(i, 26) cout << v[i] << endl;

  int c = 0, it = -1;
  rep(i, sz(t)) {
    int tt = t[i] - 'a';
    if (!sz(v[tt])) {
      cout << -1 << endl;
      return;
    }
    
    it = ub(v[tt], it);
    it = v[tt][it];
    if (it >= sz(s) / 2) {
      it -= sz(s) / 2;
      c++;
    }
  }
  cout << 1LL * c * sz(s) / 2 + it + 1 << endl;
}


Measured memory_bytes: 1896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int K;
  cin >> K;
  for (int i=0; i<N; i++) {
    if (S[K-1] != S[i]) {
      S[i] = '*';
    }
  }
  cout << S << endl;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;
constexpr int INF = 1E9;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int h, w, k;
  cin >> h >> w >> k;
  int sr, sc, tr, tc;
  cin >> sr >> sc >> tr >> tc;
  sr--; sc--; tr--; tc--;

  vector<string> board(h);
  for (int y = 0; y < h; y++) {
    cin >> board[y];
  }

  vector<set<int>> r_to_cs(h);
  vector<set<int>> c_to_rs(w);
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      r_to_cs[y].insert(x);
      c_to_rs[x].insert(y);
    }
  }
  for (int y = 0; y < h; y++) {
    r_to_cs[y].insert(-INF);
    r_to_cs[y].insert(INF);
  }
  for (int x = 0; x < w; x++) {
    c_to_rs[x].insert(-INF);
    c_to_rs[x].insert(INF);
  }

  deque<pair<int, int>> q;
  auto d_table = Make2DVector(h, w, INF);
  q.push_back({sr, sc});
  r_to_cs[sr].erase(sc);
  c_to_rs[sc].erase(sr);
  d_table[sr][sc] = 0;

  auto add_fn = [&](int r, int c, int d) {
    // cout << "add_fn(): " << r << " " << c << " " << d << endl;
    q.push_back({r, c});
    r_to_cs[r].erase(c);
    c_to_rs[c].erase(r);
    d_table[r][c] = d;
    // cout << "add_fn(): END" << endl;
  };

  while (!q.empty()) {
    int r, c;
    tie(r, c) = q.front();
    q.pop_front();
    int d = d_table[r][c];

    if (r == tr && c == tc) {
      cout << d << endl;
      return 0;
    }

    // r+
    if (DEBUG) cout << "R+" << endl;
    auto iter = c_to_rs[c].upper_bound(r);
    while (*iter <= r + k) {
      if (board[*iter][c] == '@') break;
      int r2 = *iter;
      add_fn(*iter, c, d + 1);
      iter = c_to_rs[c].upper_bound(r2);
    }
    // r-
    if (DEBUG) cout << "R-" << endl;
    // for (int r : c_to_rs[c]) {
    //   cout << r << " ";
    // }
    // cout << endl;
    iter = c_to_rs[c].upper_bound(r);
    iter--;
    while (*iter >= r - k) {
      if (board[*iter][c] == '@') break;
      int r2 = *iter;
      add_fn(*iter, c, d + 1);
      iter = c_to_rs[c].upper_bound(r2);
      iter--;
    }
    // c+
    if (DEBUG) cout << "C+" << endl;
    iter = r_to_cs[r].upper_bound(c);
    while (*iter <= c + k) {
      if (board[r][*iter] == '@') break;
      int c2 = *iter;
      add_fn(r, *iter, d + 1);
      iter = r_to_cs[r].upper_bound(c2);
    }
    // c-
    if (DEBUG) cout << "C-" << endl;
    iter = r_to_cs[r].upper_bound(c);
    iter--;
    while (*iter >= c - k) {
      if (board[r][*iter] == '@') break;
      int c2 = *iter;
      add_fn(r, *iter, d + 1);
      iter = r_to_cs[r].upper_bound(c2);
      iter--;
    }
  }

  cout << -1 << endl;
}

Measured memory_bytes: 246348
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define ll long long
#define rep(i,n) for (i = 0; i < n; ++i) 
#define REP(i,k,n) for (i = k; i <= n; ++i) 
#define REPR(i,k,n) for (i = k; i >= n; --i)
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
bool prime(ll x)
{
  if(x==1)
    return false;
  if(x==2||x==3||x==5)
    return true;
  for(ll i=2;i<=sqrt(x);i++)
  {
    if(x%i==0)
      return false;
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin); 
   //freopen("error.txt", "w", stderr); 
   freopen("output.txt", "w", stdout); 
#endif 
   
 ll T = 1 ;
 //cin>>T;

 for(ll t=0;t<T;t++)
 {
  string s , ss;
  cin>>s>>ss;
  ll ans = 1001 , n = s.size() , ns = ss.size();
  for(ll i=0;i<=n-ns;i++)
  {
    ll c = 0;
    for(ll j=0;j<ns;j++)
    {
      if(s[i+j]!=ss[j])
        c++;
    }
    ans = min(ans,c);
  }
cout<<ans<<endl;

 }
  return 0;
}


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

int dp[3];

int main(){
    int n,a,b,c,x,y,z;
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        if(i==0){
            dp[0]=a;
            dp[1]=b;
            dp[2]=c;
            continue;
        }

        x=dp[0];
        y=dp[1];
        z=dp[2];

        dp[0]=a+max(y,z);
        dp[1]=b+max(x,z);
        dp[2]=c+max(x,y);



    }

    cout<<max(dp[0],max(dp[1],dp[2]))<<endl;


    return 0;



}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    int t,sum=0;
    cin>>t;
    sum =(t/500)*1000+(((t%500)/5)*5);
    cout<<sum;


}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
//  check the problem
//  again
// 	it always
//	has a simpler solution idiot
#define MOD 1000000000 + 7;
typedef long long ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(0);
	int x,y;
	cin >> x >> y;
	bool ans = false;
	for(int i{0}; i<=x; i++){
		if(i*2+((x-i)*4)==y){
			ans = true;
			break;
		}else{
			ans = false;
		}
			}
	
	cout << (ans?"Yes":"No") << "\n";
}




Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi; 
typedef pair<int,int> pi;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)

vector<ll> dp;

int main(){
	
	ll n, h, v,w;
	
	cin >> n >> w; 
	
	dp.assign(w+1, 0);
	
	for(ll i = 0; i < n; i++){
		
		cin >> h >> v;
		
		for(ll i2 = w - h; i2 >= 0; i2--){
			dp[i2 + h] = max( dp[i2+h], dp[i2] + v );
		}
		
	}
	
	ll maxi = 0;
	
	for(ll i = 0; i <= w; i++){
		maxi = max(maxi, dp[i]);
	}
	
	cout << maxi << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ans;
  ans = n-m;
  ans += 19*m;
  for (int i=0; i<m; i++)
    ans *= 2;
  ans *= 100;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
struct node{
    int l, r;
};
const int N = 1e6 + 7;
string s[N];
int n;

vector<node>a;
vector<node>b;

bool cmp(node x, node y){
    return x.r < y.r;
}

bool cmp1(node x, node y){
    return x.l < y.l;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout .tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> s[i];
        int len = s[i].length();
        int l =0, r = 0;
        for(int j = 0; j < len; j++){
            if(s[i][j] == '(') l++;
            else if(l) l--;
            else r++;
        }
        if(l >= r) a.push_back({l, r});
        else b.push_back({l, r});
    }
    sort(a.begin(), a.end(), cmp);
    sort(b.begin(), b.end(), cmp1);
    int sum = 0, ok = 0;
    for(int i = 0; i < a.size(); i++){
        sum -= a[i].r;
        if(sum < 0){
            ok = 1;
            break;
        }
        sum += a[i].l;
    }
    int sum1 = 0;
    for(int i = 0; i < b.size(); i++){
        sum1 -= b[i].l;
        if(sum1 < 0){
            ok = 1;
            break;
        }
        sum1 += b[i].r;
    }
    if(ok){
       //cout << "No\n";
       //puts("No");
       printf("No\n");
    }else{
        if(sum == sum1){
            cout << "Yes\n";
            //puts("Yes");
            //printf("Yes\n");
        }else{
            cout << "No\n";
           // puts("Yes");
           //printf("Yes\n");
        }
    }

}

Measured memory_bytes: 42464
#include<bits/stdc++.h>
using namespace std;
int a[205];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,p=0;
		cin>>k;
		while(k%2==0){
			p++;
			k/=2;
		}
		a[i]=p;
	}
	sort(a,a+n);
	cout<<a[0]<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B,C,D;
  string a,b,c;
  cin >>a;
  if(a[0]!='9'&&a[1]!='9')Out("No");
  else Out("Yes");
}


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

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

int main(){
    int N;
    string S;
    map <string,int> memo;

    cin>>N;
    rep(i,N){
        cin>>S;
        memo[S] +=1;
    }
    int ma=0;
    for (auto it = memo.begin(); it != memo.end(); it++)
    {
        ma=max(ma,it->second);
    }
    for (auto it = memo.begin(); it != memo.end(); it++)
    {
        if (it->second==ma)
        {
            cout<<it->first<<endl;
        }
        
    }
    
    

    return 0;
}

Measured memory_bytes: 25216
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
using pii =pair<int,int>;

int n;
vector<int> a;
vector<int> b;
vector<int> c;

void input(){
    cin>>n;
    int in;
    rep(i,n){
        cin>>in;
        a.push_back(in);
    } 
    rep(i,n){
        cin>>in;
        b.push_back(in);
    } 
    rep(i,n-1){
        cin>>in;
        c.push_back(in);
    } 
}
void src(){
    int m=0;
        m+=b[a[0]-1];
    repi(i,1,n){ 
        m+=b[a[i]-1];
        if(a[i-1]+1==a[i]) m+=c[a[i-1]-1];
    }
    cout<<m;
    return;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace lineAralgebra
{
	class Edge
	{
		public int id;
		public int to;
		public Edge(int to, int id)
		{
			this.id = id;
			this.to = to;
		}
	}

	class Program
	{
		public static Dictionary<int, List<Edge>> graph = new Dictionary<int, List<Edge>>();
		public static int[] ans;

		public static void Main(String[] args)
		{
			var n = int.Parse(Console.ReadLine());
			ans = new int[n - 1];
			for (var i = 0; i < n - 1; i++)
			{
				// System.Console.WriteLine("i is" + i);
				var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

				if (!graph.ContainsKey(input[0]))
				{
					graph[input[0]] = new List<Edge>();
				}

				if (!graph.ContainsKey(input[1]))
				{
					graph[input[1]] = new List<Edge>();
				}

				graph[input[0]].Add(new Edge(input[1], i));
				graph[input[1]].Add(new Edge(input[0], i));
			}

			Dfs(1);

			var max = 0;
			foreach (var i in ans)
			{
				max = Math.Max(max, i);
			}
			System.Console.WriteLine(max);

			for (var i = 0; i < ans.Length; i++)
			{
				System.Console.WriteLine(ans[i]);
			}
		}

		public static void Dfs(int current, int parent = -1, int color = -1)
		{
			var k = 1;
			foreach (var nodes in graph[current])
			{
				var to = nodes.to;
				var id = nodes.id;
				if (to == parent) continue;
				if (k == color) k++;
				ans[id] = k;
				k++;
				Dfs(to, current, ans[id]);
			}
		}
	}
}



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

using namespace std;


int main() {
	int n = 0, k = 0;
	cin >> n >> k;
	assert(n > 0 && 100000 >= n);
	assert(k > 0 && 500 >= k);

	int answer = 0;
	for (int i = 0; i < n; i++) {
		int h = 0;
		cin >> h ;
		assert(h > 0 && h <= 500);
		if (h >= k) answer++;
	}

	cout << answer << endl;

	return 0;
}


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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000
int N,M;
int A[MAX_N+1],B[MAX_N+1];
int ans;

void solve(void) {
  int buf;
  for(int i=N;i>=1;i--) {
//    if (A[i] == 0) {
      buf = 0;
      for(int j=i;j<=N;j=j+i){
        buf += B[j];
      }
      if ((buf&1) != A[i]) {
        B[i] = 1;
        M++;
      }
//    } else {
//
//  }

  }

  if (1) {
    cout << M << endl;
    rep(i,1,N+1) {
      if (B[i]==1) {
        cout << i << endl;
      }
    }
  } else {
    cout << -1 << endl;
  }
}

int main (void)
{
  cin >> N;
  rep(i,1,N+1) {
    cin >> A[i];
  }

  solve();

  return 0;
}


Measured memory_bytes: 5760
class Dice:
    def __init__(self, default = [1, 2, 3, 4, 5, 6]):
        self.d = default

    def e(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]

    def w(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]

    def n(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]

    def s(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]

    def r(self):
        self.d[1], self.d[2], self.d[3], self.d[4] = self.d[3], self.d[1], self.d[4], self.d[2]

    def top(self):
        return self.d[0]

    def forward(self):
        return self.d[1]

    def right(self):
        return self.d[2]


def main():
    dice = Dice([int(i) for i in input().split()])
    n = int(input())
    for i in range(n):
        t, f = map(int, input().split())
        for i in range(4):
            if dice.top() == t:
                break
            dice.e()
        else:
            for j in range(3):
                if dice.top() == t:
                    break
                dice.s()

        for i in range(3):
            if dice.forward() == f:
                break
            dice.r()

        print(dice.right())


if __name__ == '__main__':
    main()



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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define mp make_pair

const int MAXN = (1 << 19);
int mi[2 * MAXN];
int inf = 1e9;
int p[MAXN];
int a[MAXN];
int n, k;
bool used[MAXN];
int num[MAXN];
int cnt;
int ans[MAXN];

int find_min(int i, int l, int r, int left, int right)
{
    if (l == left && r == right)
        return mi[i];
    int m = (l + r) / 2;
    if (right <= m)
        return find_min(i * 2, l, m, left, right);
    if (left >= m)
        return find_min(i * 2 + 1, m, r, left, right);
    return min(find_min(i * 2, l, m, left, m), find_min(i * 2 + 1, m, r, m, right));
}

int find_first(int i, int l, int r, int left, int right, int pos)
{
    if (r == l + 1)
        return l;
    int m = (l + r) / 2;
    if (right <= m)
        return find_first(i * 2, l, m, left, right, pos);
    if (left >= m)
        return find_first(i * 2 + 1, m, r, left, right, pos);
    int x = find_min(i * 2, l, m, left, m);
    if (x < pos)
        return find_first(i * 2, l, m, left, m, pos);
    return find_first(i * 2 + 1, m, r, m, right, pos);
}

void dfs(int v)
{
    used[v] = true;
    int pos = mi[MAXN + v];
    int e = MAXN + v;
    mi[e] = inf;
    e /= 2;
    while (e > 0)
    {
        mi[e] = min(mi[e * 2], mi[e * 2 + 1]);
        e /= 2;
    }
    while (true)
    {
        int x = find_min(1, 0, MAXN, max(0ll, v - k + 1), min(n, v + k));
        if (x >= pos)
            break;
        int to = find_first(1, 0, MAXN, max(0ll, v - k + 1), min(n, v + k), pos);
        dfs(to);
    }
    num[v] = cnt;
    cnt++;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        p[i]--;
        a[p[i]] = i;
    }
    for (int i = 0; i < n; i++)
        mi[MAXN + a[i]] = i;
    for (int i = MAXN + n; i < 2 * MAXN; i++)
        mi[i] = inf;
    for (int i = MAXN - 1; i >= 1; i--)
        mi[i] = min(mi[i * 2], mi[i * 2 + 1]);
    for (int i = 0; i < n; i++)
    {
        if (!used[i])
            dfs(i);
    }
    for (int i = 0; i < n; i++)
        cout << num[i] + 1 << "\n";
}


Measured memory_bytes: 40192
N=gets.to_i
ss=$<.read.split

h={}
max = 0
ss.each do |s|
  h[s] ||= 0
  h[s] += 1
  max = [max,h[s]].max
end

ret = h.select {|k,v|max == v}.keys.sort

puts ret.join("\n")


Measured memory_bytes: 60004
from itertools import combinations

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)

fail = lambda x: not all(a[i][1] < x and a[i][0].isdisjoint(x) for i in x)

while all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)


Measured memory_bytes: 3064
N = gets.to_i

#禁止されるパターン
# (AGCT) = (0123)として
# .012, .102, .021, 0.12, 01.2の5パターン

dp = Array.new(N+1){Array.new(4){Array.new(4){Array.new(4,0)}}}

#初期化。012,102,021の3パターンが禁止
4.times do |p3|
  4.times do |p2|
    4.times do |p1|
      if ![p3,p2,p1].join.match(/012|102|021/)
        dp[2][p3][p2][p1] = 1
      end
    end
  end
end


(2..N-1).each do |n|
  4.times do |p3|
    4.times do |p2|
      4.times do |p1|
        4.times do |a|
          if ![p3,p2,p1,a].join.match(/.012|.102|.021|0.12|01.2/)
            dp[n+1][p2][p1][a] += dp[n][p3][p2][p1]
            dp[n+1][p2][p1][a] %= (10**9+7)
          end
        end
      end
    end
  end
end

cnt = 0
4.times do |p3|
  4.times do |p2|
    4.times do |p1|
      cnt += dp[N-1][p3][p2][p1]
      cnt %= (10**9 + 7)
    end
  end
end

p cnt

Measured memory_bytes: 2556
#include<iostream>
#include <cmath>
#include<vector>
#define rep(i, n) for (int i=0;i<n;i++)
#include <map> 
#include<algorithm>
#include <numeric>
#include<deque>
#include<queue>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    string s = to_string(n);
    rep(i, 3) {
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;
int main(){
    int A,B;
    cin>>A>>B;
    //1<=A<=B<=100
    int max=1000;
    int ans=-1;
    FOR(i,1,max+1){
      double a=(double)i*0.08;
      double b=(double)i*0.1;
      int c=(int)floor(a);
      int d=(int)floor(b);
      if(c==A&&d==B){
          ans=i;
          break;
      }
  }
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

def Eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

n = int(input())
n2 = n

if n == 1:
    print(0)
    exit()

prime_factors = [] #素因数
for i in Eratosthenes(int(n ** 0.5)):
    if i**2 > n2:
        break
    while n2 % i == 0:
        prime_factors.append(i)
        n2 //= i
if n2 > 1:
    prime_factors.append(n2)

#↑までで素因数分解

cntr = Counter(prime_factors)
cnt = 0
#for k, v in cntr.items():
for v in cntr.values():
    sisuu = v
    sub = 1
    while sisuu - sub >= 0:
        sisuu -= sub
        cnt += 1
        sub += 1
print(cnt)
"""
ans = []
list = []
for i in prime_factors:
    for j in list:
        if j % i == 0:
            tmp = list.pop(list.index(j)) * i
            if tmp in ans:
                list.append(tmp)
                continue
            ans.append(tmp)
    if i in list:
        tmp = list.pop(list.index(i)) * i
        if tmp in ans:
            list.append(tmp)
            continue
        ans.append(tmp)
    elif i in ans:
        list.append(i)
    else:
        ans.append(i)

print(len(ans))
"""

Measured memory_bytes: 82408
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
 
using namespace std;
 
#define Node Tree
 
struct Node {
  bool root;
  bool child[2];
  Node *next[2];
  string id;
  Node() {
    child[0] = child[1] = false;
    root = false;
    id = "";
  }
};
 
void rec1(Tree *t);
 
string context;
int pos;
void rec2(Tree *t) {
  //cout << "pos = " << pos << " " << context[pos] << endl;
  if( pos < (int)context.size() ) {
    if( context[pos] == ')' ) {
      //++pos;/////
      t->child[0] = t->child[1] = false;
      t->id = "leaf";
    } else {
      //++pos;
      rec1(t);
      //++pos;
    }
  } else {
    t->child[0] = t->child[1] = false;
    t->id = "leaf";
  }
}
 
string getID() {
  string id = "";
  while( pos < (int)context.size() && context[pos] != ']' ) {
    id += context[pos];
    ++pos;
  }
  return id;
}
 
void rec1(Tree *t) {
  //cout << "pos2 = " << pos << " " << context[pos] << endl;
  if( pos < (int)context.size() ) {
    assert( context[pos] == '(' );
    ++pos; // (
    t->child[0] = true;
    t->next[0] = new Tree;
    rec2(t->next[0]);
    assert( pos < (int)context.size() );
    assert( context[pos] == ')');
    ++pos; // )
    assert( context[pos] == '[' );
    ++pos; // [
    string id = getID();
    //cout << "[[" << id << "]]" << endl;
    t->id = id;
    assert( context[pos] == ']' );
    ++pos; // ]
    ++pos; // (
    t->child[1] = true;
    t->next[1] = new Tree;
    rec2(t->next[1]);
    ++pos; // )
 
  } else {
    t->child[0] = t->child[1] = false;
    t->id = "leaf";
  }
}
 
 
string tree_walk(Tree *t,int depth) {
  string ret = "";
  //cout << '(';
  ret += "(";
  if(t->child[0]) ret += tree_walk(t->next[0],depth+1);
  else {
    //cout << "()";
    ret += "()";
  }
  //cout << "[" << (t->id) << "]";
  ret += ( "[" + (t->id) + "]" );
  if(t->child[1]) ret += tree_walk(t->next[1],depth+1);
  else ret += "()";//cout << "()";
  //cout << ')';
  ret += ")";
  return ret;
}
 
void getTree(string s,Tree *t) {
  pos = 0;
  context = s;
  rec1(t);
}
 
string itos(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
 
void dfs(Tree *t1,Tree *t2,Tree *t) {
  int v1 = (atoi)(t1->id.c_str());
  int v2 = (atoi)(t2->id.c_str());
  t->id = itos(v1+v2);
  
  if( t1->next[0]->id != "leaf" && 
      t2->next[0]->id != "leaf" ) {
    t->child[0] = true;
    t->next[0] = new Tree;
    dfs(t1->next[0],t2->next[0],t->next[0]);
  } else {
    t->child[0] = false;
  }
 
  
  if( t1->next[1]->id != "leaf" && 
      t2->next[1]->id != "leaf" ) {
    t->child[1] = true;
    t->next[1] = new Tree;
    dfs(t1->next[1],t2->next[1],t->next[1]);
  } else {
    t->child[1] = false;
  }
  
}
 
int main() {
  string s;
  cin >> s;
  Tree t1,t2;
  getTree(s,&t1);
  //tree_walk(&t1,0); cout << endl;
  cin >> s;
  getTree(s,&t2);
  //tree_walk(&t2,0);cout << endl;
  Tree answer;
  dfs(&t1,&t2,&answer);
 
  string ans = tree_walk(&answer,0);
  cout << ans.substr(1,(int)ans.size()-2) << endl;
  return 0;
}

Measured memory_bytes: 3272
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(fact(scanner.nextBigInteger()));
	}
	static BigInteger fact(BigInteger a){
		if(a.intValue() == 1){
			return BigInteger.ONE;
		}else{
			return (a.multiply( fact(a.add(BigInteger.ONE.negate()))));
		}
	}
}

Measured memory_bytes: 17200
from bisect import bisect_right, bisect_left

N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A.sort()
C.sort()
ans = 0

for i in B:
    a = bisect_left(A, i)
    b = N-bisect_right(C, i)
    ans += (a*b)

print(ans)


Measured memory_bytes: 23360