akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#define maxn 4010
#define ll long long
#define mod 1000000007
using namespace std;
int n,x[1000010],y[1000010];
ll ans=0,f[maxn][maxn],inv[8010],fac[8010];
ll ksm(ll x,ll i){
	ll res=1;
	for(;i;i>>=1,x=x*x%mod)
		if(i&1)res=res*x%mod;
	return res;
}
inline void update(int x,int y){
	if(x+1<=4000)f[x+1][y]=(f[x+1][y]+f[x][y])%mod;
	if(y+1<=4000)f[x][y+1]=(f[x][y+1]+f[x][y])%mod;
}
ll calc(int n,int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	fac[0]=inv[0]=1;
	for(register int i=1;i<=8000;i++)fac[i]=fac[i-1]*i%mod;
	inv[8000]=ksm(fac[8000],mod-2);
	for(register int i=7999;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		f[2000-x[i]][2000-y[i]]++;
	}
	for(register int i=0;i<4000;i++){
		for(register int j=0;j<=i;j++){
			update(j,i-j);
		}
	}
	for(register int i=4000;i<=8000;i++){
		for(register int j=4000;j+4000>=i;j--){
			update(j,i-j);
		}
	}
	for(register int i=1;i<=n;i++){
		ans=(ans+f[2000+x[i]][2000+y[i]]-calc(x[i]+x[i]+y[i]+y[i],x[i]+x[i]))%mod;
	}
	ans=ans*500000004%mod;
	printf("%lld",(ans+mod)%mod);
	return 0;
}

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

int main() {

  string a,b;

  while(1) {

    a.clear();
    b.clear();
    cin >> a >> b;
    if(a.size() == 1 && b.size() == 1) break;

    int hit = 0,br = 0;
    
    for(int i=0;i<4;i++)
      if(a[i] == b[i]) {
	hit++;
      }

    for(int i=0;i<4;i++)
      for(int j=0;j<4;j++) {
	if(a[i] == b[j] && i != j) {
	  br++;
	}
      }
    
    cout << hit <<" "<< br << endl;
    
  }

  return 0;

}
    
  

Measured memory_bytes: 1180
n = gets.to_i
cnt = Array.new(50,0)
for i in 1..n
    for j in 2..49
        while i%j == 0
            i /= j
            cnt[j] += 1
        end
    end
end
a = Array.new(5,0)
cnt.each do |num|
    a[0] += 1 if num >= 2
    a[1] += 1 if num >= 4
    a[2] += 1 if num >= 14
    a[3] += 1 if num >= 24
    a[4] += 1 if num >= 74
end
ans = 0
ans += a[1]*(a[1]-1)/2*(a[0]-2)
ans += a[2]*(a[1]-1)
ans += a[3]*(a[0]-1)
ans += a[4]
puts ans

Measured memory_bytes: 3836
# 解説 AC

# 参考1: https://twitter.com/rickytheta/status/1175412019006074880
# 参考2: https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-09-21agc-038

def make_prime_checker(n):
    # nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)
    is_prime = [False, True, False, False, False, True] * (n//6+1)
    del is_prime[n+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (n//i-i+1)
    return is_prime

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

def main():
    mod = 998244353
    max_A = 10**6
    N = int(input())
    A = list(map(int, input().split()))
    
    primes = [p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime]  # max_A 以下の素数のリスト
    
    g = [0] * (max_A+1)
    for a in A:
        g[a] += a
    for p in primes:
        # 倍数集合の高速ゼータ変換みたいなやつ  O((max_A)loglog(max_A))
        # 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
        # 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう？（みんぷろ 2018 本戦 A - Uncommon など）
        for k in range(max_A//p, 0, -1):
            g[k] += g[k*p]
    
    # この時点で g[d] = Σ_{d|a} a  (A の要素のうち d の倍数であるものの総和)
    
    g = [v * v % mod for v in g]
    
    # この時点で
    # g[d] = (Σ_{d|a} a)(Σ_{d|b} b)
    #      = Σ_{(d|a)∧(d|b)} ab
    #      = Σ_{d | gcd(a,b)} ab
    
    # この式変形天才すぎないか？（これを使った一連の操作を gcd 畳み込み というらしい？）
    
    for p in primes:
        # 倍数集合の高速メビウス変換みたいなやつ  O((max_A)loglog(max_A))
    
        # for k in range(1, max_A//p+1):
        #     g[k] -= g[k*p]  # 包除原理ヤバい
    
        for k, g_kp in enumerate(g[p::p], 1):  # 高速化（ゼータ変換の方は途中で g が変化するので高速化できない）
            g[k] -= g_kp  # 包除原理ヤバい
    
    # この時点で g[d] = Σ_{gcd(a,b)=d} ab
    
    modinv_list = make_modinv_list(max_A, mod)
    ans = sum((gg * minv % mod for gg, minv in zip(g, modinv_list)))
    ans %= mod
    
    # この時点で
    # ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )
    #     = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )
    #     = Σ_a Σ_b lcm(a,b)
    
    ans -= sum(A)
    ans *= modinv_list[2]
    ans %= mod
    
    # この時点で ans = Σ_{i<j} lcm(a,b)
    
    print(ans)

main()


Measured memory_bytes: 81392
#include <iostream>
#include <cstdlib>
#include <set>
using namespace std;

const int N=1001;
const int SIZE = 1000 + 100;
int parent[SIZE];
int f[SIZE];

int cal(int n){
  if( f[n] > 0 ) return f[n];
  return f[n] = (cal(n-1) + cal(n-2)) % N;
}

int find(int n){
  if( parent[n]==n ) return n;
  return parent[n] = find(parent[n]);
}

int main(){
  f[0] = 1;
  f[1] = 2;
  for( int i=2;i<SIZE;i++ ) f[i] = -1;

  int v,d;
  while( cin>>v>>d ){
    for( int i=1;i<=v;i++ )
      parent[i] = i;

    for( int i=1;i<=v;i++ ){
      for( int j=i+1;j<=v;j++ )
	if( abs( cal(i) - cal(j) ) < d )
	  parent[find(j)] = find(i);
    }
    set<int> s;
    for( int i=1;i<=v;i++ )
      s.insert(find(i));

    cout << s.size() << endl;
  }

  return 0;
}

Measured memory_bytes: 1208
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int a, b, c; cin >> a >> b >> c;
    COUT(max(c - (a - b), 0));
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define endl "\n"
#define ui unsigned int
#define lu unsigned long long
#define mod 1000000007
#define ld long double
#define f(i, n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define v vector<ll>
#define vv vector<vector<ll> >
#define vs vector<string>
#define vpr vector<pair<ll,ll>>
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define bg(x)  x.begin()
#define sz(x)  x.size()
#define in(x,n) f(i,n) cin>>x[i]
#define out(x,n) f(i,n) cout<<x[i]<<" "
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end()))
#define mem(x,val) memset(x,val,sizeof(x))
#define tc    ll t;cin>>t;while(t--)
#define prfloat(val,precise) cout<<fixed<<setprecision(precise)<<val<<endl;
const ld PI = 2 * acos(0.0);
void yes(){ cout<<"YES\n";}
void no(){cout<<"NO\n";cout<<-1<<"\n";exit(0);}
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){ ;if((x1%y1)==0)return x1/y1;return x1/y1+1;}
ll power(ll a,ll b){ if(b==0)return 1;ll d=power(a,b/2);d=m(d*d);
if(b&1)d=m(d*a);return d;}
int seg[800005];
ll query(ll pos,ll ss,ll se,ll l,ll r)
{
	if(l>r)
		return 0;
	if(l>se || r  < ss)
		return 0;
	if(ss >=l && se<=r)
		return seg[pos];
	ll mid=(ss+se)/2;
	ll max1=query(2*pos+1,ss,mid,l,r);
	ll max2=query(2*pos+2,mid+1,se,l,r);
	return max(max1,max2);
}
void update(ll pos,ll ss,ll se,ll index,ll val)
{
	if(index <ss || index >se)
		return ;
	if(ss==se)
	{
		seg[pos]=val;
		return ;
	}
	ll mid=(ss+se)/2;
	update(2*pos+1,ss,mid,index,val);
	update(2*pos+2,mid+1,se,index,val);
	seg[pos]=max(seg[2*pos+1],seg[2*pos+2]);

}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;cin>>n;
  v h(n),a(n),h1(n);
  in(h,n);
  in(a,n);
  f(i,n)
  {
  	// cin>>h[i]>>a[i];
  	h1[i]=h[i];
  }
  sort(all(h1));
 v index(n+1,0);
  for(int i=0;i<n;i++)
  	index[h1[i]]=i;
  v ans(n);
  for(int i=0;i<n;i++)
  {
  	int mx=query(0,0,n-1,0,index[h[i]]);
    	ans[i]=mx+a[i];
  	update(0,0,n-1,index[h[i]],ans[i]);
  }
  int mx=0;
  for(int i=0;i<n;i++)
  	mx=max(ans[i],mx);
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>

int main(void)
{
	int i,N,a,total=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&a);
		if(i%2==0&&a%2==1)total++;
	}
	printf("%d",total);
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=998244353;

int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	sort(a,a+n,greater<int>());
	ll ans=0;
	rep(i,n){
		if(i==0)continue;
		int b=i/2;
		ans+=a[b];
	}
	puts(ans);
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
 
using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);
 
bool eq(ld a, ld b) {
    return abs(a - b) < eps;
}
 
using Point = complex<ld>;
class Line {
public:
    Point a, b;
};
class Circle {
public:
    Point p;
    ld r;
};
 
int nct(Circle c1, Circle c2) {
    ld d = abs(c1.p - c2.p);
    ld r1 = max(c1.r, c2.r), r2 = min(c1.r, c2.r);
    if (d > r1 + r2 + eps) return 4;
    if (eq(d, r1 + r2)) return 3;
    if (d > r1 - r2 + eps) return 2;
    if (eq(d, r1 - r2)) return 1;
    return 0;
}
 
int main()
{
    ld x1, x2, y1, y2, r1, r2;
    cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
    Circle c1 = { (Point) { x1, y1 }, r1 };
    Circle c2 = { (Point) { x2, y2 }, r2 };
    cout << nct(c1, c2) << endl;
    return 0;
}

Measured memory_bytes: 3268
def check(s)
  t = ['dream','dreamer','erase','eraser'].map(&:reverse)
  while s.length > 0
    if s.length >= 5 && t.include?(s.reverse[0..4])
      s = s[0..-6]
    elsif s.length >= 6 && t.include?(s.reverse[0..5])
      s = s[0..-7]
    elsif s.length >= 7 && t.include?(s.reverse[0..6])
      s = s[0..-8]
    else
      return "NO"
    end
  end
  "YES"
end

s = gets.chomp
puts check(s)


Measured memory_bytes: 83792
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  int in(a, b, c, d);
  out(min(a, b) + min(c, d));
}


Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main(){
  int a[4];
  int total = 0;
  for(int  i=0;i<4;i++){
    cin >> a[i];
  }
  if(a[0]>a[1])total += a[1];
  else total += a[0];
  if(a[2]>a[3])total += a[3];
  else total += a[2];
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll int
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, a, n) for ( i = a; i < (n); i++)
#define fill(a,v)                    memset(a, v, sizeof(a))
#define sz(a)                       ((int)(a.size()))
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 1e9+7
ll dp[100001]={};
int main(){
	fast;
	ll i,j,W,k,tc,q,m,n,flag;	
	cin>>n>>k;
	vector <ll> a(n);
	

	rep(i,0,n){
		cin>>a[i];
	}
	rep(i,0,n){
		dp[a[i]]=1;
	}
	rep(i,1,k+1){
		rep(j,0,n){
			// if(i==5)
			// 	cout<<dp[i]<<" "<<dp[i-a[j]]<<endl;
			if(i>=a[j])
				dp[i]=(dp[i] | !dp[i-a[j]] );
		}
	}
	// rep(i,0,n+1){
	// 	rep(j,0,n+1){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	// rep(i,0,k+1)
	// 	cout<<dp[i]<<" ";
	cout<<(dp[k]?"First":"Second")<<endl;
	
	return 0;
}


Measured memory_bytes: 640
N,L = map(int,input().split())
a = [0]*N
for i in range(N):
  a[i] = L+i
all_apple_pie = sum(a)
apple_pie = [0]*N
def_apple_pie = [0]*N
for i in range(N):
  t = a[i]
  a[i] = 0
  apple_pie[i] = sum(a)
  def_apple_pie[i] = abs(all_apple_pie-apple_pie[i])
  a[i] = t
index = def_apple_pie.index(min(def_apple_pie))
print(apple_pie[index])

Measured memory_bytes: 9152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        if (n % 2 != 0) {
            System.out.println(0);
            System.exit(0);
        }

        int max = 26;
        long[] count = new long[max + 1];
        for (int i = 1; i <= max; i++) {
            count[i] = n / (pow(5, i) * 2);
//            System.out.println(i + ":" + count[i]);
        }

        long ans = 0;
        for (int i = 1; i < max; i++) {
            ans += (count[i] - count[i + 1]) * i;
        }

        System.out.println(ans);

        sc.close();
    }

    static long pow(int base, int n) {
        long ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
    int m,d;
    cin>>m>>d;
    int ans=0;
    rep(i,1,m+1){
        int d1,d10;
        rep(j,1,d+1){
            d1=j%10;
            d10=j/10;
            if(d1>=2&&d10>=2&&d1*d10==i)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3600
N = int(input())
M = 0
A = 0
R = 0
C = 0
H = 0
for i in range(N):
    S = input()
    s = S[0]
    if s == "M":
        M += 1
    elif s == "A":
        A += 1
    elif s == "R":
        R += 1
    elif s == "C":
        C += 1
    elif s == "H":
        H += 1
ans = M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H
print(ans)

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

int main()
{
    int h,w;
    cin >> h >> w;
    string c[h];
    for(int i = 0; i < h; i++)
        cin >> c[i];

    for(int i = 0; i < 2 * h; i++)
        cout << c[i/2] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>
 
#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define INF (ll)ll_MAX
 
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector< ll > vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;
 
const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;
 
using namespace std;

// ll g[200000], ig[200000];



bool ok;

void dfs1(ll u, bool vis[], ll tot[], ll p[],ll h[], vll v[]){
    if(vis[u]==1) return;
    vis[u] = 1;

    ll sum = 0;

    sum += p[u];

    ll sorr = 0;

    for(ll i=1;i<v[u].size();i++){
        // cout<<'a';
        dfs1(v[u][i],vis,tot,p,h,v);
        sum+= tot[v[u][i]];
        sorr = sorr +  tot[v[u][i]] - h[v[u][i]];
    }

    // cout<<sum;

    tot[u] = sum;

    // if(tot[u]-h[u]>sorr){
    //     cout<<tot[u]-h[u]<<' '<<sorr<<'\n';
    //     ok = false;
    //     // cout<<"NOOOOO";
    // }

    return;

}

void dfs2(ll u, bool vis[], ll tot[], ll p[],ll h[], vll v[]){
    if(vis[u]==1) return;
    vis[u] = 1;

    // ll sum = 0;

    // sum += p[u];

    ll sorr = 0;

    for(ll i=1;i<v[u].size();i++){
        // cout<<'a';
        dfs2(v[u][i],vis,tot,p,h,v);
        // sum+= tot[v[u][i]];
        sorr = sorr +  tot[v[u][i]] - h[v[u][i]];
    }

    // cout<<sum;

    // tot[u] = sum;

    // cout<<sorr<<endl;

    if(tot[u]-h[u]>sorr + 2*p[u]){
        // cout<<u<<' '<<tot[u]-h[u]<<' '<<sorr<<'\n';
        ok = false;
        // cout<<"NOOOOO";
    }

    if((tot[u]-h[u])%2==1){
        ok = false;
    }

    if(h[u]>(tot[u]) or h[u]<(-tot[u])){
        ok = false;
    }

    return;

}





void solve()
{	
    
    ll n;
    cin>>n;

    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }

    sort(a,a+n);
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k = j+1;k<n;k++){
                if(a[k]>a[j] and a[j]>a[i] and a[i]+a[j]>a[k]){
                    ans++;
                }
            }
        }
    }

    cout<<ans;


}

int main() {


    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif


    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    // cin>>t;
    ll ctr=0;
    while(t--)
    {   
        ctr++;
        // cout<<"Case #"<<ctr<<": ";
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
 
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, 0, n) cin >> a[i];

  int sum = 0;
  rep(i, 0, n) sum += a[i];

  set<int> cand;
  rep(i, 1, sum/i+1){
    if(sum%i == 0){
      cand.insert(i);
      cand.insert(sum/i);
    }
  }

  int ans = 1;
  for(int x : cand){
    vi r(n);
    rep(i, 0, n) r[i] = a[i]%x;
    sort(all(r));
    int A = 0, B = 0;
    rep(i, 0, n) B += x-r[i];
    int need = inf;
    rep(i, 0, n){
      A += r[i];
      B -= x-r[i];
      chmin(need, max(A, B));
    }
    if(need <= k) chmax(ans, x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int count_divisor(int N) {
    int cnt = 0;
    for (int i=1; i<=N; ++i) {
        if (N % i == 0) cnt++;
    }
    return cnt;
}

int main() {
    int N;
    std::cin >> N;
    
    int ans = 0;
    if (N < 104) {
        std::cout << 0;
    } else {
        for (int i=105; i<=N; ++i) {
            if (count_divisor(i) == 8 && i % 2 != 0) ans++;
        }
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 256
n= int(input())
a= list(map(int,input().split()))
 
ans = 1
over = -1
 
if 0 in a:
    print(0)
    exit(0)

for i in a:
  ans = i * ans
  if ans > 10**18:
      print(-1)
      exit(0)

print(ans)

Measured memory_bytes: 21640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MP(x,y) make_pair(x,y)
#define X first
#define Y second

using namespace std;
const int MAX=30000;
typedef pair<int,int> PII;
typedef pair<PII,int> PIII;

class S{
  public:
  int x,y,z;
  S(int a, int b, int c): x(a), y(b), z(c){};
};

map<PIII, bool> memo;


int main(void){
  int a,b,c;
  int l = 0;
  cin >> a >> b >> c;
  if(a%2 || b%2 || c%2){
    cout << 0 << endl;
    return 0;
  }
  while(++l){
    PIII st(PII(a,b),c);
    if( memo[st] == true){
      cout << "-1" << endl;
      return 0;
    }
    int s,t,u;
    memo[st] = true;
    s = b/2 + c/2;
    t = a/2 + c/2;
    u = a/2 + b/2;
//     cout << s << " " << t << " " << u << endl;
    if(s%2 || t%2 || u%2) break;
    a = s;
    b = t;
    c = u;
  }
  cout << l << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<set>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
	
	int n,k;
	cin>>n>>k;
	
    int a[n];
    int i;
    for(i=0;i<n;i++)
    {
    	
    	cin>>a[i];
    	
    	
	}
	
	
	
	sort(a,a+n);
	int s=0;
	for(i=0;i<k;i++)
	{
		
		s=s+a[i];
		
	}
	
	
	cout<<s<<endl;
		
	return 0;
	
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first 
#define se second
#define pi pair<ll,ll> 
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main(){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  set<string>s;
  int n;cin>>n;
  for(int i=0;i<n;i++){
	  string str;
	  cin>>str;
	  s.insert(str);
  }
  cout<<s.size()<<endl;
}


Measured memory_bytes: 19204
List = []

def f(n):
    s = 0;
    for i in range(n):
        for j in range(n):
            if i != j:
                s += ((List[i][0] - List[j][0])**2 + (List[i][1] - List[j][1])**2)**0.5
    
    return s/n

if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        x, y = map(int, input().split())
        List.append((x, y))
    print(f(n))



Measured memory_bytes: 3060
x = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
for i in l:
  b = 0
  a = b+i
  if (a**5-b**5)%10 != x%10:
    continue
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)
      quit()
print(l)

Measured memory_bytes: 65000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> scheduling;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        scheduling.emplace_back(b, a);
    }
    sort(scheduling.begin(), scheduling.end());
    int cur = INT_MIN;
    int cnt = 0;
    for(int i = 0; i < m; i++){
        auto p = scheduling[i];
        if(cur < p.second){
            cnt++;
            cur = p.first - 1;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 1528
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class DDCC2020_QUALA
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var X = NN;
            var Y = NN;
            var ans = 0L;
            if (X == 3) ans += 100000;
            if (X == 2) ans += 200000;
            if (X == 1) ans += 300000;
            if (Y == 3) ans += 100000;
            if (Y == 2) ans += 200000;
            if (Y == 1) ans += 300000;
            if (X == 1 && Y == 1) ans += 400000;
            Console.WriteLine(ans);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 14688
S = input()
if S[0] != 'A':
    print('WA')
    exit()
a=0
for i in range(2, len(S) - 1):
    if S[i]=='C':
        j=i
        a+=1
if a!=1:
    print('WA')
    exit()
for i in range(len(S)):
    if (i!=0)&(i!=j):
        a=S[i]
        if a.isupper():
            print('WA')
            exit()
print('AC')

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
typedef long long int64;

int q, h, s, d, n;

int main()
{
    scanf("%d%d%d%d%d", &q, &h, &s, &d, &n);
    s = std::min(std::min(4 * q, 2 * h), s);
    printf("%lld\n", std::min((int64)n * s, (int64)(n / 2) * d + (n % 2) * s));
    return 0;
}


Measured memory_bytes: 128
import math
import random


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve2(N, A):
    gcd = A[0]
    answer = 'pairwise coprime'
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            if math.gcd(A[i], A[j]) != 1:
                answer = 'setwise coprime'
            gcd = math.gcd(gcd, math.gcd(A[i], A[j]))
    if gcd > 1:
        return 'not coprime'
    return answer


def solve():
    N = read_int()
    A = read_ints()
    gcd = A[0]
    for a in A[1:]:
        gcd = math.gcd(gcd, a)
    if gcd > 1:
        return 'not coprime'

    is_prime = [True]*(10**6+1)
    B = [False]*(10**6+1)
    for a in A:
        if B[a] and a > 1:
            return 'setwise coprime'
        B[a] = True

    for p in range(2, 10**6+1):
        if is_prime[p]:
            count = B[p]
            for q in range(2*p, 10**6+1, p):
                is_prime[q] = False
                count += B[q]
            if count > 1:
                return 'setwise coprime'
    return 'pairwise coprime'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 191764
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;
#pragma region Math
// 最大公約数
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
//inline T gcd(T a, T b){return b == 0 ? a : gcd(b, a % b);}

// 最小公倍数
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
//inline T lcm(T a, T b){return a * b / gcd(a, b);}

template<class T>
T pow(T x,int n){
	T mul = x;
	T ans = (T)1;
	while(n){
		if(n&1){
			ans *= mul;
		}
		mul *= mul;
		n >>= 1;
	}
	return ans;
}
#pragma endregion //math

void solve(){
	string str;
	cin >> str;
	vector<int> num(26,0);
	for(int i=0;i<(int)str.size();++i){
		num[str[i]-'a']++;
	}
	for(int i=0;i<26;++i){
		if( num[i]%2 == 0 )continue;
		cout << "No";
		return;
	}
	cout << "Yes";
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int main(){
  int N, T;
  cin >> N >> T;
  int c[110], t[110];
  
  rep(i, N) cin >> c[i] >> t[i];
  
  rep(i, N) if(t[i]>T) c[i] = 1010;
  
  int ans=1010;
  
  rep(i, N) ans = min(ans, c[i]);
    
  if(ans==1010) cout << "TLE" << endl;
  else cout << ans << endl;  
}

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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int n;
    
    scanf("%d", &n);
    
    rep(i, 11){
        if (i*1000-n>=0) {
            printf("%d", i*1000-n);
            return 0;
        }
    }
    
    return 0;
}



Measured memory_bytes: 1732
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int x = sc.nextInt();
		// 計算
		String result = "No";
		for(int i = -120; i <= 120; i++){
		    for(int j = -120; j <= 120; j++){
		        if(pow(i, 5) - pow(j, 5) == x){
		            System.out.println(i + " " + j);
		            return;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int& h : H) cin >> h;
  int ans = 0;
  bool f = true;
  while (f) {
    f = false;
    bool b = 0 < H[0];
    for (int i = 0; i < N; i++) {
      if (H[i] == 0) {
        if (b) {
          ans++;
          b = false;
        }
      } else {
        b = true;
        f = true;
        H[i]--;
      }
    }
    if (b) ans++;
  }
  cout << ans << endl;
}

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

int main() {
  long int a, b, x;
  cin >> a >> b >> x;

  long int upper = b / x ;
  long int lower;

  if(a == 0){
    upper = b / x + 1;
  }else{
    upper = b / x ;
  } 

  if(a == 0){
    lower =  0;
  }else{
    lower =  (a - 1) / x;
  } 
  cout << upper - lower << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5+5;
char s[M][11];
unsigned long long tot[M][29];
unsigned long long pw[M],hsh[M];
inline int read()
{
	int x=0,f=1; char ch=0;
	while(!isdigit(ch)) f=(ch=='-'?-1:1),ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
int main()
{
	int n=read(); pw[1]=1;
	for(register int i=1;i<=n;i++){
		scanf("%s",s[i]+1); 
	}
	for(register int i=1;i<26;i++) pw[i+1]=pw[i]*11;
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=10;j++){
			int tmp=s[i][j]-'a'+1;
			tot[i][tmp]++;
		}
	}
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=26;j++){
			hsh[i]=hsh[i]+pw[j]*tot[i][j];
		}
	}
	sort(hsh+1,hsh+n+1);
	long long ans=0,last=1;
	for(register int i=2;i<=n;i++){
		if(hsh[i]==hsh[i-1]){
			ans+=i-last;
		}
		else last=i;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 24704
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main (void){

	int sumA = 0;
	int sumB = 0;
	int fake = 0;

	for(int i=0;i<4;i++){
		scanf("%d",&fake);
		sumA += fake;
	}
	for(int i=0;i<4;i++){
		scanf("%d",&fake);
		sumB += fake;
	}

	printf("%d\n",max(sumA,sumB));

	return 0;
}

Measured memory_bytes: 1184
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from bisect import bisect_left

def main():
    N, Q = LI()
    XST = []
    for _ in range(N):
        s, t, x = LI()
        s -= x
        t -= x
        XST.append([x, s, t])
    D = []
    for _ in range(Q):
        D.append(II())
    ans = [-1] * Q
    nexts = [-1] * Q
    XST.sort()
    for x, s, t in XST:
        i = bisect_left(D, s)
        end = bisect_left(D, t)
        while i < end:
            if nexts[i] == -1:
                ans[i] = x
                nexts[i] = end
                i += 1
            else:
                i = nexts[i]
    for y in ans:
        print(y)
    return

main()


Measured memory_bytes: 58616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int n;

void bfs(vector<vector<pair<int,int>>> &vec,vector<int> &ans,int color,int start){
    int e,v,c=0;
    vector<int> vc(n,-1);//それぞれの頂点をつっこむ時に使った色
    queue<pair<int,int>> q;
    for(auto p:vec[start]){
        q.push(p);
        ans[p.first]=c%color;
        vc[p.second]=c%color;
        c++;
    }
    while(!q.empty()){
        auto p=q.front();q.pop();
        e=p.first;v=p.second;
        c=vc[v]+1;
        for(auto np:vec[v]){
            if(ans[np.first]!=-1)continue;
            q.push(np);
            ans[np.first]=c%color;
            vc[np.second]=c%color;
            c++;
        }
    }
}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int a,b;cin>>n;
    vector<int> edge(n);
    vector<int> ans(n,-1);
    vector<vector<pair<int,int>>> vec(n,vector<pair<int,int>>(0,pair<int,int>(0,0)));
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        vec[a-1].pb(make_pair(i,b-1));
        vec[b-1].pb(make_pair(i,a-1));
        edge[a-1]++;edge[b-1]++;
    }
    int highest=0,rem;
    for(int i=0;i<n;i++){
        if(highest<edge[i]){
            highest=edge[i];
            rem=i;
        }
    }
    bfs(vec,ans,highest,rem);
    cout<<highest<<endl;
    for(int i=0;i<n-1;i++){
        cout<<ans[i]+1<<endl;
    }
}


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

int H,W;
int K;
LL G[3000][3000];
LL dp[3000][3000][4];

int main() {
 scanf("%d%d%d",&H,&W,&K);
 rep(y,H) rep(x,W) G[y][x]=0;
 rep(k,K){
  int y,x,v; scanf("%d%d%d",&y,&x,&v); y--; x--;
  G[y][x] = v;
 }
 rep(y,H)rep(x,W)rep(i,4) dp[y][x][i]=0;
 dp[0][0][1] = G[0][0];

 rep(y,H)rep(x,W)rep(i,4){
  if(y!=H-1) dp[y+1][x][0] = max(dp[y+1][x][0],dp[y][x][i]);
  if(y!=H-1) dp[y+1][x][1] = max(dp[y+1][x][1],dp[y][x][i]+G[y+1][x]);
  if(x!=W-1) dp[y][x+1][i] = max(dp[y][x+1][i],dp[y][x][i]);
  if(x!=W-1)if(i!=3) dp[y][x+1][i+1] = max(dp[y][x+1][i+1],dp[y][x][i]+G[y][x+1]);
 }

 LL ans=0;
 rep(i,4) ans=max(ans,dp[H-1][W-1][i]);
 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 355036
import queue
q = queue.Queue()

K = int(input())

for i in range(1,10):
    q.put(i)
    
for i in range(K):
    x = q.get()
    m = x % 10
    if not m == 0:
        q.put(x * 10 + (m-1))
    q.put(x * 10 + m)
    if not m == 9:
        q.put(x * 10 + (m+1))

print(x)

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	int h = 0;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (h > a[i]) {
			ans += (long long)h - a[i];
		}
		else h = a[i];
	}

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

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  bool hanten = false;
  string A;
  string B;
  for (int i = 0; i < Q; i++) {
    int mode;
    cin >> mode;
    if (mode == 1) {
      hanten = !hanten;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (f == 1 && !hanten) {
        A += c;
      } else if (f == 1 && hanten) {
        B += c;
      } else if (f == 2 && !hanten) {
        B += c;
      } else {
        A += c;
      }
    }
  }
  if (!hanten) {
    reverse(A.begin(),A.end());
    cout << A << S << B << endl;
  } else {
    reverse(B.begin(),B.end());
    reverse(S.begin(),S.end());
    cout << B << S << A << endl;
  }
  return 0;
}

Measured memory_bytes: 1088
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll N, K;
const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

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

    for(ll i=0;i<N;i++)
    {
        cin >> to[0][i];
        to[0][i]--;
    }
    REP(i, D-1)
    {
        REP(j,N){
            to[i+1][j] = to[i][to[i][j]];
        }
    }

    int v = 0;
    for(int i=D-1;i>=0;--i)
    {
        ll l = 1ll<<i;
        if(l <= K)
        {
            v = to[i][v];
            K -= l;
        }
    }
    cout << v+1 << endl;
}


Measured memory_bytes: 50416
#include "bits/stdc++.h"
using namespace std;

const int N=25;

int n,m,ans,dp[N][N];
char a[N][N];
bool vis[N][N];
int dx[]={ 0, 0,+1,-1};
int dy[]={+1,-1, 0, 0};

void init()
{
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			vis[i][j]=false;
}

bool invalid(int x,int y)
{
	return min(x,y)<0 or x>=n or y>=m or vis[x][y] or a[x][y]=='#';
}

void add(queue <pair <int,int>> &q,int x,int y,int val)
{
	q.push({x,y});
	dp[x][y]=val;
	vis[x][y]=true;
}

void go(int x,int y)
{
	queue <pair <int,int>> q;

	add(q,x,y,0);
	while(not q.empty())
	{
		auto p=q.front();
		q.pop();

		int x=p.first,y=p.second;
		ans=max(ans,dp[x][y]);
		for(int k=0;k<4;k++)
		{
			int nx=x+dx[k],ny=y+dy[k];
			if(invalid(nx,ny)) continue;
			add(q,nx,ny,dp[x][y]+1);
		}
	}
}


int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf(" %s",a[i]);

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='#') continue;
			init();
			go(i,j);
		}
	}

	printf("%d",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    ll n, m, ans=1, a, b;


    cin >> n >> m;

    for(int i=1; i*i<=m; i++){
        if(m % i != 0) continue;
        a = i;
        b = m / i;
        if(a * n <= m) ans = max(ans, a);
        if(b * n <= m) ans = max(ans, b);
    }

    cout << ans << 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;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}


int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if(a>=k) {
    cout << a-k << ' ' << b << endl;
      
  }
  else {
      
      if(a+b>=k) cout << 0 << ' ' << a+b-k << endl;
      else cout << 0 << ' ' << 0 << endl;
  }
  return 0;
}

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

tempertures = [abs(A - (T - 0.006 * h)) for h in H]
min_t = None
min_index = 0
for i, t in enumerate(tempertures):
    if min_t is None or t < min_t:
        min_t = t
        min_index = i

print(min_index+1)

Measured memory_bytes: 3188
def paint(x, y, w, h, id, flds, ids)
  f = flds[y][x]
  ids[y][x] = id
  queue = [[x, y]]

  while ! queue.empty?
    x0, y0 = queue.shift

    q0 = []
    q0.push [x0 - 1, y0] if x0 > 0
    q0.push [x0 + 1, y0] if x0 < w - 1
    q0.push [x0, y0 - 1] if y0 > 0
    q0.push [x0, y0 + 1] if y0 < h - 1

    for xy in q0
      x1, y1 = xy
      if flds[y1][x1] == f && ids[y1][x1] == 0
        ids[y1][x1] = id
        queue.push xy
      end
    end
  end
end

while true
  h, w = gets.chomp.split(" ").map{|s| s.to_i}
  break if h == 0 && w == 0

  flds = []
  ids = []

  h.times.each do
    hl = gets.chomp.split("")
    flds.push hl
    ids.push hl.map{0}
  end

  id = 0
  for y in (0...h)
    for x in (0...w)
      if ids[y][x] == 0
        id += 1
        paint(x, y, w, h, id, flds, ids)
      end
    end
  end

  puts id
end

Measured memory_bytes: 6992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] a = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int[] x = new int[3];
		int[] y = new int[3];
		x[0] = 0;
		for (int i = 0; i < 3; i++)
			y[i] = a[0][i];
		x[1] = a[1][0] - y[0];
		x[2] = a[2][0] - y[0];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (a[i][j] != x[i] + y[j]) {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N, K;
  cin >> N >> K;
  set<int> s;
  rep (i, K) {
    int d;
    cin >> d;
    rep(i, d) {
      int A;
      cin >> A;
      s.insert(A);
    }
  }
  cout << N-s.size() << endl;
}


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

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    if (x < r || (W - x) < r) cout << "No" << endl;
    else if (y < r || (H - y) < r) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	int R,G;
	cin >> R >> G;
	cout << G*2-R << endl;
	return 0;
}


Measured memory_bytes: 3608
n = gets.to_i
pu = n.times.map{gets.chomp.to_s}
m = gets.to_i
ma = m.times.map{gets.chomp.to_s}

hash = pu.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h
hash_m = ma.group_by(&:itself).map{ |key, value| [key, value.count*-1] }.to_h

sum = hash.merge(hash_m){|k, v1, v2| v1 + v2}

if sum.max{ |x, y| x[1] <=> y[1] }[1] > 0
  puts sum.max{ |x, y| x[1] <=> y[1] }[1]
else
  puts 0
end
  

Measured memory_bytes: 14196
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int total = 0;
        if(N%2==0){
            N=N-1;   
        }
        for (int i=N ; i > 0 ; i=i-2){
            int count = 0;
            for (int j=1 ; j <= N ; j=j+2){
                if(i%j==0){
                    count = count + 1;
                }
            }
            if(count==8){
                total = total + 1;
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 22868