akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a_list = list(map(int, input().split()))
max_a = max(a_list)
if max_a==0:
    print(N)
    exit()
ans = [0]*(max_a+1)
for i in a_list:
    if i==0:
        ans[0] += 1
        ans[1] += 1
    elif i==max_a:
        ans[-1] += 1
        ans[-2] += 1
    else:
        ans[i-1] += 1
        ans[i] += 1
        ans[i+1] += 1
print(max(ans))


Measured memory_bytes: 13964
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = str(readline().rstrip().decode('utf-8'))
    b = str(readline().rstrip().decode('utf-8'))
    c = str(readline().rstrip().decode('utf-8'))
    cnt = 0
    for i in range(n):
        ct = collections.Counter([a[i], b[i], c[i]])
        if len(ct) == 3:
            cnt += 2
        elif len(ct) == 2:
            cnt += 1
        elif len(ct) == 1:
            cnt += 0
    print(cnt)


if __name__ == '__main__':
    solve()


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

typedef pair<int, int> pii;
const int N = 2e5 + 100, MOD = 1000 * 1000 * 1000 + 7;

int n, m, dp[N], v[N], maxi[N], mini[N], fen[N]; // fen)
int Z = 1;
pii p[N];

int sum(int a, int b) {
	a += b;
	if (a < 0)
		a += MOD;
	else if (a >= MOD)
		a -= MOD;
	return a;
}
void _sum(int &a, int b) {
	a = sum(a, b);
}
int mul(int a, int b) {
	return 1LL * a * b % MOD;
}
void _mul(int &a, int b) {
	a = mul(a, b);
}

void add(int dex, int val) {
	for (++dex; dex < N; dex += dex & -dex)
		_sum(fen[dex], val);
}
int get(int r) {
	int res = 0;
	for (; r; r ^= r & -r)
		_sum(res, fen[r]);
	return res;
}

void input() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i].first >> p[i].second;
	sort(p, p + n);
	for (int i = 0; i < n; i++)
		v[i] = p[i].second;
}

int L(int i) {
	return lower_bound(maxi, maxi + i, v[i]) - maxi;
}
int R(int i) {
	return upper_bound(mini + i, mini + n, v[i]) - mini - 1;
}

vector<pii> ready_1() {
	maxi[0] = v[0];
	for (int i = 1; i < n; i++)
		maxi[i] = max(maxi[i - 1], v[i]);
	mini[n - 1] = v[n - 1];
	for (int i = n - 2; i >= 0; i--)
		mini[i] = min(mini[i + 1], v[i]);

	vector<pii> vec;
	for (int i = 0; i < n; i++)
		vec.push_back(pii(L(i), R(i)));
	return vec;
}

int LL(vector<pii> *vec, int i) {
	return lower_bound(vec->begin(), vec->end(), pii(i, i), [](pii a, pii b) {
		return a.second < b.second;
	}) - vec->begin();
}

int RR(vector<pii> *vec, int i) {
	return upper_bound(vec->begin(), vec->end(), pii(i, N), [](pii a, pii b) {
		return a.first < b.first;
	}) - vec->begin() - 1;
}

vector<pii> ready_2(vector<pii> vec) {
	sort(vec.begin(), vec.end());
	int mn = N;
	vector<pii> help;
	while (vec.size()) {
		pii p = vec.back();
		vec.pop_back();
		if (p.second < mn) {
			help.push_back(p);
			mn = p.second;
		}
	}
	reverse(help.begin(), help.end());
	m = help.size();
	for (int i = 0; i < n; i++) {
		vec.push_back(pii(LL(&help, i), RR(&help, i)));
		if (vec.back().first > vec.back().second) {
			vec.pop_back();
			_mul(Z, 2);
		}
	}
	return vec;
}

int solve(vector<pii> vec) {
	int ans = 0;
	sort(vec.begin(), vec.end());
	for (int i = 0; i < vec.size(); i++) {
		dp[i] = sum(get(N - 1), -(vec[i].first? get(vec[i].first - 1): 0));
		if (vec[i].first == 0)
			_sum(dp[i], 1);
		if (vec[i].second == m - 1)
			_sum(ans, dp[i]);
		add(vec[i].second, dp[i]);
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	input();
	cout << mul(Z, solve(ready_2(ready_1())));
}


Measured memory_bytes: 9072
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int N;
int A, B, C, D;
string S;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> A >> B >> C >> D >> S;

    A--, B--, C--, D--;
    bool bad = false;
    for (int i = A; i < max (C, D); i++)
    {
        if (S[i] == '#' && S[i+1] == '#')
        {
            bad = true;
        }
    }

    bool good = true;
    if (C > D)
    {
        good = false;
        for (int i = B; i <= D; i++)
        {
            if (S[i] == '.' && S[i+1] == '.' && S[i-1] == '.')
                good = true;
        }
    }

    if (bad || !good)
        cout << "No\n";
    else
        cout << "Yes\n";
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

    ll a,b;
    cin>>a>>b;
    ll ans=a/b;
    if(a%b!=0){++ans;}
    cout<<ans;

    return (0);
}


Measured memory_bytes: 256
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
H = list(map(int, input().split()))

dp = [10**9] * N
dp[0] = 0
for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
    
    if i < N - 2:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))

print(dp[-1])

Measured memory_bytes: 84804
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n, m; cin >> n >> m;

    if(abs(n-m) >= 2){
        cout << 0 << endl;
        return 0;
    }

    if(abs(n-m) == 1){
        ll ans = 1;
        rep(i,m){
            ans *= i+1;
            ans %= 1000000007;
        }
        rep(i,n){
            ans *= i+1;
            ans %= 1000000007;
        }
        cout << ans << endl;
        return 0;
    }

    if(n == m){
        ll ans = 2;
        rep(i,m){
            ans *= i+1;
            ans %= 1000000007;
        }
        rep(i,n){
            ans *= i+1;
            ans %= 1000000007;
        }
        cout << ans << endl;
        return 0;
    }
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N, M;
	cin >> N >> M;

	vector <ll> H(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> H[ii];
	}

	vector<vector<ll>> path(N, vector <ll>());
	for (int ii = 0; ii < M; ++ii){
		ll a, b;
		cin >> a >> b;
		a--; b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}

	ll ans = 0;
	for (int ii = 0; ii < N; ++ii){
		bool OK = true;
		for (int jj = 0; jj < path[ii].size(); ++jj){
			if (H[ii] <= H[path[ii][jj]]){
				OK = false;
				break;
			}
		}
		if (OK)
		{
			ans++;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 9860
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

vll poww;

ll modpow(ll a, ll b){
	ll r=1;
	while(b)
	{
		if(b&1)r=(r*a);
		a=(a*a);
		b>>=1;
	}
	return r;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll x; cin >> x;
	for(int i=0; i<=6718; i++){
		poww.pb((ll)modpow(i,5));
	}
	for(int i=0; i<poww.size(); i++){
		ll cur = x-poww[i];
		if(binary_search(all(poww),cur)){
			auto ptr = lower_bound(all(poww),cur)-poww.begin();
			cout << i << ' ' << -1*ptr << endl;
			return 0;
		}
		cur = x+poww[i];
		if(binary_search(all(poww),cur)){
			auto ptr = lower_bound(all(poww),cur)-poww.begin();
			cout << ptr << ' ' << i << endl;
			return 0;
		}
	}
}	


Measured memory_bytes: 3736
#include <iostream>
using namespace std;
int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if ((A+B)==(C+D))
	{
		cout << "Balanced" << endl;
	}
	else
	{
		if (A+B>C+D)
		{
			cout << "Left" << endl;
		}
		else
		{
			cout << "Right" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

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

  bool ans = false;
  if (s[2] == s[3] and s[4] == s[5])
    ans = true;

  std::cout << (ans ? "Yes" : "No") << std::endl;

  return 0;
}


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

class P
{
    static void Main()
    {
        int i = Console.ReadLine().Split().Select(int.Parse).ToArray()[0];
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int amax = A.Max();
        Console.WriteLine(Math.Max(amax - (i - amax) - 1, 0));
    }
}

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

int main (void){
  long n;
  cin >> n;
  
  long sq_n = static_cast<long>(sqrt(n));
  long ans = 0;
  for(long i = sq_n; i > 0; i--){
    if(n % i == 0){
      long j = n / i;
      ans = i + j - 2;
      cout << ans;
      return 0;
    }
  }
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var n = long.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var min = a.Min();
        var max = a.Max();

        long kabu = 0;
        long kane = 1000;
        if (a[0] <= a[1])
        {
            kabu = 1000 / a[0];
            kane = 1000 % a[0];
        }
        else
        {
            kabu = 0;
            kane = 1000;
        }

        // 貪欲法
        for (int i = 1; i < n; i++)
        {
            bool flag = true;
            // 単調減少なら売り
            for(int j = i+1; j < n; j++)
            {
                if (a[j - 1] < a[j]) flag = false;
            }
            if (flag)
            {
                kane += kabu * a[i];
                kabu = 0;
                if (kane < 1000) kane = 1000;
                break;
            }

            if (a[i - 1] <= a[i])
            {
                // 全部売却
                if (i != n - 1 && a[i] <= a[i + 1]) continue;

                kane += kabu * a[i];
                kabu = 0;
            }
            else if (a[i - 1] > a[i])
            {
                if (i != n - 1 && a[i] > a[i + 1]) continue;

                // 全部購入
                kabu = kane / a[i];
                kane = kane % a[i];
            }
        }

        if(kabu != 0)
        {
            kane += a.Last() * kabu;
        }

        if (kane > 1000) Console.WriteLine(kane);
        else Console.WriteLine("1000");
    }
}

Measured memory_bytes: 28232
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var n int

func main() {
	tmp := NextIntsLine()
	n = tmp[0]
	q := n / 15
	x := n * 800
	y := q * 200
	fmt.Println(x - y)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }

int main() {
	int K, N;
	cin >> K >> N;

	vector<int> a(N, 0);

	ll cost = 0;
	repeat(i, N) {
		cin >> a[i];
	}

	vector<int> diff;
	repeat(i, N-1) {
		diff.push_back( abs(a[i] - a[i+1]) );
	}
	
	diff.push_back( abs( K + a[0] - a[N-1] ) );

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

	repeat(i, N-1) {
		cost += diff[i];
	}
	cout << cost << endl;
	return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,c=0; cin>>n;
  string s; cin>>s;
  int a[1000]={0};
  for(int i=0;i<1000;i++){
    string ts=s,ss="00";
    ss+=to_string(i);
    ss=ss.substr(ss.size()-3);
    bool f=true;
    for(char c:ss){
      if(ts.find(c)!=string::npos) ts=ts.substr(ts.find(c)+1);
      else{f=false; break;}
    }
    if(f) a[i]++;
  }
  for(int i:a) if(i) c++;
  cout<<c;
}

Measured memory_bytes: 3776
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[36]={1,2,3,4,5,6,7,8,9,10,12,14,16,18,15,21,24,27,20,28,32,36,25,30,35,40,45,42,48,54,49,56,63,64,72,81};
	int n;
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<=35;i++){
		if(a[i]==n){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int n, press=1, cnt=0;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
    }
    rep(i, n){
        press = a.at(press-1);
        cnt ++;
        if(press == 2){
            cout << cnt << endl;
            break;
        }
        if(cnt >= n){
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
typedef long long ll;
struct node {
	ll d, c;
}q[maxn];
bool cmp(node a, node b) {
	return a.d < b.d;
}
priority_queue<ll> que;
int main() {
	int n, m;
	cin >> n >> m;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> q[i].d >> q[i].c;
	} 
	sort (q + 1, q + n + 1, cmp);
	for (int i = 1, j = 1; i <= m; i++) {
		while (q[j].d <= i && j <= n) {
			que.push(q[j].c); j++;
		}
		if (!que.empty()) {
			ans += que.top(); que.pop();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=5+1e5;
const int alpha='z'-'a'+1;
int nums[SIZE][alpha][alpha];
int smaller[SIZE];
string s[SIZE];
struct node{
	node* next[alpha];
	bool maked[alpha];
	bool isEnd;
	int size;
	void init(){
		size=0;
		isEnd=false;
		REP(i,alpha) maked[i]=false;
	}
};
node root;
node nodes[SIZE*10];
int nextnode=1;
node* getnext(node* now,int x,bool unmake=false){
		if(now->maked[x]) return now->next[x];
		if(unmake) return &nodes[0];
		now->maked[x]=true;
		now->next[x]=&nodes[nextnode++];
		now->next[x]->init();
		return now->next[x];
}
void add(int x){
	node* now= &root;
	REP(i,s[x].size()){
		now->size++;
		now=getnext(now,s[x][i]-'a');
	}

	now->isEnd=true;
	now->size++;
}
void analys(int x){
	node* now= &root;
	REP(i,s[x].size()){
		if(now->isEnd) smaller[x]++;
		FOR(j,'a','z'+1){
			if(s[x][i]==j) continue;
			nums[x][j-'a'][s[x][i]-'a']+=getnext(now,j-'a',true)->size;
		}
		now=getnext(now,s[x][i]-'a',true);
	}
}
bool isFaster(string p,char a,char b){
	REP(i,p.size()){
		if(p[i]==a) return true;
		if(p[i]==b) return false;
	}
}
int solve(int x,string p){
	int ans=0;
	REP(i,alpha) REP(j,i){
		ans+=nums[x][p[j]-'a'][p[i]-'a'];
		//if(nums[x][i][j])cout << x <<" " <<  char(i+'a') <<" " << char(j+'a') << " " << nums[x][i][j] << endl; 
	}
	return ans+smaller[x];
}
int main(){
	int N;
	cin.tie(0);
	cin >> N;
	REP(i,SIZE*10) nodes[i].init();
	REP(i,N){
		cin >> s[i];
		add(i);
	}
	REP(i,N){
		analys(i);
	}
	int Q,k;
	cin >> Q;
	string p;
	REP(i,Q){
		cin >> k >> p;
		cout << solve(k-1,p)+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 505088
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 100005;
const int MOD = 1e9 + 7;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n;
LL A, B, a[MAXN];
int pre1[MAXN], pre2[MAXN], dp1[MAXN], dp2[MAXN], sum1[MAXN], sum2[MAXN];

inline int Add(int x, int y) {
	x += y; if (x >= MOD) x -= MOD; return x;
}

inline int Sub(int x, int y) {
	x -= y; if (x < 0) x += MOD; return x;
}

void init() {
	read(n); read(A); read(B);
	for (int i=1;i<=n;++i) {
		read(a[i]);
	}
	pre1[1] = pre2[1] = 1;
	pre1[n] = pre2[n] = n;
	for (int i=2;i<n;++i) {
		int t = pre1[i-1];
		while (t < i && a[i+1] - a[t] >= B) ++t;
		pre1[i] = t;
	}
	for (int i=2;i<n;++i) {
		int t = pre2[i-1];
		while (t < i && a[i+1] - a[t] >= A) ++t;
		pre2[i] = t;
	}
}

void solve() {
	dp1[0] = sum1[0] = dp2[0] = sum2[0] = 1;
	int l1 = 1, l2 = 1;
	for (int i=1;i<=n;++i) {
		if (i > 1 && a[i] - a[i-1] < A) l1 = i;
		if (i > 1 && a[i] - a[i-1] < B) l2 = i;
		if (l1 <= pre1[i]) {
			dp1[i] = sum2[pre1[i]-1];
			if (l1 > 1) dp1[i] = Sub(dp1[i], sum2[l1-2]);
		}
		if (l2 <= pre2[i]) {
			dp2[i] = sum1[pre2[i]-1];
			if (l2 > 1) dp2[i] = Sub(dp2[i], sum1[l2-2]);
		}
		sum1[i] = Add(sum1[i-1], dp1[i]);
		sum2[i] = Add(sum2[i-1], dp2[i]);
	}
	printf("%d\n", Add(dp1[n], dp2[n]));
}

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int x, n;
  cin >> x >> n;
  vector<bool> seen(102);
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    seen[v] = true;
  }

  int ans = -1;
  for (int i = 0; i <= 100; ++i) {
    if (!seen[x - i]) {
      ans = x - i;
      break;
    }
    if (!seen[x + i]) {
      ans = x + i;
      break;
    }
  }
  cout << ans << "\n";

}


Measured memory_bytes: 3536
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	vector<vector<int> > v(3);
	vector<vector<ll> > cs(3);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 3; ++i) {
		v[i].resize(n);
		cs[i].resize(n);
		for (int j = 0; j < n; ++j)
			scanf("%d", &v[i][j]);
		sort(v[i].begin(), v[i].end());
	}
	for (int i = 0; i < n; ++i)
		cs[0][i] = i + 1;
	for (int i = 1; i < 3; ++i) {
		for (int j = 0; j < n; ++j) {
			int me = v[i][j];
			int idx = lower_bound(v[i - 1].begin(), v[i - 1].end(), me) - v[i - 1].begin();
			if (idx)
				cs[i][j] = cs[i - 1][idx - 1];
			if (j)
				cs[i][j] += cs[i][j - 1];
		}
	}
	cout << cs[2].back() << endl;
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define Keep_calmYou_are_still_learning ios_base::sync_with_stdio(false);cin.tie(NULL);//freopen("out.txt","w",stdout);
typedef long long ll;
typedef long double ld;
using namespace std;



int main()
{
    Keep_calmYou_are_still_learning;

    string a,b;
    cin>>a>>b;
    pair<ll,pair<ll,ll>> dp[a.size()+1][b.size()+1]={},ans={0,{-1,-1}};
    for (ll i=0;i<a.size();i++)
        for (ll j=0;j<b.size();j++)
        {
            if (a[i]==b[j])
                dp[i+1][j+1]=max(dp[i+1][j+1],{dp[i][j].first+1,{i,j}} ),ans=max(ans,dp[i+1][j+1]);
            dp[i][j+1]=max(dp[i][j+1],{dp[i][j].first,{i,j}} );
            dp[i+1][j]=max(dp[i+1][j],{dp[i][j].first,{i,j}} );
        }
    stack<char> seksek;
    while(ans.second.second>=0 && ans.second.first>=0)
    {
        if (dp[ans.second.first][ans.second.second].first<ans.first)
            seksek.push(a[ans.second.first]);
        if (ans.first==0)
            break;

        ans=dp[ans.second.first][ans.second.second];
    }
    while(!seksek.empty())
    {
        cout<<seksek.top();
        seksek.pop();
    }
    cout<<'\n';

    return 0;
}


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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int main()
{
    string N;
    cin >> N;
    cout << (N[0] == '9' || N[1] == '9' ? "Yes" : "No") << endl; 
    return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    double r;
    cin>>r;
    double ans=2*PI*r;
    cout<<setprecision(8)<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int t;

int main(){
	cin>>t;
	if(t<1200) cout<<"ABC"<<endl;
	else if(t<2800) cout<<"ARC"<<endl;
	else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;


ll a, b, c, d;

ll lcm(ll x, ll y){
    return (x / __gcd(x, y)) * y;
}

ll solve(ll a, ll x){
    return (a / x);
}

ll f(ll a, ll b, ll x){
    return solve(b, x) - solve(a - 1, x);
}

int main(){
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    if(a > b)swap(a, b);
    ll ans = 0;
    ans += f(a, b, c);
    ans += f(a, b, d);
    ans -= f(a, b, lcm(c, d));
    ans = (b - a + 1) - ans;
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

const int mod=1e9+7;

signed main()
{
    int N; cin>>N;
    vector<int> a(N),b(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    for(int i=0;i<N;i++){
        cin>>b[i];
    }
    
    int ans=1;
    for(int i=0;i<N;i++){
        if(i==0 or a[i-1]<a[i]){
            if(i==N-1 or b[i]>b[i+1]){
                if(a[i]!=b[i]) ans=0;
            }else{
                if(a[i]>b[i]) ans=0;
            }
        }else{
            if(i==N-1 or b[i]>b[i+1]){
                if(a[i]<b[i]) ans=0;
            }else{
                ans*=min(a[i],b[i]);
                ans%=mod;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
n,k=map(int,input().split())
grid=[[0]*k for _ in range(k)]
for i in range(n):
    x,y,c=map(lambda x:x,input().split())
    x,y=int(x),int(y)
    p=(x//k+y//k)%2
    if (p==0 and c=="B")|(p==1 and c=="W"): grid[x%k][y%k]+=1
    else: grid[x%k][y%k]-=1

for i in range(k):
    for j in range(1,k):
        grid[i][j]+=grid[i][j-1]

for i in range(1,k):
    for j in range(k):
        grid[i][j]+=grid[i-1][j]


ans=0
for i in range(k):
    for j in range(k):
        b=grid[i][j]*4+grid[k-1][k-1]-(grid[i][k-1]+grid[k-1][j])*2
        ans=max(ans,(n+b)//2,(n-b)//2)
print(ans)

Measured memory_bytes: 56664
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int minRate;
        int maxProfit = Integer.MIN_VALUE;
        int r = in.nextInt();
        minRate = r;

        for (int i = 1; i < n; i++) {
            r = in.nextInt();
            maxProfit = (maxProfit > r - minRate)? maxProfit : r - minRate;
            if(r < minRate) minRate = r;
        }
        System.out.println(maxProfit);
    }
}

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

int main(int argc, char const *argv[]) {
  int m, n, x, i, j;

  cin >> m >> n;
  int matrix[m + 1][n + 1] = {};

  for (i = 0; i < m; i++) {
    for (j = 0; j < n + 1; j++) {
      if (j != n) {
        cin >> x;
        matrix[i][j] = x;
        matrix[i][n] += matrix[i][j];
        matrix[m][j] += matrix[i][j];
      } else {
        matrix[m][n] += matrix[i][j];
      }
    }
  }

  for (i = 0; i < m + 1; i++) {
    for (j = 0; j < n + 1; j++) {
      cout << matrix[i][j];
      if (j != n) cout << " ";
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3124
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //文字列
        String str = sc.next();
        //命令数
        int n = Integer.parseInt(sc.next());

        for(int i=0; i<n; i++){
            //命令
            String order = sc.next();
            //a文字目
            int start = Integer.parseInt(sc.next());
            //b文字目
            int end = Integer.parseInt(sc.next());
            //命令がprintの場合
            if(order.equals("print")){
                System.out.println(print(str,start,end));
            }
            //命令がreverseの場合
            if(order.equals("reverse")){
                str = reverse(str,start,end);
            }
            //命令がreplaceの場合
            if(order.equals("replace")){
                //置換する文字
                String word = sc.next();
                str = replace(str,start,end,word);
            }
        }

    }
    //print
    public static String print(String str,int start, int end){
        StringBuilder sb = new StringBuilder();
        for(int i=0; i < str.length(); i++){
            if(start <= i && i <= end){
                sb.append(str.charAt(i));
            }
        }
        return sb.toString();
    }
    
    //reverse
    public static String reverse(String str,int start, int end){
        StringBuilder sb = new StringBuilder();
        for(int i=0; i < str.length(); i++){
            if(start <= i && i <= end){
                sb.append(str.charAt(start+end-i));
            }else{
                sb.append(str.charAt(i));
            }
        }
        return sb.toString();
    }
    //replace
    public static String replace(String str,int start, int end,String word){
        StringBuilder sb = new StringBuilder();
        for(int i=0; i < str.length(); i++){
            if(start <= i && i <= end){
                sb.append(word.charAt(i-start));
            }else{
                sb.append(str.charAt(i));
            }
        }
        return sb.toString();        
    }    

}



Measured memory_bytes: 30616
# ABC131D - Megalomania
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))
    for task, deadline in TD:  # check all tasks greedily
        cur += task
        if cur > deadline:  # fail to finish a task within its deadline
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 48708
/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  pb push_back
#define  mp make_pair
#define  sz(s) (int)s.size()
typedef long long int ll;
const int N = 1e5+5;

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

    ll n,m;cin>>n>>m;
    bool F = 0;
    ll Arr[m+2],A=-1,B=-1;
    for(int i=1;i<=m;i++)
    {
        cin>>Arr[i];
        if( Arr[i]&1 )
        {
            if( A==-1 )A = i;
            else if( B==-1 )B = i;
            else F = 1;
        }
    }
    if( F )cout<< "Impossible\n";
    else
    {
        if( m==1 )
        {
            if( Arr[1]==1 )cout<< "1\n1\n1\n";
            else cout<<Arr[1]<<"\n"<<"2\n"<<"1 "<<Arr[1]-1<< "\n";
        }
        else
        {
            if( A!=-1 )swap(Arr[1],Arr[A]);
            if( B!=-1 )swap(Arr[m],Arr[B]);
            for(int i=1;i<=m;i++)
            {
                if(i>1)cout<< " ";
                cout<<Arr[i];
            }
            cout<< "\n";
            Arr[1]++,Arr[m]--;
            if(Arr[m])cout<<m<< "\n";
            else cout<<m-1<< "\n";
            for(int i=1;i<=m;i++)
            {
                if( Arr[i] )
                {
                    if( F )cout<< " ";
                    cout<<Arr[i];
                    F = 1;
                }
            }
            cout<< "\n";
        }
    }




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }

//merge [l,m) with [m,r)
void MergeSort(VI& a, VI& tmp, int l, int m, int r) {
    if (l == m)return;
    MergeSort(a, tmp, l, l + m >> 1, m);
    MergeSort(a, tmp, m, m + r >> 1, r);
    int i = l, j = m, k = l;
    for (; i < m || j < r; ++k) {
        if (i == m)
            tmp[k] = a[j++];
        else if (j == r)
            tmp[k] = a[i++];
        else if (a[i] < a[j])
            tmp[k] = a[i++];
        else
            tmp[k] = a[j++];
    }
    for (k = l; k < r; ++k)
        a[k] = tmp[k];
}

int main() {
    init();

    int n, k; cin >> n >> k;
    VI h(n); cin >> h;

    VI tmp(n);
    MergeSort(h, tmp, 0, n >> 1, n);

    ll ans = 0;
    FOR(i, 0, n - k)ans += h[i];
    print(ans);

    return 0;
}


Measured memory_bytes: 4768
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    if ((A <= 8) && (B <= 8)) {
      System.out.println("Yay!");  
    } else {
      System.out.println(":(");
    }

  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans=0;
  REP(i,a+1) {
    REP(j,b+1) {
      REP(k,c+1) {
        if(i*500+100*j+50*k==x) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True

p = None
XY = None
N = None


def dfs(XY, cur, ans_list):
    if cur == N:
        # show(ans_list, len([i for i in ans_list if i != 0]))
        return len([i for i in ans_list if i != 0])

    flag = True
    _ans_list = [i for i in ans_list]
    for xy in XY[cur]:
        if _ans_list[xy[0]-1] == -1 or _ans_list[xy[0]-1] == xy[1]:
            _ans_list[xy[0]-1] = xy[1]
        else:
            flag = False

    ret0 = 0
    ret1 = 0

    if flag:
        if _ans_list[cur] == -1 or _ans_list[cur] == 1:
            _ans_list[cur] = 1
            ret0 = dfs(XY, cur+1, _ans_list)

    _f_ans_list = [i for i in ans_list]
    # _f_ans_list[cur] = 0
    if _f_ans_list[cur] == -1 or _f_ans_list[cur] == 0:
        _f_ans_list[cur] = 0
        ret1 = dfs(XY, cur+1, _f_ans_list)

    return max(ret0, ret1)


def main():
    global p
    global XY
    global N
    N = I()
    XY = [[] for i in range(N)]
    p = [[] for i in range(N+1)]

    for i in range(N):
        a = I()
        for j in range(a):
            x, y = MI()
            XY[i].append((x, y))
            p[x].append(y)

    # print(XY)
    print(dfs(XY, 0, [-1] * N))
    # flag = True
    # for i in range(1, len(p)):
    #     if len(p[i]) == 1 and p[i][0] == 0:
    #         flag = flag and True
    #     else:
    #         flag = flag and False

    # if flag:
    #     print(1)
    #     return

    # ans = 0
    # for i in range(1, len(p)):
    #     # print(sum(p[i]), len(p[i]))
    #     if sum(p[i]) == len(p[i]):
    #         ans += 1

    # print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5440
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j] \
                    and L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                ans += 1

print(ans)


Measured memory_bytes: 9188
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    count=0
    la=len(A)
    for i in range(0,la-1):
        for j in range(i+1,la):
            ai,aj=A[i],A[j]
            if ai>aj:
                count+=1
    
    asrt=sorted(list(A))
    d=dict()

    rui=0
    for i,a in enumerate(asrt):
        if a in d:
            continue
        else:
            d[a]=i

    ans=(count*K)%mod
    
    for a in A:
        order=d[a]
        ans=(ans+((K*(K-1)//2)%mod*order)%mod)%mod

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 41692
#include<bits/stdc++.h>
#define maxn 605
#define rep(i,j,k) for(int i=(j),LIM=(k);i<=LIM;i++)
#define per(i,j,k) for(int i=(j),LIM=(k);i>=LIM;i--)
#define LL long long
using namespace std;

int n;
int mod;
int f[2][maxn];
int up[maxn],dn[maxn],d[maxn],c[maxn];
bool cmp(const int &u,const int &v){ return d[u] < d[v]; }

int main(){
	scanf("%d%d",&n,&mod);
	rep(i,0,2*n-1) up[i] = min((int)floor(sqrt(4 * n * n - i * i)),2*n-1) , dn[i] = (i <= n ? (int)ceil(sqrt(n * n - i * i)) : 0);
	rep(i,0,n-1) d[i] = dn[i] - 1;
	rep(i,n,2*n-1) d[i] = up[i];
	rep(i,0,2*n-1) c[i] = 2*n-i-1;
	stable_sort(c,c+2*n,cmp);int ans =0 ;
	rep(k,0,n){
		memset(f,0,sizeof f);
		int now = 1, pre = 0 , cntr = 0;
		f[now][0] = 1;
		rep(i,0,2*n-1){
			int u = c[i];
			swap(now,pre);
			rep(j,0,k) if(f[pre][j]){
				if(u >= n){	
					f[now][j] = (f[now][j] + 1ll * f[pre][j] * max(up[u] + 1 - i + (cntr - j), 0)) % mod;
				}
				else{
					f[now][j] = (f[now][j] + 1ll * f[pre][j] * max(up[u] + 1 - n - (k-j) - cntr , 0)) % mod;
					if(j < k) f[now][j+1] = (f[now][j+1] + 1ll * f[pre][j] * max(dn[u] - i + (cntr - j) , 0)) % mod;
				}
				f[pre][j] = 0;
			}
			if(u < n) cntr ++;
		}
		ans = (ans + (k&1?-1ll:1ll) * f[now][k]) % mod;
	}
	printf("%d\n",(ans+mod)%mod);
}

Measured memory_bytes: 3872
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>

using namespace std;

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

	struct entry_t { string cityname; int score; int index; };
	
	// entry_t を要素とした可変長配列
	vector<entry_t> v;

	// i を N 回すマクロ
#define REP(I,N) for (int I = 0; I < (N); I++)
	REP(i, N)
	{
		// 入力
		string cityname; cin >> cityname;
		int score; cin >> score;
		int index = i + 1;

		// 可変長配列に要素を追加
		entry_t e = { cityname, score, index };
		v.push_back(e);
	}

	// みずから comparer を書く sort
	sort(v.begin(), v.end(),
		[](const entry_t &A, const entry_t &B) -> bool // ラムダ式(無名関数)
		{
			return A.cityname != B.cityname ? A.cityname < B.cityname
				: A.score != B.score ? A.score > B.score
				: false;
		});

	// ALLOFや、COMPマクロを用意して、
#define ALLOF(C) C.begin(), C.end()
#define COMP(T,A,B,...) [](const T &A, const T &B) { return __VA_ARGS__; }
	sort(ALLOF(v), COMP(entry_t, A, B, A.cityname != B.cityname ? A.cityname < B.cityname : A.score > B.score));
	// のようにしてもいい。

	REP(i, N)
	{
		// 出力して改行
		cout << v[i].index << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
constexpr double eps = 1e-12;
double deg2rad(double x) { return x / 360 * (2 * M_PI); }
double frem(double x, double y) { return fmod(fmod(x, y) + y + eps, y); }
enum face_t { ABC, ACD, ADB, BCD };
 
face_t get_face() {
    string xy; int d, l; cin >> xy >> d >> l;
    double face_theta =
        xy == "BC" ? 0 :
        xy == "CD" ? 60 :
        xy == "DB" ? 120 :
        NAN;
    double theta = deg2rad(face_theta + d);
    double x = l * cos(theta);
    double y = l * sin(theta);
    double z60 = x + y / sqrt(3);
    double z120 = - x + y / sqrt(3);
    z60 = frem(z60, 2);
    z120 = frem(z120, 2);
    double w = (z60 + z120) * (sqrt(3) / 2);
    return
        w < sqrt(3) / 2 ?
            ACD :
        w < sqrt(3) ?
            z60 > 1 ? ABC :
            z120 > 1 ? ADB :
            BCD :
        w < 3 * sqrt(3) / 2 ?
            z60 < 1 ? ABC :
            z120 < 1 ? ADB :
            BCD :
        ACD;
}
 
int main() {
    face_t a = get_face();
    face_t b = get_face();
    cout << (a == b ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll m;
    cin>>m;
    // i から　j を　1<<k 回　たす(i,j,k)
    vector<vector< vector<mp> > > g(10, vector<vector<mp> >(10,vector<mp>(64, mp(-1,0) ) ) );
    for(int i=0;i<10;i++){
	for(int j = 0;j<10;j++){
	    int add = 0;
	    if( i + j >= 10 )add++;
	    g[i][j][0] = mp( (i+j)%10 + add, 1 + add );
	}
    }
    for(int i=1;i<64;i++){
	for(int j = 0;j<10;j++){
	    for(int k = 0;k<10;k++){
		g[j][k][i].first = g[ g[j][k][i-1].first ][k][i-1].first;
		g[j][k][i].second = g[j][k][i-1].second + g[ g[j][k][i-1].first ][k][i-1].second;
	    }
	}
    }

    vector<ll> d(m),c(m);
    for(ll i=0;i<m;i++)cin>>d[i]>>c[i];
    ll res = 0;
    ll now = 0;
    //for(ll i=m-1;i>=0;i--){
    for(ll i=0;i<m;i++){
	for(ll j=0;j<64;j++){
	    if( (c[i]>>j)&1LL ){
		res += g[now][d[i]][j].second;
		now = g[now][d[i]][j].first;
	    }
	}
    }
    cout<<res-1<<endl;

    return 0;
}


Measured memory_bytes: 3456