akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h = list(map(int, input().split()))
h.reverse()
for i in range(n-1):
  if h[i]<h[i+1]:
    h[i+1]-=1
h.reverse()
for j in range(n-1):
  if h[j]>h[j+1]:
    print('No')
    exit()
else:
  print('Yes')

Measured memory_bytes: 20696
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N, M = map(int, input().split())
    bridge = [list(map(int, input().split())) for _ in range(M)]

    uf = UnionFind(N)
    ans = [N*(N-1)//2]*M

    for i in range(-1, -1 * M, -1):
        a = bridge[i][0] - 1
        b = bridge[i][1] - 1
        root_a = uf.find(a)
        root_b = uf.find(b)
        if root_a != root_b:
            ans[i-1] = ans[i] - uf.size(a) * uf.size(b)
            uf.union(a, b)
        else:
            ans[i-1] = ans[i]

    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 33092
#include <iostream>

using namespace std;

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

  if( R < 1200 )
  {
    cout << "ABC" << endl;
  }
  else if( R < 2800 )
  {
    cout << "ARC" << endl;
  }
  else
  {
    cout << "AGC" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var x, y int
	var op string
	fmt.Scan(&x, &op, &y)

	for op!="?" {
		switch op {
		case "+":
			fmt.Println(x+y)
		case "-":
			fmt.Println(x-y)
		case "*":
			fmt.Println(x*y)
		case "/":
			fmt.Println(x/y)
		}
		fmt.Scan(&x,&op,&y)
	}
}


Measured memory_bytes: 1128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 998244353;
map<string,int> mp;
string check(string s1,string s2){
	string res;
	for(int i=0;i<s2.length();i++)
		res+=min(s1[i],s2[i]);
	return res;
}
int solve(string S){
	if(S.length()==0) return 1;
	if(S.length()==1) return S[0]-47;
	if(mp.count(S)) return mp[S];
	ll now=0;int len=S.length();
	for(int i=0;i<len-1;i++){
		string sub=S.substr(0,i+1);
		for(int j=i==0?1:2;i*j+j<=len;j++){
			sub=check(S.substr((j-1)*(i+1),i+1),sub);
			now=(now+1ll*solve(sub)*solve(S.substr(i*j+j)))%mod;
		}
	}
	return mp[S]=now;
}
int main(){
	string S;
	cin>>S;
	cout<<solve(S)<<'\n';
	return 0;
}


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

using ll = long long;

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

    int n;
    cin >> n;

    vector<ll> a(n), b(n), c(n);

    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < n; j++)
        {
            ll temp;
            cin >> temp;

            if(i == 0) a[j] = temp;
            if(i == 1) b[j] = temp;
            if(i == 2) c[j] = temp;
        }
    }

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

    ll answer = 0;
    vector<ll>::iterator low, up;

    for(int i = 0; i < n; i++)
    {
        low = lower_bound(a.begin(), a.end(), b[i]);
        up = upper_bound(c.begin(), c.end(), b[i]);
        answer += (low - a.begin()) * (c.end() - up);
    }

    cout << answer << endl;

    return 0;
}


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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n, c, k; cin>>n>>c>>k;
    vector<int> bus(100010, 0), t(n);
    for(int i=0; i<n; i++) cin>>t[i];
    sort(t.begin(), t.end());
    int cnt=0, t_first=t[0], ans=1;
    for(int i=1; i<n; i++){
        cnt++;
        if(t_first+k<t[i] || c==cnt){
            cnt=0;
            ans++;
            t_first=t[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  bool ap = true;
  ll n;
  cin >> n;
  while(n--){
    ll a;
    cin >> a;
    if(a%2==0){
      if((a%3!=0)&&(a%5!=0)){
        ap = false;
      }
    }
  }
  if (ap){
    cout << "APPROVED";
  }
  else{
    cout << "DENIED";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long int ll;


int main(){
    int N, M;cin >> N >> M;
    cout << N*(N-1)/2 + M*(M-1)/2;
}


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

int main() {
  int N,sum;
  sum=0;
  cin>>N;
  for (int i=0;i<N;i++){
   int l,r;
   cin>>l>>r;
   sum=sum+r-l+1; 
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9')
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	line := nextLine()

	spl := strSprit(line)

	X := parseInt(spl[2])
	Y := parseInt(spl[3])

	xl := nextLine()
	x := intSprit(xl)
	sort.Ints(x)

	yl := nextLine()
	y := intSprit(yl)
	sort.Ints(y)

	if x[len(x)-1] >= y[0] {
		fmt.Println("War")
		return
	}

	if X >= y[0] {
		fmt.Println("War")
		return
	}
	if Y < y[0] {
		fmt.Println("War")
		return
	}

	fmt.Println("No War")
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main()
{
  ll n;
  cin>>n;
  vector<ll> a(100005);
  ll sum=0;
  for(ll i=0;i<n;i++){
    ll k;
    cin>>k;

    sum+=k;
    a[k]++;
  }
  ll q;cin>>q;

  while(q--)
  {
    ll b,c;
    cin>>b>>c;
    sum-=a[b]*b;
    sum+=a[b]*c;

    a[c]+=a[b];
    a[b]=0;

    cout<<sum<<"\n";
  }

  return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    string n;
    string m;
    string l;
 
   cin >> n >> m >> l;
  
    int a = n.size();
    int b = m.size();
    int c = l.size();
      
     if (n[a - 1] == m[0] && m[b - 1] == l[0]){
      
       cout << "YES" << endl;
     }else{
       
       cout << "NO" << endl;
     }
  
  
  
  return 0;
  
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
    ll int jhogeo = 1;
    rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
    return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}

int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int p;
  string N; cin>>p>>N;
  int ans[1000]={0};
  int a[3];
  int o,t,h;
  rep(i,0,1000){
    o=i%10;
    t=(i%100-o)/10;
    h=(i-o-t)/100;
    
    rep(j,0,3) a[j]=0;
    
    rep(j,0,N.length()){
      //cout<<h<<t<<o<<" "<<N[j]<<endl;
      if(a[0]==0&&ctoi(N[j])==h){//100の位
        a[0]=1;
       // cout<<" "<<h;
      }else if(a[0]&&!a[1]&&ctoi(N[j])==(char)t){//10
        a[1]=1;
       // cout<<" "<<t;
      }else if(a[0]&&a[1]&&ctoi(N[j])==(char)o){//1
        a[2]=1;
       // cout<<" "<<o<<endl;
        break;
      }
    }
    if(a[1]&&a[2]&&a[0]) ans[i]=1;
  }
  int sum=0;
  rep(i,0,1000) sum+=ans[i];
  cout<<sum;
    
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

from math import gcd
import sys

divisors = [False]*10**6
def make_divisors(n):
    i = 1
    while i*i <= n:
        if n % i == 0:
            if not divisors[i-1]:
                divisors[i-1] = True
            elif i != 1:
                return -1
            if i != n // i:
                if not divisors[n//i-1]:
                    divisors[n//i-1] = True
                else:
                    return -1
        i += 1
    return 1

GCD = A[0]
for i in range(1,N):
    GCD = gcd(A[i], GCD)
if GCD != 1:
    print("not coprime")
else:
    for a in A:
        if make_divisors(a) < 0:
            print("setwise coprime")
            sys.exit()
    print("pairwise coprime")

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
//using P = pair<double, double>;
using edge = struct {int to; ll cost;};

#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1e9+100;
const ll INF64 = 7e18l;

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

vector<bool> prime(55556, true);
vector<int> p;

void primeInit() {
  for(int i = 2; i <= 55555; i++) {
    if(prime[i]) {
      for(int j = 2; i*j <= 55555; j++) prime[i*j]=false;
    }
  }
  for(int i = 10; i <= 55555; i++) if(prime[i] && i % 5 == 1) p.push_back(i);
}

void solve()
{
  int n;
  cin >> n;
  primeInit();
  rep(i, n) {
    cout << p[i] << " ";
  }
  cout << "\n";
}

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


Measured memory_bytes: 256
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        long k = sc.NextLong();
        int[] a = sc.IntArray().Select(i => i - 1).ToArray();
        var cur = 0;
        while (k > 0)
        {
            if (k % 2 == 1) cur = a[cur];
            var next = new int[n];
            for (int i = 0; i < n; i++)
            {
                next[i] = a[a[i]];
            }
            a = next;
            k /= 2;
        }
        Console.WriteLine(cur + 1);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 61672
from copy import copy
class imos1d:
  def __init__(self, src):
    self.d = [0]
    self.d += copy(src)
    for i in range(len(src)):
      self.d[i+1] += self.d[i]
  
  def query(self, l, r):
    return self.d[r] - self.d[l]
  
N = int(input())
S = input()
B = [ 1 if s == '#' else 0 for s in S ]
W = [ 0 if B[i] else 1 for i in range(len(B)) ]
Bi = imos1d(B)
Wi = imos1d(W)
# print(Bi.d)
# print(Wi.d)
ans = N
for i in range(0, N+1):
  ans = min(ans,
            N - Wi.query(0, i)- Bi.query(i, N))
  # print(N - Wi.query(0, i)- Bi.query(i, N))
print(ans)

Measured memory_bytes: 24260
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.range;

struct SP { string s; int p, n; }

void main() {
	int n;
	scanf("%d\n", &n);
	SP[][string] dic;
	foreach(i;0..n) {
		auto x = readln.chomp.split.array;
		dic[x[0]] ~= SP(x[0], x[1].to!int, i);
	}
	auto keys=dic.keys;
	keys.sort!"a<b";
	foreach(key; keys) {
		auto r = dic[key];
		r.sort!((a, b) => a.p > b.p);
		foreach(x; r) {
			writeln(x.n+1);
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n,f=0;
  cin>>n;
  for(int i=0;i<=26;i++)
  {
    for(int j=0;j<=26;j++)
    {
      if(4*i+7*j==n)
        f=1;

    }
  }
  if(f)
    Yes
  else
    No
    
}
return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define MAX 2000000
#define INFTY (1<<30)
using namespace std;

int H, A[MAX + 1];

inline int parent(int i) { return i / 2; }
inline int right(int i) { return 2 * i + 1; }
inline int left(int i) { return 2 * i; }

void maxHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int largest;
	if (l <= H && A[l] > A[i])  largest = l;
	else  largest = i;
	if (r <= H && A[r] > A[largest])  largest = r;

	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int extract() {
	if (H < 1) return -1;
	int max = A[1];
	A[1] = A[H];
	H--;
	maxHeapify(1);
	return max;
}

void increaseKey(int i, int key) {
	if (A[i] > key) return;
	A[i] = key;
	while (i > 1 && A[parent(i)] < A[i]) {
		swap(A[parent(i)], A[i]);
		i = parent(i);
	}
}

void insert(int key) {
	H++;
	A[H] = -INFTY;
	increaseKey(H, key);
}

int main() {
	string input;
	string cmd;
	int key;
	stringstream ss;
	while (getline(cin,input) && input!="end") {
		ss << input;
		ss >> cmd;
		if (cmd == "insert") {
			ss >> key;
			insert(key);
		}
		else if (cmd == "extract") {
			cout << extract() << endl;
		}
		else if (cmd == "end") {
			break;
		}
		ss.clear(stringstream::goodbit);
	}
}

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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int 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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int n;cin>>n;
  vint a(n),b(n);
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  vsort(b);
  rep(i,n){
    if(a[i]==b[n-1])cout << b[n-2] << endl;
    else cout << b[n-1] << endl;
  }


}


Measured memory_bytes: 3200
#include <iostream>

using namespace std;

int main()
{
    int n, A[100000+10];
    int rezultat[100000+10];
    cin>>n;
    for(int i =1;i<=n;i++)
    {
        cin>>A[i];
        rezultat[A[i]]=i;
    }
        for(int j=1; j<=n; j++)
        {
            cout<<rezultat[j]<<" ";
        }
    return 0;
}


Measured memory_bytes: 1536
# Problem: https://atcoder.jp/contests/abc105/tasks/abc105_b
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(givenMoney):
    result = "No"
    for j in range(0,101):
        for k in range(0,101):
            nowtotal = j * 4 + k * 7
            if nowtotal == givenMoney:
                result = "Yes"
    return result


if __name__ == "__main__":
    print("{}".format(solver(II())))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;++i)
int r[18][100000],x[100000];
int main(){
int i,j,n,L,Q,a,b;
cin>>n;
rep(i,n)cin>>x[i];
cin>>L;
rep(i,n)r[0][i]=upper_bound(x,x+n,x[i]+L)-x-1;
rep(i,17)rep(j,n)r[i+1][j]=r[i][r[i][j]];
cin>>Q;
rep(j,Q){
cin>>a>>b;--a;--b;
if(a>b)swap(a,b);
int ans=0,now=a;
for(i=17;i>=0;--i)if(r[i][now]<b){now=r[i][now];ans+=1<<i;}
if(now<b){now=r[0][now];++ans;}
cout<<ans<<'\n';
}
}


Measured memory_bytes: 8192
def reppref(s, n)
	(s.codepoints * ((s.size + n - 1) / s.size))
end

s = gets.chomp
t = gets.chomp

ptn = reppref(t, s.size + t.size)
mp = [-1]
j = -1
ptn.size.times{|i|
	j = mp[j] while j >= 0 && ptn[i] != ptn[j]
	j += 1
	mp.push(j)
}

j = 0
mx = 0
reppref(s, s.size * 2 + t.size).each{|x|
	j = mp[j] while j == ptn.size || (j >= 0 && ptn[j] != x)
	j += 1
	mx = j if mx < j
}
puts (mx >= s.size + t.size ? -1 : mx / t.size)


Measured memory_bytes: 48288
from collections import deque
n,x,y = map(int,input().split())
cnt = [0]*n
for i in range(n):
    d = [float('inf')]*n
    que = deque([(i, 0)])
    while que:
        idx, c = que.popleft()
        if d[idx]!=float('inf'):
            d[idx] = min(d[idx], c)
            continue
        else:
            d[idx] = min(d[idx], c)
            if idx!=0:
                que.append((idx-1, c+1))
            if idx!=n-1:
                que.append((idx+1, c+1))
            if idx==x-1:
                que.append((y-1, c+1))
            if idx==y-1:
                que.append((x-1, c+1))
    for j in range(i+1, n):
        cnt[d[j]] += 1
for c in cnt[1:]:
    print(c)



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

int C[ 110 ];

int main()
{
int i;
int N;
int T;
int c;
int t;
int iCnt;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> T;

	iCnt = 0;
	for( i = 1; i <= N;i++ )
	{
		cin >> c;
		cin >> t;
		if( t <= T )
		{
			C[ iCnt ] = c;
			iCnt++;
		}
	}

	if( iCnt == 0 )
	{
		cout << "TLE"<< endl;

		return 0;
	}

	sort( C, C+iCnt );

	cout << C[ 0 ] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,x,count=0;
  while(true){
    cin>>n>>x;
    if(n==0 && x==0)
      break;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	for(int k=j+1;k<=n;k++){
	  if(i+j+k==x)
	    count++;
	}
      }
    }
    cout<<count<<'\n';
    count=0;
  }
  return(0);
}



Measured memory_bytes: 3104
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  const ll V = 4;
  std::vector< std::vector<ll> > dist(V, std::vector<ll>(V, INF));
  for (ll i = 0; i < V; i++) {
    dist[i][i] = 0LL;
  }

  for (ll i = 0; i < 3; i++) {
    ll a, b;
    std::cin >> a >> b;
    a--; b--;
    dist[a][b] = 1;
    dist[b][a] = 1;
  }

  for (ll k = 0; k < V; k++) {
    for (ll i = 0; i < V; i++) {
      for (ll j = 0; j < V; j++) {
	dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  ll ans = 0LL;
  for (ll i = 0; i < V; i++) {
    ans = std::max(ans, *std::max_element(dist[i].begin(), dist[i].end()));
  }

  if (ans == 3) print("YES");
  else print("NO");
  return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int n;
    cin >> n;
    cout << n / 3 << endl;

    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	int am,pm;
	while(~scanf("%d %d",&am,&pm)){
		if(am == pm && pm == 0) break;
		int maxV = -1;
		char alph;
		if(maxV < am+pm){
			alph = 'A';
			maxV = am+pm;
		}
		for(int i=0;i<4;i++){
			scanf("%d %d",&am,&pm);
			if(maxV < am+pm){
				alph = 'A'+i+1;
				maxV = am+pm;
			}
		}
		printf("%c %d\n",alph,maxV);
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const ll INF = 1e10;
int a,b,c,ma,su;
int main(){
  cin>>a>>b>>c;
  ma=max(a,max(b,c));
  su=a+b+c;
  if((ma*3-su)%2!=0){
    ma++;
  }
  cout<<(ma*3-su)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
        }
    }

    REP(i,w+2)cout << "#";
    cout << endl;
    REP(i,h){
        cout << "#";
        REP(j,w){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }
    REP(i,w+2)cout << "#";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const double PI = acos(-1);

bool C(double a, double b, double x, double theta){
  double s = sqrt(2*x / (a * tan(theta)));
  double t = s * tan(theta);

  if(t >= b) return false;

  if(s >= a){
    double u = ((2*x/(a*a)) + (a / tan(PI/2-theta))) / 2;
    if(u >= b) return false;
  }
  return true;
}

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  
  double ret = 0.0;
  if(a*a*b != x){
    double lb = 0.0, ub = PI/2.0;
    for(int i=0; i<100; i++){
      double mid = (lb+ub)/2.0;
      if(C(a,b,x,mid)) lb = mid;
      else ub = mid;
    }
    ret = lb * 180.0 / PI;
  }

  printf("%.12lf\n", ret);
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a==0){a=0;}
  else {a=(a*(a-1))/2;}
  if(b==0){b=0;}
  else {b=(b*(b-1))/2;}  
  printf("%d",a+b);
 return 0; 
}


Measured memory_bytes: 1692
def main():

    N,T = map(int,input().split())
    cost = []
    for i in range(N):
        c, t = map(int, input().split())
        if t <= T:
            cost.append(c)
    if cost == []:
        print("TLE")
    else:
        print(min(cost))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
n=int(input())
for i in range(1,3501):
  for j in range(1,3501):
    if 4*i*j-n*i-n*j>0:
      if (n*i*j)%(4*i*j-n*i-n*j)==0:
        print(i,j,(n*i*j)//(4*i*j-n*i-n*j))
        exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int cnt[2019];
int main() {
	string s; cin >> s;
	int ans = 0, now = 0, p = 1;
	cnt[0] = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		now = (now + (s[i] - '0') * p) % 2019;
		ans += cnt[now]++;
		p = p * 10 % 2019;
	}
	cout << ans;
}

Measured memory_bytes: 3736
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
int a[N],n;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	a[0]=-23333;
	fp(i,1,n){
		if(a[i]<a[i-1])return puts("No"),0;
		if(a[i]!=a[i-1])--a[i];
	}
	puts("Yes");
	return 0;
}

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

int main(){
    int64_t N,a=2,b=1,c=3;
    cin>>N;
    if(N==1){
        cout<<1<<endl;
    }else{
        for(int i=1;i<N;i++){
            c = a+b;
            a = b;
            b = c;
        }
        cout<<c<<endl;
    }
}


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

vector<pair<int, int>> edge[MAX];
long long mmax[MAX];

int main(void)
{
	int N, M, P;
	cin >> N >> M >> P;
	for (int i = 0; i < M; i++)
	{
		int A, B, C;
		cin >> A >> B >> C;
		A--;
		B--;
		edge[A].push_back({B, P - C});
	}
	for (int i = 1; i < N; i++) mmax[i] = 1234567890123LL;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			for (auto e : edge[j]) mmax[e.first] = min(mmax[e.first], mmax[j] + e.second);
		}
	}
	long long ans = mmax[N - 1];
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			for (auto e : edge[j]) mmax[e.first] = min(mmax[e.first], mmax[j] + e.second);
		}
	}
	if (ans != mmax[N - 1]) cout << -1 << endl;
	else cout << max(-ans, 0LL) << endl;
	return 0;
}


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

int main() {
    string S;
    int k = 0;

    cin >> k;
    cin >> S;

    //if (k > 100) return -1;
    //if (S.size() > 100) return -1;

    if (S.size() <= k) cout << S << endl;
    else {
        for (int i = 0; i < k; i++) cout << S[i];
        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3160
def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    g=[[] for _ in [0]*n]
    [g[a-1].append(b-1) for a,b in ab]
    [g[b-1].append(a-1) for a,b in ab]
    ans=[None]*n
    ans[0]=0
    temp=[0]
    while temp:
        i=temp.pop()
        for j in g[i]:
            if ans[j]==None:
                ans[j]=ans[i]^True
                temp.append(j)
            else:
                if ans[i]^ans[j]==0:
                    print(n*(n-1)//2-m)
                    return 0
    print(ans.count(0)*ans.count(1)-m)
main()

Measured memory_bytes: 44232
#include <cstdio>
#define MAX_N 200
using namespace std;
int N, A[MAX_N], B[MAX_N];
long long cnt;

void find(int now, int mult) {
  if(now == N + 1) {if(mult == 0) cnt++; return;}
  for(int i = A[now] - 1;i <= A[now] + 1; i++) {
    find(now + 1, mult * i % 2);
  }
  return;
}

int main() {
  scanf("%d", &N);
  for(int i = 1;i <= N; i++) scanf("%d", &A[i]);
  find(1, 1);
  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int s[200005];
int a[200005];
int main()
{
    int n,i,x,y;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
        a[i]=s[i];
    }
    sort(a,a+n);
    x=a[((n-1)-1)/2];
    y=a[((n-1)+1)/2];
    for(i=0;i<n;i++)
    {
        if(s[i]<y)
            printf("%d\n",y);
        else
            printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int sum=0;
    sum=a+b+c;
    if(sum==17){
        cout<<"YES"<<'\n';
    }
    else
    {
        cout<<"NO"<<'\n';
    }
    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
  int n, m;
  cin >> n >> m;
  
  UnionFind u(n);
  
  rep(i, 0, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    u.unite(a,b);
  }
  
  vector<bool> ck(n, false);
  
  rep(i, 0, n){
    ck[u.root(i)] = true;
  }
  
  int cnt = 0;
  
  rep(i, 0, n){
    if(ck[i])
       cnt++;
  }
  
  cout << cnt-1 << endl;
  
  return 0;
  
}

Measured memory_bytes: 3744
#include <stdio.h>
#define NUM 200000

int main()
{
    int n,i,a[NUM],j,maxv,minv;
    
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    maxv = a[1] - a[0];
    minv = a[0];
    for(j = 1;j < n;j++){
            if(maxv < (a[j] - minv)) maxv = a[j] - minv;
            if(minv > a[j]) minv = a[j];
    }
    
    printf("%d\n",maxv);
    
    return 0;
}



Measured memory_bytes: 2512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=2e6+3;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=1e9+7;
int fac[N],inv[N];
inline int C(int x,int y) { return 1LL*fac[x+y]*inv[x]%mod*inv[y]%mod; }
inline int solve(int x1,int x2,int y1,int y2) { return ((LL)C(x2+1,y2+1)-C(x2+1,y1)-C(x1,y2+1)+C(x1,y1))%mod; }
int main()
{
	int i,ans=0;
	int x1=gi(),x2=gi(),x3=gi(),x4=gi(),x5=gi(),x6=gi();
	int y1=gi(),y2=gi(),y3=gi(),y4=gi(),y5=gi(),y6=gi();
	for (i=fac[0]=1;i<N;i++) fac[i]=1LL*fac[i-1]*i%mod;
	for (i=2,inv[0]=inv[1]=1;i<N;i++) inv[i]=-1LL*(mod/i)*inv[mod%i]%mod;
	for (i=3;i<N;i++) inv[i]=1LL*inv[i]*inv[i-1]%mod;

	for (i=x3;i<=x4;i++)
		ans=(ans+(-i-y3+1LL)*solve(i-x2,i-x1,y3-y2-1,y3-y1-1)%mod*solve(x5-i,x6-i,y5-y3,y6-y3))%mod;
	for (i=y3;i<=y4;i++)
		ans=(ans+(-x3-i+1LL)*solve(x3-x2-1,x3-x1-1,i-y2,i-y1)%mod*solve(x5-x3,x6-x3,y5-i,y6-i))%mod;
	for (i=y3;i<=y4;i++)
		ans=(ans+(i+x4+0LL)*solve(x4-x2,x4-x1,i-y2,i-y1)%mod*solve(x5-x4-1,x6-x4-1,y5-i,y6-i))%mod;
	for (i=x3;i<=x4;i++)
		ans=(ans+(i+y4+0LL)*solve(i-x2,i-x1,y4-y2,y4-y1)%mod*solve(x5-i,x6-i,y5-y4-1,y6-y4-1))%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 15872
import sys
write = sys.stdout.write

#BM法をやってみーましょ
Sdash = input()
Slen = len(Sdash)
T = input()

#ord('?') = 63
#ord('a') = 97

#ずらし表の生成
Tlen = len(T)
Pat = [Tlen for i in range(26)]
for i in range(Tlen):
    Pat[ord(T[i]) - 97] = Tlen - (i+1)

#末尾から照合
flg = 0 #探索結果
index = Tlen - 1 #照合開始位置
pos = Tlen - 1 #探索の現在地
kouho = []

while index <= Slen-1:
    if pos == index - Tlen:
        flg = 1
        kouho.append(pos+1) #Tを書き始める位置
        index += 1 #照合開始位置を一つずらして再開
        pos = index
        continue
    if ord(Sdash[pos]) == 63 or Sdash[pos] == T[Tlen - (index - pos) - 1]:
        pos -= 1
        continue
    else:
        move = Pat[ord(Sdash[pos]) - 97]
        if pos + move <= index:
            index += 1
            pos = index
        else:
            index = pos + move
            pos = index
if flg == 1:
    #Sdashで'?'の部分にa, '?'以外の部分にSdashの文字を入れる
    for i in range(kouho[-1]):
        if Sdash[i] == '?':
            write("a")
        else:
            write(Sdash[i])
    write(T)
    for i in range(kouho[-1]+Tlen, Slen):
        if Sdash[i] == '?':
            write("a")
        else:
            write(Sdash[i])
    write("\n")
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// long long int sumXOR(int arr[], int n)
// {
//     long long int sum = 0;
//     for (int i = 0; i < 32; i++)
//     {
//         int zc = 0, oc = 0;
//         long long int idsum = 0;
//         for (int j = 0; j < n; j++)
//         {
//             if (arr[j] % 2 == 0)
//                 zc++;
//             else
//                 oc++;
//             arr[j] /= 2;
//         }
//         idsum = oc * zc * (1 << i);
//         sum += idsum;
//     }
//     return sum;
// }


signed main(){
	ll n; cin>>n;
  ll bits[62];
  ll ans = 0;
  rep(i,62) bits[i] = 0;
  rep(i,n){
    ll a; cin>>a;
    rep(j,61){
      if(a%2==0) bits[j]++;
      a /= 2;
    }
  }
  ll keta = 1;
  rep(i,62){
    ll sum = (bits[i]*(n-bits[i]))%MOD;
    sum = (sum*keta)%MOD;
    if(sum<0) sum += MOD;
    keta = (keta*2)%MOD;
    if(keta<0) keta += MOD;
    ans = (ans+sum)%MOD;
  }
  ans = (ans+MOD)%MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
N,M,X = map(int,input().split())
book =[]
for x in range(N):
    A_list =  list(map(int, input().split()))
    book.append(A_list)
conbination =[]
for i, _ in enumerate(book, 1):     
    for j in itertools.combinations(book, r=i):  # rには1、2、3と渡される
        conbination.append(j)
minn =100000000
for x in conbination:
    A = [0]*M
    m = 0
    for y in x:
        for z in range(len(y)):
            if z ==0:
                m +=y[z]
            else:
                A[z-1] +=y[z]
    if minn >m and X<=min(A):
        minn =m
        
if minn != 100000000:
    print(minn)
else:
    print(-1)

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

using str = string;
using ss = stringstream;

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

    str s;cin>>s;

    map<char,int> m;
    if(s[0]=='B'){m['B']=0;m['W']=1;}
    else{m['B']=1;m['W']=0;}

    int cnt=0;
    for(int i=0;i<s.size();i++)if(cnt%2!=m[s[i]]%2)cnt++;

    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 3744
/*SorooshH*/
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> tpi;
typedef pair<pii,pii> qpi;
const int MAX = 500;
const int MV = 1e5;
const int MOD = 1e9 + 7;
const int INF = 2e9;

string s;

int32_t main()
{
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> s;
    s[3] = '8';
    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,L=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
  	int x,a;
    cin>>x;
    a = abs(x-K);
   // cout<<a<<endl;
    if(x<=a){
    	L+=x*2;
    }//if
    else{
    	L+=a*2;}
  //cout<<i<<":"<<L<<endl;
  }//for
  cout<<L<<endl;
}

Measured memory_bytes: 3612
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;

//a, a + 1, a + 2, ... , b - 1, bの総和を求める関数(a <= b)。計算量はO(1)
Int Sum(Int a, Int b) {
	if (b < a)return 0;
	if ((b - a + 1) % 2 == 0)return (a + b) * (b - a + 1) / 2;
	else return (a + b) * ((b - a + 1) / 2) + (a + b) / 2;
}

void calc() {

	Int N, C, K; std::cin >> N >> C >> K;
	std::vector<Int> T(N);
	rep(i, N)std::cin >> T[i];
	std::sort(T.begin(), T.end());
	Int ans = 0;
	Int num = 1;
	Int fir = 0; //最初の乗客
	for (Int i = 1; i < N; ++i) {
		if (T[i] <= T[fir] + K && num + 1 <= C) {
			num++;
		}
		else {
			ans++;
			fir = i;
			num = 1;
		}
	}
	ans++;

	std::cout << ans;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, x;
    string com;
    list<int> ls;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> com;
        if(com == "insert"){
            scanf("%d", &x);
            ls.push_front(x);
        }
        if(com == "delete"){
            scanf("%d", &x);
            for(auto it = ls.begin(); it != ls.end(); it++){
                if(*it == x){
                    ls.erase(it);
                    break;
                }
            }
        }
        if(com == "deleteFirst"){
            ls.pop_front();
        }
        if(com == "deleteLast"){
            ls.pop_back();
        }
    }
    for(auto it = ls.begin(); it != ls.end(); it++){
        if(it != ls.begin()) printf(" ");
        printf("%d", *it);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 34504