akhauriyash/Code-Regression huggingface dataset:
import numpy as np  # NumPyモジュールをインポートする
import itertools

val = input()
val = val.split(" ")
val = [int(i) for i in val]  # 全部intに変換

I = np.zeros((val[0], val[1]+1))

for i in range(val[0]):
    val2 = input()
    val2 = val2.split(" ")
    val2 = [int(i) for i in val2]  # 全部intに変換
    I[i] = val2

seq = [i for i in range(val[0])]  # 組み合わせを考える
# print(seq)

ans = []

for i in range(val[0]):
    Comb = list(itertools.combinations(seq, i+1))
    # print(Comb)
    for j in Comb:
        Com_list = list(j)
        # print(Com_list)
        I_sum = [[I[k][l+1] for k in Com_list] for l in range(val[1])]
        # print(I_sum)
        I_sum_over_x = [sum(m) for m in I_sum if sum(m) >= val[2]]
        # print('I_sum_over_x=', I_sum_over_x)
        if(len(I_sum_over_x) == val[1]):
            # print("xxx=", j)
            I_sum2 = [I[n][0] for n in list(j)]
            # print(I_sum2)
            # print(sum(I_sum2))
            ans.append(sum(I_sum2))

# print(ans)
if(len(ans) == 0):
    print('-1')
else:
    print(int(min(ans)))

Measured memory_bytes: 27360
#define _USE_MATH_DEFINES 

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    int D,N;
    cin >> D >> N;
    int x=0;

    if(D==0){
        x = 1;
    }
    else{
        x = pow(100,D);
    }

    if(N!=100){
        cout << x*N << endl;
    }
    else{
        cout << x*(N+1) << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 998244353;

ll n,s;
v1 a;
v2 dp; // dp[s][n]
ll ans = 0;

int main(){
    cin >> n >> s;
    a = v1(n+1);
    for(ll i = 1;i <= n;i++){
        cin >> a[i];
    }
    dp = v2(s+1, v1(n+1, 0));
    for(ll i = 1;i <= n;i++){
        if(a[i] <= s){
            dp[a[i]][i] += i;
            dp[a[i]][i] %= mod;
        }
        for(ll j = 0;j < a[i] && j <= s;j++){
            dp[j][i] += dp[j][i-1];
            dp[j][i] %= mod;
        }
        for(ll j = a[i];j <= s;j++){
            dp[j][i] += dp[j-a[i]][i-1] + dp[j][i-1];
            dp[j][i] %= mod;
        }
    }
    for(ll i = 1;i <= n;i++){
        ans += dp[s][i];
        // cerr << dp[s][i] << endl;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 73728
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int A, B, count;
  cin >> A >> B;
  string check;
  count = 0;
  for(int i=A; i <= B; ++i){
    check = to_string(i);
    if(check[0] == check[4] && check[1] == check[3]){
      count++;
    }
  }
  cout << count << endl;

  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i).first;
    A.at(i).second = i + 1;
  }

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

  for (auto a : A) {
    cout << a.second << "\n";
  }
}

Measured memory_bytes: 1664
var black = 0L
var white = 0L
val map = mutableListOf<MutableList<Char>>()

fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map(String::toInt)
    map.add(Array(w + 2) { 'X' }.toMutableList())
    (1..h).forEach {
        val element = readLine()!!.toCharArray().toMutableList()
        element.add(0, 'X')
        element.add(element.size, 'X')
        map.add(element)
    }
    map.add(Array(w + 2) { 'X' }.toMutableList())

    var ans = 0L
    for (r in 1..h) {
        for (c in 1..w) {
            black = 0L
            white = 0L
            check(r, c)
            ans += black * white
        }
    }
    println(ans)
}

fun check(r: Int, c: Int) {
    val current = map[r][c]
    when (current) {
        'X' -> return
        '#' -> {
            black++
            map[r][c] = 'X'
        }
        '.' -> {
            white++
            map[r][c] = 'X'
        }
    }
    if (map[r - 1][c] != current) check(r - 1, c)
    if (map[r][c - 1] != current) check(r, c - 1)
    if (map[r + 1][c] != current) check(r + 1, c)
    if (map[r][c + 1] != current) check(r, c + 1)
}

Measured memory_bytes: 52628
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    A.sort()

    ret = 1
    for a in A:
        if 10**18 < ret*a:
            ret = -1
            break
        else:
            ret *= a

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(auto &i : a) {
        cin >> i;
        i %= k;
    }
    vector<ll> sum(n + 1, 0);
    for(int i = 0; i < n; i++) {
        sum[i + 1] = (sum[i] + a[i]) % k;
    }
    map<ll, vector<ll>> cnt;
    for(int i = 0; i <= n; i++) {
        ll diff = ((i - sum[i]) % k + k) % k;
        cnt[diff].push_back(i);
    }
    ll ans = 0;
    for(auto p : cnt) {
        auto v = p.second;
        ll tmp = (ll)v.size() * ((ll)v.size() - 1) / 2;
        for(auto i : v) {
            auto it = lower_bound(ALL(v), i + k);
            tmp -= v.end() - it;
        }
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 25216
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int w, d;
  while(cin>>w>>d,w||d) {
    int h[21]; CLR(h);
    int ans = 0;
    FOR(i,0,w){
      int in;
      cin >> in;
      h[in]++;
      ans+=in;
    }
    FOR(i,0,d){
      int in;
      cin >> in;
      h[in]--;
      if(h[in] < 0) ans+=in; 
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,a[100005];
  
  cin >> n;
  for (i=0;i<n;i++) cin >> a[i];
  
  sort(a,a+n,greater<int>());
  
  if (n%2==0){
    
    ll ans=0;
    for (i=0;i<n/2-1;i++) ans+=a[i]*2;
    ans+=a[n/2-1]-a[n/2];
    for (i=n/2+1;i<n;i++) ans-=a[i]*2;
    
    cout << ans << endl;
    
  }else{
    
    ll ans1=0,ans2=0;
    for (i=0;i<(n-3)/2;i++) ans1+=a[i]*2;
    ans1+=a[(n-3)/2]+a[(n-1)/2];
    for (i=(n+1)/2;i<n;i++) ans1-=a[i]*2;
    
    for (i=0;i<(n-1)/2;i++) ans2+=a[i]*2;
    ans2-=a[(n-1)/2]+a[(n+1)/2];
    for (i=(n+3)/2;i<n;i++) ans2-=a[i]*2;
    
    cout << max(ans1,ans2) << endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353
int main()
{
	int n; cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	int dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	
	
	
	
	
	
	
	
}

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

using namespace std;

struct Frame {
    int one, two, third, score;
    bool strike, spare;
    Frame() { score = 0; strike = spare = false; one = two = third = 0; }
};

struct Player {
    int id, score;
    Player() {}
};

bool operator < (const Player &a, const Player &b)
{
    return (a.score == b.score) ? (a.id < b.id) : (a.score > b.score);
}

int Caluculate(string s)
{
    int data[22];
    int n = 0, index = 1;

    // parse number
    while (index < s.size()) {
        int num = 0;
        while (true) {
            if ('0' <= s[index] && s[index] <= '9') {
                num *= 10;
                num += (int)(s[index++] - '0');
            }
            else
                break;
        }
        index++;
        data[n++] = num;
    }

    // スコア
    Frame frame[10];
    double game = 1.0;
    for (int i = 0; i < n; ++i) {
        if (game >= 10.0) { // 10ゲーム目
            frame[9].score += data[i];
            if (game == 10.0)
                frame[9].one = data[i];
            else if (game == 10.5)
                frame[9].two = data[i];
            else if (game == 11.0)
                frame[9].third = data[i];
            game += 0.5;
        }
        else if (game - (int)game != 0.0) {  // 後半
            if (frame[(int)game - 1].one + data[i] == 10) // スペア
                frame[(int)game - 1].spare = true;
            frame[(int)game - 1].two = data[i];
            game += 0.5;
        }
        else { // 前半
            if (data[i] == 10) { // ストライク
                frame[(int)game - 1].one = 10;
                frame[(int)game - 1].strike = true;
                game += 1.0;
            }
            else {
                frame[(int)game - 1].one = data[i];
                game += 0.5;
            }
        }
    }

    // 各フレーム(1-9)でのスコア計算
    for (int i = 0; i < 9; ++i) {
        if (frame[i].spare) // スペア
            frame[i].score = 10 + frame[i + 1].one;
        else if (frame[i].strike) { // ストライク
            frame[i].score = 10;
            if (i == 8) // 第9ホール
                frame[i].score += frame[i + 1].one + frame[i + 1].two;
            else if (frame[i + 1].strike)
                frame[i].score += 10 + frame[i + 2].one;
            else
                frame[i].score += frame[i + 1].one + frame[i + 1].two;
        }
        else
            frame[i].score = frame[i].one + frame[i].two;
    }

    // ゲームのスコア計算
    int res = 0;
    for (int i = 0; i < 10; ++i)
        res += frame[i].score;

    return res;
}

int main()
{
    int m;

    while (cin >> m, m) {
        vector<Player> player(m);

        // Input
        for (int i = 0; i < m; ++i) {
            string data;
            cin >> player[i].id;
            getline(cin, data);

            player[i].score = Caluculate(data);
        }

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

        // Output
        for (int i = 0; i < m; ++i)
            cout << player[i].id << " " << player[i].score << endl;
    }

    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    const ll MOD = 1e9 + 7;
    auto Add = [&](ll& x, ll y) { x = ( x % MOD + y % MOD ) % MOD; };
    auto Mul = [&](ll& x, ll y) { x = ( x % MOD * y % MOD ) % MOD; };
    auto Pow = [&](ll x, ll n) -> ll {
        ll t = x % MOD, r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) Mul(r, t);
            Mul(t, t);
            n >>= 1;
        }
        return r;
    };
    auto Inv = [&](ll a) -> ll {
        return Pow(a, MOD - 2);
    };
    vector<ll> f(N+1, 0); // f[i] = C(N-i,K-1)
    ll dn = 1, nu = 1;
    for ( ll i = 0; i < K-1; i++ ) {
        Mul(nu, N-i);
        Mul(dn, i+1);
    }
    Mul(nu, Inv(dn));
    f[0] = nu;
    for ( ll i = 1; i <= N; i++ ) {
        ll x = f[i-1];
        Mul(x, N-i+2-K);
        Mul(x, Inv(N-i+1));
        if ( x == 0 ) break;
        f[i] = x;
    }
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( N-1-i >= 0 ) {
            ll x = (MOD + A[N-1-i]) % MOD;
            Mul(x, f[i+1]);
            Add(ans, x);
            ll y = (MOD + A[i]) % MOD;
            Mul(y, f[i+1]);
            Add(ans, MOD - y);
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

struct Suffix_Array {
  string str;
  int strlen, nowlen;
  vector<long long> rank, tmp, sa, lcp;
  Suffix_Array(string news = "", bool reqlcp = 0) {
    str = news;
    strlen = str.size();
    nowlen = 0;
    rank.resize(strlen + 1);
    tmp.resize(strlen + 1);
    sa.resize(strlen + 1);
    constuct_sa();
    if(reqlcp) constuct_lcp();
  }

  void constuct_sa() {
    auto cmp = [&](int l, int r) {
      if(rank[l] != rank[r]) return rank[l] < rank[r];
      int rx = l + nowlen <= strlen ? rank[l + nowlen] : -1;
      int ly = r + nowlen <= strlen ? rank[r + nowlen] : -1;
      return rx < ly;
    };

    for(int i = 0; i <= strlen; ++i) {
      sa[i] = i;
      rank[i] = i < strlen ? str[i] : -1;
    }
    for(nowlen = 1; nowlen <= strlen; nowlen *= 2) {
      sort(sa.begin(), sa.end(), cmp);
      tmp[sa[0]] = 0;
      for(int i = 1; i <= strlen; ++i)
        tmp[sa[i]] = tmp[sa[i - 1]] +
                     (cmp(sa[i - 1], sa[i]) ? 1 : 0);
      for(int i = 0; i <= strlen; ++i) rank[i] = tmp[i];
    }
  }
  // Longest Common Prefix Array
  void constuct_lcp() {
    lcp.resize(strlen + 1);
    for(int i = 0; i <= strlen; ++i) rank[sa[i]] = i;
    int h = 0;
    lcp[0] = 0;
    for(int i = 0; i < strlen; ++i) {
      int j = sa[rank[i] - 1];
      if(h > 0) --h;
      for(; j + h < strlen && i + h < strlen; ++h)
        if(str[j + h] != str[i + h]) break;
      lcp[rank[i] - 1] = h;
    }
  }

  bool contain(string &nowt) {
    int lef = 0, righ = strlen, tsize = nowt.size();
    while(righ - lef > 1) {
      int mid = (lef + righ) / 2;
      if(str.compare(sa[mid], tsize, nowt) < 0)
        lef = mid;
      else
        righ = mid;
    }
    return str.compare(sa[righ], tsize, nowt) == 0;
  }
};

string s, t, st;
long long k;
Suffix_Array suf;
vector<long long> dp, memo;

bool solve();

int main() {
  cin >> s >> t >> k;
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  long long ssize = s.size(), stsize;
  st = s + "#" + t;
  stsize = st.size();
  suf = Suffix_Array(st, 1);
  memo.assign(s.size(), 0);
  long long now = 0;
  for(int i = 0; i <= stsize; ++i) {
    if(suf.sa[i] < ssize) {
      memo[suf.sa[i]] = max(memo[suf.sa[i]], now);
      now = min(now, suf.lcp[i]);
    }
    else
      now = suf.lcp[i];
  }
  now = 0;
  for(int i = stsize; i >= 1; --i) {
    if(suf.sa[i] < ssize) {
      memo[suf.sa[i]] = max(memo[suf.sa[i]], now);
      now = min(now, suf.lcp[i - 1]);
    }
    else
      now = suf.lcp[i - 1];
  }
  dp.assign(s.size() + 2, 0);
  dp[0] = 1;
  dp[1] = -1;
  for(int i = 0; i <= ssize; ++i) {
    if(i != 0) dp[i] += dp[i - 1];
    if(i == ssize || memo[i] < k || dp[i] == 0) continue;
    ++dp[i + k];
    --dp[min(i + memo[i] + 1, ssize + 1)];
  }
  return dp[ssize] > 0;
}


Measured memory_bytes: 19432
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int main(void) {

    int n;
    cin >> n;

    for (int i = 1; i <= n; ++i) {
        int x = i;
        if (x % 3 == 0) {
            printf(" %d", i);
            continue;
        }
        while (x) {
            if (x % 10 == 3) {
                printf(" %d", i);
                break;
            }
            x /= 10;
        }
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  int odd_count = 0;
  rep(i, N)
  {
    int A;
    cin >> A;
    if (A % 2 == 1)
      odd_count++;
  }
  if (odd_count % 2 == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}

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

public class P
{
	public int id { get; set; }
	public string name { get; set; }
	public int point { get; set; }
}

public class Hello
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine().Trim());
		var ps = new P[n];
		for (int i = 0; i < n; i++)
		{
			string[] line = Console.ReadLine().Trim().Split(' ');
			ps[i] = new P { id = i + 1, name = line[0], point = int.Parse(line[1]) };
		}
		foreach (var x in ps.OrderBy(y =>y.name).ThenByDescending(y =>y.point))
			Console.WriteLine(x.id);
	}
}

Measured memory_bytes: 13652
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1e9;
const int EPS = 1e-9; 

int main() {
  long long int N;
  cin >> N;
  long long int ans = 1e13;
  for (long long i = 1; i * i <= N; ++i) {
    if (N % i == 0) ans = min(ans, (N / i - 1) + (i-1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in(), x = in();
	cout << (a <= x && x <= a + b ? "YES" : "NO") << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    int ans=(1<<30);
    for(int i=k-1;i<n;i++)
    {
        int st=v[i-k+1];
        int dr=v[i];
        if(st>0)
            st=0;
        if(dr<0)
            dr=0;
        int dd=dr-st+min(abs(st),abs(dr));
        ans=min(ans,dd);
    }
    cout<<ans<<"\n";
    return 0;
}
/**

**/


Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
  int q,lim,query,x;

  while(1){
    deque<int> l;
    scanf("%d %d",&q,&lim);
    if(!q && !lim)break;
    for(int i=0;i<q;i++){
      scanf("%d %d",&query,&x);

      if(query==0){
	l.push_back(x);
	if((int)l.size()>lim)l.pop_front();
      }
      if(query==1)l.erase(l.begin()+x-1);
      if(query==2)printf("%d\n",*(l.begin()+x-1));
      if(query==3)l.erase(find(l.begin(),l.end(),x));
    }
    printf("end\n");
  }
}

Measured memory_bytes: 1096
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int main()
{
	int a,L;
	while(cin>>a>>L,L) 
	{
		int tmp[25];
		tmp[0]=a;

		for(int i = 1; i < 21; ++i)
		{
			int cnt[10],cnt2[10];
			memset(cnt,0,sizeof(cnt));
			memset(cnt2,0,sizeof(cnt2));
			for(int j = 0; j < L; ++j)
			{
				cnt[a%10]++;
				cnt2[a%10]++;
				a/=10;
			}
			int b=0,c=0;
			int pos=0;
			while(pos<10) 
			{
				if(cnt[pos]!=0)
				{
					c*=10;
					c+=pos;
					cnt[pos]--;
				}
				else pos++;
			}

			pos=9;
			while(pos>-1) 
			{
				if(cnt2[pos]!=0)
				{
					b*=10;
					b+=pos;
					cnt2[pos]--;
				}
				else pos--;
			}
			a=b-c;
			tmp[i]=a;
		}
		int ans=0;
		bool f=false;
		for(int i = 0; i < 21; ++i)
		{
			for(int j = i+1; j < 21; ++j)
			{
				if(tmp[i]==tmp[j])
				{
					ans=j-i;
					cout<<i<<" ";
					cout<<tmp[i]<<" ";
					f=true;
					break;
				}
			}
			if(f) break;
		}
		cout<<ans<<endl;
	}
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N + 1), B(N + 1), C(N + 1), D(N + 1);
    for (int i = 0; i < N + 1; i++) {
        cin >> A.at(i);
        D.at(0) += A.at(i);
    }
    for (int i = 0; i < N; i++) {
        D.at(i + 1) = D.at(i) - A.at(i);
    }
    if (A.at(0) != 0) {
        if (A.at(0) != 1 || D.at(0) != 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    B.at(0) = 1;
    C.at(0) = 1;
    bool can = true;
    for (int i = 0; i < N; i++) {
        if (C.at(i) * 2 < A.at(i + 1)) {
            can = false;
        }
        if (C.at(i) * 2 <= D.at(i + 1)) {
            B.at(i + 1) = C.at(i) * 2;
            C.at(i + 1) = C.at(i) * 2 - A.at(i + 1);
        }
        else {
            B.at(i + 1) = D.at(i + 1);
            C.at(i + 1) = D.at(i + 1);
        }
    }
    if (!can) {
        cout << -1 << endl;
    }
    else {
        long long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += B.at(i);
        }
        cout << ans + A.at(N) << endl;
    }
}

Measured memory_bytes: 6436
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Watch
{
    class Program
    {
        static void Main(string[] args)
        {
            int second = int.Parse(Console.ReadLine());

            Console.WriteLine(second / 3600 + ":" + (second % 3600) / 60 + ":" + (second % 3600) % 60);
        }
    }
}



Measured memory_bytes: 17920
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int cnt[25];
int main(){
	int n; cin >> n;
	for(int i=1;i<=n;i++){
		int cp=i;
		for(int i=0;i<25;i++){
			while(cp%prime[i]==0){
				cnt[i]++;
				cp/=prime[i];
			}
		}
	}
	int ans=0;
	for(int i=0;i<25;i++){
		if(cnt[i]>=74)ans++;
	}
	for(int i=0;i<25;i++){
		for(int j=0;j<25;j++){
			if(i==j)continue;
			if(cnt[i]>=4&&cnt[j]>=14)ans++;
			if(cnt[i]>=2&&cnt[j]>=24)ans++;
		}
	}
	for(int i=0;i<25;i++){
		for(int j=0;j<25;j++){
			for(int k=j+1;k<25;k++){
				if(i==j||i==k)continue;
				if(cnt[i]>=2&&cnt[j]>=4&&cnt[k]>=4)ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  string s;
  cin >> s;

  if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int M[105][105] = { 0 };
int C[105][105] = { 0 };

int main()
{
	int h, w;
	cin >> h >> w;
	for (int i = 0; i <= 104; i++) {
		for (int j = 0; j <= 104; j++) {
			C[i][j] = 10000000;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			char k;
			cin >> k;
			if (k == '#')M[i][j] = 1;
			else  M[i][j] = 0;
		}
	}
	C[1][0] = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (M[i][j] == 1) {
				if(M[i-1][j]==1&&M[i][j-1]==1)C[i][j] = min(C[i - 1][j], C[i][j - 1]);
				else if(M[i - 1][j] == 0 && M[i][j - 1] == 0)C[i][j] = min(C[i - 1][j], C[i][j - 1])+1;
				else if (M[i - 1][j] == 1 && M[i][j - 1] == 0)C[i][j] = min(C[i - 1][j], C[i][j - 1]+1);
				else if (M[i - 1][j] == 0 && M[i][j - 1] == 1)C[i][j] = min(C[i - 1][j]+1, C[i][j - 1] );
			}
			else if (M[i][j] == 0) {
				C[i][j] = min(C[i - 1][j], C[i][j - 1]);
			}
		}

	}
	cout << C[h][w] << endl;

}

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

int main() {
    int a;
    char s[11];

    scanf("%d", &a);
    scanf("%s", &s[0]);
    if (a >= 3200) {
        printf("%s\n", s);
    } else {
        printf("red\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define M 1046527
#define L 14

char H[M][L];
int getChar(char ch){
    if ( ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
}

long long getKey(char str[]){
    long long sum = 0;
    long long p = 1;
    for (long long i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    return key % M;
}

int h2(int key){
    return 1 + (key % (M - 1));
}

int find(char str[]){
    long long key,h,i;
    key = getKey(str);
    for(i = 0;;i ++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(str,H[h]) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    
    return 0;
}

int insert(char str[]){
    long long key,h,i;
    key = getKey(str);
    for(i = 0;;i ++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(str,H[h]) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}
int main(){
    int n;
    char ch[L],order[7];
    for (int i = 0; i < M; i++){
        H[i][0] = '\0';
    }
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%s %s",order,ch);
        if(order[0] == 'i'){
            insert(ch);
        }
        else{
            if(find(ch)){
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }
    return 0;
}


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

int gcd(int x, int y)
{
	int r = x % y;
	if(r == 0)
		return y;
	gcd(y, r);
}

int main()
{
	int x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    double p = -1;
    int64_t m_w = 0, m_s = 0;
    for (int64_t water0 = 0; water0 <= f; water0 += 100 * a) {
        for (int64_t water = water0; water <= f; water += 100 * b) {
            if (water == 0) {
                continue;
            }

            auto max_sugar = min(f - water, water / 100 * e);

            int64_t m = 0;
            for (int i = 0; i * c <= max_sugar; ++i) {
                auto sugar = i * c;
                sugar += (max_sugar - sugar) / d * d;
                m = max(m, sugar);
            }

            if ((double)(m) / (m + water) > p) {
                p = (double)(m) / (m + water);
                m_s = m;
                m_w = water;
            }
        }
    }

    cout << m_s + m_w << " " << m_s << endl;
}


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

int main(void){
	int an[9];
  	int ans[9]={0};
  	bool answer = false;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
        	cin >> an[3*i+j];
        }
	}
  	int n;
  	cin >> n;
  	for(int i=0;i<n;i++){
    	int a;
      	cin >> a;
      	for(int j=0;j<9;j++){
       		if(an[j]==a) ans[j]=1;
        }
    }
  	for(int i=0;i<3;i++){
        	if(ans[3*i]==1 && ans[3*i+1]==1 && ans[3*i+2]==1 )answer = true;        
	}
  	for(int i=0;i<3;i++){
        	if(ans[i]==1 && ans[i+3]==1 && ans[i+6]==1 )answer = true;        
	}
  	if((ans[0]==1 && ans[4]==1 && ans[8]==1)||
       (ans[2]==1 && ans[4]==1 && ans[6]==1)){ answer = true;}
  
  	if(answer){
    	cout << "Yes"<<endl;
    }else{
    	cout << "No"<< endl;
    }
	return 0;
}



Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    S.append(input())

ac = str(S.count("AC"))
wa = str(S.count("WA"))
tle = str(S.count("TLE"))
re = str(S.count("RE"))

print("AC x "+ac)
print("WA x "+wa)
print("TLE x "+tle)
print("RE x "+ re)

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//----------------------library------------------------//

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

const int NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    CIN(N,M,X);
    vi A(M);
    rep(i,M)cin>>A[i];
    int toN=0,to0=0;
    rep(i,M){
        if(X<A[i]&&A[i]<N)toN++;
    }
    rep(i,M){
        if(0<A[i]&&A[i]<X)to0++;
    }
    printf("%d\n",min(toN,to0));

    return 0;
}


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

int main() {
  int n,l;
  cin >> n >> l;
  vector<int> a(n);
  int minindex = 0;
  rep(i,n){
    a[i] = l+i;
    if (abs(a[minindex]) > abs(a[i])) minindex = i;
  }
  
  int ans = 0;
  rep(i,n){
    ans += a[i];
  }
  ans -= a[minindex];
  cout << ans << endl;
  
  return 0;
}


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

using namespace std;

int a,b;

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

	cin >> a >> b;
	if (a >= 10 || b >= 10)
		cout << -1;
	else
		cout << a*b;	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string a;
    getline(cin,a);
    for (int i=0;i<a.size()-1;i++)
    {
    	if (a[i]=='A' && a[i+1]=='C')
    	{
    		cout<<"Yes"<<endl;
    		return 0;
		}
	}
	cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <climits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
 
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main()
{
	int n, W;
	cin >> n >> W;
	vector<int> w(n), v(n);
	rep(i, n) cin >> w[i] >> v[i];

	//chmaxで更新するので0で初期化
	//品物0個の状態から始めるので(n+1)行必要, 重さ0からWまでなので(W+1)列必要
	vector<vector<long long int>> dp(n+1,vector<long long int>(W+1,0)); 

	rep(i,n){
		for(int sumw = 0; sumw <= W; sumw++){
			//i番目の品物を選ぶ
			if(sumw-w[i] >= 0)
				chmax(dp[i+1][sumw], dp[i][sumw-w[i]]+v[i]);
			//i番目の品物を選ばない
			chmax(dp[i+1][sumw], dp[i][sumw]);

			//cout << dp[i+1][sumw] << " ";
		}
		//cout << endl;
	}


	cout << dp[n][W] << endl;
	
}


Measured memory_bytes: 80256
#include <cassert>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <limits>
#include <queue>
#include <vector>
#include <tuple>
using namespace std;

struct edge {
	int to, cost, enemy;
	edge(int to_, int cost_, int enemy_):to(to_), cost(cost_), enemy(enemy_) {}
};

typedef vector<vector<edge>> graph;

int dijkstra(const graph &G, int l) {
	typedef tuple<int, int, int> state; // dist, v, money
	const int n = G.size();
	
	vector<vector<int>> dist(n, vector<int>(l + 1, numeric_limits<int>::max()));
	priority_queue<state, vector<state>, greater<state>> que;

	dist[0][l] = 0;
	que.push(state(0, 0, l));
	
	while(!que.empty()) {
		int d, v, money;
		tie(d, v, money) = que.top();
		que.pop();

		if(dist[v][money] < d) continue;
		if(v == n - 1) return d;
		
		for(const auto &e : G[v]) {
			{ // don't employ
				const int next_dist = d + e.enemy;
				if(dist[e.to][money] > next_dist) {
					dist[e.to][money] = next_dist;
					que.push(state(next_dist, e.to, money));
				}
			}
			
			
			if(e.cost <= money) { // employ
				const int next_money = money - e.cost;
				if(dist[e.to][next_money] > d) {
					dist[e.to][next_money] = d;
					que.push(state(d, e.to, next_money));
				}
			}
		}
	}
	
	assert(false);
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	for(int n, m, l; cin >> n >> m >> l && n;) {
		graph G(n);
		for(int i = 0; i < m; ++i) {
			int a, b, d, e;
			cin >> a >> b >> d >> e;
			--a; --b;
			G[a].emplace_back(b, d, e);
			G[b].emplace_back(a, d, e);
		}
		
		cout << dijkstra(G, l) << endl;
	}
	
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1468
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
ll a[3][3], b[3], it[3];

int main() {
  int n; scanf("%d", &n);
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 3; j++)
      scanf("%lld", &a[i][j]);
  ll ans = n;
  int c = 0;
  for (int i = 0; i < 3; i++)
    c += a[0][i] < a[1][i];
  for (int i = 0; i < 3; i++)
    it[i] = i;
  sort(it, it+3, [](int x, int y) { return a[1][x]-a[0][x] > a[1][y]-a[0][y]; });
  if (c == 3 || c == 0) {
    for (int i = 0; i < 3; i++) {
      b[i] = abs(a[0][i] - a[1][i]);
      a[0][i] = max(a[0][i], a[1][i]);
      a[1][i] = a[0][i] - b[i];
    }
    for (int i = 0; i <= n; i += a[1][0])
      for (int j = 0; j+i <= n; j += a[1][1])
        ans = max(ans, i/a[1][0] * a[0][0] + j/a[1][1] * a[0][1] + ((n-i-j)/a[1][2]) * a[0][2] + ((n-i-j) % a[1][2]));
  } else if (c == 2) {
    for (int i = 0; i <= n; i += a[0][it[0]])
      for (int j = 0; j+i <= n; j += a[0][it[1]]) {
        ll nx = i/a[0][it[0]] * a[1][it[0]] + j/a[0][it[1]] * a[1][it[1]] + (n-i-j);
        ans = max(ans, (nx/a[1][it[2]]) * a[0][it[2]] + (nx % a[1][it[2]]));
      }
  } else {
    ll nx = n/a[0][it[0]] * a[1][it[0]] + (n % a[0][it[0]]);
    if (a[0][it[1]] * a[1][it[2]] > a[0][it[2]] * a[1][it[1]])
      swap(it[1], it[2]);
    for (int j = 0; j <= nx; j += a[1][it[1]])
      ans = max(ans, j/a[1][it[1]]*a[0][it[1]] + ((nx-j)/a[1][it[2]]) * a[0][it[2]] + ((nx-j) % a[1][it[2]]));
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> a >> b >> c;
	cout << (a + b + c) - max({ a,b,c }) << endl;
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
s=[sorted(list(map(int,input().split()))) for i in range(m)]
a=[]
for i in range(m):
    a.append(s[i][0])
    a.append(s[i][1])
sum=0
for i in range(1,n+1):
    for j in range(2*m):
        if i==a[j]:
            sum+=1
    print(sum)
    sum=0

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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;}

struct Pos{
    int x,y;
    Pos(int x,int y):x(x),y(y){}
};

int H,W;
int Ch,Cw;
int Dh,Dw;
string field[1005];
int d[1000005];
int s[1005][1005];
bool visited1[1005][1005];
bool visited2[10000005];
int id;
set<int> E[1000005];


void init(){
    id=0;
    for(int i=0;i<1000003;++i){
        d[i]=INF;
        visited2[i]=false;
    }
    for(int i=0;i<1003;++i){
        for(int j=0;j<1003;++j){
            s[i][j]=-1;
            visited1[i][j]=false;
        }
    }
}

void bfs1(int sx,int sy){
    queue<Pos> que;
    que.push(Pos(sx,sy));
    s[sy][sx]=id;
    while(que.size()){
        Pos p=que.front();
        que.pop();
        visited1[p.y][p.x]=true;
        for(int i=0;i<4;++i){
            int nx=p.x+dx[i],ny=p.y+dy[i];
            if(nx<0||nx>=W||ny<0||ny>=H)continue;
            if(visited1[ny][nx])continue;
            if(s[ny][nx]!=-1)continue;
            if(field[ny][nx]=='#')continue;
            que.push(Pos(nx,ny));
            s[ny][nx]=id;
        }
    }
    id++;
}

void bfs2(int s){
    queue<int> que;
    que.push(s);
    d[s]=0;
    while(que.size()){
        int p=que.front();
        que.pop();
        visited2[p]=true;
        //cout << "p: " << p << endl; 
        for(auto u:E[p]){
            //cout << "u: " << u << endl;
            if(d[u]<=d[p]+1)continue;
            if(visited2[u])continue;
            que.push(u);
            d[u]=d[p]+1;
        }
    }
}

signed main(){
    init();
    cin>>H>>W;
    cin>>Ch>>Cw;
    cin>>Dh>>Dw;
    Ch--,Cw--;
    Dh--,Dw--;
    for(int i=0;i<H;++i)cin>>field[i];
    for(int y=0;y<H;++y){
        for(int x=0;x<W;++x){
            if(field[y][x]=='#')continue;
            if(s[y][x]!=-1)continue;
            bfs1(x,y);
        }
    }
    for(int y=0;y<H;++y){
        for(int x=0;x<W;++x){
            if(field[y][x]=='#')continue;
            for(int i=-2;i<=2;++i){
                for(int j=-2;j<=2;++j){
                    int nx=x+i,ny=y+j;
                    if(nx<0||nx>=W||ny<0||ny>=H)continue;
                    if(s[ny][nx]==s[y][x])continue;
                    if(field[ny][nx]=='#')continue;
                    E[s[y][x]].insert(s[ny][nx]);
                    E[s[ny][nx]].insert(s[y][x]);
                }
            }
        }
    }
    bfs2(s[Ch][Cw]);
    if(d[s[Dh][Dw]]==INF)cout<<-1<<endl;
    else cout<<d[s[Dh][Dw]]<<endl;
}

Measured memory_bytes: 88612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int n;
  cin>>n;
  vector<int> d(n);
  rep(i,n)cin>>d[i];
  sort(d.begin(),d.end());
  int sum =0;
  rep(i,n){
    if(d[i]!=d[i+1]){
      sum++;
    }
  }
  cout<<sum<<endl;
      
  
 

}


Measured memory_bytes: 256
N, M = map(int, input().split())
P = tuple(map(int, input().split()))
A = []
for _ in range(M):
    i, k = map(int, input().split())
    A.append((i-1, k-1))
class Union():
    def __init__(self, n):
        self.para = [-1] * n
    
    def find(self, n):
        if self.para[n] < 0:
            return n
        
        else:
            self.para[n] = self.find(self.para[n])
            return self.para[n]
    
    def union(self, n, m):
        n = self.find(n)
        m = self.find(m)
        if n == m:
            return False
        else:
            if self.para[n] > self.para[m]:
                n, m = m, n
            
            self.para[n] += self.para[m]
            self.para[m] = n
    
    def same(self, n, m):
        return self.find(n) == self.find(m)
ut = Union(N)
for i,k in A:
    ut.union(i, k)
for i in range(N):
    ut.find(i)

cnt = 0
for i in range(N):
    if P[i] == i + 1:
        cnt += 1
    else:
        if ut.same(P[i]-1, i):
            cnt += 1
print(cnt)

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
vector<string> s;
ll h, w;

bool dfs(int ci = 0, int cj = 0) {
  s[ci][cj] = 'o';
  if(ci == h - 1 && cj == w - 1)
    return true;
  int ni = ci;
  int nj = cj + 1;
  if(ni >= 0 && ni < h && nj >= 0 && nj < w && s[ni][nj] == '#') {
    return dfs(ni, nj);
  } else {
    ni = ci + 1;
    nj = cj;
    if(ni >= 0 && ni < h && nj >= 0 && nj < w && s[ni][nj] == '#') {
      return dfs(ni, nj);
    } else {
      return false;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  s.resize(h);
  rep(i, h) { cin >> s[i]; }
  bool flag1 = dfs();
  rep(i, h) rep(j, w) {
    if(s[i][j] == '#')
      flag1 = false;
  }
  if(flag1)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << 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;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
  int N,M;cin>>N>>M;
  vector<int> a(M),open(M,0);
  rep(i,M) {
    cin>>a[i];
    int b;cin>>b;
    int can = 0;
    rep(j,b) {
      int c;cin>>c;
      c--;
      can |= (1<<c);
    }
    open[i] = can;
  }
  vector<vector<ll>> dp(M+1,vector<ll>((1<<N),INF));
  dp[0][0] = 0;
  rep(i,M) {
    rep(j,(1<<N)) {
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
      dp[i+1][j|open[i]] = min(dp[i+1][j|open[i]],dp[i][j]+a[i]);
    }
  }
  // rep(i,M+1) {
  //   rep(j,1<<N) {
  //     cout<<dp[i][j]<<" ";
  //     if(j==(1<<N)-1) cout<<endl;
  //   }
  // }
  if(dp[M][(1<<N)-1] < INF) {
    cout<<dp[M][(1<<N)-1]<<endl;
  } else {
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 35460
use std::io::Read;
use itertools::Itertools;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    let result = generate(h, w, a, b);
    format_result(&result)
}

fn generate(h: usize, w: usize, a: usize, b: usize) -> Vec<Vec<u8>> {
    let mut line1: Vec<u8> = vec![0; w];
    let mut line2: Vec<u8> = vec![1; w];
    for i in 0..a {
        line1[i] = 1;
        line2[i] = 0;
    }

    let mut result = Vec::new();
    for _ in 0..b {
        result.push(line1.clone());
    }
    for _ in 0..(h - b) {
        result.push(line2.clone());
    }
    result
}

fn format_result(result: &Vec<Vec<u8>>) -> String {
    result.iter().map(|line| { line.iter().join("") }).join("\n")
}


Measured memory_bytes: 4096