akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <bitset>
#include <random>
#include <stack>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <ctime>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sc second
#define fs first
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<class T> T sqr(T x) { return x*x; }
ld pi = 3.1415926535897932384626433832795;
ll mod = 1e9 + 7;
const int N = 1e5 + 10;

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

vector<int> chars[30];

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		chars[s[i] - 'a'].push_back(i);
	}
	int min_ans = 1e9;
	for (int i = 0; i < 30; i++) {
		if (!chars[i].size()) continue;
		int prev = -1, max_range = -1;
		for (int j = 0; j < chars[i].size(); j++) {
			int delta = (chars[i][j] - prev - 1);
			if (prev == -1)
				delta = chars[i][j];
			max_range = max(max_range, delta);
			prev = chars[i][j];
		}
		max_range = max(max_range,(int) s.size() - 1 - prev);
		min_ans = min(min_ans, max_range);
	}
	cout << min_ans;
	return 0;
}

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

const int MOD = 1e9+7;
ll a[100005];

void solve() {
  ll x = 1;
  rep(i, 100005) {
    if (i==0) continue;
    x *= i;
    x %= MOD;
    a[i] = x;
  }
}

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

  ll ans = 0;
  solve();
  if (abs(n-m) == 1) ans = a[n]*a[m]%MOD;
  else if (abs(n-m) == 0) ans = 2*a[n]*a[m]%MOD;
  else ans = 0;
  cout << ans << endl;
}


Measured memory_bytes: 1024
N,M,X = map(int,input().split())
C = []
for i in range(N):
    C.append(list(map(int,input().split())))

cost = 100000000000000000000000
l = list(range(1,N+1))
for i in range(2**N):
    check = [0]*N
    sub_list = [0]*(M+1)
    for j in range(N):
        if (i >> j) & 1 == 1:
            check[j] = 1
    for k in range(N):
        if check[k] == 1:
            for p in range(M+1):
                sub_list[p] += C[k][p]
    flag = True
    for q in range(M):
        if sub_list[q+1] < X:
            flag = False
    if flag == True:
        cost = min(sub_list[0],cost)

if cost == 100000000000000000000000:
    print(-1)
else:
    print(cost)

Measured memory_bytes: 9180
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, k) = (line[0], line[1]);

    let mut trees: Vec<u32> = Vec::new();

    for _ in 0..n{
        trees.push(read_as_vec()[0]);
    }
    trees.sort_by_key(|x| *x);
    let mut best = trees[k] - trees[0];
    for i in 0..(n-k+1){
        if best > trees[i+k-1] - trees[i]{
            best = trees[i+k-1] - trees[i];
        }

    }
    println!("{}", best);
    
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    // 標準入力から整数a,b,cの数値を取得
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    
    // 3つの数値を比較し、色が全てが同じ場合1を出力
    if(a == b && a == c) {
      System.out.println(1);
    
    // 3つの数値を比較し、色が1つでも同じ場合2を出力  
    } else if(a == b || b == c || c == a) {
      System.out.println(2);
    
    // 3つの数値を比較し、すべて違う場合3を出力
    } else {
      System.out.println(3);
    }
  }
}


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

int main(){
	int N;
	cin >> N;
	vector<int> v(N);
	for(auto &i:v)cin >> i;
	sort(v.begin(),v.end());
	
	double ans=v[0];
	for(int i=1;i<N;i++)ans=(ans+(double)v[i])/2.0;
	printf("%.9lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)==2){
        if(a<b){
            printf("a < b\n");
        }
        else if(a>b){
            printf("a > b\n");
        }
        else{
            printf("a == b\n");
        }
    }
    return 0;
}

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

int main()
{
    int n, count = 0;

    scanf("%d", &n);
    char s[n][11];
    for (int i = 0; i < n; i++)
    {
        scanf("%s", s[i]);
    }

    qsort(s, n, 11, strcmp);

    for (int i = 0; i < n; i++)
    {
        if (strcmp(s[i], s[i + 1]) != 0)
            count++;
    }

    printf("%d", count);

    return 0;
}



Measured memory_bytes: 5740
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

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

  int Ans = (X/500)*1000;
  X -= (X/500)*500;
  Ans += (X/5)*5;

  cout << Ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {
		int n = scn.nextInt();
		int k = scn.nextInt();
		int ans = (int) (Math.log(n) / Math.log(k)) + 1;
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,h[100010],dp[100010];

int main()
{
	cin>>n;
	rep(i,n) cin>>h[i];
	dp[1]=abs(h[0]-h[1]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
		//cout<<i<<' '<<dp[i-2]<<' '<<abs(h[i-2]-h[i])<<"  "<<dp[i-1]<<' '<<abs(h[i-1]-h[i])<<endl;
	}
	cout<<dp[n-1]<<endl;
	rt0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <complex>

using namespace std;
typedef long long ll;


typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define re(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define lb lower_bound
#define ub upper_bound

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans=0;
ll a,b,c,d,e,h,w;

ll x[500005],y[500005],z[500005];
char s[100005],t[100005];
bool ok=false;
bool check[100005];
ll gcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    cin>>num;
    for(i=0;i<num;i++){
        cin>>a>>b>>c>>d;
        ll as=a;
        bool flag=false;
        for(j=0;j<100;j++){
            as -= b;
            if(as<0){
                p("No");
                flag=true;
                break;
            }
            if(as<=c)as+=d;
        }
        if(!flag){
            ll x=gcd(b,d);
            ll y=a-((a-c)/x)*x;
            if(c==y)y+=x;
            if(y-b>=0 && d>=b){
                p("Yes");
                
            }else{
                p("No");
                
            }
        }
    }
    
    return 0;
}


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

/// 1行の文字を空白で分割してVec<T>にする。
fn read_split<T : std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

fn main() {
    let input1 : usize = read_one();
    let input2 : Vec<i32> = read_split();
    let mut input2sorted = input2.clone();
    input2sorted.sort();
    let mut badcount = 0;
    for i in 0..input1 {
        if input2[i] != input2sorted[i] { badcount += 1; }
    }
    
    println!("{}", if badcount > 2 { "NO" } else { "YES" });
}



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

public class Main {
	int[] base = new int[4];
	int out , ten;
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int i = Integer.parseInt(in.readLine());
		for ( ; i > 0; i-- ) {
			for ( int n = 0; n < 4; n++ )
				m.base[n] = 0;
			m.out = 0; m.ten = 0;
			while ( m.out < 3 ) {
				String eve = in.readLine();
				m.check(eve);
			}
			System.out.println(m.ten);
		}
	}
	public void check( String str ) {
		if ( str.equals("OUT") ) {
			out++; return;
		}
		else if ( str.equals("HIT") ) {
			for ( int i = 2; i >= 0; i-- ) {
				if ( base[i] != 0 ) {
					base[i+1] = base[i];
					base[i] = 0;
				}
			}
			base[0]++;
			if ( base[3] != 0 ) {
				ten++;
				base[3] = 0;
			}
			return;
		}
		else if ( str.equals("HOMERUN") ) {
			int count = 0;
			for ( int n = 0; n < 4; n++ ) {
				if ( base[n] != 0 ) count++;
				base[n] = 0;
			}
			ten += count + 1;
			return;
		}		
	}
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class program{
  static void Main(string[] args){
    program p = new program();
    p.Run();
  }
  void Run(){
	int[] inp = Readint();
    int R=inp[0];
    int G=inp[1];
    int B=inp[2];
    int N=inp[3];
    long c=0;
    int mr=(int)(N/R);
    int mg=(int)(N/G);
    int mb=(int)(N/B);
    long a=0;
    for(int r=0;r<mr+1;r++){
      for(int g=0;g<mg+1;g++){
        a=N-r*R-g*G;
        if(a>=0 & a<=mb*B & (a % B)==0){
          c++;
        }
      }
    }
    WriteLine(c.ToString());
  }

  int[] Readint(){
    string[] s = ReadLine().Split();
    int[] res=new int[s.Length];
    Parallel.For(0,s.Length,i=>{
      res[i]=int.Parse(s[i]);
    });
    return res;
  }
}

Measured memory_bytes: 13908
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int HP[10005];

int main()
{
	int H, N;
	pair<int, int> BA[1005];
	cin >> H >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> BA[i].second >> BA[i].first;
	}

	sort(BA, BA + N);

	int les;
	for (int i = 1; i <= H; i++)
	{
		HP[i] = 100000000;
		for (int j = 0; j < N; j++)
		{
			les = max(0, i - BA[j].second);
			if (HP[les] + BA[j].first < HP[i])
				HP[i] = HP[les] + BA[j].first;
		}
	}
	cout << HP[H] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b;

  scanf("%d %d",&a,&b);

  if(a==b){
    printf("Draw\n");
    return 0;
  };
  if(a == 1) a = 14;
  if(b == 1) b = 14;

  if(a < b){
    printf("Bob\n");
  }else{
    printf("Alice\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a), _B(b); i < _B; ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1), _B(b); i >= _B; --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) REP(__i,0,n)
template<typename T>
void cmax(T & a, T b) {a = max(a, b);}
template<typename T>
void cmin(T & a, T b) {a = min(a, b);}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define CLR(a) a.clear()
#define BK(a) (a.back())
#define FT(a) (a.front())
#define DB(a) a.pop_back()
#define DF(a) a.pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {}
template<typename T, typename ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		switch (*s) {
		case '(':
		case '[':
		case '{':
			++c;
			break;
		case ')':
		case ']':
		case '}':
			--c;
			break;
		}
	}
	cerr<<" = "<<a;
	if (*s) {
		cerr<<", ";
		_BG(++s,b...);
	} else
		cerr<<endl;
}
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)

/* Reading input is now 20% cooler! */
bool RD(void) {return true;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<typename T, typename ... TT>
bool RD(T & a, TT & ...  b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define RI(a) int a; RD(a)
#define RII(a,b) RI(a); RI(b)
#define RIII(a,b,c) RI(a); RII(b,c)
#define RIIII(a,b,c,d) RI(a); RIII(b,c,d)

/* For it's time for you to fulfill your output. */
void PT(const char a) {putchar(a);}
void PT(const char * a) {fputs(a, stdout);}
void PT(char * a) {fputs(a, stdout);}
void PT(const double a) {printf("%.16f", a);}
void PT(const int a) {printf("%d", a);}
void PT(const ll a) {printf("%lld", a);}

/* The line will last forever! */
template<char sep = ' ',char end = '\n'>
void PL(void) {if (end) PT(end);}
template<char sep = ' ',char end = '\n',typename T, typename ... TT>
void PL(const T a, const TT ...  b) {PT(a); if (sizeof...(b) && sep) PT(sep); PL<sep,end>(b...);}

/* Good Luck && Have Fun ! */
ll solve(ll n,ll m)
{
	if (!(n%3))
		return 0;
	ll ans = m;
	RP1(i,n-1) {
		ll v[] = {(n-i) * m, i * (m/2), i * (m - m/2)};
		sort(v,v+3);
		cmin(ans, v[2] - v[0]);
	}
	return ans;
}
int main()
{
	ll n,m;
	RD(n,m);
	PL(min(solve(n,m),solve(m,n)));
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 45
using namespace std;

int n, ha, hb, sa, sb, ans, a[N], b[N], c[N], d[5005][5005];
int main()
{
	int i, j, k, t1, t2;
	cin >> n >> ha >> hb;
	for (i = 0; i <n; i++) {
		scanf ("%d %d %d", &a[i], &b[i], &c[i]);
		sa += a[i];
		sb += b[i];
	}
	for (i = 0; i <= 4005; i++) {
		for (j = 0; j <= 4005; j++) {
			d[i][j] = 2e9;
		}
	}
	d[0][0] = 0;
	for (i = 0; i < n; i++) {
		for (j = sa; j >= 0; j--) {
			for (k = sb; k >= 0; k--) {
				t1 = j - a[i];
				t2 = k - b[i];
				if (t1 < 0 || t2 < 0) continue;
				d[j][k] = min(d[j][k], d[t1][t2] + c[i]);
			}
		}
	}
//	cout << sa << "" << sb << endl;
//for (i = 0; i <= sa; i++) {
//	for (j = 0; j <= sb; j++) {
//		cout << d[i][j] << ' ';
//	}
//	cout << endl;
//}
	i = ha;
	j = hb;
	ans = 2e9;
	while (i <= sa && j <= sb) {
		if (d[i][j] < ans) {
			ans = d[i][j];
		}
//		ans = min(ans, d[i][j]);
		i += ha;
		j += hb;
	}
	if (ans == 2e9) {
		cout <<-1 << endl;
		return 0;
	}
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80128
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int X, Y;
	cin >> X >> Y;
	if (X % Y == 0) {
		cout << -1 << endl;
	}
	else {
		cout << X << endl;
	}
}

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

#define V             vector
#define PQ            priority_queue

#define pb            push_back
#define mp            make_pair
#define ins           insert
#define endl          '\n'
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<endl<<(#X)<<" = "<<(X)<<endl; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;

ll f(ll n) {
    ll _=1;
    for (ll i=2; i<=n; ++i) _*=i;
    return _;
}

ll c(ll n) {
    return (n*(n-1)/2);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n,m;
    cin>>n>>m;
    cout<<(c(n)+c(m))<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

class UnionFind {
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;
    UnionFind(int n) {
        Parent = vector<int>(n, -1);
    }
    //aがどのグループに属しているか調べる
    int root(int a) {
        if (Parent[a] < 0) return a;
        return Parent[a] = root(Parent[a]);
    }
    //自分のいるグループの頂点数を調べる
    int size(int a) {
        return -Parent[root(a)]; //親を取ってきたい
    }
    //aとbをくっつける
    bool connect(int a, int b) {
        //aとbを直接繋ぐのではなく、root(a)にroot(b)をくっつける
        a = root(a);
        b = root(b);
        if (a == b) {
            //すでにくっついているからくっつけない
            return false;
        }
        //大きい方(a)に小さい方(b)をくっつけたい
        //大小が逆だったらひっくり返しちゃう
        if (size(a) < size(b)) swap(a, b);
        //aのサイズを更新する
        Parent[a] += Parent[b];
        //bの親をaに変更する
        Parent[b] = a;
        return true;
    }
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<ll> ans(m);
    ans[m-1] = (ll)n*(n-1)/2;

    UnionFind Uni(n);

    for (int i=m-1; i>=1; i--) {
        if (Uni.root(a[i]) != Uni.root(b[i])) {
            ans[i-1] = ans[i] - (ll)Uni.size(a[i]) * Uni.size(b[i]);
            Uni.connect(a[i], b[i]);
        }
        else ans[i-1] = ans[i];
    }

    rep(i, m) {
        cout << ans[i] << endl;
    }
    
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll from[256][256];
ll to[256][256];
ll fact[300];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	fact[0]=1;
	FOR(i,256) fact[i+1]=fact[i]*(i+1)%mo;
	from[0][0]=to[0][0]=1;
	
	FOR(i,N) {
		cin>>x;
		
		FOR(j,255) FOR(y,256) (to[j+1][y^x] += from[j][y])%=mo;
		memmove(from,to,sizeof(from));
	}
	
	ll ret=0;
	FOR(x,256) ret+=from[x][K]*fact[x]%mo;
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;

int main()
{
  ll n;cin>>n;
  ll hoge;
  bool flag=true;
  for(ll i=0;i<n;i++){
    cin>>hoge;
    if(hoge%2==0){
      if(hoge%3!=0&&hoge%5!=0){
        flag=false;
      }
    }
  }
  string ans;
  ans= flag ? "APPROVED":"DENIED";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)
if X>abs(K*D):
    print(X-abs(K*D))
else:
    A = X%D
    B = D-A
    kk = K - X // D
    if kk%2 == 0:
        print(A)
    else:
        print(B)



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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll x, n;
  cin >> x >> n;
  set<ll> st;
  rep(i, n) {
    ll p;
    cin >> p;
    st.insert(p);
  }

  ll canda = INF;
  ll ans = 0;
  for (ll i = 0; i <= 101; i++) {
    if (st.find(i) != st.end()) continue;
    if (abs(i - x) < canda) {
      ans = i;
      canda = abs(i - x);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
#
# coding: utf-8

cnt, cyokaku, eikaku, donkaku = 0, 0, 0, 0

def solve(max_n, no2, no3):
    global cnt, cyokaku, eikaku, donkaku

    if max_n >= no2 + no3:
        print cnt, cyokaku, eikaku, donkaku
        return False
    cnt += 1
    max_vp = max_n ** 2
    no2pno3 = no2**2 + no3**2
    if max_vp == no2pno3:
        cyokaku += 1
    elif max_vp > no2pno3:
        donkaku += 1
    else:
        eikaku += 1

    return True

while True:
    a, b, c = map(int, raw_input().split())
    if a<b : a, b = b, a
    if a<c : a, c = c, a
    if not solve(a, b, c): break



Measured memory_bytes: 4668
def op(a,b):
    return max(a,b)

class segmentTree:
    def __init__(self,n,op,init_value):
        dataLen=1 << (n - 1).bit_length()
        self.data=[init_value]*(2*dataLen)
        self.op=op
        self.length=dataLen
    def getIdx(self,left,right):
        idxs=[]
        l=left
        r=right
        while True:
            idx=1
            valueL=0
            valueR=self.length-1
            while l!=valueL or valueR>=r:
                if l<=(valueR+valueL)//2:
                    valueR-=(valueR-valueL+1)//2
                    idx*=2
                else:
                    valueL+=(valueR-valueL+1)//2
                    idx=idx*2+1
            idxs.append(idx)
            if valueR==r-1:
                break
            l=valueR+1
        return idxs
    def get(self,n):
        return self.data[n+self.length]

    def set(self,n,value):
        idx1=n+self.length
        self.data[idx1]=value
        while idx1!=1:
            idx2=idx1^1
            if idx1>idx2:
                idx1,idx2=idx2,idx1
            self.data[idx1//2]=self.op(self.data[idx1],self.data[idx2])
            idx1//=2
    def query(self,l,r):
        idxs=self.getIdx(l,r)
        ret=self.data[idxs[0]]
        for idx in idxs:
            ret=self.op(ret,self.data[idx])
        return ret


N,K=map(int,input().split())
A=[]
for i in range(N):
  A.append(int(input()))

N=300000
seg = segmentTree(N, op, 0)

for i in A:
  l=min(N,max(0,i-K))
  r=max(0,min(N,i+K))
  v=seg.query(l,r+1)
  seg.set(i,v+1)
print(seg.query(0,N))


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

using namespace std;
typedef long long ll;
int main()
{
    ll x,y;
    cin>>x>>y;
    ll counter = 0;
    while(x<=y)
    {
        x= x*2;
        counter++;
        //cout<<x<<endl;
    }
    cout<<counter<<endl;
    return 0;
}


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



void dfs(string s, char mx, int n){
    if (s.size() == n){
        cout << s << endl;
        return;
    }
    for (char i = 'a'; i <= mx + 1; i++){
        string t = s;
        t += i;
        char mxx = max(mx, i);
        dfs(t, mxx, n);
    }
}

int main(){
    int n;
    cin >> n;
    dfs("", 'a'-1, n);
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll>vec;
int main(){
    ll n;
    cin>>n;
    ll cnt=0;
    for(ll i=1;i<n/i-1;i++){

        if(n%i==0) cnt+=n/i-1;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val input = readLine()?.split(" ") ?: return
    val list = arrayListOf<Double>()
    input.forEach { list.add(it.toDouble()) }

    println("${"%f".format(list[0] * list[0] * Math.PI)} ${"%f".format(2 * list[0] * Math.PI)}")
}



Measured memory_bytes: 32020
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;

struct point {double x,y;};

void koch(int n, point a, point b){
	if(n==0)
	return;
	point s,t,u;
	double rad = M_PI*(60.0/180.0);
	s.x=(2.0*a.x+1.0*b.x)/3.0;
	s.y=(2.0*a.y+1.0*b.y)/3.0;
	t.x=(2.0*b.x+1.0*a.x)/3.0;
	t.y=(2.0*b.y+1.0*a.y)/3.0;
	u.x=((t.x-s.x)*cos(rad))-((t.y-s.y)*sin(rad))+s.x;
	u.y=((t.x-s.x)*sin(rad))+((t.y-s.y)*cos(rad))+s.y;
	
	koch(n-1,a,s);
	printf("%.8f %.8f\n",s.x,s.y);
	koch(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	koch(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	koch(n-1,t,b);
}

int main(){
	point p1,p2;
	int n;
	scanf("%d",&n);
	p1.x=0;
	p1.y=0;
	p2.x=100;
	p2.y=0;
	printf("%.8f %.8f\n",p1.x,p1.y);
	koch(n,p1,p2);
	printf("%.8f %.8f\n",p2.x,p2.y);
}

Measured memory_bytes: 3180
#include<stdio.h>
int main(void)
{
	int a;
	int b;

	
	scanf("%d %d", &a, &b);
		if(a < b)
			{
				printf("a < b\n", a, b);
			}
		else if(a > b)
			{
				printf("a > b\n", a, b);
			}
		else if(a == b)
			{
				printf("a == b\n", a, b);
			}
	return 0;
}


Measured memory_bytes: 2044
h, w = gets.split.map(&:to_i)
s = []
h.times {s << gets.chomp}

visit = Array.new(h + 1) {Array.new(w + 1)}
visit[1][1] = 1
queue = [[1, 1]]
dir = [[-1, 0], [0, -1], [1, 0], [0, 1]]

while !queue.empty?
    i, j = queue.shift
    break if i == h && j == w

    dir.each do |x, y|
        if (i + x).between?(1, h) && (j + y).between?(1, w) && visit[i + x][j + y].nil?
            visit[i + x][j + y] = visit[i][j] + 1
            queue << [i + x, j + y] if s[i + x - 1][j + y - 1] == "."
        end
    end
end

puts visit[h][w].nil? ? -1 : s.inject(0) {|r, v| r + v.count(".")} - visit[h][w]

Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main () {
  int n; cin >> n;
  cout << 48-n << endl;
}

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

long int a[600000], L[600000], R[600000];
int n, i, j, k, t=0; //global variable retains its value

void merge(int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
		for (i=0; i<n1; i++) { 
			L[i] = a[left+i];
		}
		
		for (i=0; i<n2; i++) { 
			R[i] = a[mid+i]; 
		}

	L[n1] = 10000000000; //sentinel means a very large value, so just type a very large value here that fits in the array
	R[n2] = 10000000000;
	i = 0; //so this initialises i=0 again, instead of using the retained value
	j = 0;

	for (k=left; k<right; k++){ 
		if (L[i] <= R[j]) { a[k] = L[i]; i = i+1; t++; } //comparison is made here, so t should be here
		  else { a[k] = R[j]; j = j+1; t++; } //comparison is done here too, so t should be here too

		}
}

void mergesort(int left, int right) {   //if 2 arguments are given in (), always call the same function with TWO arguments
	if ( left+1 < right ) {
		int mid = (left+right)/2;
		mergesort(left, mid);
		mergesort(mid, right);
		merge(left, mid, right);
		}
}

int main() {
	cin >> n;
	for ( i=0; i<n; i++) cin >> a[i]; 
    mergesort(0, n);
	for ( i=0; i<n-1; i++) cout << a[i] << " ";
	cout << a[n-1] << endl;
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 10808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double  
#define mp make_pair
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
int main()
{
    io();
    int n;
    cin >> n;
    int mx = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int h;
        cin >> h;
        ans += (h >= mx);
        mx = max(mx, h);
    }
    cout << ans;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,py,px;
string S[41];
int sum[41][41];
int dp[41][41][41][41];
int memo[41][41][41][41];
int num(int L,int T,int R,int D) {
	if(R<=L || D<=T) return 0;
	if(memo[L][T][R][D]==-1) {
		memo[L][T][R][D]=sum[D][R]-sum[D][L]-sum[T][R]+sum[T][L];
	}
	return memo[L][T][R][D];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	MINUS(memo);
	cin>>H>>W;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			if(S[y][x]=='P') py=y,px=x;
			sum[y+1][x+1]=sum[y][x+1]+sum[y+1][x]-sum[y][x]+(S[y][x]=='#');
		}
	}
	FOR(i,41) FOR(j,41) FOR(x,41) FOR(y,41) dp[i][j][x][y]=101010;
	dp[0][0][H][W]=0;
	
	int ret=101010;
	int y2,x2;
	for(int h=H;h>=1;h--) for(int w=W;w>=1;w--) {
		FOR(y,H-h+1) FOR(x,W-w+1) {
			// LU
			for(x2=0;x2<=x;x2++) for(y2=0;y2<=y;y2++)     dp[y][x][y+h][x+w]=min(dp[y][x][y+h][x+w],dp[y2][x2][y+h][x+w]+num(x,y2,x+w,y)  +num(x2,y,x,y+h));
			// RU
			for(x2=x+w;x2<=W;x2++) for(y2=0;y2<=y;y2++)   dp[y][x][y+h][x+w]=min(dp[y][x][y+h][x+w],dp[y2][x][y+h][x2]  +num(x,y2,x+w,y)  +num(x+w,y,x2,y+h));
			// LD
			for(x2=0;x2<=x;x2++) for(y2=y+h;y2<=H;y2++)   dp[y][x][y+h][x+w]=min(dp[y][x][y+h][x+w],dp[y][x2][y2][x+w]  +num(x,y+h,x+w,y2)+num(x2,y,x,y+h));
			// RU
			for(x2=x+w;x2<=W;x2++) for(y2=y+h;y2<=H;y2++) dp[y][x][y+h][x+w]=min(dp[y][x][y+h][x+w],dp[y][x][y2][x2]    +num(x,y+h,x+w,y2)+num(x+w,y,x2,y+h));
			
			if(y<=py && py<y+h && x<=px && px<x+w) {
				ret=min(ret,dp[y][x][y+h][x+w]+num(x,y,px+1,py+1));
				ret=min(ret,dp[y][x][y+h][x+w]+num(px,y,x+w,py+1));
				ret=min(ret,dp[y][x][y+h][x+w]+num(x,py,px+1,y+h));
				ret=min(ret,dp[y][x][y+h][x+w]+num(px,py,x+w,y+h));
			}
		}
	}
	
	cout<<ret<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 22528
#include <stdio.h>
#include <stdlib.h>
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
typedef long long ll;

ll n;
ll w[105];
ll ans = 1000000000;

int main()
{
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) {
        ll tmp;
        scanf("%lld", &tmp);

        w[i] = w[i - 1] + tmp;
    }

    for (int i = 1; i < n; i++) {
        ans = min(ans, llabs(w[n] - w[i] - w[i]));
    }

    printf("%lld\n", ans);

    return 0;
}


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

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

        for (int i = 1; i <= 9; ++i) {
                for (int j = 1; j <= 9; ++j) {
                        if (i * j == n) {
                                cout << "Yes" << endl;
                                return 0;
                        }
                }
        }

        cout << "No" << endl;

        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#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)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<llong> h(n,0);
    REP(i,n) cin>>h[i];
    reverse(h.begin(),h.end());
    int ans=0;
    int tmp=0;
    REP(i,n-1)
    {
        if(h[i]<=h[i+1]) ++tmp;
        else tmp=0;
        
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;



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

    long long ans = 0;
    vector<long long> ab(n);

    for(long long i = 0; i < n; i++){
        long long a, b;
        cin >> a >> b;
        ans -= b;
        ab.push_back(a+b);
    }

    sort(ab.begin(), ab.end(), greater<long long>());

    for(long long i = 0; i < n; i++){
        if(i % 2 == 0){
            ans += ab[i];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4660
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());
  vector<ll> wa(N);
  wa[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    wa[i] = wa[i + 1] + A[i];
  }
  int ans = 0;
  REP(i, N - 1) {
    ans = i + 1;
    if (A[i] > 2 * wa[i + 1]) break;
    if (i == N - 2) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4824
(require '[clojure.string :as str])

(defn luckyPin3 [n s]
  (->>
   (for [i (range 1000)
         :let [a (format "%03d" i)
               a0 (get a 0)
               a1 (get a 1)
               a2 (get a 2)]
         :when (some? 
                (some->>
                 (str/index-of s a0 0)
                 (inc)
                 (str/index-of s a2)
                 (inc)
                 (str/index-of s a1)))]
     a)
   (count)))

(println (luckyPin3 (read-line) (read-line)))

Measured memory_bytes: 71436
#include <algorithm>
#include <cassert>
#include <iostream>
#include <set>

using namespace std;

pair<int, int> red[100];
pair<int, int> blue[100];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> red[i].first >> red[i].second;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> blue[i].first >> blue[i].second;
    }

    sort(red, red + n);
    sort(blue, blue + n);

    int cnt = 0;
    int j = 0;
    multiset<int> s;
    assert(s.begin() == s.end());
    for (int i = 0; i < n; i++)
    {
        while (j < n && red[j].first < blue[i].first)
        {
            s.insert(red[j].second);
            j++;
        }
        auto it = s.lower_bound(blue[i].second);
        if (it != s.begin())
        {
            it--;
            cnt++;
            s.erase(it);
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
import sys
import math
import numpy as np

def main():
  scan = sys.stdin.readline
  
  n = int(scan().rstrip())
  coordinates = np.array(
    tuple(tuple(int(x) for x in scan().rstrip().split()) for _ in range(n))
  )
  
  dist = np.array(
    tuple(
      tuple(
        np.sqrt(
          (coordinates[i][0] - coordinates[j][0]) ** 2 + (coordinates[i][1] - coordinates[j][1]) ** 2
        )
        for i in range(n)
      )
      for j in range(n)
    )
  )
  
  total = 0
  for pattern in itertools.permutations(range(n)):
    for i in range(n):
      if i == 0:
        continue
      else:
      	total += dist[pattern[i - 1]][pattern[i]]
    
  ave = total / math.factorial(n)
  
  print(ave)
  
  
if __name__ == "__main__":
  main()
  

Measured memory_bytes: 14432
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;




long long int N,M,K,sum=0,res=0;
string str;

int main()
{
    cout << fixed << setprecision(18);
    
    cin>>N>>M;
    for(long long int i = 0; i < 115000; i++){
        if(i*(8)/100==N&&i*10/100==M){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}



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

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

   vector<vector<int>> X(N, vector<int>(D));
   for (int i=0; i<N; i++)
      for (int j=0; j<D; j++)
         cin >> X.at(i).at(j);

   int r2;
   double r;
   int cnt = 0;
   int ceilr;

   for (int i=0; i<N; i++)
      for (int i2=i+1; i2<N; i2++){
         r2 = 0;
         for(int j=0; j<D; j++){
            r2 = r2 + pow(X.at(i2).at(j)-X.at(i).at(j), 2);
            //cout << r2 << endl;
         }
         r = sqrt(r2);
         ceilr = ceil(r);
         if (pow(ceilr, 2) == r2){
            cnt++;
            //cout << i << i2 << r <<  endl;
         }
      }
   cout << cnt << endl;
}



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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i = a; i < b; i++)
#define FORD(i,a,b) for(ll i=(a);i>=(int)(b);i--)
#define sf(n) scanf("%lld", &n)
#define sfc(x) scanf("%c", &x)
#define pf(x) printf("%lld", x)
#define pff(x) printf("%lf", x)
#define pfc(x) printf("%c", x)
#define pfs(x) printf("%s", x)
#define sf2(a,b) scanf("%lld %lld", &a, &b)
#define sf3(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define pfn(n) printf("%lld\n", n)
#define pfs(n) printf("%lld ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define ll long long
#define all(c) (c).begin(),(c).end()
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
// const ll INF = 2e18;

// bool prime[1000009];
// unordered_map<ll,ll> largest_factor;
// void SieveOfEratosthenes(ll n)
// {
//     memset(prime,true, sizeof(prime));
//     prime[1]=false;
//     for (ll p=2; p*p<=n; p++)
//     {
//         if (prime[p] == true)
//         {
//             for (ll i=p*p; i<=n; i += p){
//                 prime[i] = false;
//                 largest_factor[i]=p;
//             }

//         }
//     }
// }


// ll power(ll x,ll y)
// {
//     if (y == 0)
//         return 1;
//     else if (y%2 == 0)
//         return power(x, y/2)*power(x, y/2);
//     else
//         return x*power(x, y/2)*power(x, y/2);
// }


// ll mod_power(ll a,ll b,ll m){
//     ll res=1;
//     a%=m;
//     while(b){
//         if(b&1){
//             res=res*a%m;
//         }
//         a=a*a%m;
//         b>>=1;
//     }
//     return res;
// }


int main(){
    fast
    ll n;
    cin>>n;
    string s;
    vector<string> v;
    map<string,ll> mp;
    FOR0(i,n){
        cin>>s;
        mp[s]++;
        if(mp[s]==1)v.pb(s);
    }
    sort(all(v));
    ll maxi=0;
    FOR0(i,v.size()){
        maxi = max(maxi,mp[v[i]]);
    }
    FOR0(i,v.size()){
        if(mp[v[i]]==maxi)cout<<v[i]<<endl;
    }
}




Measured memory_bytes: 25712