akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2*100000)
n, m = map(int,input().split())
mark = [-2] * (n-1)
dist = [0] * (n-1)
path = [[] for _ in range(n-1)]
path0 = []

for _ in range(m):
    a, b = map(lambda x: int(x)-2, input().split())
    if a == -1:
        path0.append(b)
        dist[b] = 1
        mark[b] = -1
    elif b == -1:
        path0.append(a)
        dist[a] = 1
        mark[a] = -1
    else:
        path[a].append(b)
        path[b].append(a)

while len(path0) > 0:
    i = path0.pop(0)
    d = dist[i]
    for p in path[i]:
        if dist[p] > d + 1 or dist[p] == 0:
            dist[p] = d + 1
            mark[p] = i
            path0.append(p)

print("Yes")
for i in mark: print(i+2)


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

int  N;
int A[200010];
int B[200010];

si nexts;

int ii(int i) {
  return (i+N)%N;
}

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

  cin >> N;
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> B[i];
  rep(i,N) {
    if(B[i] > A[i] && B[ii(i-1)] < B[i] && B[ii(i+1)] < B[i]) nexts.insert(i); 
  };
  ll ans = 0;
  while(nexts.size()) {
    int i = *(nexts.begin());
    ll diff = B[i] - max(A[i], max(B[ii(i-1)], B[ii(i+1)])) - 1;
    ll down = (B[ii(i-1)] + B[ii(i+1)]);
    ll cc = diff/down + 1;
    ans += cc;
    B[i] -= down * cc;
    if (B[i]<A[i]) {
      cout << "-1\n";
      return 0;
    }
    int i1 = ii(i-1);
    int i2 = ii(i+1);
    nexts.erase(i);
    if(B[i1] > A[i1] && B[ii(i1-1)] < B[i1] && B[ii(i1+1)] < B[i1]) nexts.insert(i1); 
    if(B[i2] > A[i2] && B[ii(i2-1)] < B[i2] && B[ii(i2+1)] < B[i2]) nexts.insert(i2); 
  }
  rep(i,N) {
    if (A[i]!=B[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{

    int a;
    int b;
    long long answer=0;
    //    int n[101];
    int data[1001];


    scanf("%d", &a);
    scanf("%d", &b);

    for (int i = 0; i < a; i++)
    {
        scanf("%d", &data[i]);//データ

    }

    qsort(data,a, sizeof(int), compare_int);

    for (int i = 0; i < b; i++)
    {
        answer += (long long)data[i];
    }
    printf("%lld",answer);

    printf("\n");
}

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

int d;

int main() {
  cin >> d;
  if(d == 22)
    cout << "Christmas Eve Eve Eve" << endl;
  else if(d == 23)
    cout << "Christmas Eve Eve" << endl;
  else if(d == 24)
    cout << "Christmas Eve" << endl;
  else
    cout << "Christmas" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

vector<bool> searched(200000, 0);
vector<ll> memo(200000, 0);
vector<vector<int>> edge(200000, vector<int>(0));

void update(int cur){
  if (searched[cur])
    return;


  searched[cur] = 1;
  for (int i = 0; i < edge[cur].size(); i++){
    if (!searched[edge[cur][i]]){
      memo[edge[cur][i]] += memo[cur];
      update(edge[cur][i]);
    }
  }

  return;
}

int main(void){
  int n, q;
  cin >> n >> q;

  int a, b;
  for (int i = 0; i < n - 1; i++){
    cin >> a >> b;
    a--; b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }


  ll p, x;
  for (int i = 0; i < q; i++){
    cin >> p >> x;
    p--;
    memo[p] += x;
  }

  update(0);

  for (int i = 0; i < n; i++){
    cout << memo[i] << " ";
  }
  cout << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 24320
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    string ans = "Yes";
    REP(i,26)
    {
        char c = 'a' + i;
        set<char> x;
        REP(j,s.size())
        {
            if(s[j] == c)x.insert(t[j]);
        }
        if(x.size() > 1)
        {
            ans = "No";
            break;
        }

        x.clear();
        REP(j,t.size())
        {
            if(t[j] == c)x.insert(s[j]);
        }
        if(x.size() > 1)
        {
            ans = "No";
            break;
        }
    }
    PUTS(ans);
}

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

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

	int K, S;
	cin >> K >> S;
	int ans = 0;
	for(int i = 0; i <= K; i++) {
		int rem = S - i;
		if(rem < 0) continue;
		if(rem <= K) ans += rem + 1;
		else if(rem <= 2 * K) ans += 2 * K - rem + 1;
	}
	cout << ans << endl;
}

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

ave = sum(a)/N
ans = 0
dif = 1e+3
for i in range(N):
    if abs(a[i] - ave) < dif:
        ans = i
        dif = abs(a[i] - ave)

print( ans )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string sa,sb,ans;
int f[3010][3010];
int main()
{
	cin>>sa>>sb;
	for(int i=1;i<=sa.size();i++)
	{
		for(int j=1;j<=sb.size();j++)
		{
			if(sa[i-1]==sb[j-1])
				f[i][j]=f[i-1][j-1]+1;
			else
				f[i][j]=max(f[i-1][j],f[i][j-1]);
		}
	}
	int i=sa.size(),j=sb.size();
	while(i && j)
	{
		if(sa[i-1]==sb[j-1])
		{
			ans+=sa[i-1];
			i--;
			j--;
			continue;
		}
		if(f[i-1][j]>f[i][j-1])
			i--;
		else
			j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}


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



int main(void){
    int n;
    cin >> n;
    double sum = 0;
    rep(i,n){
        double x;
        string u;
        cin >> x >> u;
        if (u == "BTC") x *= 380000.0;
        sum += x;
    }
    printf("%.20f\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);
const int MOD = 1e9 + 7;

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<bool> sb(n+1, false);
    for (int i = 0, a; i < m; ++i) {
        cin >> a;
        sb[a] = true;
    }
    vector<long long> dp(n+1,0);
    dp[0] = 1;
    dp[1] = !sb[1];
    for (int i = 2; i <= n; ++i) {
        if (sb[i]) dp[i] = 0;
        else {
            dp[i] = (dp[i-1]%MOD + dp[i-2]%MOD) % MOD;
        }
    }
    cout << dp[n] << '\n';
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

//input
int main(void)
{
    lli N;
    cin >> N;
    int tmp = 0;
    int maxnum = -1;
    string s = to_string(N);
    for (int i = 0; i < s.length(); i++)
    {
        int d = s[i] - '0';
        if (i > 0 && d != 9)
        {
            tmp = 0;
            tmp += (s[0] - '0');
            tmp -= 1;
            for (int j = 1; j < s.length(); j++)
            {
                tmp += 9;
            }
            cout << tmp << endl;
            return 0;
        }
        tmp += d;
    }
    cout << tmp << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int dp[45][410][410];
int main()
{
  int n,ma,mb;cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  rep(i,n) cin >> a[i] >> b[i] >> c[i];


  rep(i,42) rep(j,405) rep(k,405) dp[i][j][k] = 1e+9;

  dp[0][0][0] = 0;

  rep(i,n) {
    rep(j,401) {
      rep(k,401) {
  	dp[i+1][j + a[i]][k + b[i]] = min(dp[i+1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
  	dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
      }
    }
  }

  int res = 1e+9;
  int aa = ma, bb = mb;
  while(aa <= 400 && bb <= 400) {
    res = min(res, dp[n][aa][bb]);
    aa += ma;
    bb += mb;
  }

  if(res == 1e+9) cout << -1 << "\n";
  else cout << res << "\n";
  return 0;
}


Measured memory_bytes: 28928
s=input()
l=len(s)
ans="AC"
cnt=0
if(s[0]!="A"):
  ans="WA"
for i in range(1,l):
  if(s[i].isupper()):
    if(s[i]=="C" and 2<=i and i<=l-2):
      cnt+=1
    else:
      ans="WA"
      break
if(cnt!=1):
  ans="WA"
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int max(int a,int b){return (a>b)?a:b;}
int min(int a,int b){return (a>b)?b:a;}
int main(){
  int n,a,b,c,d,st,en;
  string s;
  bool f=true,can_c=false;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  cin >> s;
  en = max(c,d);
  for(int i=a;i<c;i++){
    if(s[i]=='#'&&s[i+1]=='#'){
      f=false;
      break;
    }
  }
  for(int i=b;i<d;i++){
    if(s[i]=='#'&&s[i+1]=='#'){
      f=false;
      break;
    }
  }
  if(d<c){
    for(int i=b;i<=d;i++){
      if(s[i]=='.'&&s[i+1]=='.'&&s[i-1]=='.'){
        can_c=true;
        break;
      }
    }
    if(can_c==false) f=false;
  }
  if(f) cout << "Yes\n";
  else cout << "No\n";
}


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

const int MAX = 101000;


int main() {
    int N;
    cin >> N;
    vector<int> dp(MAX,N);
    dp[0]=0;
    for(int i=1;i<=N;++i) {
        for(int j=1;j<=i;j*=6) dp[i] = min(dp[i], dp[i-j]+1);
        for(int j=9;j<=i;j*=9) dp[i] = min(dp[i], dp[i-j]+1);
    }
    cout << dp[N] << endl;
}


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

int main(int argc, char const *argv[]) {
  string s;
  int ans = 0, cnt = 0;
  cin >> s;

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
      cnt++;
      ans = max(ans, cnt);
    } else {
      cnt = 0;
    }
  }

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

void quicksort(int, int);
int Partition(int, int);

typedef struct{
  int num;
  char mark[2];
  int order;
}card;

card A[100000];

int main(){
  int i, n, flag=0;

  scanf("%d",&n);
  if( n<1 || 100000<n ) exit(0);
  
  for( i=0 ; i<n ; i++ ){
    scanf("%s",A[i].mark);
    scanf("%d",&A[i].num);
    if( A[i].num<1 || 1000000000<A[i].num ) exit(1); 
    
    A[i].order = i;
  }
  
  quicksort(0, n-1);


  for( i=1 ; i<n ; i++ ){
    if( A[i-1].num == A[i].num){
      if(A[i-1].order > A[i].order){
      flag=1;
      break;
      }
    }
  }

  if(flag == 1) printf("Not stable\n");
  else printf("Stable\n");
  
  for( i=0 ; i<n ; i++ ){
    printf("%s %d\n",A[i].mark, A[i].num);
  }

  return 0;
}

void quicksort(int p, int r){
  int q;
  
  if(p < r){
    q = Partition(p, r);
    quicksort(p, q-1);
    quicksort(q+1, r);
  }
}

int Partition(int p, int r){
  int i, j, x, k;
  card tmp;

  x = A[r].num;
  i = p-1;

  for( j=p ; j<r ; j++ ){
    if( A[j].num <= x ){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  
  return i+1;
}

Measured memory_bytes: 1780
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

# 素因数分解、リストで返す
#############################################################
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    a.sort()
    return a
#############################################################

primes = defaultdict(int)

for i in range(N):
    p = prime_factorize(A[i])
    p_set = set(p)
    for pi in p_set:
        primes[pi] += 1

# print(primes)

if len(primes) == 0:
    print("pairwise coprime")
    exit()

max_cnt = max(primes.values())
min_cnt = min(primes.values())

if max_cnt == 1:
    print("pairwise coprime")
elif max_cnt != N:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 177604
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
int main(){
    cin>>N;
    ll ans=0;
    for(ll i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0){
            ans+=i;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(void){
    int N, c[101], a, b, i, j, temp;
    scanf("%d", &N);
    for(i = 1; i <= N; i++){
        scanf("%d", &c[i]);
    }
    for(i = 1; i <= N; i++){
        for(j = N; j > i; j--){
            if(c[j-1] < c[j]){
                temp = c[j-1];
                c[j-1] = c[j];
                c[j] = temp;
            }
        }
    }
    a = 0;
    b = 0;
    for(i = 1; i <= N; i++){
        if(i % 2 == 1) a += c[i];
        else b += c[i];
    }
    printf("%d\n", a - b);
    return 0;
}


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

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define fori0(x) for(int i=0;i<x;i++)
#define forj0(x) for(int j=0;j<x;j++)
#define fork0(x) for(int k=0;k<x;k++)
#define fori1(x) for(int i=1;i<=x;i++)
#define forj1(x) for(int j=1;j<=x;j++)
#define fork1(x) for(int k=1;k<=x;k++)
#define foriv(v) for(int i=0;i<v.size();i++)
#define forjv(v) for(int j=0;j<v.size();j++)
#define forkv(v) for(int k=0;k<v.size();k++)
#define testcase(t) for(int te=1;te<=t;te++)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define FastRead ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

ll MOD = 1000000007; // 998244353; // = (119<<23)+1
const int MX = 1e6+7;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);

template<class T> bool ckmin(T& a, const T& b)
{
    return a > b ? a = b, 1 : 0;
}
template<class T> bool ckmax(T& a, const T& b)
{
    return a < b ? a = b, 1 : 0;
}
int num,num1,num2,num3,num4;
int test;
struct ss{
    int F,S,T;
};
int mark[1000001];
int main()
{
    FastRead;
    cin>>num1;
    int arr[num1];
    for(int i=0;i<num1;i++){
        cin>>arr[i];
        mark[arr[i]]++;
    }
    if(mark[1]>1){
        cout<<0<<endl;
        return 0;
    }
    if(mark[1]==1){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<num1;i++){
        num=arr[i];
        if(mark[arr[i]]>1){
            continue;
        }
        for(int j=2;j<=sqrt(num);j++){
            if(num%j==0){
                if(mark[j]>=1){
                    mark[num]++;
                    break;
                }
                num3=num/j;
                if(mark[num3]>=1){
                    mark[num]++;
                    break;
                }
            }
        }
    }
    int Ans=0;
    for(int i=0;i<num1;i++){
        if(mark[arr[i]]==1){
            Ans++;
        }
    }
    cout<<Ans<<endl;

}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}


void Main() {
    ll N;
    cin >> N;
    vector<ll> div = divisor(N);
    ll ans = INF;
    rep(i, div.size()) {
        ans = min(ans, div[i] - 1 + N / div[i] - 1);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {
  // 一年の秒数
  int a,b;
  cin >>a;
  cin>>b;
  cout <<b*2-a<<endl;
 // int seconds = 365 * 24 * 60 * 60;

  // 以下のント* を消して追記する
  /*cout << /1年は何秒か  << endl;
  cout << 2年は何秒か  << endl;
  cout << /5年は何秒か/ << endl;
  cout << 10年は何秒か
  */
}


Measured memory_bytes: 3632
import java.util.*;

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

    int n = sc.nextInt();
    long k = sc.nextLong();
    int[] a = new int[n];
    LinkedHashSet<Integer> order = new LinkedHashSet<>();
    order.add(1);
    int tmp = 0;
    int ans = 0;
    int j = 0;
    boolean bool = true;

    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    while(bool){
      if(order.add(a[j])){
        order.add(a[j]);
        j = a[j] - 1;
      } else {
        tmp = a[j];
        bool = false;
      }
    }
    
    ArrayList<Integer> odr = new ArrayList<>(order);
    int index = odr.indexOf(tmp);
    int roop = odr.size() - index;

    if(k <= index){
      ans = odr.get((int)k);
    } else {
      ans = odr.get(index + (int)((k - index) % roop));
    }

    System.out.println(ans);

  }
}


Measured memory_bytes: 66920
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  int dia = a[0];
  auto makePath = [] (int dia) {
    vector<int> res;
    for (int i = dia; i >= (dia + 1) / 2; i--) res.push_back(i);
    for (int i = dia / 2 + 1; i <= dia; i++) res.push_back(i);
    sort(res.rbegin(), res.rend());
    return res;
  };
  vector<int> path = makePath(dia);
  int m = (int) path.size();
  vector<int> done(n);
  int j = 0;
  for (int i = 0; i < m; i++) {
    for (; j < n && a[j] > path[i]; j++);
    if (a[j] < path[i]) {
      cout << "Impossible\n";
      return 0;
    }
    done[j++] = 1;
  }
  // for (int i = 0; i < n; i++) cerr << a[i] << " " ;
  // cerr << endl;
  // for (int i = 0; i < n; i++) cerr << done[i] << " " ;
  // cerr << endl;
  for (int i = 0; i < n; i++) {
    if (!done[i] && (dia + 1) / 2 + 1 > a[i]) {
      cout << "Impossible\n";
      return 0;
    }
  }
  cout << "Possible\n";
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<long> data(n);
  for(int i = 0; i < n; i++)
  {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  long sum = 0;
  for(int i = 0; i < n; i++)
  {
    sum = sum + data.at(i);
  }
  cout << data.at(0) << " " << data.at(n-1) << " " << sum << endl;

}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  set<int> ans;
  REP(i, k) {
    if (a + i > b) {
      break;
    }
    ans.insert(a + i);
  }
  RREP(i, k) {
    if (b - i < a) {
      break;
    }
    ans.insert(b - i);
  }

  for (auto x : ans) {
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define MAX 6000
#define INF 1<<29
using namespace std;
int V,d[MAX],cost[MAX][MAX];
bool used[MAX];
void di(int);

int main(){

  int m,a,b,c,e,f,g;


  while(cin >> V >> m)
    {
      for(int i=0;i<=V+2;i++)for(int j=0;j<=V+2;j++)cost[i][j]=INF;
      for(int i=0;i<m;i++)
	{
	  cin >> a;
	  if(a == 1)
	{
	  cin >> b >> c >> e;
	  if(cost[b][c] != INF)
	    {
	      cost[b][c]=min(cost[b][c],e);
	      cost[c][b]=min(e,cost[c][b]);
	    }
	  else 
	    {
	      cost[b][c]=e;
	      cost[c][b]=e;
	    }
	}
	  else if(a == 0)
	    {
	      cin >> f >> g;
	      di(f);
	      if(d[g] == INF)
		{
		  cout << "-1" << endl;
		}
	      else 
		{
		  cout << d[g] << endl;
		}
	    }
	}
  }
  return 0;
}

void di(int s)
{

  for(int i=0;i<=V;i++)d[i]=INF;
  for(int i=0;i<=V;i++)used[i]=false;
  d[s]=0;
  while(true)
    {
      int v=-1;
      for(int u=1; u<=V ;u++)
	{
	  if(!used[u] && (v == -1 || d[u]<d[v]))v=u;
	}
      
      if(v == -1)break;
      used[v]=true;
      for(int u=1;u<=V;u++)
	{
	  d[u]=min(d[u],d[v]+cost[v][u]);
	}
    }
}

Measured memory_bytes: 1324
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = []
    B = []

    for i in range(n):
        a,b = readInts()
        A.append(a)
        B.append(b)
    l = 0
    for i in range(n-1,-1,-1):
        # 前回分からだんだん加算されていくパターン
        A[i] += l
        if A[i] % B[i] == 0:
            continue
        #print("before",A[i],B[i])
        ama = A[i] % B[i] # 9 4 ≡ 1 増やす数は、4 - 1 = 3
        up_ = B[i] - ama
        #print("after",A[i]+up_,B[i])
        l += up_
    print(l)
if __name__ == '__main__':
  main()


Measured memory_bytes: 17120
#include <stdio.h>

int main(void) {
	int N, A, B;
	if (scanf("%d%d%d", &N, &A, &B) != 3) return 1;
	if ((B - A - 1) % 2 == 0) {
		/* アリスが後ずさりする */
		puts("Borys");
	} else {
		/* ボリスが後ずさりする */
		puts("Alice");
	}
	return 0;
}


Measured memory_bytes: 1648
N = int(input())
S = input()
left_attention = [0 for i in range(N)]
right_attention = [0 for i in range(N)]

for i in range(1, N):
    left_attention[i] = left_attention[i - 1]
    if S[i - 1] == "W":
        left_attention[i] += 1

for i in range(N - 2, -1, -1):
    right_attention[i] = right_attention[i + 1]
    if S[i + 1] == "E":
        right_attention[i] += 1
        
ans = N
for i in range(N):
    ans = min(ans, left_attention[i] + right_attention[i])

print(ans)

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

int main() {
	
	int n; cin >> n;
	vector<ll> a(n + 1, 0);
	vector<ll> accum(n + 1, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		accum[i] += a[i];
		accum[i] += accum[i - 1];
	}
	ll thresholdValue = 9223372036854775807LL;
	int thresholdIndex;
	for (int i = 1; i <= n; i++) {
		ll tmp = abs(accum[i] - (accum[n] - accum[i]));
		if (chmin(thresholdValue, tmp)) {
			thresholdIndex = i;
		}
	}
	cout << thresholdValue << endl;
	return 0;
}

Measured memory_bytes: 6408
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(int i = z; i < n; i++)
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;


/*
 vector<int> B(1, A.at(0));
 int st = A.at(0);
 rep(i, 1, N){
     if(A.at(i) != st){
         B.push_back(A.at(i));
         st = A.at(i);
     }
 }
 
 int M = B.size();
 rep(i, 0, M) cout << B.at(i) << endl;
 
 */

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A.at(i);
    sort(all(A));
    vector<bool> dp(1000001, true);
    vector<bool> same(1000001, false);
    
    int count = 0;
    
    rep(i, 0, N){
        
        if(dp[A[i]]){
            if ((i < N - 1) && A[i] == A[i + 1]) count--;
            count++;
            ll x = A.at(i);
            same[x] = true;
            while(x <= 1000000){
                dp[x] = false;
                x += A.at(i);
            }
        }
        else{
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

double a,b,h,m,ans, ang;
int main(){
    ios_base::sync_with_stdio(0);
    scanf("%lf %lf %lf %lf", &a,&b,&h,&m);
    
    ang = abs(h*5-m + m/12)*6;
    ang = min(ang,360-ang);
    ang = acos(-1)*ang/180.0;
    ans = sqrt(a*a + b*b - 2*a*b*cos(ang));
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 4288
A,B,C = map(int,input().split())
K = int(input())
for i in range(0,K+1):
    for j in range(0,K+1):
        for h in range(0,K+1):
            if A*(2**i)<B*(2**j)<C*(2**h) and (i+j+h)<=K:
                print("Yes")
                exit()
print("No")

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

vector<vector<int> > G(100010);
ll sum = 0;
ll N,K;
long long dfs(int now,int from){
    int num;
    if (from == -1) num = K-1;
    else num = K-2;

    if (K < G[now].size()) return 0;
    ll ans = 1;
    for (auto e : G[now]){
        if (e == from) continue;
        ans *= num;
        num--;
        ans %= MOD;
    }

    for (auto e : G[now]){
        if (e == from) continue;
        ans *= dfs(e,now);
        ans %= MOD;
    }
    return ans;
}
int main(){
    cin >> N >> K;
    //init();
    /*
    if (K == 1){
        cout << 0 << endl;
        return 0; 
    }
    */
    for (int i = 0; i < N-1; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    cout << K*dfs(0,-1)%MOD << endl;
}


Measured memory_bytes: 10368
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back


using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 200001;
const ll mod = 1e9 + 7;

int main(){
    inp_out_work

    ll r;
    cin>>r;
    cout<< r*r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
// !-------------PBDS-----------------!
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int,null_type,std::greater_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// !-------------PBDS-----------------! remember about greater/_equal<int>, less/_equal<int>

using namespace std;
typedef long long ll;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    string s;
    cin >> s;
    int n = (int)s.size()-1;
    if(s[n] == 's'){
        s += "es";
    } else{
        s += "s";
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 3660
from collections import defaultdict

n = int(input())
ss = [input().strip() for _ in range(n)]

counts = defaultdict(int)

for s in ss:
    counts[s] += 1

items = list(counts.items())
items = sorted(items, key=lambda c: c[1], reverse=True)

max_value = items[0][1]
max_items = [item for item in items if item[1] == max_value]

keys = [item[0] for item in max_items]
keys = sorted(keys)

for key in keys:
    print(key)


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

int main() {
  int n;
  cin >> n;

  int a[10][10];
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      a[i][j] = 0;
    }
  }
  
  for (int i=1; i<=n; i++) {
    int lower = i%10;
    int upper = i;
    while (upper >= 10) {
      upper /= 10;
    }
    a[upper][lower] += 1;
  }

  int sum = 0;
  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      sum += a[i][j] * a[j][i];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 764
#include<cstdio>
#include<algorithm>
using namespace std;
int n,wk;
int w[100002],v[100002];
long long f[102][100002],ans;

int main(){
	scanf("%d%d",&n,&wk);
	for(int i=1;i<=n;i++) scanf("%d%d",&w[i],&v[i]);
	for(int i=1;i<=n;i++){
		for(int j=wk;j>=0;j--) 
			if(j>=w[i]) f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]);
			else f[i][j]=f[i-1][j];
	}
	for (int i=0;i<=wk;i++) ans = max(ans, f[n][i]);
	printf("%lld",ans);
}

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

int main() {
  int N, K, R, S, P;
  string T, U;
  cin >> N >> K >> R >> S >> P >> T;

  ll score = 0;
  for (int i = 0; i < N; i++) {
    if (i - K >= 0 && T[i - K] == T[i]) {
      if (T[i] == 'r' && U[i - K] == 'P') {
        U.push_back('R');
        continue;
      } else if (T[i] == 's' && U[i - K] == 'R') {
        U.push_back('S');
        continue;
      } else if (T[i] == 'p' && U[i - K] == 'S') {
        U.push_back('P');
        continue;
      }

      if (T[i] == 'r') {
        U.push_back('P');
        score += P;
        continue;
      } else if (T[i] == 's') {
        U.push_back('R');
        score += R;
        continue;
      } else if (T[i] == 'p') {
        U.push_back('S');
        score += S;
        continue;
      }
    }

    if (T[i] == 'r') {
      U.push_back('P');
      score += P;
    } else if (T[i] == 's') {
      U.push_back('R');
      score += R;
    } else if (T[i] == 'p') {
      U.push_back('S');
      score += S;
    }
  }
  cout << score << endl;
}

Measured memory_bytes: 3764
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

vector<vector<pair<int,int > > >graph(100100);
bool visited[100100];
int color[100100];
int par[100100];
int answer[100100];
queue<int>que;
int main(){
    int n,max_V =0;
    cin>>n;
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        //a--;
        //b--;
        graph[a].push_back(make_pair(b,i+1));
        graph[b].push_back(make_pair(a,i+1));
    }

    REP(i,n+1){
        max_V = max(max_V,(int)graph[i].size());
    }
    que.push(1);
    while(!que.empty()){
        int v = que.front(); // キューから先頭頂点を取り出す
        //cout << "ppp" << par[v] << endl;
        visited[v]=true;
        int count = 1;
        que.pop();
        //cout << v << " " << color[v]<<endl;
        // v から辿れる頂点をすべて調べる
        for (pair<int,int> nv : graph[v]) {
            if (visited[nv.first]) {
                continue; // すでに発見済みの頂点は探索しない
            }
            if(color[v] == count){
                count = count%max_V+1;
            }
            color[nv.first]=count;
            answer[nv.second]=count;
            count = count%max_V+1;
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            que.push(nv.first);
        }
    }
    cout << max_V << endl;
    FOR(i,1,n)cout << answer[i] << endl;
    return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
int h,dev;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		char s;cin>>s;
		if(s=='I')h+=1;
		if(s=='D')h-=1;
		dev=max(dev,h);
	}
	cout<<dev<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using P = pair<int,int>;

int h,w;
int d[2][8] = {{-1,-1,-1,0,0,1,1,1},{-1,0,1,-1,1,-1,0,1}};
vector<vector<P>> memo;
vector<string> s;

string solve();

int main() {
    while(1){
        cin >> h >> w;
        if(h + w == 0)break;
        s.resize(h);
        for(int i = 0;i < h;++i)
            cin >> s[i];
        cout << solve() << endl;
    }
    return 0;
}

string solve(){
    string ans;
    memo.assign(26,vector<P>(0,{0,0}));
    for(int i = 0;i < h;++i)
        for(int j = 0;j < w;++j)
            memo[s[i][j]-'A'].push_back({i,j});
    for(int alph = 0;alph < 26;++alph){
        int memosize = memo[alph].size();
        for(int j = 0;j < memosize;++j)
            for(int k = 0;k < memosize;++k){
                P memoj = memo[alph][j],memok = memo[alph][k];
                for(int dj = 0;dj < 8;++dj)
                    for(int dk = 0;dk < 8;++dk){
                        P nowj = memoj,nowk = memok;
                        string now;
                        if(j == k && dj == dk)continue;
                        while(s[nowj.fi][nowj.se] == s[nowk.fi][nowk.se]){
                            now += s[nowj.fi][nowj.se];
                            (nowj.fi += d[0][dj] + h) %= h;
                            (nowj.se += d[1][dj] + w) %= w;
                            (nowk.fi += d[0][dk] + h) %= h;
                            (nowk.se += d[1][dk] + w) %= w;
                            if(nowj == memoj && nowk == memok)break;
                        }
                        if(now.size() <= 1)continue;
                        if(now.size() > ans.size() || (now.size() == ans.size() && now < ans))
                            ans = now;
                    }
            }
    }
    return ans.size() == 0? "0":ans;
}


Measured memory_bytes: 3092
#include<iostream>
#define MAX 500000
#include<algorithm>

using namespace std;
int main(){
	bool pri[600000];
	fill(pri,pri+MAX+10,1);
	pri[0]=pri[1]=0;
	for(int i=0;i*i<MAX;i++)
	if(pri[i]){
		for(int j=i*2;j<=MAX;j+=i)
		pri[j]=0;
	}
	int n,ans;
	while(cin>>n,n){
		ans=0;
		for(int i=n+1;i<=2*n;i++)
		if(pri[i])
		ans++;
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int total = 1; int odd = 1; 
	for(int i = 0; i < N; i++){
		total *= 3; 
		int a; cin >> a; 
		if(a % 2 == 0) odd *= 2;  
	}
	cout << total - odd << endl; 
}

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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};

mint calc(int n, vector<ll> &xs) {
    mint xa = 0;
    for (int k = 1; k <= n; k++) {
        ll l = xs[k - 1] * (k - 1);
        ll r = xs[k - 1] * (n - k);

        mint now = l - r;
        xa += now;
    }
    return xa;
}

int main() {
    int n, m;
    cin >> n >> m;

    vector<ll> xs(n), ys(m);
    rep(i, n) cin >> xs[i];
    rep(i, m) cin >> ys[i];

    mint x = calc(n, xs);
    mint y = calc(m, ys);
    mint ans = x * y;
    cout << ans << endl;

}


Measured memory_bytes: 1792
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
s = [[i,0] for i in p] + [[i,1] for i in q] +  [[i,2] for i in r]
s.sort(key=lambda z:z[0])
ans = 0
k = [0,0,0]
k1 = [x,y,x+y]
while sum(k)<x+y:
  t = s.pop()
  if k[t[1]]<k1[t[1]]:
    ans += t[0]
    k[t[1]] += 1
print(ans)

Measured memory_bytes: 126316
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int digits[10];
int ans[10];
int cnt;
int K;

void prt_ans()
{
    bool flag = false;
    for (int i = 0; i < 10; i++)
    {
        if (ans[i] != 0)
        {
            flag = true;
        }
        if (flag)
        {
            cout << ans[i];
        }
    }
    cout << endl;
}

void cpy_digits()
{
    for (int i = 0; i < 10; i++)
    {
        ans[i] = digits[i];
    }
}

void dfs(int i, int num, bool flag)
{
    if (!flag)
    {
        if (i != 9)
        {
            digits[i] = 0;
            dfs(i + 1, 0, false);
        }
        for (int j = 1; j <= 9; j++)
        {
            digits[i] = j;
            if (i != 9)
            {
                dfs(i + 1, j, true);
            }
            else
            {
                cnt++;
                if (cnt == K)
                {
                    cpy_digits();
                }
            }
        }
    }
    else
    {
        for (int j = max(0, num - 1); j <= min(9, num + 1); j++)
        {
            digits[i] = j;
            if (i != 9)
            {
                dfs(i + 1, j, true);
            }
            else
            {
                cnt++;
                if (cnt == K)
                {
                    cpy_digits();
                }
            }
        }
    }
}

int main()
{
    cin >> K;

    dfs(0, 0, false);

    prt_ans();
}

Measured memory_bytes: 256