akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FASTIO
#define endl "\n"  // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (int i = 0; i < n; ++i) cin >> c[i];
#define exit_message(s) return 0 * printf(s)
#define show_all(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, a, n) cout << "Displaying array \"" << #c << "\" : \n"; for (int (i) = (a); (i) < (n); ++(i)) cout << (c)[(i)] << " "; cout << "\n";
#define forl(i, a, n) for (int i = (a); (i) < (n); ++(i))
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

// What follows is a magical ordered set data structure.
// Supports the following functions:
// find_by_order(int k) - returns k'th smallest element (0-indexed)
// order_of_key(int k) - returns number of elements strictly smaller than k.
using namespace __gnu_pbds;
#define ordered_set tree <ll, null_type, greater_equal <ll>, rb_tree_tag, tree_order_statistics_node_update>

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;
const long double eps = 1e-7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long true_rand(long long n)
{
	// Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_int_distribution<long long> uid(0, n - 1);
    return uid(rng);
}

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;
	
	return res;
}

const int N = 3e5 + 5;

int32_t main()
{
	#ifdef FASTIO
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	#endif
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int n;
	cin >> n;
	long double sum = 0.0;
	forl(i, 0, n)
	{
		long double a;
		cin >> a;
		a = 1.0 / a;
		sum += a;
	}
	sum = 1.0 / sum;
	cout << fixed << setprecision(10);
	cout << sum << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

long p;
queue<long> que;

long two(long n){
  long tmp = 1;
  while(n > 0){
    tmp *= 2;
    n--;
  }
  return tmp;
}

long search_next(vector<long> &nexthp, vector<long> &hp_id, vector<long> &s,long now){
  long next_hp = nexthp.at(now);
  //cout << "nexthp is " << next_hp;
  long id = hp_id.at(next_hp);
  if(s.at(id) == next_hp){
    while(!que.empty()){
      long tmp = que.front();
      que.pop();
      nexthp.at(tmp) = next_hp;
    }
    hp_id.at(next_hp) = id + 1;
    if(id+1 <= p){
      if(s.at(id+1) != next_hp){
        nexthp.at(now) = nexthp.at(next_hp);
      }
      //id = hp_id.at(nexthp.at(next_hp));
      //if(s.at(id) == next_hp)
    }
    return s.at(id);
  }else{
    que.push(now);
    return search_next(nexthp,hp_id,s,next_hp);
  }
}

int main(){
  long n;
  cin >> n;
  p = two(n);
  vector<long> s(p);
  rep(i,p){
    cin >> s.at(i);
  }
  sort(s.begin(),s.end(),greater<long>());
  long s0 = s.at(0);
  long s1 = s.at(1);
  if(s0 == s1){
    cout << "No" << endl;
    return 0;
  }
  
  long f = 1;
  for(long i=p-1;i>=1;i--){
    if(s.at(i) != s.at(i-1)){
      s.at(i) = f;
      f++;
    }else{
      s.at(i) = f;
    }
  }
  s.at(0) = f;
  vector<long> nexthp(f+1);
  vector<long> hp_id(f+1);
  //map<long,long> nexthp;
  //map<long,long> hp_id;
  long tmp,tmp2;
  s.push_back(0);

  rep(i,p){
    if(s.at(i) != s.at(i+1)){
      tmp = s.at(i);
      tmp2 = s.at(i+1);
      //cout << tmp << " " << tmp2 << endl;
      nexthp.at(tmp) = tmp2;
      hp_id.at(tmp2) = i+1;
    }
  }
  //cout << hp_id.at(-1);
  long now,nextid,next;
  vector<long> slime;
  slime.push_back(s.at(0));
  long num = slime.size();
  while(num < p){
    //cout << num;
    rep(i,num){
      //cout << " #2 ";
      now = slime.at(i);
      next = search_next(nexthp,hp_id,s,now);
      //cout << " #3 ";
      //cout << "now and next : " << now << " " << next << endl;
      if(next == 0){
        //cout << num << " " << now << endl;
        cout << "No" << endl;
        return 0;
      }
      slime.push_back(next);
    }
    num = slime.size();
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 12156
#include<bits/stdc++.h>
#define N 500005
#define oo (1<<30)
using namespace std;
int n,m,q,a[N],b[N],d[N];
int main()
{
	int i;
	//freopen("E.in","r" , stdin);
	//freopen("E.out","w",stdout);
	scanf("%d %d",&n,&m),a[0]=m;
	for(i=1;i<=n;i++)
		scanf("%d",&d[i]),a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	b[n]=1;
	for(i=n;i>=1;i--) 
		if(b[i]<=d[i]/2) b[i-1]=b[i];
		else b[i-1]=b[i]+d[i];
	cin>>q;
	while(q--){
		scanf("%d",&i);
		if(a[i-1]>=b[i]) printf("YES\n");
		else printf("NO\n");
	  }
	return 0;
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

int n;
const int full=1000001;
vector<int>adj[full];
bool vis[full];
int par[full];
int depth[full];
ll h[full];
ll l[full];
void dfs(int i)
{
    vis[i]=1;
    for(int j=0;j<adj[i].size();j++)
    {
        if(h[i]<=h[adj[i][j]])
        {
           l[i]=1; 
        }
        if(vis[adj[i][j]]==0)
        {
            dfs(adj[i][j]);
        }
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int n,m;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    for(i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].push_back(a);
    }
    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }
    int c=0;
    for(i=1;i<=n;i++)
    {
        if(l[i]==0)
        {
            c++;
        }
    }
    cout<<c;
}

Measured memory_bytes: 33100
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,b) for (ll i=a;i<=ll(b);i++)
using namespace std;

ll ctoi(const char c){if('0'<=c&&c<='9') return (c-'0');return -1;}
#define ALL(x) begin(x),end(x)
  
int main(){
  ll n;
  cin >> n;
  
  ll ans = 1000000000001;
  for(ll i = 1; i <= sqrt(n); i++){
    if(n%i!=0) continue;
    ll m = n/i;
    ll moveDist = (i-1)+(m-1);
    ans = min(ans,moveDist);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int volume = int.Parse(Console.ReadLine());

                if (volume == 0) break;

                int minPrice = int.MaxValue;

                for (int c = 0; c <= volume; c += 500)
                {
                    int restB = volume - c;

                    for (int b = 0; b <= restB; b += 300)
                    {
                        int restA = restB - b;

                        if (restA % 200 != 0) continue;

                        int na = restA / 200, nb = b / 300, nc = c / 500;
                        int price = na * 380 + nb * 550 + nc * 850;

                        int ma = na / 5, mb = nb / 4, mc = nc / 3;
                        int discount = ma * 380 + mb * 330 + mc * 306;

                        price -= discount;

                        minPrice = Math.Min(minPrice, price);
                    }
                }
                sb.AppendLine(minPrice.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    while(cin>>n, n) {
        vector<char> v(n);
        rep(i,n) cin >> v[i];
        vi cnt(27);
        int i;
        int mx = 0;
        for(i=0;i<n;++i) {
            int rem = n-i-1;
            cnt[v[i]-'A']++;
            auto it = max_element(ALL(cnt));
            mx = *it;

            vi tmp = cnt;
            sort(tmp, greater<int>());
            if(tmp[1]+rem<mx) break;
        }
        auto it = max_element(ALL(cnt));
        mx = *it;
        vi tmp = cnt;
        sort(tmp, greater<int>());
        if(mx>tmp[1]) cout << char('A'+(it-cnt.begin())) << " " << i+1 << endl;
        else cout << "TIE" << endl;
    }
    return 0;
}

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

int main(){
  int A, B, num;
  string message;
  
  cin >> A >> B;
  num = A % 500;
  if(num <= B){
    message = "Yes";
  }else{
    message = "No";
  }
  
  cout << message << endl;
}

Measured memory_bytes: 764
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1000000007;
const int N=50;
int n,m;
struct matrix{
	int a[N+1][N+1];
	int *operator[](int x){return a[x];}
	matrix(){memset(a,0,sizeof(a));}
	matrix(bool x){
		memset(a,0,sizeof(a));
		for(int i=1;i<=n;i++)a[i][i]=1;
	}
	void read(){
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>a[i][j];
	}
	friend matrix operator*(matrix x,matrix y){
		matrix res;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				(res[i][j]+=x[i][k]*y[k][j]%mod)%=mod;
		return res;
	}
	friend matrix operator*=(matrix &x,matrix y){return x=x*y;}
	int sum(){
		int res=0;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)(res+=a[i][j])%=mod;
		return res;
	}
}Delta;
matrix qpow(matrix x,int y){
	matrix res(0);
	while(y){
		if(y&1)res*=x;
		x*=x;
		y>>=1;
	}
	return res;
}
signed main(){
	cin>>n>>m;
	Delta.read();
	cout<<qpow(Delta,m).sum();
	return 0;
}
/*1
4 2
0 1 0 0
0 0 1 1
0 0 0 1
1 0 0 0
*/
/*2
3 3
0 1 0
1 0 1
0 0 0
*/
/*3
6 2
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 1 0
0 0 0 0 0 1
0 0 0 0 0 0
*/
/*4
1 1
0
*/
/*5
10 1000000000000000000
0 0 1 1 0 0 0 1 1 0
0 0 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 1 0 1
1 1 1 0 1 1 0 1 1 0
0 1 1 1 0 1 0 1 1 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 0 0 1 0 1
1 0 0 0 1 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
1 0 1 1 1 0 1 1 1 0
*/

Measured memory_bytes: 512
// D - Maze Master
#include <bits/stdc++.h>

using namespace std;

#define	INF	100000000

void floyd(vector<vector<int> > &cost)
{
	for (int k = 0, n = cost.size(); k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}


int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) cin >> s[i];
	vector<vector<int> > g(h * w, vector<int>(h * w, INF));
	for (int i = 0; i < g.size(); i++) g[i][i] = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (s[i][j] != '.') continue;
			int u = i * w + j;
			if (i + 1 < h && s[i + 1][j] == '.')
				g[u][u + w] = g[u + w][u] = 1;
			if (j + 1 < w && s[i][j + 1] == '.')
				g[u][u + 1] = g[u + 1][u] = 1;
		}
	floyd(g);
	int ans = 0;
	for (int i = 0; i < g.size(); i++)
		for (int j = 0; j < g.size(); j++)
			if (g[i][j] < INF)
				ans = max(ans, g[i][j]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 896
#pragma region Macros
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7752
from bisect import bisect_right
n = int(input())
MX = 100010
dp = [float('inf') for _ in range(MX)]
dp[0] = 0
pow_6, pow_9 = [6], [9]
while True:
    flg = False
    if pow_6[-1]*6 <= MX:
        pow_6.append(pow_6[-1]*6)
        flg = True
    if pow_9[-1]*9 <= MX:
        pow_9.append(pow_9[-1]*9)
        flg = True
    
    if flg == False:
        break

for i in range(1, MX):
    tmp = [1]
    if i >= 6:
        x = bisect_right(pow_6, i)
        tmp.append(pow_6[x-1])
    if i >= 9:
        y = bisect_right(pow_9, i)
        tmp.append(pow_9[y-1])
    for t in tmp:
        dp[i] = min(dp[i], dp[i-t]+1)
print(dp[n])

Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;
class ParseError
{
};
int expr(State &begin);
int a, b, c, d;
int main()
{
    string S, P;
    while (cin >> S >> P)
    {
        if (S == ".")
            return 0;
        map<int, int> mp;
        State s = S.begin();
        a = P[0] - '0';
        b = P[1] - '0';
        c = P[2] - '0';
        d = P[3] - '0';
        int x = expr(s);
        int cnt = 0;
        for (int i = 0; i < 10000; i++)
        {
            s = S.begin();
            int k = i;
            a = k / 1000;
            b = (k / 100) % 10;
            c = (k / 10) % 10;
            d = k % 10;
            if (x == expr(s))
                cnt++;
        }
        cout << x << " " << cnt << endl;
    }
}
//パースして、その評価結果を返す。
int expr(State &begin)
{
    int res;
    if (*begin == '[')
    {
        begin++;
        int x, y;
        if (*begin == '+')
        {
            begin++;
            x = expr(begin);
            y = expr(begin);
            res = x | y;
        }
        else if (*begin == '*')
        {
            begin++;
            x = expr(begin);
            y = expr(begin);
            res = x & y;
        }
        else if (*begin == '^')
        {
            begin++;
            x = expr(begin);
            y = expr(begin);
            res = x ^ y;
        }
        begin++;
        return res;
    }
    if (*begin == 'a')
        res = a;
    else if (*begin == 'b')
        res = b;
    else if (*begin == 'c')
        res = c;
    else if (*begin == 'd')
        res = d;

    begin++;
    return res;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6+7;
const ll mod = 1e9 + 9;
#define afdafafafdafaf y1;
int ar[maxn], n, m;
int ans[maxn];
int f[maxn];

char ch[maxn];
int ins = 0;
int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", ar+i);
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++)ans += ar[i] * ar[j];
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 2304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(),l=s.nextInt();
        String arr[] = new String[n];
        for(int i=0;i<n;i++)arr[i]=s.next();
        Arrays.sort(arr);
        for(int i=0;i<n;i++) System.out.print(arr[i]);
        System.out.println();

    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25556
#-*- coding: UTF-8 -*-

n = int(input())

p = list(map(int, input().split()))
f = 0

for i in range(len(p) - 1):
    pi = p[i]
    if p[i] != i+1:
        if p[p[i] - 1] == i + 1:
            p[i], p[pi - 1] = p[pi - 1], p[i]
            f += 1
        else:
            f = 2

if 0 <= f <= 1:
    print("YES")
else:
    print("NO")


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

vector <ll> bamboo;
ll ans = LLONG_MAX;
ll n,A,B,C;

void func(ll index,ll a,ll b,ll c,ll cost) {
	if (index == bamboo.size()){
		if (a == 0 || b == 0 || c == 0) return;
		ans = min(ans,abs(A-a)+abs(B-b)+abs(C-c)+cost-30);
		return;
	}
	func(index+1,a+bamboo[index],b,c,cost+10);
	func(index+1,a,b+bamboo[index],c,cost+10);
	func(index+1,a,b,c+bamboo[index],cost+10);
	func(index+1,a,b,c,cost);
}

int main() {
	cin >> n >> A >> B >> C;
	bamboo.resize(n);
	for (int z=0;z<n;z++){
		cin >> bamboo[z];
	}
	func(0,0,0,0,0);
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=tuple(tuple(map(int,input().split())) for _ in range (m))
s=set()
t=set()
for i in range(m):
    if 1 in p[i]:
        s.add(p[i][0])
        s.add(p[i][1])
    if n in p[i]:
        t.add(p[i][0])
        t.add(p[i][1])
res=s&t
if res:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

int main(){
  int n;
  cin >> n;
 vector<pair<int,int>> an(n);
  for(int i=0;i<n;i++){
    int  a,b;
    cin >> b >> a;
    an[i] = make_pair(a,b);
  }
  sort(an.begin(),an.end());
  int time=0;
  for(int i=0;i<n;i++){
    time+=an[i].second;
    if(time>an[i].first){cout << "No" << endl;
                        return 0;}
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
d = a.copy()
for i in range(n-1):
    d[i+1] += d[i]
ans = 0
mod = 10**9+7
for i in range(n-1):
    ans += a[i]*(d[-1]-d[i])
    ans %= mod
print(ans)

Measured memory_bytes: 31596
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    n %= 10;
    if (3==n) {
        cout<<"bon"<<endl;
    } else if (0==n||1==n||6==n||8==n) {
        cout<<"pon"<<endl;
    } else {
        cout<<"hon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
# input
n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n-1]]

# calc
w_ls = {i+1: 0 for i in range(n)}
for a in a_ls:
	w_ls[a] += 1

# result
for i in range(n):
	print(w_ls[i+1])

Measured memory_bytes: 54432
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;


int main() {
	string w, t;
	cin >> w;
	for (auto & e : w) {
		if (e >= 'A' && e <= 'Z') e += 32;
	}
	int sum = 0;
	while (cin >> t) {
		for (auto & e : t) {
			if (e >= 'A' && e <= 'Z') e += 32;
		}
		if (t == w) sum++;
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3124
# coding=utf-8

if __name__ == "__main__":
    N = int(input())
    p_num = list(map(int, input().split()))

    is_change = [el1 for (el1, el2) in zip(p_num, range(1, len(p_num)+1)) if el1 != el2]

    if len(is_change) <= 2:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
//#include <limits>
//#include <type_traits>
//#include <boost/integer/common_factor_rt.hpp>
using namespace std;

int main(){

  long ans,sum;
  int i,j,N,M,Q;
  int a[50],b[50],c[50];
  long d[50]={};
  int e[10]={};
  bool can;
  can=true;
  //using T = int32_t;
  ans=0;
  sum=0;
  cin>>N>>M>>Q;
  for(i=0;i<Q;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }

  for(i=0;i<N;i++){
    e[i]=1;
  }
  
  for(;;){
    e[N-1]+=1;
    for(i=N-1;i>-1;i--){
      if(e[i]==M+1)e[i-1]+=1;
    }
    for(i=1;i<N;i++){
     if(e[i]==M+1)e[i]=e[i-1];
    }
    for(j=0;j<Q;j++){
      if((e[b[j]-1]-e[a[j]-1])==c[j])sum+=d[j];
    }
   if(ans<sum)ans=sum;
    sum=0;
    //cout<<e[0]<<" "<<e[1]<<" "<<e[2]<<" "<<e[3]<<" "<<e[4]<<" "<<e[5]<<" "<<e[6]<<" "<<e[7]<<" "<<e[8]<<" "<<e[9]<<endl;
    if(e[0]>(M/2))break;
   }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3172
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int a, b;
  string s, t, u;
  cin >> s;
  cin >> t;
  scanf("%d %d", &a, &b);
  cin >> u;

  if (u == s) {
    a -= 1;
  }

  if (u == t) {
    b -= 1;
  }

  cout << a << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int a,b,c;

int main() {
	scanf("%d%d",&a,&b);
	int num = 0 ;
	for(int i = 1 ; i <= 3 ; i++) {
		num = a*b*i;
		if(num % 2 == 1) {
			printf("Yes ");
			break;
		} else {
			printf("No");
			break;
		}
	} 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int alpha[27];
int main() {
  long long i,sum = 0,cnt = 1;
  string str;
  cin>> str;
  for(i = 0; str[i]; i++){
    alpha[str[i]-'a']++;
  }
  for(i = 0; i < 26; i++){
    cnt= alpha[i];
    if(cnt)sum-= (cnt*(cnt-1))/2;
  }
  i = str.size();
  sum+= (i*(i-1))/2;
  cout << sum+1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
//const int maxn=;
typedef long long ll;
int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=max(a*c,max(a*d,max(b*c,b*d)));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
long long n,m,dp[1007][1007];
char array1[1007][1007];
bool isvalid(int i,int j){
    return i>=0&&i<=n&&j>=0&&j<=m;
}
long long solve(int i,int j){
   if(i>n)
        return 0;
    if(j>m)
        return 0;
    if(array1[i][j]=='#')
        return 0;
    if(i==n-1&&j==m-1)
        return 1;
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    return dp[i][j]=((solve(i+1,j)%MOD)+(solve(i,j+1)%MOD))%MOD;
}
int main()
{
int i,j;
memset(dp,-1,sizeof(dp));
cin>>n>>m;
for(i=0;i<n;i++){
    for(j=0;j<m;++j){
        cin>>array1[i][j];
    }
}
printf("%lld",solve(0,0));





    return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100009];
int in[100009],dp[100009];
stack<int>s;
int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++) {
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		in[b]++;
	}
	for(int i=1;i<=n;i++)
		if(in[i]==0)
			s.push(i);
	while(!s.empty()) {
		int p=s.top();
		s.pop();
		for(int i=0;i<g[p].size();i++) {
			dp[g[p][i]]=max(dp[g[p][i]],dp[p]+1);
			in[g[p][i]]--;
			if(in[g[p][i]]==0) s.push(g[p][i]);
		}
	}
	int MAX=0;
	for(int i=1;i<=n;i++) MAX=max(MAX,dp[i]);
	cout<<MAX<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ote(x) cout<<(x)<<endl
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int a,b; cin>>a>>b;
	int count = 0;
	rp(i,a,b+1) if(i/10000 == i%10 && i%10000/1000 == i%100/10) count++;
	ote(count);
}

Measured memory_bytes: 256
/**
 * ??¨?¨????

??¨?¨??????????????°???????????????°???????????????????????????

??¨????????°r??¨?????°c???r ?? c
???????´????????????¨?????????????????§???????????¨??????????¨?????????\????????°????????¨???????????????????????°?????????????????????????????????

Input
???????????????r??¨c????????????????????§??????????????????????¶????r??????????????????c????????´??°????????????????????§?????????????????????

Output
(r+1) ?? (c+1)
?????°????????¨??????????????????????????????????????£???????????´??°????????????????????§????????£??????????????????????????????????????¨??????????????????????¨?????????????????????????????????¨??????????????????????¨?????????????????????????????????¨??¨??????????¨????????????\??????????????????

Constraints
1 ??? r, c ??? 100
0 ??? ????´? ??? 100
Sample Input
4 5
1 1 3 4 5
2 2 2 4 5
3 3 0 1 1
2 3 4 4 6
Sample Output
1 1 3 4 5 14
2 2 2 4 5 15
3 3 0 1 1 8
2 3 4 4 6 19
8 9 9 13 17 56
 */

#include <iostream>
#include <sstream>
#include <vector>

int main(int argc, char const *argv[]) {
  unsigned int r, c;
  std::string Param;
  std::istringstream iss;

  while (true) {

    getline(std::cin, Param);
    iss.str(Param);
    iss >> r >> c;
    iss.clear();

    if (r > 100 || r == 0 || c > 100 || c == 0) {
      std::cout << "Error: 1 <= r, c <= 100" << std::endl;
    } else {
      break;
    }
  }

  static std::vector<std::vector<unsigned int>> SpreadSheet(
      r + 1, std::vector<unsigned int>(c + 1, 0));
  unsigned short RowCount = 0;

  while (RowCount < r) {
    getline(std::cin, Param);
    iss.str(Param);
    for (size_t i = 0; i < c; i++) {
      iss >> SpreadSheet[RowCount][i];
      if (SpreadSheet[RowCount][i] > 100) {
        std::cout << "Error: 0 <= rci <= 100" << std::endl;
        break;
      } else {
        SpreadSheet[RowCount][c] += SpreadSheet[RowCount][i];
        SpreadSheet[r][i] += SpreadSheet[RowCount][i];
        SpreadSheet[r][c] += SpreadSheet[RowCount][i];
      }
    }
    RowCount++;
    iss.clear();
  }
  for (const auto &Row : SpreadSheet) {
    for (size_t i = 0; i <= c; i++) {
      std::cout << Row[i];
      if (i < c) {
        std::cout << " ";
      }
    }
    std::cout << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  int ans = min(N * A, B);

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    int n = 0, sn = 0;
    for(int i = 0; i < str.length(); i++) {
      int a = str.charAt(i) - '0';
      n = a + n * 10;
      sn += a;
    }
    System.out.println(((n % sn == 0) ? "Yes" : "No"));
  }
}

Measured memory_bytes: 22740
// copied
#include <cstdio>
static const int MAXH = 102;
static const int MAXN = MAXH * MAXH;

int n, m, k;
int a[MAXN];

int g[MAXH][MAXH] = {{ 0 }};

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

    int pos = 0;
    for (int i = 0; i < k; ++i) {
        scanf("%d", &a[i]);
        for (int j = pos; j < pos + a[i]; ++j) {
            int r = j / m, c = j % m;
            if (r & 1) c = m - 1 - c;
            g[r][c] = i + 1;
        }
        pos += a[i];
    }
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            printf("%d%c", g[i][j], j == m - 1 ? '\n' : ' ');

    return 0;
}


Measured memory_bytes: 1744
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		long ans = 1;
		for(int i = 0;i < N;i++) {
			ans = solve(ans,scn.nextLong());
		}
		System.out.println(ans);
	}

	public static long solve(long a, long b) {
		long A = Math.max(a, b), B = Math.min(a, b);
		while(A%B !=0) {
			long buf = A%B;
			A = B;
			B = buf;
		}
		return a/B*b;
	}
}


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

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
typedef long long ll;
typedef unsigned long long ull;
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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(a>b){a=b;return true;}return false;}

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define possible(n) cout<<((n)?"possible":"impossible")<<endl
#define Possible(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int r,g,b;
    cin>>r>>g>>b;
    YES(!((g*10+b)%4));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int INF = 1000000007;
 
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  int A, B, C;
  cin >> A >> B >> C;
  if(C - B == B - A){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;

}

Measured memory_bytes: 892
r, g, b, n = map(int, input().split())

dp = [0 for i in range(n+1)]
dp[0] = 1

for i in range(r, n+1, r):
    dp[i] = 1

for i in range(g, n+1):
    dp[i] += dp[i-g]

for i in range(b, n+1):
    dp[i] += dp[i-b]

print(dp[n])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int>> a,s;
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    a.push_back(make_pair(p,i));
    s.push_back(make_pair(p,i));
  }
  sort(s.begin(),s.end());
  reverse(s.begin(),s.end());
  int ans_first=s[0].first;
  int ans_first_index=s[0].second;
  int ans_second=s[1].first;
  int ans_second_index=s[1].second;
  for(int i=0;i<n;i++){
    int a_index=a[i].second;
    if(a_index==ans_first_index){
      cout<<ans_second<<endl;
    }else{
      cout<<ans_first<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 6544
#include<bits/stdc++.h>
#define int long long
#define ll int64_t
using namespace std;

const int M = 1e9+7;

vector<int> minp(1000005);
void soe() {
	for(int i = 0; i < 1000005; i++) minp[i] = i;
	for(int i = 2; i*i <= 1000005; i++) {
		if(minp[i] == i) {
			for(int j = i*i; j < 1000005; j += i) if(minp[j] == j) minp[j] = i;
		}
	}
}

map<int,int> lcm;
void pfact(int n) {
	map<int,int> map;
	while(n != 1) {
		map[minp[n]]++;
		n /= minp[n];
	}
	for(auto p:map) {
		lcm[p.first] = max(lcm[p.first] , p.second);
	}
}

int _power(int x , int p) {
	int res = 1;
	while(p) {
		if(p & 1) res = (res * x)%M;
		p /= 2;
		x = (x * x)%M;
	}
	return res;
}

int calc() {
	int res = 1;
	for(auto p:lcm) {
		res = (res * _power(p.first , p.second))%M;
	}
	return res;
}
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
	soe();
	int n;
	cin >> n;
	int a[n] , LCM = 1;
	for(int i = 0; i < n; i++) cin >> a[i] , pfact(a[i]);
	LCM = calc();
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int val = (LCM * _power(a[i] , M-2));
		ans = (ans + val)%M;
	}
	cout << ans << "\n";
		
    return 0;
}


Measured memory_bytes: 8832
de = true
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
edges = {}
(n-1).times do
  a, b = gets.chomp.split.map(&:to_i)
  edges[a] ||= []
  edges[a].push b
  edges[b] ||= []
  edges[b].push a
end
edges.default = []

edges.each do |k, vs|
  if vs.size == n - 1
    puts (1..n).to_a.join(' ')
    exit
  end
end

size1 = n / 3
size1 += 1 if n % 3 > 0
size2 = n / 3
size2 += 1 if n % 3 > 1
size3 = n / 3

q = [[1, 1]]

ans = Array.new(n+1)
visited = Set.new
until q.empty?
  node, layer = q.shift
  ans[node] = layer
  visited.add node

  layer = layer == 1 ? 2 : 1
  edges[node].each do |v|
    next if visited.include?(v)
    q.push [v, layer]
  end
end

count1 = count2 = count3 = 0
ans.shift

if ans.count{|e| e == 1} <= n/3 || ans.count{|e| e == 2} <= n/3
  target = ans.count{|e| e == 1} <= n/3 ? 1 : 2
  n.times do |i|
    if ans[i] == target
      ans[i] = count3 * 3 + 3
      count3 += 1
    end
  end
  n.times do |i|
    if ans[i] % 3 != 0
      if count1 < size1
        ans[i] = count1 * 3 + 1
        count1 += 1
      elsif count2 < size2
        ans[i] = count2 * 3 + 2
        count2 += 1
      else
        ans[i] = count3 * 3 + 3
        count3 += 1
      end
    end
  end
else
  n.times do |i|
    if ans[i] == 1
      if count1 == size1
        ans[i] = count3 * 3 + 3
        count3 += 1
      else
        ans[i] = count1 * 3 + 1
        count1 += 1
      end
    elsif ans[i] == 2
      if count2 == size2
        ans[i] = count3 * 3 + 3
        count3 += 1
      else
        ans[i] = count2 * 3 + 2
        count2 += 1
      end
    end
  end
end
puts ans.join(' ')

# p ans.sort


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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < ((int)n); ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;
    if (t.substr(0, (int)s.size()) == s) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

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

int main() {
    int N;
    cin >> N;
    int tb = 0, xb = 0, yb = 0;
    bool flg = true;
    REP(i,N){
        int t,x,y;
        cin >> t >> x >> y;
        int dt = t - tb, dx = x - xb, dy = y - yb;
        int pos = dt - abs(dx) - abs(dy);
        if ( pos < 0 or abs(pos) % 2 != 0 ) flg = false;
        tb = t;
        xb = x;
        yb = y;
    }
    
    if ( flg ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3528
import scala.util.Random.nextInt
import scala.math.BigInt
import scala.io.StdIn.readInt
object Main {
    def main(args: Array[String]): Unit = {
        val len = readInt()
        var ret = (1 to len).foldLeft(0) {(a, b) => 
            if (isPrime(readInt(), 50)) a + 1
            else a
        }
        println(ret)
    }
    def isPrime(n: Int, k: Int): Boolean = {
        if (n == 2) return true
        if (n == 1 || n % 2 == 0) return false
        
        def f1(dd: Int, ss: Int): (Int, Int) = {
            if (dd % 2 == 0) f1(dd / 2, ss + 1)
            else (dd, ss)
        }
        val (d, s) = f1(n - 1, 0)

        (1 to k).foreach { dummy1 =>
            var isPP = false
            val a = nextInt(n - 1) + 1

            var r = BigInt(a).modPow(d, n)
            if (r == BigInt(1) || r == BigInt(n - 1)) isPP = true

            (1 to s).foreach { dummy2 =>
                r = r.modPow(2, n)
                if (r == BigInt(n - 1)) isPP = true
            }

            if (!isPP) return false
        }
        return true
    }
}


Measured memory_bytes: 137008
#include <iostream>

using namespace std;
int main()
{
	int n;
	cin >>n;

	for (int i = 0; i <= 25; i++) {
		for (int j = 0; j <= 14;j++) {
			int total = 4 * i + 7 * j; // 合計金額
			if (n == total) {
				cout << "Yes" << endl;
				return 0;
			}
		}

	}
	cout << "No" << endl;
	return 0;
}

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

namespace SquareSearch
{
    class Program
    {
        static char GetCharOrDefault(string s, int index, char defaultChar)
        {
            if (s.Length <= index)
            {
                return defaultChar;
            }

            return s[index];
        }



        static bool SearchSquare(string line, int[] lengthOfRow, int targetSquareLength)
        {
            var isFound = false;

            var count = 0;
            for (var i = 0; i < lengthOfRow.Length; ++i) { 
                if (GetCharOrDefault(line, i, ' ')  != '*') {
                    ++lengthOfRow[i];
                }
                else {
                    lengthOfRow[i] = 0;
                }

                if (targetSquareLength <= lengthOfRow[i])
                {
                    ++count;
                    if (targetSquareLength <= count)
                    {
                        isFound = true;
                    }
                }
                else
                {
                    count = 0;
                }
            }

            return isFound;
        }


        static void Main(string[] args)
        {

            var answer = new List<int>();

            while (true) 
            {
                var input = Console.ReadLine();
                var rank = 0;
                {
                    if (int.TryParse(input, out rank) == false)
                    {
                        break;
                    }

                    if (rank == 0)
                    {
                        break;
                    }
                }

                var lengthOfRow = new int[rank];
                var targetSquareLength = 1;

                for (var i = 0; i < rank; ++i)
                {
                    var column = Console.ReadLine();
                    if (SearchSquare(column, lengthOfRow, targetSquareLength))
                    {
                        ++targetSquareLength;
                    }
                }
                answer.Add(targetSquareLength - 1);
            }

            foreach (var n in answer) {
                Console.WriteLine(n);
            }
        }
    }
}

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

#define oo ll(1e16)
#define maxn 200005
#define block 400

using namespace std;
typedef long long ll;

int n, q, a, b;
ll d[maxn];
ll L[maxn], R[maxn];

ll ret = 0;

ll get(int st, int en, int ok) {
  ll ret = oo;

  for (int i = st; i <= en;)
    if (i % block == 1 && i + block <= en + 1) {
      ret = min(ret, (ok ? L[(i - 1) / block] : R[(i - 1) / block]));
      i += block;
    }
    else {
      ret = min(ret, d[i] + (ok ? -i : i));
      ++i;
    }

  return ret;
}

int main(){
  ios_base::sync_with_stdio(0);

  cin >> n >> q >> a >> b;

  fill(d + 1, d + n + 1, oo);
  fill(L, L + n + 1, oo);
  fill(R, R + n + 1, oo);

  d[b] = 0;
  L[(b - 1) / block] = -b;
  R[(b - 1) / block] = b;

  while (q--) {
    int x;
    cin >> x;

    ll tem = min(get(1, x, 1) + x, get(x, n, 0) - x);

    d[a] = min(d[a], tem - abs(x - a));

    int bl = (a - 1) / block;

    L[bl] = oo;
    R[bl] = oo;

    for (int i = max(bl * block + 1, 1); i <= bl * block + block && i <= n; ++i) {
      L[bl] = min(L[bl], d[i] - i);
      R[bl] = min(R[bl], d[i] + i);
    }

    ret += abs(x - a);

   // for (int i = 1; i <= n; ++i) cerr << d[i] + ret << ' '; cerr << "\n\n";

    a = x;
  }

  ll ma = 0;
  for (int i = 1; i <= n; ++i)
    ma = min(ma, d[i]);

  cout << ma + ret;

  return 0;

}


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

int main() {
  int x;
  cin >> x;
  int f_reminder = x % 500;
  int fh = (x - f_reminder) / 500;
  int s_reminder = f_reminder % 5;
  int f = (f_reminder - s_reminder) / 5;
  int answer = (fh * 1000) + (f * 5);
  cout << answer;
};

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll cal(ll b, ll n)
{
  ll ret = 0;
  while (n > 0) {
    ret += (n % b);
    n /= b;
  }
  return ret;
}

int main()
{
  ll N, S; scanf("%lld %lld", &N, &S);

  if (S >= N) {
    printf("%lld\n", (S == N) ? N + 1 : -1);
    return 0;
  }

  for (ll b = 2; b * b <= N; ++b) {
    if (cal(b, N) == S) {
      printf("%lld\n", b);
      return 0;
    }
  }

  ll val = N - S;
  ll ans = LLINF;
  for (ll p = 1; p * p <= val; ++p) {
    if (val % p != 0) { continue; }
    ll b = val / p + 1;
    if (cal(b, N) == S) { ans = min(ans, b); }
  }
  printf("%lld\n", ans == LLINF ? -1 : ans);
  return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}

ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

        
//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  ll K;cin>>K;
  ll cnt=1;
  ll sv=7;
  ll now= sv%K;
  if(K==1||K==7){
    cout<< 1<<endl;
  }
  else{bool ok=false;
  for(int i=0;i<=K;i++){
     
     now = (now*10+7)%K;
     cnt++;
     if(now==0){
       ok=true;
       break;
     }
  }
  if(ok)cout<<cnt<<endl;
  else cout<<-1<<endl;
      }
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x, y; cin >> n >> x >> y;
    if (x > y) swap(x, y);
    auto calc = [&](int i, int j) {
        int ret = j - i;
        ret = min(ret, abs(i-x) + 1 + abs(j-y));
        ret = min(ret, abs(i-y) + 1 + abs(j-x));
        return ret;
    };

    vector<int> ans(n, 0);
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            ans[calc(i, j)]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256