akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void solveA(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << a*b/2 << endl;
}
void solveB(){
  int s;
  cin >> s;
  set<int> st;

  int m = 1;
  for(int i=0;i<2000000;i++){
    auto itr = st.find(s);
    if (itr != st.end()) {
      break;
    }

    st.insert(s);
    if (s%2 == 0) {
      s/=2;
    }
    else {s=3*s+1;}
    m++;
  }
  cout << m << endl;  
}

void solveC(){
}
void solveD(){
}

int main(){
  solveB();
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main (String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        while (true) {
            boolean flag = false;
            for (int i = 0; i < N; i++) {
                if (A[i] % 2 != 0) {
                    flag = true;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < N; i++) {
                A[i] = A[i] / 2;

            }
            cnt++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
import java.util.*;
public class Main {
    public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    int n = s.nextInt(), m = s.nextInt() - 1;
	    char[] cs = s.next().toCharArray();
	    //A - a = -32
	    cs[m] += ('a' - 'A');
	    System.out.println(cs);
    }
}

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

int main(){
  int N,A,B;
  cin >> N >> A >> B;

  if(N*A <= B){
    cout << N*A << endl;
  } else {
    cout << B << endl;
  }
}

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

public class Program
{
    private long N;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        
        Console.WriteLine((N)*(N-1)/2);
    }

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

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

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

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

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    vector<int> v(N);
    for (auto &&i : v) {
        cin >> i;
    }

    int ans = 0;

    int pre = v[0];
    FOR(i, 1, N) {
        if (pre == v[i]) {
            ans++;
            pre = -1;
        } else {
            pre = v[i];
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> num(100010);
    ll a,b;
    rep(i,n){
        cin>>a>>b;
        num[a-1]+=b;
    }
    ll sum=0;
    rep(i,100000){
        sum+=num[i];
        if(sum>=k){
            cout<<i+1;
            return 0;
        }
    }
}

Measured memory_bytes: 4016
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    string str;
    cin >> str;
    int num = str.size();
    int cnt =0;
    for(int i=0;i<num;i++){
        if(str[i]!=str[num-i-1]){
             cnt++;
             str[i] = str[num-i-1];
        }
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
	
	int n,a,b;
	
	cin >> n;
	cin >> a;
	cin >> b;
	
	if(n*a < b){
		cout << n*a << endl;;
	}else{
		cout << b << endl;
	}
	
	return 0;
}

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

int main () {

    char S[4]; cin >> S;
    sort (S, S + 4);
    if (S[0] == S[1] && S[2] == S[3] && S[1] != S[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

char s[200];
char *p;

int E();
int F();
int T();
int N();

#ifdef DEBUG
#define dump(s) cerr << s << endl
#else
#define dump(...)
#endif

int E(){
    int res = F();
    while(*p=='+' || *p=='-'){
        if(*p=='+') p++, res += F();
        else if(*p=='-') p++, res -= F();
    }
    return res;
}

int F(){
    int res = T();
    while(*p=='*' || *p=='/'){
        if(*p=='*') p++, res *= T();
        else if(*p=='/') p++, res /= T();
    }
    dump(res);
    return res;
}

int T(){
    int res;
    if(*p=='(') p++, res = E(), p++;
    else res = N();
    return res;
}

int N(){
    int res = 0;
    while(isdigit(*p)){
        res = res*10 + *p - '0';
        p++;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        p = s;
        cout << E() << endl;
    }
}

Measured memory_bytes: 1164
import Control.Applicative

m = 10^9 + 7
modm n = mod n m

mul' x y = modm $ modm x * modm y

power' x 0 = 1
power' x 1 = modm x
power' x n
  | (n `mod` 2) == 0 = let i = power' x (n `div` 2) in mul' i i
  | otherwise = mul' x $ power' x (n - 1)

div' x y = mul' x $ power' y (m - 2)

product' xs = foldl mul' 1 xs

factorial' n = product' [1..n]

npr' n r = product' [n - i | i <- [0..(r - 1)]]

ncr' n r = modm $ (npr' n r) `div'` (factorial' r)

main = do
  [n, k] <- (map read). words <$> getLine :: IO [Int]
  mapM_ (putStrLn.show) $ (flip map) [1..k] $ \x -> modm $ product' [(ncr' (n - k + 1) x), (ncr' (k - 1) (x - 1))]


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  
  int k, n;
  cin >> k >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec[i];
  int differ = 0;
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
    if (i) {
      chmax(differ, vec[i] - vec[i-1]);
    }
  }
  
  chmax(differ, k + vec[0] - vec[n-1]);
  cout << k - differ << '\n';
  
}


Measured memory_bytes: 1024
#include <iostream>

int main(void) {
    std::string S, T;
    int len_S;
    
    std::cin >> S >> T;
    
    len_S = S.length();
    
    if(T.substr(0, len_S)==S) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3624
N = int(input())
L = []
for i in range(N):
    L.append(list(map(int,input().split())))

import itertools
import math

D = list(itertools.permutations(L, 2))
R = []
for i in range(len(D)):
    length = ((D[i][0][0] - D[i][1][0])**2 + (D[i][0][1] - D[i][1][1])**2)**0.5
    for j in range(math.factorial(N-1) * 2):
        R.append(length)

print(sum(R) / (2*math.factorial(N)))

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

#define MAX_N 100000
#define MAX_M 100000
#define MAX_A 1000000000
#define MAX_B 100000

typedef long long ll;

int a[MAX_N], b[MAX_N];
std::map<int, int> nums;

int main() {
  int n, m;

  std::cin >> n >> m;
  for(int i = 0; i < n; ++i) {
    std::cin >> a[i] >> b[i];
    nums[a[i]] = 0;
  }
  for(int i = 0; i < n; ++i) {
    nums[a[i]] += b[i];
  }

  std::sort(a, a + n);

  ll ans = 0;
  int num = 0, i = 0;
  while(num + nums[a[i]] < m) {
    num += nums[a[i]];
    ans += (ll) nums[a[i]] * a[i];
    nums[a[i]] = 0;
    ++i;
  }
  ans += (ll) (m - num) * a[i];

  std::cout << ans << std::endl;
}

Measured memory_bytes: 5760
MOD = 998244353
N, K = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(K)]
dp = [0]*(N+1)
dp[1] = 1
dp_rui = [0]*(N+1)
dp_rui[1] = 1
for i in range(2,N+1):
    for l, r in S:
        r2 = i-l
        l2 = i-r
        if l == r:
            if i - l >= 0:
                dp[i] += dp[i-l]
        elif r2 > 0 and l2 >= 0:
            dp[i] += dp_rui[r2]-dp_rui[l2-1]
        elif r2 > 0 and l2 < 0:
            dp[i] += dp_rui[r2]
    dp_rui[i] = dp_rui[i-1]+dp[i] % MOD
    dp[i] %= MOD
print(dp[-1]%MOD)


Measured memory_bytes: 71336
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

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

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll x = 0;
    rep(i, n){
        cin >> a[i];
        x ^= a[i];
    }
    rep(i, n){
        ll ans = x ^ a[i]; 
        cout << ans << " ";
    }




}



Measured memory_bytes: 4760
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

const int M = 1e9 + 7;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

using vi = vector<int>;
using vvi = vector<vi>;

template<class T> inline void add(T& a, const T& b) {
	a += b; 
	if (M <= a) a -= M;
}

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

	string k; int d; cin >> k >> d;
	vvi f(d, vi(2)); f[0][0] = 1;
	rep(i, 0, sz(k)) {
		vvi g(d, vi(2));
		rep(x, 0, d) {
			rep(c, 0, 10) add(g[(x + c) % d][1], f[x][1]);
			rep(c, 0, k[i] - '0') add(g[(x + c) % d][1], f[x][0]);
			add(g[(x + k[i] - '0') % d][0], f[x][0]);
		}
		swap(f, g);
	}
	cout << (f[0][0] + f[0][1] + M - 1) % M;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
    // input
    int N; cin >> N;
    int T, A; cin >> T >> A;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H.at(i);

    // compute
    vector<double> dif(N);
    for (int i; i < N; i++){
        dif.at(i) = abs(T - H.at(i) * 0.006 - A);
    }

    int ans = min_element(dif.begin(), dif.end()) - dif.begin();
    
    // output
    cout << ans+1 << endl;
    
}

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

using namespace std;
typedef long long ll;

const int N = 1e6 + 10;
int c[N], sieve[N];
vector<int> primes;

int main() {
    int n, a;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        c[a]++;
    }
    for (int i = 2; i < N; i++) {
        if (sieve[i]) continue;
        for (int j = 2 * i; j < N; j += i) {
            sieve[j] = 1;
        }
    }
    for (int i = 2; i < N; i++) {
        if (!sieve[i]) primes.push_back(i);
    }
    bool pairwise = 1;
    for (auto p : primes) {
        int cnt = 0;
        for (int i = p; i < N; i += p) cnt += c[i];
        if (cnt > 1) {
            pairwise = 0;
            break;
        }
    }
    if (pairwise) {
        puts("pairwise coprime");
        return 0;
    }
    bool setwise = 1;
    for (auto p : primes) {
        int cnt = 0;
        for (int i = p; i < N; i += p) cnt += c[i];
        if (cnt == n) {
            setwise = 0;
            break;
        }
    }
    if (setwise) puts("setwise coprime");
    else puts("not coprime");
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	array<llong, 3> A, B;

	cin >> N;
	cin >> A[0] >> A[1] >> A[2];
	cin >> B[0] >> B[1] >> B[2];

	llong ans = 0;

	if (A[0] <= B[0] && A[1] <= B[1] && A[2] <= B[2]) {
		for (int g = 0; g <= N; ++g) {
			for (int s = 0; s <= N - g; ++s) {
				int b = N - g - s;
				llong res = g%A[0] + s%A[1] + b%A[2];
				res += g/A[0]*B[0] + s/A[1]*B[1] + b/A[2]*B[2];
				ans = max(ans, res);
			}
		}
	} else if (A[0] <= B[0] && A[1] <= B[1] && A[2] > B[2]) {
		llong check = 0;
		for (int g = 0; g <= N; ++g) {
			int s = N - g;
			llong res = g%A[0] + s%A[1];
			res += g/A[0]*B[0] + s/A[1]*B[1];
			check = max(check, res);
		}
		ans = check%B[2] + check/B[2]*A[2];
	} else if (A[0] <= B[0] && A[1] > B[1] && A[2] <= B[2]) {
		llong check = 0;
		for (int g = 0; g <= N; ++g) {
			int b = N - g;
			llong res = g%A[0] + b%A[2];
			res += g/A[0]*B[0] + b/A[2]*B[2];
			check = max(check, res);
		}
		ans = check%B[1] + check/B[1]*A[1];
	} else if (A[0] <= B[0] && A[1] > B[1] && A[2] > B[2]) {
		llong check = N%A[0] + N/A[0]*B[0];
		for (int s = 0; s <= check; ++s) {
			int b = check - s;
			llong res = s%B[1] + b%B[2];
			res += s/B[1]*A[1] + b/B[2]*A[2];
			ans = max(ans, res);
		}
	} else if (A[0] > B[0] && A[1] <= B[1] && A[2] <= B[2]) {
		llong check = 0;
		for (int s = 0; s <= N; ++s) {
			int b = N - s;
			llong res = s%A[1] + b%A[2];
			res += s/A[1]*B[1] + b/A[2]*B[2];
			check = max(check, res);
		}
		ans = check%B[0] + check/B[0]*A[0];
	} else if (A[0] > B[0] && A[1] <= B[1] && A[2] > B[2]) {
		llong check = N%A[1] + N/A[1]*B[1];
		for (int g = 0; g <= check; ++g) {
			int b = check - g;
			llong res = g%B[0] + b%B[2];
			res += g/B[0]*A[0] + b/B[2]*A[2];
			ans = max(ans, res);
		}
	} else if (A[0] > B[0] && A[1] > B[1] && A[2] <= B[2]) {
		llong check = N%A[2] + N/A[2]*B[2];
		for (int g = 0; g <= check; ++g) {
			int s = check - g;
			llong res = g%B[0] + s%B[1];
			res += g/B[0]*A[0] + s/B[1]*A[1];
			ans = max(ans, res);
		}
	} else if (A[0] > B[0] && A[1] > B[1] && A[2] > B[2]) {
		for (int g = 0; g <= N; ++g) {
			for (int s = 0; s <= N - g; ++s) {
				int b = N - g - s;
				llong res = g%B[0] + s%B[1] + b%B[2];
				res += g/B[0]*A[0] + s/B[1]*A[1] + b/B[2]*A[2];
				ans = max(ans, res);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

/*

できること
Aで利率が高いのに変える

A1でできること
どんぐりを売る
買い戻せるので全部売っていい
パターン5000^2

Bでできること
余ったどんぐりを売る/売らない


dp[どんぐり]: どんぐりをつぎ込んだときの金を得る量

Mを買うとき A > BのときBで売ってAで買う
A < Bのとき Aで売ってBで買う

*/

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n,T;
ll t[300001];
int main(void){
	scanf("%d%lld",&n,&T);
	for(int i=0;i<n;i++){
		scanf("%lld",&t[i]);
	}
	ll res=0;
	ll prev=t[0];
	for(int i=1;i<n;i++){
		if(t[i]-prev>=T){
			res+=T;
		}else{
			res+=t[i]-prev;
		}
		prev=t[i];
	}
	printf("%lld\n",res+T);
	return 0;
}


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

public class Main {	
	private static void solve(){
		//Implement solution here.
		int N = ni();
		int M = ni();		
		
		boolean[] da = new boolean[N + 1];
		int[] dv = new int[N + 1];
		boolean ok = true;
		for(int i = 0; i < M; i++) {
			int s = ni();
			int c = ni();
			if(!da[s]) {
				if(N > 1 && s == 1 && c == 0) {
					ok = false;
					break;
				}
				dv[s] = c;
				da[s] = true;
			} else {
				if(c == dv[s]) {
					continue;
				} else {
					ok = false;
					break;
				}
			}
		}
		
		if(ok) {
			int result = 0;
			if(N > 1 && !da[1])result += Math.pow(10, N - 1);
			for(int i = 1; i <= N; i ++) {
				result += dv[i] * Math.pow(10, N - i);
			}
			System.out.println(result);
		}else {
			System.out.println(-1);
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 22612
import random
import time
import copy
start=time.time()
d=int(input())
c=list(map(int, input().split()))
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
s=[]
solution=[]
last=[0]*26
sco=0
for i in range(d):
  s.append(list(map(int, input().split())))
for day in range(1,d+1):
  man=[]
  for i in range(26):
    man.append(s[day-1][i]+last[i]*c[i])
  con=man.index(max(man))
  sco+=s[day-1][con]
  last[con]=day
  for (i,j) in zip(last,range(26)):
    sco-=cli[i][j]
  solution.append(con)
#print(sco)
while time.time()-start<1.9:
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(3)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[i][j]
  if sc>sco:
    solution=copy.deepcopy(sol)
    sco=sc
for i in solution:
  print(i+1)
#print(sco)

Measured memory_bytes: 10492
#include <iostream>
#define N_MAX 1000
#include <string>
using namespace std;

int N,A,B,i,j,k;
string S,Sa;
int l[N_MAX];
int r[N_MAX];
int num[N_MAX] = {0};
int ans=0;

int main(){
  cin >> S;
  bool s = false;
  for (i=0;i<S.size();i++){
    if(!s && S[i] == 'A') {
      A = i;
      s = true;
    }

    if(s && S[i] == 'Z'){
      B = i;
      if (ans < B-A+1) ans = B-A+1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int a = V[0];
            int b = V[1];
            char c = (a + b == 15) ? '+'
                   : (a * b == 15) ? '*'
                                   : 'x';
            Console.WriteLine(c);
        }
    }
}


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

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

using namespace std;
using ll = long long;

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

  int r[n];
  rep(t, n) cin >> r[t];

  int minv = r[0], maxv = INT_MIN;
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }

  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	vector<ll> v;
	for (int i = 0; i < n; i++) {
		ll x;
		scanf("%lld", &x);
		v.push_back(x);
	}
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		ans += min((v[i] - v[i-1]) * a, b);
	}
	cout << ans << endl;

}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int a,b; cin>>a>>b;
	
	int ans = a-b*2;
	if(ans<0) cout<<0<<endl;
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*input
1
1000
*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define is_empty(v) v.empty()
#define vs			vector< string >
#define vvi			vector< vector< ll,ll > >
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define inf         1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define reprr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sum(v)      accumulate(v.begin(),v.end(),(ll)0)
//map <long long int,long long int> ma;
//set <long long int, greater <long long int> > s;


int solve()
{
	ll n;cin>>n;
	double ans=0;
	rep(i,0,n) {
		double x;cin>>x;
		ans+=1/x;
	}

	ans=1/ans;
	printf("%0.6f\n",ans);
	// cout<<setprecision(6)<<ans<<"\n";
}

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

	ll t=1;
	//cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<ArrayDeque<Integer>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            ArrayDeque<Integer> deq = new ArrayDeque<>();
            for (int j = 0; j < m; j++) {
                deq.add(sc.nextInt());
            }
            list.add(deq);
        }
        boolean[] canceled = new boolean[m + 1];
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            int[] counts = new int[m + 1];
            for (ArrayDeque<Integer> deq : list) {
                while (canceled[deq.peek()]) {
                    deq.poll();
                }
                counts[deq.peek()]++;
            }
            int max = 0;
            int maxIdx = 0;
            for (int j = 1; j <= m; j++) {
                if (max < counts[j]) {
                    max = counts[j];
                    maxIdx = j;
                }
            }
            min = Math.min(min, max);
            canceled[maxIdx] = true;
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 60372
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>

int N;
int ans;
int main() {
	std::cin >> N;
	for (int i = 1; i < 100000; i++) {
		if (N >= i*i) {
			ans = i*i;
		}
		else {
			std::cout << ans << std::endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;
const long long INF = 1000000000000000000;

struct BIT{
    int n;
    vector<int> bit;

    BIT(int N){
        bit.resize(N+1);
        n = N;
    }
    void add(int a, int w){
        for(int x = a;x <= n; x += x&-x){
            bit[x] += w;
        }
    }
    int sum(int a){
        int ret = 0;
        for(int x = a; x > 0; x -= x&-x){
            ret += bit[x];
        }
        return ret;
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i] -= k;
    }
    vector<pair<long long, int>> accum(n+1);
    for(int i=1;i<n+1;i++){
        accum[i] = make_pair(accum[i-1].first + a[i-1], i);
    }

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

    vector<int> order(n+1);
    long long num = -INF;
    int noword = 0;
    for(int i=0;i<n+1;i++){
        int pos = accum[i].second;
        if(accum[i].first > num)
            noword++;
        num = accum[i].first;
        order[pos] = noword;
    }
    BIT bit(n+1);
    long long ans = 0;
    for(int i=0;i<n+1;i++){
        int num = bit.sum(order[i]);
        ans += num;
        bit.add(order[i], 1);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main(){
	int r,c,x[101][101],j,i,k,l,m,n,o,p,y,kazane,goukei,max,a[101];
	cin>>r>>c;
	goukei=0;
	max=0;
	y=0;
	kazane=0;
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			cin>>x[i][j];
		}
	}
	for(k=0;k<r;k++){
		goukei=0;
		for(l=0;l<c;l++){
			cout<<x[k][l];
			if(l<c-1){
				cout<<" ";
			}
			goukei=goukei+x[k][l];
		}
		a[y]=goukei;
		cout<<" "<<goukei<<endl;
		y=y+1;
	}
	for(m=0;m<c;m++){
		max=0;
		for(n=0;n<r;n++){
			max=max+x[n][m];
		}
		cout<<max<<" ";
	}
	for(o=0;o<y;o++){
		kazane=kazane+a[o];
	}
	cout<<kazane<<endl;
	return 0;
}

Measured memory_bytes: 3116
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int N,M;
vector<int> unko;
vector<int> unko2;
int a[200005];
int main(void) {
	
	cin >> N>>M;
	FOR(i, 0, M) {
		int c, b;
		cin >> c >> b; if (b == N)a[c]=1;
		if (c == 1)unko2.push_back(b);
	}
		for (auto it2 = unko2.begin(); it2 != unko2.end(); it2++) {
			if (a[*it2]==1) { ct("POSSIBLE"); system("pause"); return 0; }
		}
	
	ct("IMPOSSIBLE");
	
	return 0;
}

Measured memory_bytes: 1776
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  ll ans=0;
  int n; cin >> n;
  int a[n],b[n],c[n];
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) cin >> c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);

  REP(i,n) {
    ll A = lower_bound(a, a+n, b[i]) - a;
    ll C = n - (upper_bound(c, c+n, b[i]) - c);
    ans+=A*C;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 1408
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int N, K;
const int MAX_N = 2000 + 100;
VI tree[MAX_N];
int dist[MAX_N];
int dist1[MAX_N];
int dist2[MAX_N];
bool visit[MAX_N];
bool visit1[MAX_N];
bool visit2[MAX_N];

void dfs(int u, int d) {
    visit[u] = true;
    dist[u] = d;
    for (auto v : tree[u]) {
        if (!visit[v]) {
            dfs(v, d + 1);
        }
    }
}

void dfs2(int u, int d, bool flg) {
    if (flg) {
        visit1[u] = true;
        dist1[u] = d;
        for (auto v : tree[u]) {
            if (!visit1[v]) {
                dfs2(v, d + 1, flg);
            }
        }
    } else {
        visit2[u] = true;
        dist2[u] = d;
        for (auto v : tree[u]) {
            if (!visit2[v]) {
                dfs2(v, d + 1, flg);
            }
        }
    }
}

int count_over(int u, int k) {
    REP(i, MAX_N) {
        dist[i] = 0;
        visit[i] = false;
    }
    dfs(u, 0);
    int res = 0;
    FOR(i, 1, N + 1) {
        if (dist[i] > k) {
            res += 1;
        }
    }
    return res;
}

int count_over2(int u, int v, int k) {
    REP(i, MAX_N) {
        dist1[i] = 0;
        visit1[i] = false;
        dist2[i] = 0;
        visit2[i] = false;
    }
    dfs2(u, 0, true);
    dfs2(v, 0, false);
    //cout << u << " " << v << endl;
    REP(i, MAX_N) {
        dist[i] = min(dist1[i], dist2[i]);
    }
    /*
    FOR(i, 1, N + 1) {
        cout << dist[i] << " ";
    }
    cout << endl;
    */
    int res = 0;
    FOR(i, 1, N + 1) {
        if (dist[i] > k) {
            res += 1;
        }
    }
    return res;
}

void solve1() {
    int ans = INF;
    FOR(i, 1, N + 1) {
        ans = min(ans, count_over(i, K / 2));
    }
    cout << ans << endl;
}

void solve2() {
    int ans = INF;
    FOR(i, 1, N + 1) {
        for (auto v : tree[i]) {
            ans = min(ans, count_over2(i, v, (K - 1) / 2));
        }
    }
    cout << ans << endl;
}

int main(int argc, char const* argv[])
{
    cin >> N >> K;
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        tree[a].PB(b);
        tree[b].PB(a);
    }
    if (K % 2 == 0) {
        solve1();
    } else {
        solve2();
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
    int a,n;
    int sl[200010];

    for (int i=0; i<=200005; i++) sl[i] = 0;

    cin >> n;
    for (int i=1; i<n; i++){
        cin >> a;
        sl[a] += 1;
    }

    for (int i=1; i<=n; i++){
        cout << sl[i] << endl;
    }

    return 0;

}

Measured memory_bytes: 4404
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
    	int a = Integer.parseInt(sc.next());
    	int b = Integer.parseInt(sc.next());
    	int c = Integer.parseInt(sc.next());

    	System.out.println(a * b / 2);
	}
}


Measured memory_bytes: 22484
program abc160c
  integer :: k, n, a(200001), diff(200000)
  read *, k, n, a(1:n)
  diff(1:n) = a(2:n+1) - a(1:n)
  diff(n) = a(1) + k - a(n)
  print *, sum(diff(1:n)) - maxval(diff(1:n))
end program abc160c


Measured memory_bytes: 2304
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int calc(int x){
  int res = 0;
  while(x){
    res++;
    x /= 10;
  }
  return res;
}

int main(int argc, char const* argv[])
{
  ll n;
  cin >> n;
  int res = inf;
  for(int i = 1; (ll)i * i <= n; i++){
    if(n % i != 0)continue;
    res = min(res, max(calc(i), calc(n / i)));
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    int a[n][m];
    int b[m];

    int i, j;

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (j = 0; j < m; j++) {
        scanf("%d", &b[j]);
    }

    int c[n];

    for (i = 0; i < n; i++) {
        c[i] = 0;
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            c[i] += a[i][j] * b[j];
        }
    }

    for (i = 0; i < n; i++) {
        printf("%d\n", c[i]);
    }

    return 0;
}



Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
int h[100000];
int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> h[i];
	sort(h, h + N);
	ll ans = 1LL << 60;
	for (int i = 0; i + K <= N; i++) {
		ans = min(ans, (ll)h[i + K - 1] - h[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
N = int(input())
S = input()

R = S.count('R')
G = S.count('G')
B = S.count('B')

ans = R * G * B

for i in range(N):
    for j in range(i + 1, N):
        if S[i] != S[j]:
            k = 2 * j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1

print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int n,a[300];
int dp[301][301];

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>a[i];
    memset(dp,0,sizeof(dp));
    for(int k=2;k<=n;k++){
      for(int i=0;i+k<=n;i++){
        dp[i][i+k]=dp[i+1][i+k];
        for(int j=0;j<k-1;j++){
          if(abs(a[i]-a[i+1+j])<=1&&dp[i+1][i+1+j]==(i+1+j)-(i+1)){
            dp[i][i+k]=max(dp[i][i+k],dp[i+1][i+1+j]+dp[i+1+j+1][i+k]+2);
          }
        }
      }
    }
    cout<<dp[0][n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3388
#include<stdio.h>

int insertionSort(int A[], int n, int g) {
  int cnt = 0;
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while ( j >= 0 && v < A[j]) {
      A[j + g] = A[j];
      j -= g;
      cnt++;
    }
    A[j + g] = v;
  }

  return cnt;
}

void shellSort(int A[], int n) {
  int im, m = 1, v = 1, G[100], sum = 0;
  for ( im = 0; v <= n; im++ ) {
    G[im] = v;
    m *= 3;
    v += m;
  }

  printf("%d\n", im);
  for ( int i = im - 1; i >= 0; i-- ) {
    if ( i != (im - 1) ) printf(" ");
    printf("%d", G[i]);
    sum += insertionSort(A, n, G[i]);
  }

  printf("\n%d\n", sum);
  for ( int i = 0; i < n; i++ ) {
    printf("%d\n", A[i]);
  }
}

int main() {
  int n, A[1000000];
  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) scanf("%d", &A[i]);

  shellSort(A, n);

  return 0;
}



Measured memory_bytes: 6584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 
ll md=1e9+7;
ll f[200005],b[200005];
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n >> k;

	x=0;
	for(i=0;i<=n;i++)
		x+=i,f[i]=x;
	x=0;
	for(i=n;i>=0;i--)
		x+=i,b[i]=x;

	ll ans=0;
	for(i=k;i<=n+1;i++)
	{
		x=f[i-1],y=b[n+1-i];
		ans+=(y-x+1);
		ans%=md;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	ll cnt=0;
	sort(a,a+n);
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			for(ll k=n-1;k>j;k--)
			{
				if(a[k]<a[i]+a[j])
				{
					cnt=cnt+k-j;
					break;
				}
			}
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X;
    int answer = 0;
    rep(i,0,N) {
        vector<int> Xi;
        rep(j,0,D) {
            int Xij;
            cin >> Xij;
            Xi.push_back(Xij);
        }
        X.push_back(Xi);
    }
    rep(i,0,N-1) {
        rep(j,i+1,N) {
            int sum = 0;
            rep(k,0,D) {
                sum += (X.at(i).at(k) - X.at(j).at(k)) * (X.at(i).at(k) - X.at(j).at(k));
            }
            if (sum == (int)sqrt(sum) * (int)sqrt(sum)) {
                answer++;
            }
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<pair<string, int>> p(n);
	map<pair<string, int>, int> mp;
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
		mp[pair<string, int>(p[i].first, p[i].second)] = i + 1;
	}
	sort(all(p));
	priority_queue<P> que;
	string now = p[0].first;
	rep(i, n) {
		if (p[i].first == now) {
			que.emplace(p[i].second, mp[pair<string, int>(p[i].first, p[i].second)]);
			now = p[i].first;
		}
		else {
			while (que.size()) {
				cout << que.top().second << endl;
				que.pop();
			}
			que.emplace(p[i].second, mp[pair<string, int>(p[i].first, p[i].second)]);
			now = p[i].first;
		}
	}
	while (que.size()) {
		cout << que.top().second << endl;
		que.pop();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;

char s[N];
int num[100];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	long long ans = 1;
	for (int i = 0; i < n; i++){
		ans += i - num[s[i] - 'a'];
		num[s[i] - 'a']++;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> c(n);
	vector<vector<int>> G(n,vector<int>());
	rep(i,n - 1){
		int a,b;cin >> a >> b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	rep(i,n) cin >> c.at(i);
	sort(c.rbegin(),c.rend());
	vector<bool> visited(n);
	vector<int> ans(n);
	int sum = 0, k = 1;
	ans.at(0) = c.at(0);
	visited.at(0) = true;
	stack<int> st;
	st.push(0);
	while(!st.empty()){
		int cur = st.top();st.pop();
		rep(i,G.at(cur).size()){
			int next = G.at(cur).at(i);
			if(visited.at(next)) continue;
			st.push(next);
			ans.at(next) = c.at(k);
			sum += c.at(k);
			k++;
			visited.at(next) = true;
		}
	}
	cout << sum << endl;
	rep(i,n){
		if(i == n - 1) cout << ans.at(i) << endl;
		else cout << ans.at(i) << " ";
	}
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val dn = readLine()!!.split(" ").map(String::toInt).groupBy { it }.mapValues { it.value.size }

    val m = readLine()!!.toInt()
    val tn = readLine()!!.split(" ").map(String::toInt).groupBy { it }.mapValues { it.value.size }

    var flg = true
    for ((k, v) in tn) {
        flg = flg && dn.getOrElse(k, { 0 }) >= v
    }
    if (flg) {
        "YES"
    } else {
        "NO"
    }.let(::println)
}

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

int main() {
  int K,A,B,X;
  cin>>K;
  cin>>A>>B;

  if((A+K-1)/K*K<=B){
    cout<<"OK"<<endl;
  }
  else{
    cout<<"NG"<<endl;
  }
}


Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[] table = new bool[1000001];
        bool[] res = new bool[1000001];
        foreach (var item in a.OrderBy(x => x))
        {
            if (res[item]) res[item] = false;
            if (table[item]) continue;
            res[item] = true;
            for (int i = item; i < table.Length; i += item)
                table[i] = true;
        }
        Console.WriteLine(res.Count(x => x));
    }
}

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

#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>

const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int maxm = 3e5 + 10;
const double PI = acos(-1.0);

ll fac[maxn*2],inv[maxn*2],finv[maxn*2];
ll p100[maxn * 2];
int n, a, b, c;

ll fpow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b&1) ans = ans*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return ans;
}


void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<200005;i++)
	{
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		fac[i]=fac[i-1]*(ll) i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}

ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%mod)%mod;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> n >> a >> b >> c;
    make();
    ll ans = 0;
    ll pa = (ll)a*inv[a+b]%mod;
    ll pb = (ll)b*inv[a+b]%mod;
    ll powa = fpow(pa ,n);
    ll powb = fpow(pb ,n);
    for(int i = 0 ; i < n ; i++){
        ans += C(n + i - 1 , i) * fpow(pb, i) % mod * powa % mod * (ll)(n + i)% mod;
        ans %= mod;
        ans += C(n + i - 1 , i) * fpow(pa, i) % mod * powb % mod * (ll)(n + i)% mod;
        ans %= mod;
    }
    ans = ans * inv[a + b] % mod * 100ll % mod;
    cout << ans << endl;
}



Measured memory_bytes: 4992