akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <cmath>
#include <iomanip>

using namespace std;

void solve (int i, long long ans);

int MAX_N = 200005;

long int N;
long long a[200005];
long long b[200005] = {0};

int main()
{
    cin >> N;
    long long ans = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        b[a[i]] += 1;
    }

    for (int i = 0; i < N+1; i++)
    {
        if (b[i] >= 2)
        {
            ans += b[i] * (b[i]-1) / 2;
        }
    }

    for (int i = 0; i < N; i++)
    {
        solve(i,ans);
    }
    return 0;
}

void solve (int i, long long ans)
{
    long long temp = ans;
    if (b[a[i]] >= 3)
    {
        temp = temp - b[a[i]] * (b[a[i]]-1) / 2 + (b[a[i]]-1) * (b[a[i]]-2) / 2;
    } else if (b[a[i]] == 2)
    {
        temp = temp - b[a[i]] * (b[a[i]]-1) / 2;
    }
    cout << temp << endl;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

ll solve()
{
    ll N, K;

    std::cin >> N >> K;

    N = N % K;

    ll minValue = N;
    unordered_set<ll> seen;

    while (minValue != 0 && seen.count(N) == 0) {

        seen.insert(N);
        N = abs(N - K);
        minValue = min(minValue, N);
    }

    cout << minValue << endl;

    return 0;
}

int main()
{
//    std::cout << solve() << std::endl;
    solve();

    return 0;
}

Measured memory_bytes: 256
def f(m):
    return 0 if m < 2 else m * (m-1) // 2

def solve(n, a):
    D = {}
    for x in a:
        if not x in D:
            D[x] = 0
        D[x] += 1
    total = 0
    for x, num in D.items():
        total += f(num)
    for x in a:
        num = D[x]
        print(total - f(num) + f(num-1))

n = int(input())
a = list(map(int, input().split()))
solve(n, a)

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 105;
int sum[N];
int n;

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        cin >> n;
        set<pii> s;
        range(i,1,n)range(j,i+1,n){
            sum[i] += j;
            sum[j] += i;
            s.insert({i,j});
        }

        bool flag = false;
        if(n&1)flag = true;
        range(i,1,n)rloop(j,n-flag){
            if(j == i)break;
            if(sum[i] - j == sum[j] - i){
                s.erase({i,j});
                sum[i] -= j;
                sum[j] -= i;
            }
        }

        range(i,1,n)assert(sum[1] == sum[i]);
        cout << SZ(s) << endl;
        for(auto p : s){
            cout << p.fr << " " << p.sc << endl;
        }



    return 0;
}


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

typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

string S, T, U;
int A, B;

int main() {
	cin >> S >> T >> A >> B >> U;
	if (S == U)A--;
	else B--;
	cout << A << sp << B << endl;
}

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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main(){
    int k;
    int n;
    cin >> k;
    n = 7;
    int c = 1;
    while(n%k != 0){
        c++;
        n*=10;
        n+=7;
        n%=k;
        if(c>=10000000){
            cout << -1;
            return 0;
        }
    }
    cout << c;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3620
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
const int BG = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<string> S(n);
    rep(i, n) cin >> S[i];

    string ans = S[0];
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < ans.size(); j++)
        {
            int flag = 1;
            for (int l = 0; l < S[i].size(); l++)
            {
                if (ans[j] == S[i][l])
                {
                    S[i][l] = '0';
                    flag = 0;
                    break;
                }
            }
            if (flag)
            {
                ans[j] = '1';
            }
        }
    }
    string a;
    for (char i : ans)
    {
        if (i != '1')
        {
            a.push_back(i);
        }
    }
    sort(a.begin(), a.end());
    cout << a << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string W;
int main(){
	cin>>W;

	int A[26]={};
	for(int i=0;i<W.size();i++){
		A[W[i]-97]++;
	}

	string ans="Yes";
	for(int i=0;i<26;i++){
		if(A[i]%2!=0)ans="No";
	}

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


Measured memory_bytes: 384
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = a * (a-1) + b * (b-1);
        ans /= 2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
import sys
input = sys.stdin.readline

N = int(input())
S = []
for _ in range(N):
    S.append(input().rstrip())

from collections import Counter

c = Counter(S)

ans = []

max_count = max(c.values())

for i in c:
    if c[i] == max_count:
        ans.append(i)
ans.sort()

for j in ans:
    print(j)

Measured memory_bytes: 90568
<?php
  fscanf(STDIN, "%d", $n);
  $nums = explode(' ', trim(fgets(STDIN)));
  $ans = 1;

  if (in_array(0, $nums)) {
    echo 0;
    return;
  }

  for ($i = 0; $i < $n; $i++) {
    $ans *= $nums[$i];
  }

  if ($ans > pow(10, 18)) {
    $ans = -1;
  }

  echo $ans;

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int N;
    string S;
    cin >> S;
    N = S.size();

    int ans = 0;
    int cnt = 0;
    rep(i, N)
    {

        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
        {
            cnt++;
            ans = max(ans, cnt);
        }
        else
        {
            cnt = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N - 1);

	for (auto &x : A) {
		cin >> x;
		--x;
	}

	for (auto &x : B) {
		cin >> x;
	}

	for (auto &x : C) {
		cin >> x;
	}

	int ans = 0;

	int p = N;
	for (int i : A) {
		ans += B[i];
		if (p + 1 == i) {
			ans += C[p];
		}
		p = i;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
      cout<<"bust"<<endl;
    }
    else{
      cout<<"win"<<endl;
    }
}

Measured memory_bytes: 256
def fact(n, k, mod):
    res = 1
    for i in range(k):
        res = res * (n - i) % mod
    return res

def c(x, y, mod):
    y = min(x, x - y)
    return (fact(x, y, mod) * pow(fact(y, y, mod), mod - 2 , mod)) % mod

P = 10**9 + 7
X, Y = map(int, input().split())
if (X + Y) % 3 > 0:
    print(0)
    exit()
n = (X + Y) // 3
x = X - n
y = Y - n
if 0 > x or 0 > y:
    print(0)
    exit()
print(c(x + y, x, P))

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

int main(){
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0; i < S.size(); ++i){
        if(S[i] != T[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
};

typedef vector<vector<Edge>> Graph;

void connect(Graph& g, int f, int t, int w = 1) {
	g[f].push_back({ f,t, w });
	g[t].push_back({ t,f, w });
}
signed main(void) {

	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n)cin >> a[i];
	vector<int> ans;
	while (a.size()) {
		bool ok = false;
		for (int i = a.size() - 1; 0 <= i; i--) {
			if (i + 1 == a[i]) {
				ans.push_back(i + 1);
				a.erase(a.begin() + i);
				ok = true;
				break;
			}
		}

		if (ok == false) {
			cout << -1 << endl;
			return 0;
		}
	}
	reverse(ALL(ans));
	for (auto itr : ans) {
		cout << itr << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int main(void)
{
  int N,a,b,c;
  //read
  scanf("%d",&N);
  //check
  a = N/100;
  b = (N-a*100)/10;
  c = N%10;
  //write
  //printf("%d,%d,%d,%d",N,a,b,c);
  if(a-7==0||b-7==0||c-7==0)
  {
	printf("Yes");
   }else{
  	printf("No");
  }
  return 0;
  

}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[300000],b[300000];
ll sum[300000];

int main(){
	int n,m,K;cin>>n>>m>>K;
	rep(i,n)scanf("%d",&a[i]);
	rep(i,m)scanf("%d",&b[i]),sum[i+1]=sum[i]+b[i];
	ll A=0;
	int Max=0;
	int id=upper_bound(sum,sum+m+1,K)-sum;
	Max=max(Max,id-1);
	rep(i,n){
		A+=a[i];
		if(A>K)break;
		int id=upper_bound(sum,sum+m+1,K-A)-sum;
		Max=max(Max,i+1+id-1);
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define FOR(i,a,b) for(ll i=(a); i<(b); ++i)
inline ll in() { ll x; cin >> x; return x; }

#define int ll
void solve() {
  int n = in(), k = in();
  int r = in(), s = in(), p = in();
  string t; cin >> t;
  vi win(n, 0);

  int ans = 0;
  FOR (i,0,n) {
    if (i>=k && t[i-k]==t[i] && win[i-k]) continue;

    if (t[i]=='r') ans+=p;
    if (t[i]=='s') ans+=r;
    if (t[i]=='p') ans+=s;

    win[i] = 1;
  }

  cout << ans << endl;
}

#undef int
int main() {
  solve();
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K,X;
  cin>>K>>X;
  FOR(i,X-K+1,X+K-1){
    cout<<i<<' ';
  }
  cout<<X+K-1<<endl;
}


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

namespace _1600
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                int[] point = new int[x[0]];
                for (int i = 0; i < x[0]; i++) point[i] = int.Parse(Console.ReadLine());
                int max = 0; int ret = 0;
                for (int i = x[1]; i <= x[2]; i++)
                {
                    if (max <= point[i - 1] - point[i])
                    {
                        max = point[i - 1] - point[i];
                        ret = i;
                    }
                }
                Console.WriteLine(ret);
            }
        }
    }
}


Measured memory_bytes: 9820
A, B, C, X, Y = map(int, input().split())
a1 = A * X + B * Y
a2 = B * (Y - X) + C * 2 * X
a3 = A * (X - Y) + C * 2 * Y
a4 = a3 if X > Y else a2
a5 = C * 2 * max(X, Y)
ans = min(a1, a4, a5)
print(ans)


Measured memory_bytes: 3060
program answer
  implicit none
  integer :: i, n, ans
  integer, allocatable :: d(:)
  read(*,*) n
  allocate(d(n))
  read(*,*) d
  call msort(d)

  ans=d(n/2+1)-d(n/2)
  write(*,*) ans

  deallocate(d)
  stop
contains
  recursive subroutine msort(array)
    implicit none
    integer :: i, j, k, n, mid, array(:)
    integer, allocatable :: tmp(:)
    n=size(array)
    allocate(tmp(n))
    if(n==1) then
       return
    end if
    mid=n/2
    call msort(array(1:mid))
    call msort(array(mid+1:n))
    tmp=array
    do i = mid+1, n
       tmp(i)=array(mid+1+n-i)
    end do
    i=1
    j=n
    do k = 1, n
       if(tmp(i)>=tmp(j)) then
          array(k)=tmp(j)
          j=j-1
       else
          array(k)=tmp(i)
          i=i+1
       end if
    end do
    deallocate(tmp)
    return
   end subroutine msort
 end program answer

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

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

    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);
    vector<bool> b(N);
    vector<ll> c(N);

    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }

    ll pos = 0;
    ll count = 0;

    while(true) {
        if(count == K) {
            cout << pos + 1LL << endl;
            return 0;
        }
        if(b[pos]) {
            K -= c[pos];
            K %= (count - c[pos]);
            break;
        }
        b[pos] = true;
        c[pos] = count;
        pos = A[pos];
        count++;
    }

    for(ll i = 0; i < K; i++) {
        pos = A[pos];
    }

    cout << pos + 1LL << endl;
}

Measured memory_bytes: 6372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)


int main() {

int S; cin >> S ;

ll ans=0;

numrep(i,S){
  if(i%3!=0&&i%5!=0) ans+=i;
}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    ld tmp;
    cin >> N;
    vector<ll> A(N);
    vector<vector<ll>> B(40,vector<ll>(40));
    rep(i,N){
        cin >> tmp;
        A[i] = ll(tmp*1e9+0.5);
    }
    rep(i,N){
        ll cnt2 = 0;
        ll cur = A[i];
        while(cur % 2 == 0){
            cnt2++;
            cur /= 2;
        }
        ll cnt5 = 0;
        while(cur % 5 == 0){
            cnt5++;
            cur /= 5;
        }
        B[cnt2][cnt5]++;
    }
    ll ans = 0;
    map<Pll,ll> mp;
    rep(i,40){
        REP(k,0,40){
            REP(j,0,40){
                REP(l,0,40){
                    if(Pll(i,k) > Pll(j,l)) continue;
                    if(i+j < 18 || k+l < 18) continue;
                    if(i==j && k==l){
                        ans += (B[i][k]*(B[j][l]-1))/2;
                    }else{
                        ans += B[i][k]*B[j][l];
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S, Sfront;
    int Q;
    bool isReversed = false;
    
    cin >> S >> Q;
    vector<int> T(Q), F(Q);
    deque<char> C(Q);
    for(int i=0;i<Q;i++){
        cin >> T.at(i);
        if(T.at(i)==2){
            cin >> F.at(i) >> C.at(i);
        }
    }

    for(int i=0;i<Q;i++){
        if(T.at(i)==1){
            //reverse(S.begin(),S.end());
            isReversed = !isReversed;
        }else{
            if(F.at(i)==1){
                if(isReversed){
                    S += C.at(i);
                }
                else{
                    //S = C.at(i) + S;
                    Sfront += C.at(i);
                }
                
            }else{
                if(isReversed){
                    //S = C.at(i) + S;
                    Sfront += C.at(i);
                }
                else{
                   S += C.at(i);
                }
            }
        }
    }
	
    reverse(Sfront.begin(),Sfront.end());
  
    S = Sfront + S;

    if(isReversed) reverse(S.begin(),S.end());
    
    cout << S << endl;
}

Measured memory_bytes: 3032
N,M=map(int,input().split())
def f(n):
  ans = 1
  i = 1
  while i <= n:
    ans = (ans * i)%(10**9+7)
    i += 1
  return ans
if abs(N-M) >= 2:
  print(0)
if abs(N-M) == 1:
  t = max(N,M) 
  print((f(t)*f(t-1))%(10**9+7))
if N == M:
  print(((2*f(N)**2)%(10**9+7)))


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int N = S.length();
  if (4 <= N && S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var i string
  fmt.Scan(&i)
  switch i {
  case "SUN":
    fmt.Println("7")
  case "MON":
    fmt.Println("6")
  case "TUE":
    fmt.Println("5")
  case "WED":
    fmt.Println("4")
  case "THU":
    fmt.Println("3")
  case "FRI":
    fmt.Println("2")
  case "SAT":
    fmt.Println("1")
  default:
    return
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
vector<int> v1,v2;
int x1=0,x2=0,y1=0,y2=0;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int t;
		cin >>t;
		if (i%2) v2.push_back(t);
		else v1.push_back(t);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	int ta=0,tta=-1,ba=0;
	for (int i=0;i<v1.size();i++)
	{
		if (v1[i]!=tta)
		{
			if (ta>x1) x2=x1,x1=ta,ba=tta;
			else if (ta>x2) x2=ta;
			ta=1,tta=v1[i];
		}
		else ta++;
	}
	if (ta>x1) x2=x1,x1=ta,ba=tta;
	else if (ta>x2) x2=ta;
	int tb=0,ttb=-1,bb=0;
	for (int i=0;i<v2.size();i++)
	{
		if (v2[i]!=ttb)
		{
			if (tb>y1) y2=y1,y1=tb,bb=ttb;
			else if (tb>y2) y2=tb;
			tb=1,ttb=v2[i];
		}
		else tb++;
	}
	if (tb>y1) y2=y1,y1=tb,bb=ttb;
	else if (tb>y2) y2=tb;
	//cout <<x1<<" "<<y1<<" "<<ba<<" "<<bb<<"\n";
	if (ba!=bb) cout <<n-x1-y1;
	else
	{
		if (x1-x2<y1-y2) cout <<n-y1-x2;
		else cout <<n-x1-y2;
	}
	return 0;
} 

Measured memory_bytes: 892
#!/usr/bin/env python3
import sys
from decimal import Decimal as D

input = sys.stdin.readline


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


A, B = MI()

for i in range(1, 2501):
    a = int(D(i) * D("0.08"))
    b = int(D(i) * D("0.1"))

    if A == a and B == b:
        print(i)
        exit()

print(-1)


Measured memory_bytes: 9736
n,c,k = [int(x) for x in input().split()]
l = []
for x in range(n):
    num = int(input())
    second = num+k;
    l.append([num,second])

cnt = 1
pas = 1;
l = sorted(l,key=lambda x:x[1])
hold = l[0];
for x in range(1,n):
    if l[x][0] <= hold[1]:
        if pas == c:
            cnt += 1
            pas = 1
            hold = l[x]
        else:
            pas += 1
        pass
    else:
        cnt+= 1
        hold = l[x]
        pas = 1
print(cnt)


Measured memory_bytes: 22104
#include <algorithm>
#include <iostream>

using namespace std;

const int kMaxN = 200001;

struct V {
  long long x, y, _y;
  bool operator<(const V &v) const { return x < v.x; }
} v[kMaxN];

long long p[kMaxN], a[2][kMaxN], ans;
int n;

void D() {
  sort(p + 1, p + 1 + n, [](int i, int j) { return v[i].y < v[j].y; });
  v[p[1]]._y = 1;
  for (int i = 2; i <= n; i++) {
    v[p[i]]._y = v[p[i - 1]]._y + (v[p[i]].y != v[p[i - 1]].y);
  }
}

int L(int x) { return x & -x; }

long long F(int t, int x) {
  long long mx = -(1LL << 40);
  for (; x; x -= L(x)) {
    mx = max(mx, a[t][x]);
  }
  return mx;
}

void I(int t, int x, long long v) {
  for (; x <= n; x += L(x)) {
    a[t][x] = max(a[t][x], v);
  }
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i].x >> v[i].y;
    p[i] = i;
    a[0][i] = a[1][i] = -(1LL << 40);
  }
  sort(v + 1, v + 1 + n);
  D();
  for (int i = 1; i <= n; i++) {
    ans = max(ans, F(0, v[i]._y) + v[i].x + v[i].y);
    ans = max(ans, F(1, n - v[i]._y + 1) + v[i].x - v[i].y);
    I(0, v[i]._y, -v[i].x - v[i].y);
    I(1, n - v[i]._y + 1, -v[i].x + v[i].y);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 13004
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 21;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    Yes(a+b == c || b+c == a || c+a == b);
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c,d,e,f,g,i;
    e=0,f=0,g=0;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        e=a+b+c+d;
        g=e/60;
        f=e%60;
        printf("%d\n%d\n",g,f);

return 0;
}

Measured memory_bytes: 596
#include<iostream>

using namespace std;

typedef pair<int,int> P;
const int MAX = 20;
P pos;
char m[MAX][MAX];
int r,c;

void input(){
  for(int i = 0; i < r; i++)
    for(int j = 0; j < c; j++){
      cin >> m[i][j];
      if(m[i][j] == '<' || m[i][j] == '>' || 
	 m[i][j] == '^' || m[i][j] == 'v') pos = P(i,j);
    }
}

bool inside(P p){
  return (0 <= p.first && p.first < r && 0 <= p.second && p.second < c);
}

void shoot(char c){

  int x = 0, y = 0;
  P p = pos;
  if(c == '^') y = -1;
  if(c == 'v') y = 1;
  if(c == '>') x = 1;
  if(c == '<') x = -1;

  while(1){
    p.first += y;
    p.second += x;
    if(!inside(p)) break;
    if(m[p.first][p.second] == '#') break;
    if(m[p.first][p.second] == '*'){
      m[p.first][p.second] = '.';
      break;
    }
  }
}

void move(char c, int x, int y){
  if(inside(P(pos.first+y,pos.second+x)) && m[pos.first+y][pos.second+x] == '.'){
    m[pos.first][pos.second] = '.';
    m[pos.first+y][pos.second+x] = c;
    pos.first += y;
    pos.second += x;
  }else{
    m[pos.first][pos.second] = c;
  }
}

int main(){
  bool flag = false;
  int X;
  cin >> X;
  while(X--){
    if(flag) cout << endl;
    flag = true;

    cin >> r >> c;
    input();
    int num;
    cin >> num;
    for(int i = 0; i < num; i++){
      char c;
      cin >> c;
      if(c == 'S') shoot(m[pos.first][pos.second]);
      if(c == 'U') move('^',0,-1);
      if(c == 'D') move('v',0,1);
      if(c == 'L') move('<',-1,0);
      if(c == 'R') move('>',1,0);
    }

    for(int i = 0; i < r; i++){
      for(int j = 0; j < c; j++)
	cout << m[i][j];
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

vector<string> split(const string& src, char dlm) {
	istringstream iss(src);

	string s;
	vector<string> res;
	while (getline(iss, s, dlm)) {
		res.push_back(s);
	}

	return res;
}

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

	string S;  cin >> S;
	int N = S.size();
	int ALL = pow(2, N - 1);
	vs exps;

	FOR(i, 0, ALL) {
		int t = i;
		string ts = { S[0] };
		FOR(j, 1, N) {
			if (t & 0x01) ts += "+";
			ts += S[j];
			t >>= 1;
		}
		exps.push_back(ts);
	}

	ll ans=0;
	for (string exp : exps) {
		vs tms  = split(exp, '+');
		for (auto tm : tms) {
			ans += stoll(tm);
		}
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int divisors(int n) {
    int divs = 0;
    repSE(i, 1, int(sqrt(n))+1) {
        if (n % i == 0) {
            divs ++;
            if (i != n / i) {
                divs ++;
            }
        }
    }
    return divs;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    repSE(i,1,n+1) {
        if (i%2 == 1 && divisors(i) == 8) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()

ostream& operator<<(ostream& o, vector<ll> &A){
    FOR(i, 0, A.size()){
        if(i){
            o << ' ';
        }
        o << A[i];
    }
    o << endl;
    return o;
}

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

    vector<ll> A;
    FOR(i, 0, N){
        A.push_back(i+1);
    }

    do{
        cout << A;
    }while(next_permutation(ALL(A)));

    return 0;
}


Measured memory_bytes: 3168
S = input()
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else:
    print(1)

Measured memory_bytes: 3060
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let a: Vec<i64> = (0..m).map(|_| iter.next().unwrap().parse().unwrap()).collect();
    let total: i64 = a.into_iter().sum();

    if total <= n as i64 {
        println!("{}", n as i64 - total);
    }else {
        println!("{}", -1);
    }
}


Measured memory_bytes: 2136
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <iostream>

using namespace std;
const int maxx = 1e3 + 10;
int x[maxx];

int main()
{
    int n,k,a;
    bool vis;
    while(cin>>n>>k)
    {
        for(int i=0; i<k; i++)
        {
            cin>>a;
            x[a]++;
        }
        while(n)
        {
            vis = true;
            int c = n;
            while(c)
            {
                int a = c % 10;
                c /= 10;
                if (x[a])
                {
                    vis = false;
                    break;
                }
            }
            if (vis)
                break;
            n++;
        }
        cout << n << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 357, 375, 537, 573, 735, 753
        // 3357, 3375, 3537, 3557, 3573, 3575, 3577

        long N = scanner.nextInt();
        long num = 357;
        int count = 0;
        while (num <= N) {
            if (is753(String.valueOf(num))) {
                count++;
            }
            num = Long.valueOf(next753(String.valueOf(num)));
        }

        System.out.println(count);
    }

    static String next753(String s) {
        char[] array = s.toCharArray();
        int index = array.length - 1;
        while (true) {
            char c = array[index];
            if (c == '3') {
                array[index] = '5';
                break;
            } else if (c == '5') {
                array[index] = '7';
                break;
            } else {
                array[index] = '3';
                index--;
                if (index == -1) {
                    return "3" + String.valueOf(array);
                }
            }
        }
        return String.valueOf(array);
    }

    static boolean is753(String s) {
        return s.indexOf('3') != -1
                && s.indexOf('5') != -1
                && s.indexOf('7') != -1;
    }

}


Measured memory_bytes: 30420
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    while (q--) {
        int b, e, t;
        cin >> b >> e >> t;
        for (int i = 0; i < e-b; ++i) {
            swap(a[b+i], a[t+i]);
        }
    }
    rep(i, n) cout << a[i] << (i == n-1 ? '\n' : ' ');
}



Measured memory_bytes: 3144
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

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


int n,s;
int ans=0;
int a[100];
//int dp[12][12][10][120] = {0};

int solve(int n,int c,int d,int s){
	if(c==n){
		if(s<=9&&s>=d){
			//cout<<"s="<<s<<endl;
			/*rep(i,n-1){
				cout<<a[i+1]<<" ";
			}
			cout<<s<<endl;*/
			ans++;
		}
	}
	else{
		//cout <<"d = "<< d <<endl;
		for(int i=d;i<10;i++){
			//cout<<"i = "<<i<<endl;
			a[c] = i;
			solve(n,c+1,i+1,s-i);
		}
	}
	return ans;
}
	
	

int main(){
	while(cin>>n>>s,!(n==0&&s==0)){
		ans = 0;
		rep(i,100) a[i] = 0;
		//cout<<n<<" "<<s<<endl;
		//solve(n,n,s);
		//dp[n][1][1][s] = solve(n,n,1,s);
		cout << solve(n,1,0,s) <<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
	int n, p, am, pm, i, ban,gou,mos=0;
	while (1)
	{
		scanf("%d", &n);
		if (n == 0)
			break;
		for (i = 0; i < n; i++)
		{
			scanf("%d %d %d", &p, &am, &pm);
			gou = am + pm;
			if (mos < gou)
			{
				mos = gou;
				ban = p;
			}
		}
		printf("%d %d\n", ban, mos);
		mos = 0;
	}
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,pair<int,int> >  p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};


int main(){
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='o') count++;
    }
    int n=(int)s.size();
    n=15-n;
    if(count+n>=8) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}



Measured memory_bytes: 256
import numpy as np
from itertools import combinations

h, w, k = list(map(int, input().split()))
c = np.array([list(input()) for i in range(h)])

temp = list(range(h))
dh = ["No"]
for i in range(1, h+1):
    dh += combinations(temp, i) 

temp = list(range(w))
dw = ["No"]
for i in range(1, w+1):
    dw += combinations(temp, i) 

cnt = (c == "#").sum()
ans = 0
for dhh in dh:
    for dww in dw:
        error = 0
        if dhh != "No":
          for i in dhh:
            error += (c[i, :] == "#").sum()
        if dww != "No":
          for j in dww:
            error += (c[:, j] == "#").sum()
        if dhh != "No" and dww != "No":
          for i in dhh:
            for j in dww:
              if c[i, j] == "#":
                    error -= 1
        
        if cnt - error == k:
            ans += 1
print(ans)
    
    


Measured memory_bytes: 27296
#include<stdio.h>

int main()
{
    long long int a,b,sum=0,cnt=0;

    while(scanf("%lld %lld",&a,&b)==2)
    {
        sum=a+b;
        cnt=0;
        while(sum)
        {
            sum=sum/10;
            cnt++;
        }

        printf("%lld\n",cnt);
    }

    return 0;
}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>




	


int main()
{
	int i,t,k,Ans=0,s=0,d,j,N,D,x[10][10];

	

	scanf("%d %d", &N, &D);

	for (j = 0; j < N; j++) {
		for (i = 0; i < D; i++) scanf("%d", &x[j][i]);
	}

	for (j = 0; j < N-1; j++) {
		for (k = j+1; k < N; k++) {

			s = 0;

			for (i = 0; i < D; i++) {
				d = x[j][i] - x[k][i];

				s = s + d * d;
			}

			for (t = 0; t <= 40* sqrt(D); t++) {
				if (s == t * t) {
					Ans++;
				}
			}
		}
	}
	
	printf("%d\n", Ans);

}


Measured memory_bytes: 128
import numpy as np

N = int(input())
A = np.zeros(N, np.int32)
for i in range(N):
  A[i] = int(input())

A_asc = np.sort(A)
max1 = A_asc[-1]
max2 = A_asc[-2]

for a in A:
  if a == max1:
    print(max2)
  else:
    print(max1)

Measured memory_bytes: 15564
#define ll long long int

#include <bits/stdc++.h>

using namespace std;

int main() {

    int N;
    cin >> N;
    map<ll, int> mp;

    for (int x = 1; x * x <= N; x++) {

        for (int y = 1; y * y <= N - (x * x); y++) {

            for (int z = 1; z * z <= N - ((x * x) + (y * y)); z++) {

                mp[((x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x))]++;
            }
        }
    }
    for (int i = 1; i <= N; i++)cout << mp[i] << endl;


    return 0;
}

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

typedef signed long long ll;
const int MX = 1e6 + 5;

int main() {
	int n, m;
	cin >> n >> m;
	string A = "", B = "";
	for(int i = 0; i < n; A.push_back('0' + m), i++);
	for(int i = 0; i < m; B.push_back('0' + n), i++);

	if(A < B) cout << A << endl;
    else cout << B << endl;
    return 0;
}

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

long long gcd(long x, long y)
{
    if (y == 0)
        return x;

    return gcd(y, x % y);
}
long long lcm(long x, long y)
{
    return x * y / gcd(x, y);
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

int main()
{
    string S;
    cin>>S;

    for(int i=2;i<S.length();i+=2){

        string temp=S.substr(0,S.length()-i);

        int x=S.length()-i;
        x/=2;

        if(temp.substr(0,x)==temp.substr(x)){
            cout<<S.length()-i<<endl;
            return 0;
        }


    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N;
  cin>>N;
  bool ok = 1;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    if(A%2 == 0)
    {
      if(A%3 ==0 || A%5 == 0)
      {

      }
      else
      {
        ok = 0;
      }
      
    }
  }
  cout<<(ok?"APPROVED":"DENIED")<<endl;
  
  
  
  return;
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256