akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll H, W, D;
    cin >> H >> W >> D;
    auto table = make_vec_nd((ll)0, W, H);
    rep(h,0,H) {
        rep(w,0,W) {
            cin >> table[w][h];
            table[w][h]--;
        }
    }
    struct P {
        ll x;
        ll y;
    };
    vector<P> id_to_coord(W*H);
    rep(h,0,H) {
        rep(w,0,W) {
            id_to_coord[table[w][h]] = P{w, h};
        }
    }
    auto mp = make_vec_nd((ll)0, D, W*H/D+1);
    rep(start,0,D) {
        for (ll n = 1; start + D * n < W * H; n++) {
            ll dest = start + D * n;
            ll prev = start + D * (n-1);
            P dest_p = id_to_coord[dest];
            P prev_p = id_to_coord[prev];
            ll dist = abs(dest_p.x - prev_p.x) + abs(dest_p.y - prev_p.y);
            mp[start][n] = mp[start][n-1] + dist;
        }
    }
    ll Q;
    cin >> Q;
    rep(q,0,Q) {
        ll L, R;
        cin >> L >> R;
        L--;
        R--;
        cout << mp[R%D][R/D] - mp[L%D][L/D] << endl;
    }
}



Measured memory_bytes: 7552
// #include <bits/stdc++.h>
#include <iostream>
#include <ctime>
#include <vector>
#include <algorithm>

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

using namespace std;
using ll = long long;

void solve() {
    string s;
    cin >> s;
    vector <char> words = {'A', 'C', 'G', 'T'};
    int answer = 0, cur = 0;

    for (int i = 0; i < s.size(); ++i) {
        if(find(all(words),s[i])!=words.end()) {
            ++cur;
            answer = max(cur, answer); 
        }
        else cur = 0;
    }
    cout << answer << endl;
}

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

#ifndef ONLINE_JUDGE
    double st = clock();
#endif

    solve();

#ifndef ONLINE_JUDGE
    // cerr <<"\ntime = " <<  (clock() - st)/CLOCKS_PER_SEC << endl;
#endif 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int A,B,K; cin >> A >> B >> K;
    VI div;
    for(int i = 100; i > 0; i--)
    {
        if(A%i == 0 && B % i == 0) div.push_back(i);
    }
    cout << div[K-1] << endl;



}


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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

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

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

signed main() {
    i64 x;
    cin >> x;
    auto a = x / 500;
    x %= 500;
    auto b = x / 5;
    auto ans = a * 1000 + b * 5;
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long H, long long W, long long N){
  ll m=max(H,W);
  cout<<N/m+(N%m?1:0)<<endl;
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long N;
    scanf("%lld",&N);
    solve(H, W, N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> v[200010];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		int u,vv;
		scanf("%d %d",&u,&vv);
		v[u].push_back(vv);
		v[vv].push_back(u);
	}
	for(int i=0;i<v[1].size();i++){
		int g=v[1][i];
		for(int j=0;j<v[g].size();j++){
			if(v[g][j]==n){
				puts("POSSIBLE");
				return 0;
			}
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  bool res = false;
  for (int i = 0; i < S.size(); i++){
    if (S == T) res = true;
    S = S[S.size() - 1] + S.substr(0,S.size() - 1);
  }
  cout << (res ? "Yes" : "No");
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

M = [H[:]]

a = 0
while M!=[]:
	m = M.pop(0)
	a += min(m)
	s = list(map(lambda x:x-min(m), m))

	start = 0
	for i in range(len(s)):
		if s[i]==0:
			t = s[start:i]
			start = i+1
			if t!=[]: M.append(t)

	t = s[start:]
	if t!=[]: M.append(t)

print(a)

Measured memory_bytes: 3064
//#pragma warning(disable : 4996)
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<fstream>
#include<stdio.h>
#include<map>
#include<set>
#include<limits.h>
#include<list>
#include <cassert>
#include<sstream>
#include<locale>
#include <bitset>
using namespace std;
using ll = long long int;

int main() {
	long long  n, ans;
	cin >> n;
	for(int i=sqrt(n);i>0;--i)
		if (n % i == 0)
		{
			cout << (i + (n / i) - 2) << endl;
			break;
		}
	return 0;
} 





Measured memory_bytes: 3672
#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.at(i) != T.at(i)) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3916
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  double k=0;
  rep(i,a){
  k+=b[i];
  }
  k/=a;
  double m=INF;
  rep(i,a){
  if(abs(k-b[i])<m)
    m=abs(k-b[i]);
  }
  int j;
  rep(i,a){
  if(abs(k-b[i])==m){
    j=i;
    break;
  }
  }
  out(j);
}


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

int main() {
	long long dp[100010][4] = {};
	string s;
	cin >> s;
	int N = s.size();
	long MOD = 1000000007;
	for (int i = N; i >= 0; --i) {
		for (int j = 3; j >= 0; --j) {
			if (i == N) {
				dp[N][3] = 1;
			}
			else {
				dp[i][j] = dp[i + 1][j] * (s[i] == '?' ? 3 : 1);
				if (j < 3 && (s[i] == "ABC"[j] || s[i] == '?')) {
					dp[i][j] += dp[i+1][j+1];
				}
			}
			dp[i][j] %= MOD;
		}
	}
	cout << dp[0][0] << endl;
}

Measured memory_bytes: 3584
N = int(input())
A = list(map(int, input().split()))

mod = int(1e9+7)

CNT = [0] * (N+10)
CNT[-1] = 3
ans = 1
for a in A:
  CNT[a] += 1
  ans *= CNT[a-1]
  ans %= mod
  CNT[a-1] -= 1

print(ans)

Measured memory_bytes: 20668
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 1000005
#define INF 1000000000
#define MOD 1000000007
#define print(cs) printf("Case %lld:\n",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
int main()
{
    ll i,j,k,l,n,m,r;
    in(n);
    ll arr[n];
    unordered_map<ll,ll>visit;
    for(i=0;i<n;i++)
    {
        in(arr[i]);
        visit[arr[i]]++;
    }
    ll cnt=0;
    if(visit[1LL])
    {
        if(visit[1]==1)puts("1");
        else puts("0");
        exit(0);
    }
    for(i=0;i<n;i++)
    {
        if(visit[arr[i]]>1)continue;
        bool ok=false;
        for(j=2;j*j<=arr[i];j++)
        {
            if(arr[i]%j==0&&(visit[j]||visit[arr[i]/j]))
            {
                ok=true;
                break;
            }
        }
        if(!ok)cnt++;
    }
    out(cnt);endl;
}


Measured memory_bytes: 33248
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define inf 1e8

using namespace std;

int n, m, s[202][202], h[202][202], dp[1024][202], l[1024];

int main()
{
	int i, j, k, x, y, z;
	char c[2];
	while (scanf("%d%d", &n, &m) && (n || m))
	{
		for (i = 1; i <= n; i++)
		{
			fill(h[i], h[i] + n + 1, inf);
			fill(s[i], s[i] + n + 1, inf);
			fill(dp[i], dp[i] + n + 1, inf);
			h[i][i] = s[i][i] = 0;
		}
		for (i = 0; i < m; i++)
		{
			scanf("%d%d%d%s", &x, &y, &z, c);
			if (c[0] == 'L')
			{
				h[y][x] = min(h[y][x], z);
				h[x][y] = h[y][x];
			}
			else
			{
				s[y][x] = min(s[y][x], z);
				s[x][y] = s[y][x];
			}
		}
		for (k = 1; k <= n; k++)
			for (i = 1; i <= n; i++)
				for (j = 1; j <= n; j++)
				{
					h[i][j] = min(h[i][j], h[i][k] + h[k][j]);
					s[i][j] = min(s[i][j], s[i][k] + s[k][j]);
				}
		scanf("%d", &m);
		for (i = 0; i < m; i++)
			scanf("%d", &l[i]);
		for (j = 1; j <= n; j++)
			dp[0][j] = s[l[0]][j] + h[j][l[0]];
		for (i = n; i <= m; i++)
			fill(dp[i], dp[i] + n + 1, inf);
		for (i = 1; i < m; i++)
		{
			for (j = 1; j <= n; j++)
			{
				for (k = 1; k <= n; k++)
				{
					if (j != k)
						dp[i][k] = min(dp[i][k], dp[i-1][j] + h[l[i-1]][j] + s[j][k] + h[k][l[i]]);
					else
						dp[i][k] = min(dp[i][k], dp[i-1][k] + h[l[i-1]][l[i]]);
				}
			}
		}
		printf("%d\n", *min_element(dp[m-1] + 1, dp[m-1] + n + 1));
	}
	return 0;
}

Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll x, y;
    cin >> x >> y;
    if (y % 2 != 0)
    {
        ce("No");
    }
    else
    {
        if (y >= x * 2 && y <= x * 4)
        {
            ce("Yes");
        }
        else
        {
            ce("No");
        }
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> D(H);
  rep(i, H)
  {
    string s;
    cin >> s;
    D.at(i) = s;
  }
  rep(i, W + 2) cout << "#";
  cout << endl;
  rep(i, H)
  {
    cout << "#" << D.at(i) << "#" << endl;
  }
  rep(i, W + 2) cout << "#";
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string.h>
using namespace std;

main()
{
	int n,m;
	cin>>n;
	if(n<=9)m=n;
	else if(n<=99)m=n%10;
	else m=n%10%10;
	switch(m){
		case 2:case 4:case 5:case 7:case 9:cout<<"hon";break;
		case 0:case 1:case 6:case 8:cout<<"pon";break;
		case 3:cout<<"bon";break;
	}
	return 0;
}

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

int main() {
    int64_t n;
    cin >> n;
    vector<vector<int64_t>> g(n, vector<int64_t>(n));
    for (auto& e : g) for (auto& f : e) cin >> f;
    
    bitset<90000> c;
    for (int64_t i = 0; i < n; i++) {
        for (int64_t j = 0; j < n; j++) {
            for (int64_t k = j + 1; k < n; k++) {
                if (g[j][k] == g[j][i] + g[i][k] && i != j && j != k && k != i) {
                    c.set(j*n+k);
                } else if (g[j][k] > g[j][i] + g[i][k]) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    int64_t ans = 0;
    for (int64_t i = 0; i < n; i++) {
        for (int64_t j = i + 1; j < n; j++) {
            if (!c[i*n+j]) ans += g[i][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int k = sc.nextInt();

		if(n<k) {
			for(int i =0;i<k;i++) {
				System.out.print(n);
			}
		}else {
			for(int i =0;i<n;i++) {
				System.out.print(k);
			}
		}
		System.out.println("");

	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;


int main(void) {
	string s;
	cin >> s;
	int eng[30] = { 0 };
	REP(i, s.size()) {
		eng[s[i] - 96]++;
	}
	for (int i = 1; i<=26;i++) {
		if (eng[i] == 0) {
			printf("%c\n", i + 96);
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

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

typedef long long ll;

int main(){
    string S;
    cin >> S;
    int len = S.size();
    int ans = 0;
    for (int i=0;i<len-1;i++){
        if (S[i] == S[i+1]){
            if (S[i+1] == '1'){
                S[i+1] = '0';
            }else{
                S[i+1] = '1';
            }
            ans += 1;
        }
    }
    ans = min(ans, len - ans);
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long n,s;
long long count(long long b){
    long long ans=0,val=n;
    while(val){
        ans+=val%b;
        val/=b;
    }
    return ans;
}
signed main(){
    cin >> n >> s;
    for(long long i=2;i*i<=n;i++){
        if(count(i)==s){
            cout << i;
            return 0;
        }
    }
    for(long long i=sqrt(n)-1;i>=1;i--){
        if(i>s){
			continue;
		}
        long long tmp = n - (s - i);
        if((tmp % i) != 0){
			continue;
		}
        if((tmp / i) <= (s - i)){
			continue;
		}
        if((tmp / i) == 1){
			continue;
		}
        cout << tmp / i;
        return 0;
    }
    if(s == 1){
        if(n == 1) cout << 2;
        else cout << n;
        return 0;
    }
    if(s == n){
        cout << n + 1;
        return 0;
    }
    cout << -1;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  int i=0;
  if(A<=B){
    while(i<B){
      cout << A;
    i++;
    }
  }
  else if(A >=B){
    while(i<A){
      cout << B;
    i++;
    }
  }  
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,x;
    cin >> n >> x;
    int l[n];
    for (int i=0; i < n; i++){
        cin >> l[i];
    }

    int cnt = 1;
    int sum = 0;
    for(int i=0; i<n; i++){
        sum += l[i];
        if(sum <= x){
            cnt += 1;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

bool isPrime(int x) {
    if (x == 1) return false;
    if (x == 2) return true;
    if (x%2 == 0) return false;
    int i = 3;
    while (i <= sqrt(x)) {
        if (x%i == 0) return false;
        i += 2;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int t; cin >> t;
        sum += isPrime(t);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3096
import Data.List

modulus :: Integer
modulus = 10^9 + 7

fact :: Integral a => a -> a
fact n = f n 1
  where
    f 0 b = b
    f a b = b `seq` f (a - 1) (a * b)

factorization :: Integral a => a -> [a]
factorization 1 = []
factorization n = v : factorization (n `div` v)
  where
    factors x = [i | i <- [1..x], x `mod` i == 0]
    v = factors n !! 1

solve :: Integer -> Integer
solve n = foldl f 1 . group . factorization $ fact n
  where
    lengthI = fromIntegral . length
    f a g = a * (lengthI g + 1) `mod` modulus

main :: IO ()
main = do
    n <- readLn :: IO Integer
    print $ solve n

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

struct LowestCommonAncestor{
    const int MAX_LOG_V = 50;
    vector<vector<int> > G, parent;
    int root = 0, V;
    vector<int> depth;
    LowestCommonAncestor(int _V){
        V = _V;
        G.resize(V);
        parent.resize(MAX_LOG_V, vector<int>(V));
        depth.resize(V);
    }
    void add_edge(int u, int v){
        G[u].push_back(v);
        G[v].push_back(u);
    }
    void dfs(int v, int p, int d){
        parent[0][v] = p;
        depth[v] = d;
        for(int i = 0; i < G[v].size(); i++){
            if(G[v][i] != p) dfs(G[v][i], v, d + 1);
        }
    }
    void build(){
        dfs(root, -1, 0);
        for(int k = 0; k + 1 < MAX_LOG_V; k++){
            for(int v = 0; v < V; v++){
                if(parent[k][v] < 0) parent[k + 1][v] = -1;
                else parent[k + 1][v] = parent[k][parent[k][v]];
            }
        }
    }
    int query(int u, int v){
        if(depth[u] > depth[v]) swap(u, v);
        for(int k = 0; k < MAX_LOG_V; k++){
            if((depth[v] - depth[u]) >> k & 1){
                v = parent[k][v];
            }
        }
        if(u == v) return u;
        for(int k = MAX_LOG_V - 1; k >= 0; k--){
            if(parent[k][u] != parent[k][v]){
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];    
    }
};

int main(){
    int n;
    cin >> n;
    LowestCommonAncestor lca(n);
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int c;
            cin >> c;
            lca.add_edge(i, c);
        }
    }
    lca.build();
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int u, v;
        cin >> u >> v;
        cout << lca.query(u, v) << endl;
    }
}


Measured memory_bytes: 31152
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n;
cin>>n;
if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) cout<<"hon";
else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) cout<<"pon";
else cout<<"bon";
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3612
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();

		long x = n;

		long g1 = a*x/b;
		long g2 = x/b;
		long g = g1 - a*g2;

		while ( x/b==n/b && x>0 && x/b>0 ) {
			x = x - x%b -1l;
		}

		g1 = a*x/b;
		g2 = x/b;
		g = Math.max(g, g1 - a*g2);

		System.out.println(g);
	}
}

Measured memory_bytes: 35724
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    char a, b; cin >> a >> b;
    if(a == b) cout << "H\n";
    else cout << "D\n";
    return 0;
}

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

using namespace std;

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

int getval(string str){
	
	int ret = 0;
	int st=1;
	rep(i,str.size()){
		if(str[i]=='m'){
			ret+=st*1000;
			st=1;
		}
		if(str[i]=='c'){
			ret+=st*100;
			st=1;
		}
		if(str[i]=='x'){
			ret+=st*10;
			st=1;
		}
		if(str[i]=='i'){
			ret+=st*1;
			st=1;
		}
		if(str[i]>='2' && str[i]<='9'){
			st = str[i]-'0';
		}
	}
	
	return ret;
}

string getstr(int num){
	
	string ret = "";
	int st;
	st = num/1000;
	if(st!=0){
		if(st!=1)ret += char('0'+st);
		ret += 'm';
	}
	num%=1000;
	
	st = num/100;
	if(st!=0){
		if(st!=1)ret += char('0'+st);
		ret += 'c';
	}
	num%=100;
	
	st = num/10;
	if(st!=0){
		if(st!=1)ret += char('0'+st);
		ret += 'x';
	}
	num%=10;
	
	st = num;
	if(st!=0){
		if(st!=1)ret += char('0'+st);
		ret += 'i';
	}
	
	return ret;
}

int main(){
	int n;
	cin>>n;
	
	rep(i,n){
		string s1,s2;
		cin>>s1>>s2;
		
		int val = getval(s1)+getval(s2);
		cout<<getstr(val)<<endl;
	}
}

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

int main()
{
  long long n;
  cin >> n;
  
  long long ans = 0;
  for(int i = 1; i <= n; ++i)
  {
    ans += (i % 3 != 0 && i % 5 != 0 ? i : 0);
  }
  
  cout << ans << endl;
}


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

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

using namespace std;

int main(){
  string s;
  cin >> s;
  int ptr = -1, ptr2 = -1;
  rep(i,(int)s.size()) {
    if( ptr == -1 && s[i] == 'C' ) {
      ptr = i;
    }
  }
  for(int i=(int)s.size()-1;i>=0;--i) {
    if( ptr2 == -1 && s[i] == 'F') {
      ptr2 = i;
    }
  }
  if( ptr != -1 && ptr2 != -1 && ptr < ptr2 ) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll a,b,c,d;
cin>>a>>b>>c>>d;
int turn=1;
while(c>0&&a>0){
	if(turn==1){
	turn^=1;
	c=c-b;
}
	else{
		turn^=1;
	a=a-d;
}
	
}
if(turn==0)
cout<<"Yes";
else
cout<<"No";




}


Measured memory_bytes: 3632
#include<cstdio>
int main()
{
	int n,m,x,l=0,r=0;
	scanf("%d%d%d",&n,&m,&x);
	for(int i=1;i<=m;i++)
	{
		int t;scanf("%d",&t);
		if(t<x) l++;else r++;
	}
	printf("%d\n",l<r?l:r);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int
ascend(const void *a, const void *b)
{
  ll x = *(ll *)a, y = *(ll *)b;
  if (x > y) return 1;
  if (x < y) return -1;
  return 0;
}

int
main(int argc, char *argv[])
{
  int n;
  ll a[100010];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

  qsort(a, n, sizeof(ll), ascend);

  ll ans = 0;

  if (n % 2 == 0) {
    for (int i = 0; i < n / 2 - 1; i++) {
      ans -= 2 * a[i];
    }
    ans -= a[n / 2 - 1];
    ans += a[n / 2];
    for (int i = n / 2 + 1; i < n; i++) ans += 2 * a[i];
  } else {
    for (int i = 0; i < n / 2; i++) ans -= 2 * a[i];
    for (int i = n / 2 + 1; i < n; i++) ans += 2 * a[i];
    ans += Max(a[n / 2] - a[n / 2 + 1], a[n / 2 - 1] - a[n / 2]);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> arr;
typedef vector<arr> matrix;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;
typedef map<int, arr> graph;
typedef vector<char> chararr;
typedef vector<chararr> charmat;
typedef pair<int, int> fraction;
ll MOD = 1000000007;
int n;
vector<vector<bool> > match(21, vector<bool>(21, false));
ll dp[21][1 << 21];

ll fun(int r , int mask) {
	if (r == n && mask == ((1 << n) - 1)) return 1;
	else if (r == n) return 0;
	ll &ans = dp[r][mask];
	if (ans != -1) return ans;
	ans = 0;
	for (int c = 0; c < n; ++c) {
		if (((1 << c)&mask) == 0) {
			if (match[r][c]) ans = (ans + fun(r + 1, mask | (1 << c))) % MOD;
		}
	}
	return ans;
}
int main() {



	cin >> n;
	int x;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> x;
			if (x == 1) match[i][j] = true;

		}
	}

	memset(dp, -1, sizeof(dp));
	cout << fun(0, 0);
}

Measured memory_bytes: 347620
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define ld long double
#define vii vector<ii>
#define vll vector<ll>
#define maxn -879879

template<typename T>
void trace(T a){ cout << a << '\n';}
template<typename T, typename... Args>
void trace(T a, Args ...args){ cout << a << ' '; trace(args...);}

int main(){
	int n,k;
	cin >> n >> k;
	trace(n%k);
 	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<61;
int iinf=1<<30;
double pi=3.14159265358979323846;
double pi2=pi/2.0;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    ll l[n];
    rep(i,0,n)cin>>l[i];
    sort(l,l+n);
    int ans=0;
    rep(i,0,n){
        rep(j,i+1,n){
            rep(k,j+1,n){
                if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i])continue;
                if(l[k]<l[i]+l[j])ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3664
n, k = map(int, input().split())

cnt = 0
cnt += ((n - 2) // 11) * 5#(n - 1) -2 + 1
for i in range(2 + ((n - 2) // 11) * 11, n):
    for j in range(2, 6 + 1):
        if 9 * (7 * (i - 1) + j) % 11 == k:
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main()
{
    int i,n;
    double ax, ay, ar;
    double bx, by, br;
    double dist;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lf %lf %lf", & ax, & ay, & ar);
        scanf("%lf %lf %lf", & bx, & by, & br);
        dist = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
        if(dist>ar+br) {
            printf("0\n");
        }
        else if(dist==ar==br){
            printf("1\n");
        }
        else if(dist<ar-br&&ar>br) {
            printf("2\n");
        }
        else if(dist<br-ar&&ar<br) {
            printf("-2\n");
        }
        else {
            printf("1\n");
        }
    }
    return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
double pi=3.1415926535898;
//double pi=acos(-1.0);
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define rng(i,a,b) for(int i=a;i>=int(b);i--)
#define rep(i,a,b) for(int i=a;i<=int(b);++i)
#define lop(i,n)   for(int i=0;i<int(n);i++)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define pii        pair<int,int>
#define pis        pair<int,string>
#define vi         vector<int>
#define xx         first
#define yy         second
//#define max(a,b) a<b?b:a  __builtin_popcount;
//#define min(a,b) a<b?a:b  freopen("output.txt","w",stdout),freopen("input.txt","r",stdin);
const ll M  = 1e9+7 ;
const int N = 50500;
const int X = 0x7f7f7f7f;
const double eps = 1e-4;
//////////////////////    Hi    ^_^  hack me if you can :P
ll g(ll x,ll y)
{
    ll r = 0;
    if(x>y)
    {
        x=-x;
        r=1;
    }
    r+=abs(y-x);
    return r;
}
int main()
{
    speed;
    ll x,y;
    cin>>x>>y;
    if(x==y)
    {
        cout<<0;
        r0;
    }
    if(x==-y)
    {
        cout<<1;
        r0;
    }
    cout<<min({g(x,y),g(-x,y)+1,g(x,-y)+1,g(-x,-y)+2});
    r0;
}

/*

https://ideone.com/goT6Vy//http:
codeforces.com/problemset/problem/466/D

, vector < pair <int,int > >, greater <pair <int, int> >
http://codeforces.com/contest/295/submission/17929453
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);

ll pwmod(ll a, ll n, ll mod)
{
    ll ret = 1;
    while (n)
    {
        if (n & 1) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return ret;
}

for (int i=0; i<n; i++)            Hi    ^_^  hack me if you can :P

int mx[]= {0,0,1,-1, 1,1,-1,-1};
int my[]= {1,-1,0,0, 1,-1,1,-1};
bool inside (int i,int j){return (i>=0 && i<n && j>=0 && j<m);}

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void gcd(LL n,LL m,LL &d,LL &xx,LL &yy)
{
    if(!m)
    {
        d=n;
        xx=1;
        yy=0;
    }
    else
    {
        gcd(m,n%m,d,yy,xx);
        yy-=xx*(n/m);
    }
}

int getm(int l,int r)
{
    if(l>r)
        return N;
    if(l==r)
        return 0;
    if(l==r-1)
        return s[l] != s[r];
    if(s[l]==s[r])
        return getm(l+1,r-1);
    else
        return 1+min(getm(l+1,r),getm(l,r-1));
}

int BIT[si], a[si], n;
void update(int x, int delta)
{
    for(; x <= N; x += x&-x)
        BIT[x] += delta;
}
int query(int x)
{
    int sum = 0;
    for(; x > 0; x -= x&-x)
        sum += BIT[x];
    return sum;
}

#define sc(x)      scanf("%d",&x)
#define scl(x)     scanf("%lld",&x)
#define pr(x)      printf("%d ",x)
#define prl(x)     printf("%lld ",x)
#define prln(x)    printf("%d\n",x)
#define prlln(x)   printf("%lld\n",x)
#define scd(x)     scanf("%lf",&x)
#define prd(x)     printf("%.10f\n",x)


*/


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
  string s;
  cin >> s;
  const int n = s.size();
  char c = s[n / 2];
  for (int l = (n - 1) / 2, r = n / 2; l >= 0; --l, ++r) {
    if (s[l] != c || s[r] != c) {
      cout << r << endl;
      return 0;
    }
  }
  cout << n << endl;
	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	ll ans = 0;
	int t = n - 1;
	rep(i, n) {
		int lim = 2;
		if  (i == 0) lim = 1;
		rep(j, lim) {
			if (t > 0) {
				ans += a[i];
				--t;
			}
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4044
#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;
// char alphabet[26] = {'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'};
void swap(int* a,int* b){
    int temp = *a;
    *a=*b;
    *b=temp;
}	
int32_t main(){
 	fastIO;
 	int n;cin>>n;
 	int ans=0;
 	ans+=(n/500)*1000;
 	n=n%500;
 	ans+=(n/5)*5;
 	cout<<ans<<endl;
} 	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    sort(v.rbegin(),v.rend());
    //rep(i,n) cout << v[i] << " ";
    //cout << endl;
    ll sum = v[0];
    int cnt = 1;
    int id = 1;
    for(int i = 2; i < n; i++){
        if(cnt%3 == 0){
            id++;
            cnt = 1;
        }
        sum += v[id];
        cnt++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4852
import sys
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    edge[x-1].append(y-1)
dp = [-1]*N

def calc(x):
    if dp[x]!=-1:
        return dp[x]
    if not len(edge[x]):
        dp[x] = 0
        return 0
    dp[x] = max([calc(i) for i in edge[x]])+1
    return dp[x]

ans = 0
for i in range(N):
    if dp[i] != -1: continue
    ans = max(ans, calc(i))
print(ans)

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

namespace ConsoleApp15
{
    class Class311
    {
        static string[] Words = new string[4] { "dream", "dreamer", "erase", "eraser" };
        static void Main()
        {
            string S = Console.ReadLine();
            var dp = new bool[S.Length + 1];
            List<int> lastlist = new List<int>();
            List<int> newlist = new List<int>();
            lastlist.Add(0);
            while (lastlist.Count>0)
            {
                foreach(int i in lastlist)
                {
                    for(int j = 0; j < 4; j++)
                    {
                        if(i+Words[j].Length<=S.Length)
                        {
                            if (Words[j] == S.Substring(i, Words[j].Length))
                            {
                                newlist.Add(i + Words[j].Length);
                            }
                        }
                    }
                }
                lastlist = new List<int>(newlist);
                newlist = new List<int>();
                if(lastlist.Contains(S.Length))
                {
                    Console.WriteLine("YES");return;
                }
            }
            Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 17756
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

    

n=int(input())
A=list(map(int,str.split(input())))
q = int(input())
m=list(map(int,str.split(input())))




mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print("no")
        continue
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

Measured memory_bytes: 7772
import std.stdio,std.range,std.algorithm,std.conv,std.array,std.string;

void main()
{
    int[1000] field;
    int[1000] dice;

    while(true)
    {
        auto input=readln.split;
        int N=input[0].to!int;
        int M=input[1].to!int;
        if(N==0&&M==0)break;

        foreach(i; 0..N)
        {
            field[i]=readln.chomp.to!int;
        }
        foreach(i; 0..M)
        {
            dice[i]=readln.chomp.to!int;
        }

        int i, cur;
        while(true)
        {
            cur+=dice[i++];
            if(cur >= N - 1) break;
            cur+=field[cur];
            if(cur >= N - 1) break;
        }
        i.writeln;
    }
}

Measured memory_bytes: 1056
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	bool f = s.size() % 2 == 1;
	bool g = s[0] == s.back();
	bool h = f^g;
	dump(f, g, h);
	cout << (h ? "First" : "Second") << endl;
	return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		b[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		c[i] = nextInt()
	}
	sort.Ints(a)
	sort.Ints(b)
	sort.Ints(c)

	ia := 0
	ic := 0
	var ans int64

	for ib := 0; ib < n; ib++ {
		for ia < n && b[ib] > a[ia] {
			ia++
		}
		for ic < n && c[ic] <= b[ib] {
			ic++
		}
		ans += int64(ia) * int64(n-ic)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6016
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

int main(void) {
	int a,b,k;
	cin >> a >> b >> k;
	for(int i=0; i<k; i++){
		if(i%2==0){
			if(a%2==1)a--;
			b+=a/2;
			a/=2;
		}
		else {
			if(b%2==1)b--;
			a+=b/2;
			b/=2;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}

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

using namespace std;

int main(){
  int n, k, d[109], a[109][109];
  map<int, int> m;
  cin >> n >> k;
  for(int i=0;i<k;i++){
    cin >> d[i];
    for(int j=0;j<d[i];j++){
      cin >> a[i][j];
      m[a[i][j]]++;
    }
  }
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(m[i]==0)cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3644
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int a,b,ten=10,sum;
    double tmp;
    cin >> a >> b;
    while(ten<=b){
        ten *= 10;
    }
    sum = a * ten + b;
    tmp = sqrt(sum);
    tmp = (int)tmp * (int)tmp;
    if(sum==tmp){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256