akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	int l, r;
	cin >> l >> r;
	if(l%2019 == 0 || l/2019 != r/2019) {
		cout << 0 << endl;
		return 0;
	}
	int mn = INF;
	for(int i=l;i<=r;i++)
		for(int j=l;j<i;j++)
			mn = min(mn, i%2019*(j%2019)%2019);
	cout << mn << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

int cmp(pair <int,int> p1, pair <int,int> p2){
    if(p1.second > p2.second) return 0;
    if(p1.second == p2.second){
      if(p1.first > p2.second) return 1;
    }
    return 1;
}


int main()
{
   int n, m;
   cin >> n >> m;
   vector <pair<int,int> > vec, vec1;
   
   for(int i = 0; i < m; i++){
       int l, r;
       cin >> l >> r;
       r--;
       vec1.push_back({r,l});
   }
   
   sort(vec1.begin(), vec1.end());
   for(int i = 0; i < m; i++){
       vec.push_back({vec1[i].second, vec1[i].first});
   }
   
   int cnt = 0;
   int las = 0;
   for(int i = 0; i < m; i++){
       cnt++;
       int j = i+1;
       while(j < m && vec[j].first <= vec[i].second && vec[j].second >= vec[i].second){
             j++;
       }
       if(j == m) break;
       i = j-1;
   }
   cout << cnt << endl;
}


Measured memory_bytes: 2548
def main():
    a = []
    b = []
    for _ in range(10):
        a.append(int(input()))
    for _ in range(10):
        b.append(int(input()))
    a.sort(reverse = True)
    b.sort(reverse = True)

    aa = 0
    bb = 0
    for x in range(3):
        aa += a[x]
        bb += b[x]

    print(aa, bb)

if __name__ == "__main__":
    main()

Measured memory_bytes: 7792
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int a, b, c;
	re(a,b,c);
	if(a+b+c >= 22) cout<<"bust\n";
	else cout<<"win\n";
	
}


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

int n, m, k;

void solve(int test)
{
  cin >> n;
  int odd = (n + 1) / 2;
  cout.setf(ios::fixed);
  cout.precision(11);
  cout << 1. * odd / n << '\n';
}

void precalc()
{
}

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


Measured memory_bytes: 256
import Data.List
import Control.Monad
f ::Int -> [String] -> Bool
f x y = if (x== length y) then True else False
main = do
 n <- readLn 
 s <-  replicateM n getLine
 let s' = group (sort s)
 let s'' = map (length) (s')
 mapM_ putStrLn (map head (filter (f (maximum s'')) s'))

Measured memory_bytes: 177276
import java.util.*;

public class Main {
	
	public static int GCD(int num1, int num2) {
		if (num2 == 0) return num1;
		else return GCD(num2, num1%num2);
	}
	
    public static void main(String args[]) {
    	Scanner in = new Scanner(System.in);
    	int a = in.nextInt();
    	int b = in.nextInt();
    		if (a < b) {
    			int tmp = a;
    			a = b;
    			b = tmp;
    		}
    		System.out.println(GCD(a, b));
    }
}


Measured memory_bytes: 26112
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if(n < k)
    return 0;
  if(n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll n, k;
  cin >> n >> k;
  COMinit();
  for(int i = 0; i < k; i++) {
    cout << COM(k - 1, i) * COM(n - k + 1, i + 1) % MOD << '\n';
  }
  return 0;
}

Measured memory_bytes: 15532
#include<bits/stdc++.h>
int n,m,i,head[100005],Next[200005],adj[200005],u,v,c[100005],ansa,ansb,k;
void Push(int u,int v)
{
	Next[++k]=head[u];
	head[u]=k;
	adj[k]=v;
}
void dfs(int i,int d)
{
	int j;
	c[i]=d;
	for(j=head[i];j!=0;j=Next[j])
		if(c[adj[j]]==-1)
			dfs(adj[j],d^1);
		else
			if(c[adj[j]]!=(d^1))
			{
				printf("%lld",1ll*n*(n-1)/2-m);
				exit(0);
			}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(i=1;i<=m;++i)
	{
		scanf("%d %d",&u,&v);
		Push(u,v);
		Push(v,u);
	}
	memset(c,-1,sizeof(c));
	dfs(1,0);
	for(i=1;i<=n;++i)
		if(c[i])
			++ansa;
		else
			++ansb;
	std::cout<<1ll*ansa*ansb-m;
}


Measured memory_bytes: 2944
#include <iostream>
#include <stdio.h>

int main(){
	double r,x,s,l;
	std::cin >> x;
	r = x * 1.00000000000000000000000000000000000000000000;
    s = r * r * 3.141592653589;
    l = 2 * r * 3.141592653589;
    printf("%.7lf", s);
    std::cout <<" ";
    printf("%.7lf", l);
}

Measured memory_bytes: 3288
#include<stdio.h>
int main(){
  int N=0;
  scanf("%d",&N);
  int count=0;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(N==i*j){
        count++;
      }
    }
  }
  if(count==0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int t;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>t;
        deq.emplace_back(t);
    }
    long long int a, b;
    for (int j=0;j+1<n;j++) {
        a=deq[j];
        b=deq[j+1];
        if (a<b) {
            swap(a,b);
        }
        while (a%b!=0) {
            long long int tmp=b;
            b=a%b;
            a=tmp;
        }
        deq[j+1]=( (max(deq[j],deq[j+1])/b)*min(deq[j],deq[j+1]) );
    }
    cout<<deq.back()<<endl;
}

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


#define ll long long

using namespace std;

int factorial(int n)
{
  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}

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

    int n;
    cin >> n;
    int ncopy = n;
    int a,b;
    vector< pair<int,int> > towns;
    while(n--)
    {
        cin >> a >> b;
        towns.push_back(make_pair(a,b));
    }

    long double res = 0;
    int prevA, prevB;

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

    do{
        double medRes = 0;
        for(int i = 0; i < towns.size(); ++i)
        {

            if(i != 0)
            {
                double xDiff = (towns[i].first-prevA)*(towns[i].first-prevA);
                double yDiff = (towns[i].second-prevB)*(towns[i].second-prevB);
                medRes += sqrt(xDiff + yDiff);
            }
            prevA = towns[i].first;
            prevB = towns[i].second;
        }
        res += medRes;
    } while(next_permutation(towns.begin(),towns.end()));

    cout << fixed << setprecision(12) << res/(double)factorial(ncopy) << endl;






    return 0;
}


Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
      primes(i) = primes(i) + primes(i-1)
      primes(i+1) = primes(i+1) + primes(i)
    }

    for(i<-Math.sqrt(n).toInt+1 to n)
      primes(i) = primes(i)+primes(i-1)

    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(1000000)
    for(i <- stdin.getLines) {
      println(p(i.toInt))
    }
  }
}

Measured memory_bytes: 63628
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n;
    cin >> n;
    vi a(n), ao, ae;
    rep(i, n){
        cin >> a[i];
        i%2 == 0 ? ae.emplace_back(a[i]) : ao.emplace_back(a[i]);
    }

    // 最適な位置の偶奇
    sort(all(a));
    map<ll, ll> pos;
    rep(i, n) pos[a[i]] = i%2;

    // 元々偶数番目にあるものと奇数番目にあるものを独立してソート
    sort(all(ao));
    sort(all(ae));
    vi aSyn;
    rep(i, ao.size()){
        aSyn.emplace_back(ae[i]);
        aSyn.emplace_back(ao[i]);
    }
    if(ae.size() > ao.size()) aSyn.emplace_back(*ae.rbegin());

    // 接触する2要素について、本来あるべき偶奇の位置が異なっていればカウント
    vi ans(2, 0);
    for(ll i=0; i<aSyn.size(); i++){
        if(i%2 != pos[aSyn[i]]) ans[i%2]++;
    }
    cout << max(ans[0], ans[1]) << endl;
}

Measured memory_bytes: 12092
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()

    val ps = Array(N) { readLine()!!.split(" ").map { it.toLong() } }
        .sortedWith(Comparator { a, b ->
            val c = if (a[1] == b[1]) a[0] - b[0] else a[1] - b[1]
            when {
                c < 0 -> -1
                c > 0 -> 1
                else -> 0
            }
        })

    val ll = ArrayList<Long>()
    val lr = ArrayList<Long>()

    func(ll, lr, ps)

    val rl = ArrayList<Long>()
    val rr = ArrayList<Long>()

    func(rl, rr, ps.reversed())

    rl.reverse()
    rr.reverse()

    var res = 0L

    for (i in 1 until N - 1) {
        val v0 = Math.max(lr[i] - ll[i] + 1, 0L)
        val v1 = Math.max(rr[i] - rl[i] + 1, 0L)

        res = Math.max(
            res,
            v0 + v1
        )
    }

    for (i in 0 until N) {
        val t = Math.min(lr[i], rr[i + 1]) - Math.max(ll[i], rl[i + 1]) + 1
        res = Math.max(
            res,
            ps[i][1] - ps[i][0] + 1 + Math.max(t, 0L)
        )
    }

    println(res)
}

private fun func(
    left: ArrayList<Long>,
    right: ArrayList<Long>,
    ps: List<List<Long>>
) {
    left.add(1)
    right.add(1e9.toLong())

    for (l in ps) {
        left.add(Math.max(left.last(), l[0]))
        right.add(Math.min(right.last(), l[1]))
    }
}

private fun slow(N: Int, ps: List<List<Long>>): Long {
    var res = 0L
    for (i in 1 until (1 shl N) - 1) {
        val a = ps.filterIndexed { index, list -> (i shr index) and 1 == 1 }
        val b = ps.filterIndexed { index, list -> (i shr index) and 1 == 0 }

        val v0 = Math.max(a.map { it[1] }.min()!! - a.map { it[0] }.max()!! + 1, 0L)
        val v1 = Math.max(b.map { it[1] }.min()!! - b.map { it[0] }.max()!! + 1, 0L)

        res = Math.max(res, v0 + v1)

        if (v0 + v1 == 540049931L) {
            System.out.printf("%x\n", i)
        }
    }
    return res
}


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

ll solve(ll ai, ll aj, ll bi, ll bj) {
  if (aj > bj) {
    swap(ai,bi);
    swap(aj,bj);
  }
  ll s = 1;
  rep(i,30) s *= 3;
  ll dist = abs(ai-bi) + abs(aj-bj);
  ll res = dist;
  while (1) {
    s /= 3;
    if (s <= 0) break;
    ll nai = ai/s, nbi = bi/s;
    if (nai != nbi) break;
    ll naj = aj/s, nbj = bj/s;
    if (nai%3 == 1 && abs(naj-nbj) > 1) {
      ll up = s*nai-1;
      ll bot = nai*s + s;
      ll loss = min(ai,bi) - up;
      loss = min(loss, bot - max(ai,bi));
      res += loss*2;
      break;
    }
  }
  return res;
}

int main() {
  int q;
  cin >> q;
  while(q--) {
    ll ai,aj,bi,bj;
    cin >> ai >> aj >> bi >> bj;
    ai--; aj--; bi--; bj--;
    ll ans1 = solve(ai,aj,bi,bj);
    ll ans2 = solve(aj,ai,bj,bi);
    cout << max(ans1, ans2) << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  double r;
  cin>>r;
  printf("%.10f\n",2*r*M_PI);
  return(0);
}


Measured memory_bytes: 3784
N = int(input())
res = []
for i in range(1, N+1):
    if '3' in str(i) or i%3 == 0:
        res.append(i)

i = 0
print(" ", end="")
for r in res:
    print(r, end="")
    if i == len(res)-1:
        #pass
         print('\n', end="")
    else:
        print(" ", end="")

    i += 1



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

#define ll long long int

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

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 111;

int N;
int X[MAX];

ll sub(ll x) {
    ll res = 0;
    REP (i, N) {
        res += (x - X[i]) * (x - X[i]);
    }
    return res;
}

ll solve() {
    ll ans = 1e18;
    FOR (x, 1, 101) ans = min(ans, sub(x));
    return ans;
}

int main() {
    cin >> N;
    REP (i, N) cin >> X[i];
    cout << solve() << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef int_fast64_t ll;

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    constexpr ModFact() : fact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
    }
};
 
ModFact<100000, ll, MOD> fact;

ll ans;
int N, M, cnt = 0;
constexpr ll th = 1LL<<45;
char S[200000];

int main() {
    scanf("%d%s", &N, S);
    M = N << 1;
    ans = fact.fact[N];
    char *E = S + M, *C = S;
    while(C < E) {
		if((*C++^cnt)&1) {
            ans = ans * cnt % MOD;
            if(--cnt < 0) break;
        } else ++cnt;
	}
    printf("%lld\n", cnt == 0 ? ans : 0);
    return 0;
}


Measured memory_bytes: 384
use std::collections::{BTreeMap, BTreeSet};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let l: usize = sc.read();
    let mut trie = Trie::default();
    for _ in 0..n {
        let s = sc.chars();
        trie.add(s, 0);
    }

    let mut result = vec![];
    trie.traverse(l, &mut result);
    let result = result
        .into_iter()
        .map(|r| 1 << r.trailing_zeros())
        .fold(0, |xor, r| xor ^ r);
    println!("{}", if result != 0 { "Alice" } else { "Bob" });
}

struct Trie {
    zero: Option<Box<Trie>>,
    one: Option<Box<Trie>>,
}

impl Default for Trie {
    fn default() -> Trie {
        Trie {
            zero: None,
            one: None,
        }
    }
}
impl Trie {
    fn traverse(&self, l: usize, result: &mut Vec<usize>) {
        if self.zero.is_none() != self.one.is_none() {
            result.push(l);
        }
        if let Some(one) = self.one.as_ref() {
            one.traverse(l - 1, result);
        }
        if let Some(zero) = self.zero.as_ref() {
            zero.traverse(l - 1, result);
        }
    }

    fn add(&mut self, s: Vec<char>, pos: usize) {
        if s.len() == pos {
            return;
        }
        match s[pos] {
            '0' => {
                if self.zero.is_none() {
                    self.zero = Some(Box::new(Trie::default()));
                }
                self.zero.as_mut().unwrap().add(s, pos + 1);
            }
            '1' => {
                if self.one.is_none() {
                    self.one = Some(Box::new(Trie::default()));
                }
                self.one.as_mut().unwrap().add(s, pos + 1);
            }
            _ => unreachable!(),
        }
    }
}

fn grundy(h: usize, map: &mut BTreeMap<usize, usize>) -> usize {
    if map.contains_key(&h) {
        return *map.get(&h).unwrap();
    }
    let mut set = BTreeSet::new();
    for add in 1..(h + 1) {
        let mut g = 0;
        for r in 1..add {
            g ^= grundy(h - r, map);
        }
        set.insert(g);
    }

    let g = (0..).find(|x| !set.contains(x)).unwrap();
    map.insert(h, g);
    g
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 14204
#include<iostream>
#include<string>
#include<cmath>
#include <iomanip>

#define PI 3.14159265359

using namespace std;

int main(){
	int jishin, hunshin, hour, minute;
  	long double kakudo, rajian, answer;
  
  cin>>jishin>>hunshin>>hour>>minute;
  
  kakudo=abs(minute*6-(hour*30+minute*0.5));
  
  rajian=kakudo*PI/180;
  
  answer=sqrt(pow(jishin, 2)+pow(hunshin, 2)-2*jishin*hunshin*cos(rajian));
  
  cout<<std::fixed << std::setprecision(20)<<answer<<endl;
  
  
}

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int MAX=20000;
        int MIN=0;
        
        while(true){
            String[] data=reader.readLine().split(" ");
            final int a=Integer.parseInt(data[0]);
            final int b=Integer.parseInt(data[2]);
            
            if(data[1].equals("?")) break;
        
            if((MIN<=a && a<=MAX) && (MIN<=b && b<=MAX)){
                if(data[1].equals("+")) System.out.print(a+b+"\n");
                else if(data[1].equals("-")) System.out.print(a-b+"\n");
                else if(data[1].equals("*")) System.out.print(a*b+"\n");
                else if(data[1].equals("/")) System.out.print(a/b+"\n");
            }
        }
    }
}

Measured memory_bytes: 24388
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  var params = inputs.split('\n')[0].split(' ').map(Number);
  (function(a,b,c) {
    if (a < b && b < c) {
        console.log('Yes');
    }else{
        console.log('No');
    }

  }(params[0],params[1],params[2])); 
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

using namespace std;

int main()

{
    int a,b,i;
    cin>>a>>b;
    if(a>b)
    {
        for(i=0;i<a;i++) cout<<b;
    }
    else
    {
        for(i=0;i<b;i++) cout<<a;
    }
}

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

int main() {
	int N; cin >> N;
	long double c1 = 0, c2 = 0;
	for (int i = 1; i <= N; i++) {
		c2++;
		if (i % 2 == 1) c1++;
	}
	printf("%.12Lf\n", c1 / c2);
	return 0;
}

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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);
const ll mod = 1e9 + 7;

void solve() {
    ll n, k;
    cin >> n >> k;
    ll sum = 0;
    for(ll i = k; i<=n+1; i++) {
        ll mi = (i * (i-1))/2;
        ll ma = i*n - mi;
        sum += (ma - mi + 1);
        sum %= mod;
    }
    cout << sum << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>

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

int main() {
  int s, w;
  std::cin >> s >> w;

  if (s <= w)
    std::cout << "unsafe" << '\n';
  else
    std::cout << "safe" << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 100005

int dp[3][ARRAY_MAX];//0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
int a[ARRAY_MAX];
int b[ARRAY_MAX];
int c[ARRAY_MAX];

int main(){

    int n;
    cin >> n;
    REP(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];

    for(int i = i;i < n;i++){
        dp[0][i] = max(dp[1][i-1]+a[i],dp[2][i-1]+a[i]);
        dp[1][i] = max(dp[0][i-1]+b[i],dp[2][i-1]+b[i]);
        dp[2][i] = max(dp[0][i-1]+c[i],dp[1][i-1]+c[i]);        
    }
    cout << max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) << endl;



    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
const int N = 100010,mod = 1e9 + 7;
int f[N];
int a[N];
int n;

int qmi(int a,int k)
{
    int res = 1;
    while(k)
    {
        if(k&1) res = (LL)res * a %mod;
        a = (LL)a * a % mod;
        k>>=1;
    }
    return res;
}

void init(int n)
{
    for(int i=1;i<=n;i++) f[i] = qmi(i,mod-2),f[i] = (LL)f[i] + f[i-1] % mod;
}

int main()
{
    scanf("%d",&n);
    init(n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    
    LL ans = 0;
    for(int i=1;i<=n;i++) ans = (ans + (((LL)f[i] + f[n-i+1] - f[1]) % mod + mod) % mod * a[i] % mod)%mod;
    for(int i=1;i<=n;i++) ans = ans * i % mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4476
#include <stdio.h>
#include <limits.h>

#define MAX 100

int min( int x, int y )
{
  if( x<=y ) return x;
  else return y;
}

int main()
{
  int n,p[MAX+1],m[MAX+1][MAX+1],j,i,k,l;

  scanf("%d",&n);

  for( i=1 ; i<=n ; i++ ){
    scanf("%d%d",&p[i-1],&p[i]);    
  }

  for( i=1 ; i<=n ; i++ )
    m[i][i]=0;
  for( l=2 ; l<=n ; l++ ){
    for( i=1 ; i<=n-l+1 ; i++ ){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for( k=i ; k<=j-1 ; k++ ){
        m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }

  printf("%d\n",m[1][n]);

  

  return 0;
  
        
}




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

using namespace std;

#define MAX_N 366
#define MAX_C 9
#define MAX_R 2402

struct State{
  int d,c,r[4];
  State(int d,int c,int r[4]) : d(d),c(c) {
    for(int i = 0 ; i < 4 ; i++){
      this->r[i] = r[i];
    }
  }
};

int N,arr[MAX_N];
bool visited[MAX_N][MAX_C][MAX_R];
const int d[5] = {-1,-3,1,3,0};

int next(int c,int dir){
  if(c%3 == 0 && dir == 0){ return -1; }
  if(c/3 == 0 && dir == 1){ return -1; }
  if(c%3 == 2 && dir == 2){ return -1; }
  if(c/3 == 2 && dir == 3){ return -1; }
  return c + d[dir];
}

bool check(int d,int c){
  c += c/3;
  for(int i = 0 ; i < 16 ; i++){
    if((arr[d] >> i & 1) && i == c){ return true; }
    if((arr[d] >> i & 1) && i == c+1){ return true; }
    if((arr[d] >> i & 1) && i == c+4){ return true; }
    if((arr[d] >> i & 1) && i == c+5){ return true; }
  }
  return false;
}

void calc(int c,int *r){
  if(c == 0){ r[0] = 0; }else{ r[0]++; }
  if(c == 2){ r[1] = 0; }else{ r[1]++; }
  if(c == 6){ r[2] = 0; }else{ r[2]++; }
  if(c == 8){ r[3] = 0; }else{ r[3]++; }
}

int getValue(int *r){
  int res = 0;
  for(int i = 0 ; i < 4 ; i++){
    res *= 7; res += r[i];
  }
  return res;
}

int solve(){
  int r[4] = {0}; calc(4,r);
  memset(visited,false,sizeof(visited));
  visited[0][4][getValue(r)] = true;
  queue<State> Q;
  Q.push(State(0,4,r));
  while(!Q.empty()){
    State s = Q.front(); Q.pop();
    int day = s.d,cloud = s.c;
    if(check(day,cloud)){ continue; }
    if(day == N-1){ return 1; }
    for(int i = 0 ; i < 5 ; i++){
      int cc = cloud,nr[4];
      for(int j = 0 ; j < 2 ; j++){
        int nc = next(cc,i);
        if(nc == -1){ break; }
        memcpy(nr,s.r,sizeof(nr)); calc(nc,nr);
        if(*max_element(nr,nr+4) >= 7){
          cc = nc;
          continue;
        }
        int value = getValue(nr);
        if(!visited[day+1][nc][value]){
          visited[day+1][nc][value] = true;
          Q.push(State(day+1,nc,nr));
        }
        cc = nc;
        if(i == 4){ break; }
      }
    }
  }
  return 0;
}

int main(){
  while(cin >> N,N){
    for(int i = 0 ; i < N ; i++){
      int x,bit = 0;
      for(int j = 0 ; j < 16 ; j++){
        cin >> x;
        if(x == 1){ bit |= (1<<j); }
      }
      arr[i] = bit;
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 8976
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


class Impossible(Exception):
    pass

def f(q, qq, state):
    '''
    >>> f((0, 1), None, [2, 1, 0])
    1
    >>> f((0, 1), None, [1, 2, 0])
    0
    >>> f((0, 1), None, [0, 1, 0])
    0
    >>> f((1, 2), None, [0, 1, 0])
    2
    >>> f((0, 2), None, [1, 0, 0])
    2
    >>> f((0, 1), (0, 3), [1, 1, 0])
    0
    >>> f((0, 1), (0, 3), [1, 2, 0])
    0
    >>> f((0, 1), [], [1, 1, 0])
    1
    >>> f((0, 1), None, [0, 0, 0])
    -1
    >>> f((1, 2), None, [0, 0, 0])
    -1
    >>> f((0, 1), (0, 3), [1, 0, 0])
    1
    '''
    n, m = q
    if state[n] == state[m] == 0:
        return -1
    if state[n] == state[m] == 1:
        if n in qq:
            return n
        return m
    if state[n] > state[m]:
        return m
    return n
        

def solve(N: int, A: int, B: int, C: int, s: "List[str]"):
    D = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
    E = 'ABC'
    Q = tuple(map(lambda x: D[x], s))
    state = [A, B, C]
    for q, qq in zip(Q, Q[1:] + (tuple(),)):
        r = f(q, qq, state)
        if r == -1:
            raise Impossible
        yield E[r]
        state[r] += 1
        state[q[q.index(r)^1]] -= 1


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    try:
        ans = list(solve(N, A, B, C, s))
        print(YES)
        print(*ans, sep='\n')
    except Impossible:
        print(NO)

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 27104
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=501234;

int n,a[17][17],bt[17],flg[1<<17];
ll dp[1<<17],dp2[1<<17];
queue<int> q2;

int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        bt[i]=1<<i-1;
        for(int j=1; j<=n; ++j)
            scanf("%d",&a[i][j]);
    }
    bt[n+1]=1<<n;
    for(int i=2,l=0,r=0; i<=n; ++i)
    {
        for(int j=1,tmp=0; j<i; ++j)
        {
            tmp=bt[i]|bt[j];
            dp[tmp]=a[j][i];
            flg[tmp]=1;
            q2.push(tmp);
        }
        while(!q2.empty())
        {
            int tmp=q2.front();
            q2.pop();
            for(int j=1,tmp2=0; j<i; ++j)
            {
                tmp2=tmp|bt[j];
                if(tmp2!=tmp && flg[tmp2]==0)
                {
                    dp[tmp2]=dp[tmp]+a[j][i];
                    flg[tmp2]=1;
                    q2.push(tmp2);
                }
            }
        }
    }
    for(int i=2; i<=n; ++i)
        for(int j=bt[i]+1; j<bt[i+1]; ++j)
            dp[j]+=dp[j^bt[i]];
    for(int i=2; i<=n; ++i)
        for(int i2=bt[i]+1,j2=0; i2<bt[i+1]; ++i2)
        {
            dp2[i2]=dp[i2];
            j2=i2&-i2;
            for(int j=bt[i]; j<i2; j+=j2)
            {
                while((j|i2)!=i2) j+=j&-j;
                ll tmp3=dp[j]+dp2[j^i2];
                if(dp2[i2]<tmp3) dp2[i2]=tmp3;
            }
        }
    printf("%lld",dp2[(1<<n)-1]);
    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"

using namespace std;


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

	int k, x;
	cin >> k >> x;
	int l = max(x - k + 1, -1000000);
	int r = min(x + k - 1, 1000000);

	for (int i = l; i <= r; i ++) cout << i << ' '; cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int n;
    cin >> n;
 
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
 
    int min = a[0], max = a[0];
    for (int i = 1; i < n; i++){
        if (a[i] <= min){
            min = a[i];
        }else if(a[i]>=max){
            max = a[i];
        }
    }
 
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
wuniversity = deque([])
for i in range(20):
    wuniversity.append(int(input()))

kuniversity = deque([])
for i in range(10):
    kuniversity.append(wuniversity.pop())

kuniversity = sorted(kuniversity)
wuniversity = sorted(wuniversity)

print(wuniversity[-1]+wuniversity[-2]+wuniversity[-3], end=' ')
print(kuniversity[-1]+kuniversity[-2]+kuniversity[-3])

Measured memory_bytes: 7940
N = int(input())
A = []
for i in range(N):
   A.append(input())
S = 0
for i in range(N-1):
    if A[i][-1] == A[i+1][0]:
        S += 1
B = 0
for i in range(N):
    for j in range(N):
        if A[i] == A[j]:
            B += 1
        else:
            B += 0

if S == N-1 and B == N:
    print('Yes')
else:
    print('No')

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

int main(){
    int m1, d1, m2, d2;
    scanf("%d%d%d%d", &m1, &d1, &m2, &d2); 
    if(m1 != m2) printf("1\n");
    else printf("0\n");
}  

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

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

  int senn = n / 1000 * 1000;
  int ichiigai = n / 10;

  if ((n - senn) % 111 == 0 || (ichiigai % 111 == 0)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
// 難さんすう すーぱーさんすうと呼ぼう
// Mを素因数分解しといて例えばM=12としてM=(2^2) * (3^1)なるが、それぞれの因数をそれぞれの乗数ぶん振り分ける感じにした組み合わせが答え
// N = 3なら [1, 1, 1]の3つのどれかに振り分ける つまり以下
// 因数2を2つ,因数3を1つ を振り分けて、
//			[2^1, 2^1, 2^0], [3^1, 3^0, 3^0]
// 				-> [1*(2^1 * 3^1)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^0)] = 6*2*1 = 12
// あるいは
//			[2^2, 2^0, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^2 * 3^0)] * [1*(2^0 * 3^0)] * [1*(2^0 * 3^1)] = 4*1*3 = 12
// あるいは
//			[2^1, 2^1, 2^0], [3^0, 3^0, 3^1] ならば
//				-> [1*(2^1 * 3^0)] * [1*(2^1 * 3^0)] * [1*(2^0 * 3^1)] = 2*2*3 = 12
//
// 解説の""計算量はNに依らない""が意味不明だけど、説明してくれないので無視
// すーぱーさんすうの世界ではこれを重複組合せと呼ばうらしい 漢字だね 画数が多い
// n種類のものから重複を許してr個選ぶ場合の数 = nHr = (n+r-1)Cr に帰着できるらしい

// nCr mod Pなので気をつける
package main

import (
	"fmt"
	"math"
)

var MOD int

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	// arr := factorization(M)
	arr := primeFactorization(M)
	ans := 1
	MOD = int(math.Pow10(9)) + 7
	for _, v := range arr {
		// ans = ans * comb(v+N-1, v, MOD) % MOD
		ans = ans * ncrMod(v+N-1, v, MOD) % MOD
	}
	fmt.Println(ans)
}

func factorization(n int) map[int]int {
	a := make(map[int]int)
	for i := 2; i*i <= n; {
		if n%i == 0 {
			a[i]++
			n /= i
		} else {
			i++
		}
	}
	if n > 1 {
		a[n]++
	}
	return a
}

func primeFactorization(x int) map[int]int {
	ret := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			x /= i
			if _, ok := ret[i]; ok {
				ret[i] += 1
			} else {
				ret[i] = 1
			}
		}
	}
	if x > 1 {
		ret[x] += 1
	}
	return ret
}

func ncrMod(n, r, mod int) int {
	// 呼び出すたびにテーブルを作るのは愚
	_n := 1000000
	g1 := make([]int, _n+1)
	g1[0], g1[1] = 1, 1
	g2 := make([]int, _n+1)
	g2[0], g2[1] = 1, 1
	inverse := make([]int, _n+1)
	inverse[0], inverse[1] = 0, 1
	for i := 2; i <= _n; i++ {
		g1[i] = (g1[i-1] * i) % mod
		inverse[i] = mod - inverse[mod%i]*(mod/i)%mod
		g2[i] = (g2[i-1] * inverse[i]) % mod
	}

	return g1[n] * (g2[r] * g2[n-r] % mod) % mod
}

func comb(n, m, MOD int) int {
	return factorial(n, n-m+1, MOD) * pow(factorial(m, 2, MOD), MOD-2, MOD) % MOD
}

func pow(x, n, MOD int) int {
	r := 1
	for ; n > 0; n /= 2 {
		if n%2 == 1 {
			r = r * x % MOD
		}
		x = x * x % MOD
	}
	return r
}

func factorial(n, m, MOD int) int {
	r := 1
	for i := m; i <= n; i++ {
		r = r * i % MOD
	}
	return r
}


Measured memory_bytes: 32768
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int l = 0, r = 0;
    cin >> l >> r;
    if (l/2019 != r/2019) cout << 0 << endl;
    else if (l%2019 == 0) cout << 0 << endl;
    else {
        int mini = 3000;
        for (int i=l; i<=r; i++) {
            for (int j=i+1; j<=r; j++) {
                int buf =  (i%2019) * (j%2019);
                buf %= 2019;
                if (buf < mini) mini = buf;
            }
        }
        cout << mini << endl;
    }
    return 0;
}


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

int main() {
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int N;
  cin>>N;
  string s;
  cin>>s;
  vector<int64_t> r(N),b(N),g(N);
  r[0]=b[0]=g[0]=0;
  for(int i=1;i<N;i++){
    if(s[i]=='R')
      r[0]++;
    if(s[i]=='B')
      b[0]++;
    if(s[i]=='G')
      g[0]++;
  }
  for(int i=1;i<N;i++){
    if(s[i]=='R')
      r[i]=r[i-1]-1;
    else
      r[i]=r[i-1];
    if(s[i]=='B')
      b[i]=b[i-1]-1;
    else
      b[i]=b[i-1];
    if(s[i]=='G')
      g[i]=g[i-1]-1;
    else
      g[i]=g[i-1];
  }
  //rep(i,N)
    //cout<<r[i]<<b[i]<<g[i]<<endl;
  int64_t answer=0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      if(s[i]!=s[j]){
        if(s[i]!='R' && s[j]!='R'){
          answer+=r[j];
        if(2*j-i<N && s[2*j-i]=='R')
          answer--;
        }
        if(s[i]!='G' && s[j]!='G'){
          answer+=g[j];
        if(2*j-i<N && s[2*j-i]=='G')
          answer--;
        }
        if(s[i]!='B' && s[j]!='B'){
          answer+=b[j];
        if(2*j-i<N && s[2*j-i]=='B')
          answer--;
        }
      }
    }
  }
  cout<<answer;
            
      
      
  
  
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll N, D;
    cin >> N >> D;
    vector<ll> X(N), Y(N);
    rep(i, N){
        cin >> X.at(i) >> Y.at(i);
    }
    ll c = 0;
    rep(i, N){
        if(X.at(i)*X.at(i) + Y.at(i)*Y.at(i) <= D*D){
            c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 6368
#include <stdio.h>
#define INF 20000000
#define NIL -1
#define WHITE 0
#define BLACK 1

int main(){
  int i,j,mincost,u,v,sum=0;
  int n,a[101][101],d[101],pi[101],color[101];

  //input
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      scanf("%d",&a[i][j]);
    }
  }
  //processing
  for(i=1;i<=n;i++){
    d[i] = INF;
    pi[i] = NIL;
    color[i] = WHITE;
  }
  d[1] = 0;
  while(1){
    mincost=INF;
    for(i=1;i<=n;i++){
      if(color[i]!=BLACK&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INF)break;
    color[u]=BLACK;
    for(v=1;v<=n;v++){
      if(color[v]!=BLACK&&a[u][v]<d[v]&&a[u][v]!=-1){
	pi[v]=u;
	d[v]=a[u][v];
      }
    }
  }
  for(i=1;i<=n;i++){
    sum+=d[i];
  }
  //output
  printf("%d\n",sum);
  return 0;
}

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

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};       //注意这块有的数据可能因为走的方向不同而导致TLE
char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{
    int f[N2],space,MD;
};

Puzzle state;
int limit;
int path[LIMIT];

struct State{
    Puzzle puzzle;
    int estimated;
    bool operator < (const State &s) const{
        return estimated>s.estimated;
    }
};

int getallMD(Puzzle pz){
    int sum=0;
    for(int i=0;i<N2;i++){
        if(pz.f[i]==N2) continue;
        sum+=MDT[i][pz.f[i]-1];
    }
    return sum;
}

bool isSolved(){
    for(int i=0;i<N2;i++){
        if(state.f[i]!=i+1) return false;
    }return true;
}

bool dfs(int depth,int pre){
    if(state.MD==0) return 1;
    if(depth+state.MD>limit) return false;
    int sx=state.space/N;
    int sy=state.space%N;
    Puzzle tmp;
    for(int r=0;r<4;r++){
        int tx=sx+dx[r];
        int ty=sy+dy[r];
        if(tx<0||ty<0||tx>=N||ty>=N)
            continue;
        if(max(pre,r)-min(pre,r)==2) continue;//去重
        tmp=state;
        state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
        state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
        swap(state.f[sx*N+sy],state.f[tx*N+ty]);
        state.space=tx*N+ty;
        if(dfs(depth+1,r)){
            path[depth]=r;
            return true;
        }
        state=tmp;
    }
    return false;
}

string iterative_deepening(Puzzle in)
{
    in.MD=getallMD(in);//初始状态的曼哈顿距离
    for(limit=in.MD;limit<=LIMIT;limit++){
        state=in;
        if(dfs(0,-100)){
            string ans="";
            for(int i=0;i<limit;i++){
                ans+=dir[path[i]];
            }
            return ans;
        }
    }
    return "unsolvable";
}


int main(){
    for(int i=0;i<N2;i++){
        for(int j=0;j<N2;j++){
            MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
        }
    }
    Puzzle in;
    for(int i=0;i<N2;i++){
        cin>>in.f[i];
        if(in.f[i]==0){
            in.f[i]=N2;
            in.space=i;
        }
    }
    string ans=iterative_deepening(in);
    cout<<ans.size()<<endl;
    return 0;
}



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

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << ((e-a<=k)?"Yay!":":(") << endl;
}


Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))


s = ns()
k = ni()

check = set()

for left in range(0, len(s)):
    for right in range(left+1, left+k+1):
        check.add(s[left:right])

print(sorted(list(check))[k-1])



Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int q; cin >> q;
  rep(z,q) {
    string s,t; cin >> s >> t;
    int N = s.size();
    int M = t.size();
    s = ' ' + s;
    t = ' ' + t;

    vector<vector<int>> dp(N+1, vector<int>(M+1));

    rep(i,N+1) {
      rep(j,M+1) {
        if(i == 0 || j == 0) continue;
        if(s[i] == t[j]) dp[i][j] = dp[i-1][j-1] + 1;
        else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }

    cout << dp[N][M] << endl;
  }
}


Measured memory_bytes: 6856
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n;
	while (cin >> n, n){
		vector<string> vs;
		vector<int> vi;
		REP(i, n){
			string s;
			int d = 0;
			cin >> s;
			REP(j, s.length()){
				if(s[j] == '.')
				d++;
			}
			vi.push_back(d);
			vs.push_back("");
			REP(j, d){
				if(j<d-1)vs[i] += " ";
				if (j==d - 1)vs[i] += "+";
			}
			vs[i] += s.substr(d, s.length() - d);
			//cout << vs[i] << endl;
		}
		int b = 0;
			for (int j = 0; j < n-1; j++){
				for (int i = j + 1; i < n;i++){
					if (vi[j]>vi[i])break;
					if (vi[j] == vi[i]){
						for (int k = j + 1; k < i;k++){
							vs[k][vi[j]-1] = '|';
						}
						break;
					}
				}
				}
		REP(i, n){
			cout << vs[i] << endl;
		}

	}
}

Measured memory_bytes: 1876