akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
string s, aans;
int k, tot, last, cnt[30];
int main()
{
	char mmin = 'z';
	cin>>s>>k;
	for(int i=0; i<s.size(); i++) cnt[(int)(s[i] - 'a' + 1)]++;
	while(tot != k) {
		vector<string>ans;
		ans.clear();
		for(int i=last+1; i<=26; i++) if(cnt[i]) {
			last = i;
			break;
		}
		for(int i=0; i<s.size(); i++)
			if(s[i] == (char)(last+'a'-1)) {
				for(int j=i, sum = 1; j<s.size() && sum <= k; j++, sum++) {
					string st = s.substr(i, j-i+1);
					ans.push_back(st);
				}
			}
		sort(ans.begin(), ans.end());
		tot++;
		if(tot == k) {
			aans = ans[0];
			break;
		}
		for(int i=1; i<ans.size(); i++) {
			if(ans[i] != ans[i-1]) tot++;
			if(tot == k) {
				aans = ans[i];
				break;
			}
		}
	}
	cout<<aans;
	return 0;
}

Measured memory_bytes: 1660
def examC():
    C = [LI() for _ in range(3)]
    ans = "Yes"
    cur = [0]*3
    for i in range(2):
        cur[0] = C[0][i+1]-C[0][i]
        cur[1] = C[1][i+1]-C[1][i]
        cur[2] = C[2][i+1]-C[2][i]
        if not cur[0]==cur[1]==cur[2]:
            ans = "No"
    for i in range(2):
        cur[0] = C[i+1][0]-C[i][0]
        cur[1] = C[i+1][1]-C[i][1]
        cur[2] = C[i+1][2]-C[i][2]
        if not cur[0]==cur[1]==cur[2]:
            ans = "No"
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++) {
        if (i * 2 + (x - i) * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3612
<?php

fscanf(STDIN, "%d", $x);

$info = array();

//配列をつくる
for ($i = 0; $i < $x; $i++) {
    fscanf(STDIN, "%d %d %d %d", $tou, $kai, $ban, $num);
    if (!isset($info[$tou][$kai][$ban])) {
        $info[$tou][$kai][$ban] = $num;
    } else {
        $info[$tou][$kai][$ban] += $num;
    }
}

//何棟かのループ
for ($j = 1; $j <= 4; $j++) {
//    何階かのループ
    for ($m = 1; $m <= 3; $m++) {
//        何番目の部屋かのループ
        for ($n = 1; $n <= 10; $n++) {
            echo " ";
            if (empty($info[$j][$m][$n])) {
                echo 0;
            } else {
                print_r($info[$j][$m][$n]);
            }
        }
        echo "\n";
    }
    if ($j < 4) {
        echo "####################" . "\n";
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 998244353;

ll next(ll a) {
    vector<int> v;
    while (a > 0) {
        v.push_back(a % 10);
        a /= 10;
    }
    reverse(v.begin(), v.end());

    int i;
    for (i = (int)v.size() - 1; i > 0; i--) {
        if (v[i - 1] - v[i] == 1) {
            v[i] = v[i - 1];
            break;
        } else if (v[i - 1] == v[i] && v[i] != 9) {
            v[i]++;
            break;
        }
    }
    ll ret = 0;
    if (i == 0) {
        if (v[i] != 9) {
            v[i]++;
        } else {
            ret = 1;
            v[i] = 0;
        }
    }
    i++;
    for (; i < (int)v.size(); i++) {
        v[i] = max(0, v[i - 1] - 1);
    }

    for (int i = 0; i < (int)v.size(); i++) {
        ret = (ret * 10) + v[i];
    }

    return ret;
}

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> v;
    vector<int> last(n, -1);

    if (s[0] == 'o') last[0] = 0;

    for (int i = 1; i < n; i++) {
        last[i] = last[i - 1];
        if (s[i] == 'o') last[i] = i;
    }

    //debug
    // cout << "last: ";
    // for (int ii : last) cout << ii << " ";
    // cout << endl;

    for (int i = 0; i < n; i++) {
        if (k == 0) break;
        if (s[i] == 'o') {
            v.push_back(i);
            k--;
            i += c;
        }
    }

    // debug
    // cout << "init v: ";
    // for (int ii : v) cout << ii << " ";
    // cout << endl;

    vector<int> ans;

    k = v.size();

    if (v[k - 1] < last[n - 1]) {
        v[k - 1] = last[n - 1];
    } else {
        ans.push_back(v[k - 1]);
    }

    for (int i = k - 2; i >= 0; i--) {
        // cout << "i: " << i << endl;
        // cout << v[i + 1] - c - 1 << endl;
        // cout << "last of above: " << last[v[i + 1] - c - 1] << endl;
        if (v[i + 1] - c - 1 >= 0 && v[i] < last[v[i + 1] - c - 1]) {
            v[i] = last[v[i + 1] - c - 1];
        } else {
            ans.push_back(v[i]);
        }
    }

    for (int i = (int)ans.size() - 1; i >= 0; i--) cout << ans[i] + 1 << "\n";

    return 0;
}

Measured memory_bytes: 4236
//02, 12, 2018, 10:02:56 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;

    cin >> s;

    int num = 0;
    int best = 1e9;
    
    for(int i = 0 ; i <= int(s.length()) - 3 ; i++){
        num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');

        best = min(best, abs(753 - num));
    }

    cout << best << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Problem {
    private Scanner sc;
    private int A;
    private int B;
    private int Q;
    private long[] s;
    private long[] t;

    Problem() {
        sc = new Scanner(System.in);
        A = sc.nextInt();
        B = sc.nextInt();
        Q = sc.nextInt();

        s = new long[A];
        t = new long[B];

        for (int i = 0; i < A; i++) {
            s[i] = sc.nextLong();
        }
        for (int i = 0; i < B; i++) {
            t[i] = sc.nextLong();
        }
    }

    int find(long[] P, long q) {
        int st = 0;
        int ed = P.length - 1;
        if (q < P[st]) return -1;
        if (q > P[ed]) return P.length - 1;

        while (st != ed) {
            if (q == P[st]) return st;
            if (q == P[ed]) return ed;

            int pivot = (st + ed) / 2;

            if (P[pivot] <= q && q < P[pivot+1]) {
                return pivot;
            } else if (q < P[pivot]) {
                ed = pivot;
            } else {
                st = pivot;
            }
        }
        return st;
    }

    long query(long q) {
        int si = find(s, q);
        int ti = find(t, q);

        int sLeft = si;
        int sRight = (si >= 0 && s[si] == q) ? si : si + 1;
        int tLeft = ti;
        int tRight = (ti >= 0 && t[ti] == q) ? ti : ti + 1;

        long ans = Long.MAX_VALUE;

        if (sLeft >= 0 && tLeft >= 0) {
            ans = Math.min(ans, Math.max(q - s[sLeft], q - t[tLeft]));
        }
        if (sRight < A && tRight < B) {
            ans = Math.min(ans, Math.max(s[sRight] - q, t[tRight] - q));
        }
        if (sLeft >= 0 && tRight < B) {
            ans = Math.min(
                    ans,
                    Math.min(Math.abs(s[sLeft] - q), Math.abs(t[tRight] - q)) + Math.abs(s[sLeft] - t[tRight])
            );
        }
        if (tLeft >= 0 && sRight < A) {
            ans = Math.min(
                    ans,
                    Math.min(Math.abs(t[tLeft] - q), Math.abs(s[sRight] - q)) + Math.abs(t[tLeft] - s[sRight])
            );
        }
        return ans;
    }

    void solve() {
        long[] ans = new long[Q];
        for (int i = 0; i < Q; i++) {
            long q = sc.nextLong();
            ans[i] = query(q);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(ans[i]);
        }
    }
}

public class Main {
    public static void main(String[] args) {
        new Problem().solve();
    }
}


Measured memory_bytes: 97980
#include<iostream>
#include<vector>

using namespace std;

int a,b,c,x;

int my_rand(){
    int _x = x;
    x = (a * x + b) % c;
    return _x;
}

int main(void){
  int n;

  while(cin >> n >> a >> b >> c >> x, n|a|b|c|x){
    vector<int>y(n),data(10000);

    for(int i=0;i<n;i++)cin >> y[i];
    
    for(int i=0;i<=10000;i++)data[i]=my_rand();

    int k = 0;
    for(int i=0;i<=10000;i++){
      if(y[k]==data[i])k++;
      if(n==k){
	cout << i << endl;
	goto end;
      }
    }
    cout << -1 << endl;
  end:;
  }
  
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int32 n;
vector<int64> a;

int main(void){
	cin >> n;
	a.resize(n);
	REP(i, n) cin >> a[i];
	vector<int64> k;
	if(n%2){
		k.push_back(1); k.push_back(1);
		FOR(i, 1, n-1){
			k.push_back(2*(i%2 ? -1 : 1));
		}
	}else{
		k.push_back(1); k.push_back(-1);
		FOR(i, 1, n-1){
			k.push_back(2*(i%2 ? -1 : 1));
		}
	}
	sort(all(k), greater<int64>());
	sort(all(a), greater<int64>());
	int64 res = 0, sum = 0;
	REP(i, n){
		sum += k[i]*a[i];
	}
	res = sum;
	k.clear();
	if(n%2){
		k.push_back(-1); k.push_back(-1);
		FOR(i, 1, n-1){
			k.push_back(2*(i%2 ? 1 : -1));
		}
	}else{
		k.push_back(1); k.push_back(-1);
		FOR(i, 1, n-1){
			k.push_back(2*(i%2 ? -1 : 1));
		}
	}
	sort(all(k), greater<int64>());
	sum = 0;
	REP(i, n){
		sum += k[i]*a[i];
	}
	cout << max(res, sum) << endl;
}


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


int main()
{
	int n;
	int time;
	int c[1001];
	int t[1001];
	cin >> n >> time;
	int cost=1001;
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
		if (t[i] <= time) {
			if(cost > c[i])  cost = c[i];

		}
	}
	if (cost == 1001) cout << "TLE" << endl;
	else cout << cost << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        char[] S = sc.next().toCharArray();
        char[] T = sc.next().toCharArray();

        int[] start = new int[26];
        int[] end = new int[26];

        Arrays.fill(start, -1);
        Arrays.fill(end, -1);

        for (int i = 0; i < S.length; i++) {
            int a = S[i] - 'a';
            int b = T[i] - 'a';

            if ((start[a] != -1 && end[b] != a) || (end[b] != -1 && start[a] != b)) {
                System.out.println("No");
                return;
            }
            start[a] = b;
            end[b] = a;
        }
        System.out.println("Yes");
    }


}


Measured memory_bytes: 28744
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
struct edge
{
	int to,nxt;
}e[N<<1]; int n,head[N],cnt,x,y,dlt[N],mx[N],c[N],sz[N],ext[N];
inline void addedge(CI x,CI y)
{
	e[++cnt]=(edge){y,head[x]}; head[x]=cnt;
	e[++cnt]=(edge){x,head[y]}; head[y]=cnt;
}
#define to e[i].to
inline void calc(CI now,CI fa,CI lim)
{
	ext[now]=1; for (RI i=head[now];i;i=e[i].nxt)
	if (to!=fa&&to<lim) calc(to,now,lim),ext[now]+=ext[to];
}
inline void DFS1(CI now=1,CI fa=0)
{
	sz[now]=1; mx[now]=max(mx[fa],now);
	for (RI i=head[now];i;i=e[i].nxt) if (to!=fa)
	DFS1(to,now),sz[now]+=sz[to],dlt[now]+=dlt[to];
	if (mx[now]==now) calc(now,fa,mx[fa]),dlt[now]=-sz[now];
	if (mx[fa]==fa) dlt[now]+=sz[now];
}
inline void DFS2(CI now=1,CI fa=0)
{
	if (fa)
	{
		if (mx[now]==now) c[now]+=ext[now]; else
		if (mx[fa]==fa) c[now]+=dlt[now]-ext[now]; c[now]+=c[fa];
	}
	for (RI i=head[now];i;i=e[i].nxt) if (to!=fa) DFS2(to,now);
}
#undef to
int main()
{
	RI i; for (scanf("%d",&n),i=1;i<n;++i)
	scanf("%d%d",&x,&y),addedge(x,y);
	for (DFS1(),DFS2(),i=2;i<=n;++i) printf("%d ",c[i]);
	return 0;
}

Measured memory_bytes: 32652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(0);
    int n, t; cin >> n >> t;
    // vector<int> A(n), B(n);
    vector<P> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;
    sort(ALL(ab));
    // dp[i][j] : i番目までの料理でj分で食べれる料理の美味しさの合計の最大値
    vector<vector<ll>> dp(n+1, vector<ll>(t+1, 0));
    rep(i, n) {
        rep(j, t+1) {
            if (j - ab[i].first >= 0)
                dp[i+1][j] = max(dp[i][j], dp[i][j - ab[i].first] + ab[i].second);
            else
                dp[i+1][j] = dp[i][j];
        }
    }
    ll ans = 0;
    rep(i, n) chmax(ans, dp[i][t-1] + ab[i].second);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70784
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
 
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs
 
void solve()
{
    set<ll> s;
    IN(n);
    rep(i, n)
    {
        IN(a);
        s.emplace(a);
    }
    cout << (s.size() == n ? "YES" : "NO") << endl;
}
 
int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);
 
    solve();
 
    return 0;
}

Measured memory_bytes: 9728
n,k = map(int,input().split())	
li = tuple(map(int,input().split()))
dp = [0] + [float("inf")]*(n-1)
for i in range(1,n):
    for j in range(max(0, i-k),i):
        dp[i] = min(dp[i], dp[j] + abs(li[i] - li[j]))
print(dp[-1])


Measured memory_bytes: 58464
/**
 * File              : A.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 26.01.2020
 * Last Modified Date: 26.01.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;

int main() {
    int h, a;
    cin >> h >> a;
    cout << h/a + (h%a != 0);
    return 0;
}


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


int main() {
    int* a;
    int l;
    int j;
    int N;
    int count=0;

    cin >> N;
    a = new int[N];
    for (l = 0; l < N; l++) cin >> a[l];
  
    
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j>i; j--) {
            if (a[j]<a[j-1]) {
                swap(a[j],a[j-1]);
                count++;
            }
        }
   }
        for (int k=0; k<N; k++) {
            cout<<(k!=0?" ":"")<<a[k];
        }
        cout<<endl<<count<<endl;
        delete[] a;
        

    }


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

template<typename T>
struct edge {
    int src, to;
    T cost;
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

using State = string::const_iterator;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    int n, w, d; cin >> n >> w >> d;
    vector<P> events;
    REP(i, n) {
        int x, y;
        char dir;
        cin >> x >> y >> dir;
        if (dir == 'W') {
            events.emplace_back(-x + y, x + y);
        }
        if (dir == 'N') {
            events.emplace_back(x + y, (d - y) - (w - x) + d + w);
        }
        if (dir == 'E') {
            events.emplace_back((d - y) - (w - x) + d + w, (d - y) + (w - x) + d + w);
        }
        if (dir == 'S') {
            events.emplace_back((d - y) + (w - x) + d + w, -x + y + 2 * d + 2 * w);
        }
    }
    sort(ALL(events), [&](P a, P b){ return a.second < b.second; });

    int ans = n;
    REP(i, SZ(events)) {
        auto tmp = events;
        REP(j, i) {
            if (tmp[j].second < tmp[i].second) {
                tmp[j].first += 2*d + 2*w;
                tmp[j].second += 2*d + 2*w;
            }
        }
        sort(ALL(tmp), [&](P a, P b){ return a.second < b.second; });
        int sum = 1, prev = tmp[0].second;
        FOR(k, 1, SZ(tmp)) {
            if (prev < tmp[k].first) {
                prev = tmp[k].second;
                ++sum;
            }
        }
        chmin(ans, sum);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3228
fn main(){
  let cs: Vec<u32> = (2..18).map(|i| i * i).collect();

  let mut dp: Vec<u32> = vec![1;301];

  for c in cs {
    let mut ndp: Vec<u32> = vec![0;301];
    for i in 0 .. 301 {
      let ii = i as u32;
      if ii < c {
        ndp[i] = dp[i];
      } else {
        let j = (ii - c) as usize;
        ndp[i] = dp[i] + ndp[j];
      }
    }
    dp = ndp;
  }

  loop {
    let n: usize = read();
    
    if n == 0 { break; }

    println!("{}", dp[n]);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}



Measured memory_bytes: 5024
def rec(num, string, total, xy_list, n):
    x, y = xy_list[num]
    if string:
        pre_one = int(string[-1])
        pre_x, pre_y = xy_list[pre_one]
        distance = ((x - pre_x)**2 + (y - pre_y)**2)**0.5
        total+=distance
    string+=str(num)

    if len(string)==n:
        return total

    all_total = 0
    ret_list = [i for i in range(n) if str(i) not in string]
    for one in ret_list:
        all_total+=rec(one, string, total, xy_list, n)
    return all_total

def main():
    n = int(input())
    xy_list = []
    k = 1
    for i in range(n):
        x, y = list(map(int, input().split(" ")))
        xy_list.append((x, y))
        k*=(i+1)

    all_total = 0
    for i in range(n):
        all_total+=rec(i, "", 0, xy_list, n)
    print(all_total/k)

if __name__=="__main__":
    main()


Measured memory_bytes: 9360
X,Y,Z,K = (int(i) for i in input().split())  
A = [int(i) for i in input().split()] 
B = [int(i) for i in input().split()] 
C = [int(i) for i in input().split()] 

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ans = []
b=0
c=0
for a in range(len(A)):
	for b in range(len(B)):
		for c in range(len(C)):
			if (a+1)*(b+1)*(c+1)<=K:
				ans.append(A[a]+B[b]+C[c])
			else:
				break

ans.sort(reverse=True)
for i in range(K):
	print(ans[i])

Measured memory_bytes: 8712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long []arr = {a,b,c,d};
		long total = 0;
		long max = Long.MIN_VALUE;
		for(int i = 0 ; i < 2; i++)
		{
			for(int j = 2; j<4; j++)
			{
					total = arr[i] * arr[j];
				
				if(total > max)
				{
					max = total;
					
				}
				
			}
		}
		System.out.println(max);
	}

}

Measured memory_bytes: 27064
#include<stdio.h>

int main(){
    int A,B,C;
    int ans;

    scanf("%d %d %d", &A, &B, &C);

    ans = C-(A-B);
    if(ans>0){
        printf("%d", ans);
    }else{
        printf("0");
    }

    return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

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

    double n,m,d; cin >> n >> m >> d;
    double ans = 0;
    if(d == 0)ans = 1.0 / n;
    else ans = 2 * (n - d) / (n * n);
    ans *= (m - 1.0);
    cout << fixed << setprecision(15);
    cout << ans << endl;
}

Measured memory_bytes: 256
h , w = map(int,input().split())
s = [input() for i in range(h)]
coulef = [[0 for i in range(w)] for j in range(h)]
courig = [[0 for i in range(w)] for j in range(h)]
coudow = [[0 for i in range(w)] for j in range(h)]
couup = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    cou = 0
    for j in range(w):
        if s[i][j] == ".":
            cou += 1
            courig[i][j] = cou
        elif s[i][j] == "#":
            cou = 0
for i in range(h):
    cou = 0
    for j in reversed(range(w)):
        if s[i][j] == ".":
            cou += 1
            coulef[i][j] = cou
        elif s[i][j] == "#":
            cou = 0
for i in range(w):
    cou = 0
    for j in range(h):
        if s[j][i] == ".":
            cou += 1
            coudow[j][i] = cou
        elif s[j][i] == "#":
            cou = 0
for i in range(w):
    cou = 0
    for j in reversed(range(h)):
        if s[j][i] == ".":
            cou += 1
            couup[j][i] = cou
        elif s[j][i] == "#":
            cou = 0

ans = 0
for i in range(h):
    for j in range(w):
        now = couup[i][j]+coudow[i][j]+coulef[i][j]+courig[i][j]
        ans = max(ans,now-3)
print(ans)

Measured memory_bytes: 210596
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>

long sn(long n) {
  long sn = n%10;
  while (n / 10 != 0) {
    n/=10;
    sn += n%10;
  }
  return sn;
}

double nsn(long n) {
  return (double)n/(double)sn(n);
}

using namespace std;

int main() {
  long K;
  long delta = 1;
  long ans = 1;
  long count = 0;
  cin >> K;
  while (true) {
    cout << ans << endl;
    if ((nsn(ans) <= nsn(ans+delta) && nsn(ans+delta) <= nsn(ans+delta*10))) {
      ans += delta;
    } else {
      delta *= 10;
      ans += delta;
    }
    count++;
    if (count >= K) {
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)
int dp[50100];
int main(){
	int n,m;
	cin >> n >> m;
	int hako[25];
	REP(i,50100)dp[i] = INT_MAX;
	REP(i,m){
		int a;
		cin >> a;
		hako[i] = a;
	}
	dp[0] = 0;
	REP(i,n){
		REP(j,m){
			if(i+hako[j] <= n and dp[i+hako[j]] > dp[i]+1){
				dp[i+hako[j]] = dp[i]+1;
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1356
def main():
    strA = input()
    listA = strA.split(" ")

    N = int(listA[0])
    R = int(listA[1])

    nRate = 0
    if N >= 10:
        nRate = R
    else:
        nRate = R + (100 * (10 - N))

    print(nRate)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    int sum = 0;
    for(int i = 0; i < K; i++){
        sum += A.at(i);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,a,b) for (int i=(a); i<(b);i++)
#define frr(i,a,b) for(int i=(a-1);i>=(b);i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll,ll>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define ln(a) a.length()
#define sz(a) a.size()
ll M=1000000007;
int a[100000];
int b[100001];

int solve(int n,int t)
{
   
   if(b[n]!=-1)return b[n];
   if(t+1>=n)return abs(a[n-1]-a[0]);
   int k=M;
   fr(i,1,t+1)
   	{ k=min(k,abs(a[n-1]-a[n-1-i])+solve(n-i,t));
   	    if(i==n-1)break;
   		}
   
   
   b[n]=k;
   return k;

}

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

	int n;cin>>n;int t;cin>>t;
   memset(b,-1,sizeof(b));
	fr(i,0,n)cin>>a[i];
   cout<<solve(n,t)<<endl;

}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    ll sum =0;
    for(int i = 0; i < m; i++){
    cin >> a[i];
    sum += a[i];
    }
    cout << (sum > n ? -1 : n - sum) << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong N;
llong ans;
void dfs(llong n,int flag)
{
    if(n>N)
        return ;
    if(flag==7)
        ans++;
    dfs(n*10+3,flag|1);
    dfs(n*10+5,flag|2);
    dfs(n*10+7,flag|4);
} //再帰関数

int main()
{
cin>>N;
dfs(0,0);
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
int mod = (int) 1e9 + 7;

int main(){
    
    string s, t;
    cin >> s >> t;
    
    if(t.size() - s.size() != 1){
        cout << "No" << "\n";
    }
    
    rep(i,s.size()) if(s[i] != t[i]){
        cout << "No" << "\n";
        return 0;
    }
    
    cout << "Yes" << "\n";

    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll f(int k, int n, int num) {
	// 1以上n以下でmod kでnumとなる数の個数
	if (num == 0) {
		return n / k;
	} else {
		return max(0, (n - num) / k + 1);
	}
}
int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int a = 1; a <= n; a++) {
		int b = (k - (a % k)) % k;
		int c = (k - b) % k;
		if ((a + c) % k == 0) {
			ll cnt = f(k, n, b);
			cnt *= f(k, n, c);
			ans += cnt;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <climits>

using namespace std;

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

int main(){
	bool isFirst = true;
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		if(!isFirst){ cout << "----------" << endl; }
		isFirst = false;
		vector<string> field(n + 2);
		getline(cin, field[0]);
		field[0] = field[n + 1] = string(82, ' ');
		for(int i = 1; i <= n; ++i){
			getline(cin, field[i]);
			field[i] = " " + field[i] + string(81 - field[i].size(), ' ');
		}
		map<int, int> results;
		for(int i = 1; i <= n; ++i){
			for(int j = 1; j < field[i].size() - 1; ++j){
				if(field[i][j] != '*'){ continue; }
//cerr << "begin: " << i << ", " << j << endl;
				vector<int> mintable(n + 2, INT_MAX), maxtable(n + 2, 0);
				int a = i, b = j, da = 0, db = 0, maxy = i, d = 3;
				do {
					a -= da; b -= db;
					for(int k = 0; k < 8; ++k){
						if(field[a + dy[(d + k) % 8]][b + dx[(d + k) % 8]] == '*'){
							da = dy[(d + k) % 8]; db = dx[(d + k) % 8];
							d = (d + k) % 8;
							break;
						}
					}
//cerr << "dir: " << da << ", " << db << " (" << a << ", " << b << ")" << endl;
					while(field[a][b] == '*'){
						field[a][b] = ' ';
//cerr << "check: " << a << ", " << b << endl;
						mintable[a] = min(mintable[a], b);
						maxtable[a] = max(maxtable[a], b);
						maxy = max(maxy, a);
						a += da; b += db;
					}
					field[a - da][b - db] = '*';
				} while(a != i || b != j);
				field[a - da][b - db] = ' ';
				int size = 0;
				for(int k = i; k <= maxy; ++k){
//cerr << mintable[k] << " - " << maxtable[k] << endl;
					size += maxtable[k] - mintable[k] + 1;
				}
				++(results[size]);
//for(int k = 0; k < n + 2; ++k){ cerr << field[k] << endl; }
			}
		}
		for(map<int, int>::iterator it = results.begin(); it != results.end(); ++it){
			cout << it->first << " " << it->second << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>

int n;
char rawstr[1234567];
char str[1234567];

bool cond(int x)
{
	int lastco = 0;
	for (int i = n - 1; i >= 0; --i)
	{
		if (str[i] == 'I')
		{
			str[i] = 'X';
			lastco++;
			if (lastco == x)break;
		}
	}
	if (lastco != x)return false;
	int xco = 0;
	for (int i = n - 1; i >= 0; --i)
	{
		if (str[i] == 'X')
		{
			++xco;
		}
		if (str[i] == 'O' && xco > 0)
		{
			--xco;
			str[i] = 'Y';
		}
	}
	if (xco != 0)return false;
	int yco = 0;
	for (int i = n - 1; i >= 0; --i)
	{
		if (str[i] == 'Y')
		{
			++yco;
		}
		else if (str[i] != 'X' && str[i] != 'O' && yco > 0)
		{
			--yco;
			str[i] = 'Z';
		}
	}
	if (yco != 0)return false;
	return true;
}

int main()
{
	scanf("%d", &n);
	scanf("%s", rawstr);
	int lower = 0;
	int upper = n;
	while (lower + 1 < upper)
	{
		strcpy(str, rawstr);
		int middle = (lower + upper) / 2;
		if (cond(middle))
		{
			lower = middle;
		}
		else
		{
			upper = middle;
		}
	}
	printf("%d\n", lower);
	return 0;
}

Measured memory_bytes: 4656
from collections import deque

N, Q = list(map(int,input().split()))
G = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
p = [0 for _ in range(N)]
for i in range(Q):
    in1, in2 = list(map(int,input().split()))
    p[in1 - 1] += in2

ans = [0 for _ in range(N)]
ans[0] = p[0]

def bfs(s):
    q = deque([s])
    seen = [False] * N
    
    while(q):
        node = q.popleft()
        seen[node] = True
        for nx in G[node]:
            if seen[nx] == False:
                q.append(nx)
                ans[nx] += (p[nx] + ans[node])

bfs(0)
print(*ans)

Measured memory_bytes: 132776
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    int n,m; cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int sum = 0;
    rep(i, n) sum += a[i];
    if (n-sum >= 0) cout << n-sum << endl;
    else cout << "-1" << endl;

}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ b.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/

Measured memory_bytes: 7220
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string[] s = SpRead(' ');
        int H = int.Parse(s[0]);
        int W = int.Parse(s[1]);
        char[,] list = new char[50, 50];
        for (int i = 0; i < H; i++)
        {
            s = Console.ReadLine().ToCharArray().Select(a => a.ToString()).ToArray();
            for (int j = 0; j < W; j++) { list[i, j] = Char.Parse(s[j]); }
        }
        bool flag = true;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (list[i, j] == '#')
                {
                    if (i != 0)
                    {
                        if (list[i - 1, j] == '#') { flag = true; continue; }
                        else flag = false;
                    }
                    if (i != W - 1)
                    {
                        if (list[i + 1, j] == '#') { flag = true; continue; }
                        else flag = false;
                    }
                    if (j != 0)
                    {
                        if (list[i, j - 1] == '#') { flag = true; continue; }
                        else flag = false;
                    }
                    if (j != H - 1)
                    {
                        if (list[i, j + 1] == '#') { flag = true; continue; }
                        else flag = false;
                    }
                    if (!flag)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }


            }
        }
        Console.WriteLine("Yes");
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


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

class UnionFind {
public:
  vector<int> parent;
  UnionFind(int n) { parent = vector<int>(n, -1); }
  int root(int a) {
    if(parent[a] < 0)
      return a;
    return parent[a] = root(parent[a]);
  }
  int size(int a) { return -parent[root(a)]; }
  bool connect(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b)
      return false;
    if(size(a) < size(b))
      swap(a, b);
    parent[a] += parent[b];
    parent[b] = a;
    return true;
  }
};

int main() {
  int n, m, x, y, o = 0;
  cin >> n >> m;
  vector<int> p(n);
  for(int i = 0; i < n; i++)
    cin >> p.at(i);
  UnionFind uni(n);
  for(int i = 0; i < m; i++){
    cin >> x >> y;
    uni.connect(--x, --y);
  }
  for(int i = 0; i < n; i++)
    if(uni.root(p.at(i)-1)==uni.root(i))
      o++;
  cout << o << endl;
}

Measured memory_bytes: 1024
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
 
using namespace std;
 
typedef long long ll;

#define ff first
#define se second
#define all(a) begin(a),end(a)
typedef vector<int> VI;
// const ll mod = 1e9 + 7;

string convert(ll n) {
    string ans = "";
    while (n > 0) {
        n -= 1;
        ans.push_back('a' + (n % 26));
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

void solve() {
    ll n;
    cin >> n;
    cout << convert(n);
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3128
import Control.Monad
import Data.List

main = do
    [n, m] <- map read <$> words <$> getLine
    a      <- map read <$> words<$>getLine
    putStrLn $ show $ solve m a

solve :: Int -> [Int] -> Integer
solve m a = sum $ map (calc . fromIntegral . length) $ group $ sort $ foldr add [0] a
  where
    calc l = l * (l - 1) `div` 2
    add v sumarray = ((v + head sumarray) `mod` m) : sumarray

Measured memory_bytes: 52604
# a1,a2,a3 = map(int, input().split())
s = input()
s_rev = s[::-1]
len_s = len(s)
ans = 0


# 対象となる位置が両方異なっている場合は、普通に計算すると2個の間違いだが1にしてあげる
for i in range(len_s):
  if s[i] != s_rev[i]:
    ans += 1
  
print(int(ans/2))

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

int calc(string s, int type){
	int cutA=-1, cutM=-1;
	for(int i=0; i<(int)s.length(); i++){
		if(s[i]=='+') cutA = i; 
		if(s[i]=='*') cutM = i;
	}
	if(cutA==-1 && cutM==-1){
		return stoi(s);
	}else if(cutA==-1 || (type==0 && cutM>cutA)){
		return calc(s.substr(0,cutM), type) * calc(s.substr(cutM+1, s.length()-cutM), type);
	}else{
		return calc(s.substr(0,cutA), type) + calc(s.substr(cutA+1, s.length()-cutA), type);
	}
}

int main(){
	string str;
	int ans;
	cin >> str >> ans;

	if(ans == calc(str,0)){
		if(ans == calc(str, 1)){
			cout << "U" << endl;
		}else{
			cout << "L" << endl;
		}
	}else{
		if(ans == calc(str, 1)){
			cout << "M" << endl;
		}else{
			cout << "I" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3208
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

a, b, c = map(int, input().split())
K = int(input())

ok = False
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i + j + k > K:
                continue
            aa = a * 2**i
            bb = b * 2**j
            cc = c * 2**k
            if aa < bb and bb < cc:
                ok = True

if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61804
N, K = map(int, input().split())
if K > (N - 1) * (N - 2) // 2:
    print(-1)
else:
    c = 0
    lst = []
    for i in range(2, N+1):
        c+=1
        lst.append([1, i])
    cnt = 0
    f = 0
    for i in range(2, N+1):
        for j in range(i+1, N+1):
            if cnt == (N-1)*(N-2)//2-K:
                f=1
                break
            c+=1
            cnt+=1
            lst.append([i, j])
        if f:
            break
    print(c)
    for l in lst:
        print(*l)

Measured memory_bytes: 4120
//Dream your Code, Code your Dream [Siriuslight -Subham Pal]
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;    typedef long long ll;    typedef long double ld;
const ll inf = 1e9, N = 1e5+5;
const ll INF = 1e18, MOD = 1e9+7;
ll power(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll gcd(ll a,ll b){if(b>a)swap(a,b);if(!b)return a;return gcd(b,a%b);}


int main(){
    FIO;
    cout << setprecision(10) << fixed;
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8){
        cout << "Yay!";
    }
    else{
        cout << ":(";
    }
    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    set<int> st;
    int a,b,c;
    cin >> a >> b >> c;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    cout << st.size() << '\n';
    return 0;
}

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

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;
 
#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

const int DR[] = {-1, 1, 0, 0};
const int DC[] = {0, 0, -1, 1};

void solve(int test)
{
    int N;
    cin >> N;
    int i, j;
    VInt p(N*N);
    FOR(i, 0, SIZE(p)) cin >> p[i];

    vector<VInt> v(N, VInt(N, 1));
    vector<VInt> d(N, VInt(N));
    FOR(i, 0, N)
        FOR(j, 0, N)
            d[i][j] = min(min(i, N - 1 - i), min(j, N - 1 - j));

    Int res = 0;
    FOR(i, 0, SIZE(p))
    {
        int r = (p[i]-1) / N;
        int c = (p[i]-1) % N;
        res += d[r][c];
        v[r][c] = 0;
        queue<PII> q;
        q.push(PII(r, c));
        while(!q.empty())
        {
            r = q.front().first;
            c = q.front().second;
            q.pop();
            FOR(j, 0, 4)
            {
                int rr = r + DR[j];
                int cc = c + DC[j];
                if(rr < 0 || N <= rr || cc < 0 || N <= cc) continue;
                if(d[rr][cc] > d[r][c] + v[r][c])
                {
                    d[rr][cc] = d[r][c] + v[r][c];
                    q.push(PII(rr, cc));
                }
            }
        }
    }
    cout << res << endl;
}

int main()
{
    int T, t;
    T = 1;
    FOR(t, 0, T) solve(t);
    return 0;
}


Measured memory_bytes: 6168
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int a, b, c, x, y;

int main() {
    cin >> a >> b >> c >> x >> y;
    if (a + b <= c * 2) {
        cout << a * x + b * y << endl;
    }
    else {
        int m = min(x, y);
        if (x == y) {
            cout << c * x * 2 << endl;
        }
        else if(x > y) {
            if (a >= c * 2) {
                cout << c * 2 * m + c * 2 * (x - m) << endl;
            }
            else {
                cout << c * 2 * m + a * (x - m) << endl;
            }
        }
        else {
            if (b >= c * 2) {
                cout << c * 2 * m + c * 2 * (y - m) << endl;
            }
            else {
                cout << c * 2 * m + b * (y - m) << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct top2_t {
  vector<int> v;
  top2_t() {
  }
  top2_t(int x)
      : v{x} {
  }
  top2_t& operator+=(const top2_t& rhs) {
    v.insert(v.end(), rhs.v.begin(), rhs.v.end());
    sort(v.rbegin(), v.rend());
    if (v.size() > 2) v.resize(2);
    return *this;
  }
};

struct ans_t {
  ll less;
  ll over;
};

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n)
      : x(n + 1) {
  }
  void add(int k, T a) {
    for (++k; k < x.size(); k += k & -k) x[k] += a;
  }
  T sum(int k) {
    T s;
    for (; k > 0; k &= k - 1) s += x[k];
    return s;
  }
};

vector<ans_t> solve(const vector<int>& P) {
  int N = P.size();
  fenwick_tree<top2_t> bit(N);
  vector<ans_t> res(N);
  for (int i = 0; i < N; i++) {
    auto x = bit.sum(P[i]);
    auto v = x.v;
    ll less = 0, over = 0;
    if (v.empty()) {
      less = i + 1;
      over = 0;
    } else if (v.size() == 1) {
      less = i - v[0];
      over = v[0] + 1;
    } else {
      less = i - v[0];
      over = v[0] - v[1];
    }
    res[i] = {less, over};
    bit.add(P[i], top2_t(i));
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> P(N);
    for (int& x : P) cin >> x;
    for (int& x : P) x = N - x;
    auto ans_f = solve(P);
    reverse(P.begin(), P.end());
    auto ans_b = solve(P);
    reverse(ans_b.begin(), ans_b.end());
    reverse(P.begin(), P.end());
    ll res = 0;
    for (int i = 0; i < N; i++) {
      auto f = ans_f[i], b = ans_b[i];
      res += (f.over * b.less + f.less * b.over) * (N - P[i]);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 9176