akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] as;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        int count = 0;
        while (true) {
            for (int i = 0; i < n; i++) {
                if (as[i] % 2 != 0) {
                    System.out.println(count);
                    return;
                }
                as[i] >>= 1;
            }
            count++;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 19284
/** author: __nishad__ **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    string s;
    cin>>s;

    cout<<(s == "ABC"? "ARC" : "ABC");


}



Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
using namespace std;

typedef long long int ll;

int patterns[2][10];
int s, t, b;

void getMovablePoints(int* ret, int s) {
	//up
	ret[0] = s - 3;
	//right
	ret[1] = s + 1;
	if(ret[1] % 3== 0)
		ret[1] = s;
	//down
	ret[2] = s + 3;
	//left
	ret[3] = s - 1;
	if(s % 3 == 0)
		ret[3] = s;
	for (int i = 0; i < 4; i++) {
		if(ret[i] < 0 || 8 < ret[i] || ret[i] == b)
			ret[i] = s;
	}
}

int main() {
	int n;
	while(cin >> n, n) {
		char _s, _t, _b;
		cin >> _s >> _t >> _b;
		s = _s - 'A';
		t = _t - 'A';
		b = _b - 'A';
		for (int i = 0; i < 9; i++) {
			patterns[0][i] = patterns[1][i] = 0;
		}
		patterns[0][s] = 1;
		int *pattern, *nextPattern;
		for (int i = 0; i < n; i++) {
			pattern = patterns[i % 2];
			nextPattern = patterns[(i+1) % 2];
			for (int j = 0; j < 9; j++) {
				nextPattern[j] = 0;
			}
			for (int j = 0; j < 9; j++) {
				int movablePoints[4];
				getMovablePoints(movablePoints, j);
				for (int k = 0; k < 4; k++) {
					nextPattern[movablePoints[k]] += pattern[j];
				}
			}

		}
		ll sum = 0;
		for (int i = 0; i < 9; i++) {
			sum += nextPattern[i];
		}

		printf("%.8lf\n", (double)nextPattern[t] / sum);

	}
	return 0;
}

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

dp = [0 for _ in range(N)]

for i in range(N): #0 <= i < N
    if i == 0:
        continue
    elif i == 1:
        dp[i] = abs(H[i]- H[i-1])
    else:
        dp[i] = min(dp[i-1]+ abs(H[i]-H[i-1]), dp[i-2]+ abs(H[i]- H[i-2]))

print(dp[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

int f(int n, int k) {
    if (n == 1) return 0;
    return (f(n - 1, k) + k) % n;
}

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

    int n, k, m;
    while (cin >> n >> k >> m, n) {
        cout << (f(n - 1, k) + m) % n + 1 << endl;
    }
}

Measured memory_bytes: 3336
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<int, int>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<DS, vector<int>> mp;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int f = s[0] - '0';
        int x = s.back() - '0';
        mp[{f, x}].push_back(i);
    }
    ll ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            ll x = mp[{i, j}].size();
            ll y = mp[{j, i}].size();
            x *= y;
            ans += x;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

#define MAX_N 10010000

ll Y[MAX_N];

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

    ll ans = 0;
    for(ll k = 1; k  <= N; k++){
        Y[k] += 1;
        ans += k * Y[k];
        for(ll x = 2*k; x < MAX_N; x += k){
            Y[x]++;
        }
    }

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


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

int main(){
  int x,n;
  cin >>x >>n;
  vector<int> d(102);
  rep(i,n){
    int p;
    cin >>p;
    d[p] = 1;
  }
  pair<int, int> ans(99999, -1);
  for(int i = 0; i<=101; i++){
    if(d[i]==1) continue;
    int dif = abs(x-i);
    ans = min(ans, pair<int, int>(dif, i));
  }
  cout << ans.second << endl;
  return 0; 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define int long long
int a[45];
int b[45];
using namespace std;
signed main(){
   int n;
   cin>>n;
   int sum=0;
   for(int i=0;i<n;i++){
       cin>>a[i];
   }
   for(int i=0;i<n;i++){
       cin>>b[i];
   }
   for(int i=0;i<n;i++){
       if(a[i]-b[i]>0){
           sum+=a[i]-b[i];
       }
   }
   cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX(x,y) (((x)<(y))?(y):(x))

typedef long long ll;

int main(void){
  ll t[100000],a[100000];
  ll maxT,maxA,mtp,map,tM=1,aM=1;
  int N,i,j,k;
  ll const mod=(ll)1E9+7;

  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%lld",&t[i]);
  for(i=0;i<N;i++) scanf("%lld",&a[i]);
  for(i=maxT=maxA=0;i<N;i++){
    if(maxT<t[i]) maxT=t[mtp=i];
    if(maxA<a[N-1-i]) maxA=a[map=N-1-i];
  }
  if(maxT!=maxA || t[mtp]!=a[mtp] || t[map]!=a[map] || mtp>map){
    puts("0");
    return 0;
  }

  for(i=0;i<N && t[i]!=maxT;i++){
    if(i!=0 && t[i]==t[i-1]){
      tM*=t[i-1];
      tM%=mod;
    }
  }

  for(j=N-2;j>i;j--){
    if(a[j]==a[j+1]){
      aM*=a[j+1];
      aM%=mod;
    }
  }

  printf("%lld\n",aM*tM%mod);
  
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
  int C[4]={0},N,four=scanf("%d",&N);
  char temp[4],judge[4][4]={"AC","WA","TLE","RE"};
  while(N--)
  {
    four=scanf("%s",temp);
    if(temp[0]=='A')C[0]++;
    else if(temp[0]=='W')C[1]++;
    else if(temp[0]=='T')C[2]++;
    else C[3]++;
  }
  four=4;while(four--)printf("%s",judge[3-four]),printf(" x %d\n",C[3-four]);
}

Measured memory_bytes: 1696
S = input()

# 下からi桁(1-indexed)まで使ったときの、13で割ったときあまりがjになるパターン
dp = [[0 for _ in range(13)] for _ in range(len(S)+1)]
dp[0][0] = 1

for i, s in enumerate(S[::-1]):
    r_now = [1, 10, 9, 12, 3, 4][i%6]
    if s == "?":
        for d in range(10):
            for r_before, count in enumerate(dp[i]):
                j = (r_now*d+r_before)%13
                dp[i+1][j] = (dp[i+1][j]+count)%(10**9+7)
    else:
        d = int(s)
        for r_before, count in enumerate(dp[i]):
            j = (r_now*d+r_before)%13
            dp[i+1][j] = (dp[i+1][j]+count)%(10**9+7)
    # for dp_i in dp:
    #     print(dp_i)
    # print("")

print(dp[len(S)][5])

Measured memory_bytes: 67372
#include <stdio.h>

int main(void)
{
	int a, b, x;
	char op;
	x=0;
	while(1)
	{
		scanf("%d %c %d", &a, &op, &b);
		if(op=='+')
		{
			x=a+b;
			printf("%d\n", x);
		}
		else if(op=='-')
		{
			x=a-b;
			printf("%d\n", x);
		}
		else if(op=='*')
		{
			x=a*b;
			printf("%d\n", x);
		}
		else if(op=='/')
		{
			x=a/b;
			printf("%d\n", x);
		}
		else
		{
			break;
		}
	}
	
	return 0;
}


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

int main(){
	string str, pat;
	vector<char> num;
	
	str.reserve(1000001);
	num.reserve(1000001);
	pat.reserve(73);
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	while(true){
		str.clear();
		pat.clear();

		while(true){
			getline(cin, pat);
			if( pat.empty() || !cin ) break;
			str += pat;
		}
		if( str.empty() || !cin ) break;

		getline(cin, pat);
		cin.ignore();
		
		sort(pat.begin(), pat.end());
		pat.erase( unique(pat.begin(), pat.end()), pat.end());

		num.resize(str.size());
		int j;
		for(j = 0; j < str.size(); ++j){
			int x = lower_bound(pat.begin(), pat.end(), str[j]) - pat.begin();
			if( x < pat.size() && str[j] == pat[x] ){ num[j] = x; }
			else{ num[j] = pat.size(); }
		}
		
		int cnt[73] = {};
		cnt[pat.size()] = 10000000;
		int d = 0;
		for(j = 0; j < num.size() && d < pat.size(); ++j){
			if( ++cnt[num[j]] == 1 ){
				++d;
			}
		}

		if( d < pat.size() ){
			cout << "0\n\n";
			continue;
		}
		
		int a = 0, b = j;
		int shortest = 1;

		for(int i = 0; j <= num.size(); ){
			char x = num[i++];
			if( --cnt[x] == 0 ){
				bool found = false;
				while(j < num.size()){
					++cnt[num[j]];
					if( x == num[j++] ){
						found = true;
						break;
					}
				}
				if( !found ) break;
			}
			
			if( b - a > j - i ){
				a = i;
				b = j;
				shortest = 1;
			}
			else if( b - a == j - i ){
				++shortest;
			}
		}

		cout << shortest << "\n\n";
		while( a < b ){
			int len = min(b - a, 72);
			cout << str.substr(a, len) << '\n';
			a += len;
		}

		cout << '\n';
	}
}

Measured memory_bytes: 2068
c1, c2 = input().split()
n = input().split()
n1 = int(n[0])
n2 = int(n[1])
u = input()
if(u == c1):
  print(str(n1 - 1) + " " + str(n2))
else:
  print(str(n1) + " " + str(n2 - 1))

Measured memory_bytes: 3060
//no one wants to die,yet death is the destination we all share 
// don't think you are,know you are!!

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
	string s;
	cin>>s;
	ll sum=0;
	forn(i,s.length()){
		sum=(sum+s[i]-'0')%9;
	}
	if(sum==0) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3696
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
void ManyMedians() {
	int N;
	cin >> N;
	int t[200001];
	int org[200001];
	for (int i = 0; i < N; i++)
	{
		cin >> t[i];
		org[i] = t[i];
	}
	sort(t, t + N);
	int l = t[N / 2 - 1];
	int h = t[N / 2];
	for (int i = 0; i < N; i++)
	{
		if (org[i] <= l) {
			cout << h << endl;
		}
		else {
			cout << l << endl;
		}
	}
}
int main() {
	ManyMedians();
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  if(n%1000==0) cout<<0<<endl;
  else cout<<1000-n%1000<<endl;
}

Measured memory_bytes: 3624
let n = read_int ()
let i, ans = ref 1, ref 0
let f m = if m > 0 && n / m = n mod m then ans := !ans + m
let _ =
  while !i * !i <= n do if n mod !i = 0 then (f @@ !i - 1; f @@ n / !i - 1); incr i done;
  Printf.printf "%d\n" !ans

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

int main()
{
    string S;
    cin >> S;
    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;
    return 0;
}

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

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int r;
    cin >> r;
    cout << r * r;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <set>
#include <map>
#include <cstring>
using namespace std;

typedef long long ll;

int n, k;
const int maxn = 2e5+1;
ll a[maxn];
map<ll, int> ma;
int tot;
int bit[maxn+5];
void add(int x, int y)
{
    while (x <= tot)
    {
        bit[x] += y;
        x += x&-x;
    }
}
int sum(int x)
{
    int ret = 0;
    while (x)
    {
        ret += bit[x];
        x -= x&-x;
    }
    return ret;
}
int main()
{
    a[0] = 0;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; ++i)
        scanf("%d", a+i);
    for (int i = 1; i <= n; ++i)
        a[i] -= k;
    for (int i = 1; i <= n; ++i)
        a[i] += a[i-1];
    for (int i = 1; i <= n; ++i)
        ma[a[i]];
    ma[0];
    tot = 0;
    for (map<ll, int>::iterator it = ma.begin(); it != ma.end(); ++it)
    {
        it->second = ++tot;
    }
    memset(bit, 0, (tot+1)*sizeof(int));
    ll ans = 0;
    add(ma[0], 1);
    for (int i = 1; i <= n; ++i)
    {
        ans += sum(ma[a[i]]);
        add(ma[a[i]], 1);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  if(N / 10 == 9 || N % 10 == 9) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

for i in range(N-1,0,-1):
    if H[i] - H[i-1] == -1:
        H[i-1] -= 1

for j in range(N-1):
    if H[j] > H[j+1]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 14396
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        var S = Console.ReadLine();
        var list = new List<string>();
        
        for(var i = 0;i < S.Length;i++){
            list.Add(S[i].ToString());
        }
        var plus = list.Where(p => p == "+").Count();
        var minus = list.Where(m => m == "-").Count();
        Console.WriteLine(plus - minus);
    }
}


Measured memory_bytes: 13396
#include<atcoder/all>
using namespace atcoder;

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int f(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
    int N, K; cin >> N >> K;
    int A[300000]; rep(i, N) cin >> A[i];
    segtree<int, f, e> G(300001);
    int ans = 0;
    rep(i, N) {
        int tmp = 0;
        if (i) tmp = G.prod(max(0, A[i] - K), min(300001, A[i] + 1 + K));
        ans = max(ans, tmp + 1);
        G.set(A[i], tmp + 1);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int c1;
    cin>>c1;
    char c;
    cin>>c;
    int ans;
    cin>>ans;
    
    if(ans<5)cout<<"Heisei"<<endl;
    else cout<<"TBD"<<endl;
    
    
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)
		cout << c << "\n";
	else if (a == c)
		cout << b << "\n";
	else
		cout << a << "\n";
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

// 

public class ABC133_B // ←Class名変更！！    Program
{
    public static void Main()
    {
        var nd = Ria();
        var n = nd[0];
        var d = nd[1];

        var dots = new int[n][];
        for (var i = 0; i < n; i++)
        {
            dots[i] = Ria();
        }

        var result = 0;
        for (int j = 0; j < n; j++)
        {
            for (int k = j+1; k < n; k++)
            {
                var v = 0;
                for (int m = 0; m < d; m++)
                {
                    v += (dots[j][m] - dots[k][m]) * (dots[j][m] - dots[k][m]);
                }
                var du_v = Sqrt(v);
                var diff= Abs(du_v-(int)du_v);
                if (diff<0.000001)
                {
                    result++;
                }

            }
        }

        WriteLine($"{result}");

    } // Main

    public static string Rs() { return ReadLine(); }
    public static char Rc() { var c = ReadLine(); return c[0]; }    //最初の1文字だけ返す
    public static int Ri() { return int.Parse(ReadLine()); }
    public static long Rl() { return long.Parse(ReadLine()); }
    public static char[] Rca() { return ReadLine().ToCharArray(); }
    public static int[] Ria() { return Array.ConvertAll(ReadLine().Split(' '), int.Parse); }
    public static long[] Rla() { return Array.ConvertAll(ReadLine().Split(' '), long.Parse); }
} // Class


Measured memory_bytes: 13268
########関数部分##############
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
############################
 
#####関数をつかってみる．#####
######今回は二進数に変換######

n, k = map(int, input().split())
n = Base_10_to_n(n, k)
print(len(n))

Measured memory_bytes: 3060
def main():
    N = int(input())
    A = [1]
    ret = []
    for _ in range(100):
        A.append(A[-1] * 26)
    for n in range(1, 100):
        # Nは何文字の番号か調べる
        if N > A[n]:
            N -= A[n]
            continue
        N -= 1
        for _ in range(n):
            N, r = divmod(N, 26)
            ret.append(r)
        break
    ret = [chr(ord('a') + x) for x in ret]
    return ''.join(reversed(ret))


print(main())


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    
    long long sum = 0;
    sum += min(A, K);
    K -= A;
    if (K > 0) {
        K -= B;
        if (K > 0) {
            sum -= min(K, C);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>

using namespace std;

#define ll long long

signed main(void) {
    ll n;
    cin >> n;
    ll div5 = 0LL;
    if(n%2LL==1LL){
        cout << 0LL << endl;
        return 0;
    }
    for(ll i=1LL;;i++){
        ll temp = pow(5LL,i);
        // ll temp = n/pow(5LL,i);
        if(temp>n) break;
        // if(temp<1LL) break;
        // div5 += temp/2LL;
        div5 += n/temp/2LL;
    }
    cout << div5 << endl;
    return 0;
}

Measured memory_bytes: 384
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let s: String = read();
    let cv: Vec<usize> = s.chars().map(|c| c as usize - 'a' as usize).collect();
    let mut cnt: Vec<usize> = vec![0; 26];

    let mut ans = 1;

    for i in 0..cv.len() {
        let c = cv[i];
        ans += i - cnt[c];
        cnt[c] += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
int main()
{
	int n; cin>>n;
	ll g=0;
	for(int i=0; i<n; i++){
		ll a; cin>>a;
		g=gcd(g, a);
	}
	cout<<g<<endl;
	return 0;
}

Measured memory_bytes: 256
# 2020/07/27
# エイシング プログラミング コンテスト 2020 - C

# Input
n = int(input())
alist = [0] * (n + 1)

# Calc
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            calc_n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if calc_n <= n:
                alist[calc_n] = alist[calc_n] + 1
            else:
                break

# Output
for i in range(1, n+1):
    print(alist[i])


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

double p, t;

const double EPS = 1e-10;

double rec(int k, double l, double r, double a, double b, double prob){
	if (a < l + EPS && r - EPS < b) return prob;
	if (r < a + EPS || b - EPS < l) return 0;
	if (k == 0){
		double m = (l + r) / 2;
		return a < m + EPS && m - EPS < b ? prob : 0;
	}

	double mid = (l + r) / 2;

	double ap = p, bp = 1 - p;
	if (mid < t) swap(ap, bp);

	return rec(k - 1, mid, r, a, b, prob*ap)
		+ rec(k - 1, l, mid, a, b, prob*bp);
}

int main(){
	int k, l, r;
	cin >> k >> l >> r;
	double e;
	cin >> p >> e >> t;

	cout.setf(ios::fixed);
	cout.precision(12);
	cout << rec(k, l, r, t - e, t + e, 1) << endl;

	return 0;
}

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll ans = (n * (n - 1)) / 2;
    ans += n % 1;
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"

int main(){
	int N;//スポットの数
	int spot[100002]; //スポットの座標
	int j,i,k;
	int sum=0; //全体の金額
	int sum_i;
	
	scanf("%d",&N);
	
	spot[0]=0;
	spot[N+1]=0;
	
	for(i=1;i<=N;i++){
		scanf("%d",&spot[i]);
	}
	
	for(j=1;j<=N+1;j++){
		sum+=abs(spot[j]-spot[j-1]);
	}
	
	for(k=1;k<=N;k++){
		sum_i=sum+abs(spot[k-1]-spot[k+1])-abs(spot[k-1]-spot[k])-abs(spot[k]-spot[k+1]);
		printf("%d\n",sum_i);
	}
	return 0;
}
	

Measured memory_bytes: 1536
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    char A[100];
    char X[100] ;
    char C[100];
    if (scanf("%s %s %s", &A, &X, &C) < 3) return 0;

    printf("%c%c%c\n", A[0], X[0], C[0]);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<int> ans;
    rep(i, N) {
        vector<int> B;
        bool ok = false;
        for(int i = (int)A.size() - 1; i >= 0; i--) {
            if(i + 1 == A[i] && !ok) {
                ok = true;
                ans.pb(i + 1);
            }
            else {
                B.pb(A[i]);
            }
        }
        if(!ok) {
            output(-1);
            return 0;
        }
        reverse(all(B));
        A = B;
    }
    reverse(all(ans));
    rep(i, N) {
        output(ans[i]);
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define pb push_back 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define double long double
 
using namespace std;

int main()
{
    IOS;
    ll h,a;
    cin >> h >> a;
    ll x = (h/a) + bool(h%a);
    cout << x;
}   

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

int main() {
	int a;
	cin >> a;
	unordered_set<string>b;
	for (int c = 0; c < a; c++) {
		string d, e;
		cin >> d >> e;
		if (d == "insert")b.insert(e);
		else {
			if (b.find(e) == b.end())cout << "no" << endl;
			else cout << "yes" << endl;
		}
	}
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;

char A[55][55], B[55][55];
bool vis[55][55][55][55];
constexpr int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
bool solve() {
    int W, H;
    cin >> W >> H;
    if (W == 0) return false;
    int sxa, sya, sxb, syb, gxa, gya, gxb, gyb;
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
            if (A[i][j] == 'L') {
                sxa = i;
                sya = j;
            }
            if (A[i][j] == '%') {
                gxa = i;
                gya = j;
            }
        }
        REP(j, W) {
            cin >> B[i][j];
            if (B[i][j] == 'R') {
                sxb = i, syb = j;
            }
            if (B[i][j] == '%') {
                gxb = i, gyb = j;
            }
        }
    }
    REP(ia, H) REP(ja, W) REP(ib, H) REP(jb, W) { vis[ia][ja][ib][jb] = false; }
    using arr4 = array<int, 4>;
    queue<arr4> que;
    que.push({sxa, sya, sxb, syb});
    while (!que.empty()) {
        arr4 arr = que.front();
        que.pop();
        int i = arr[0], j = arr[1], x = arr[2], y = arr[3];
        vis[i][j][x][y] = true;
        // Aが動く
        REP(k, 4) {
            int ni = i + dx[k], nj = j + dy[k];
            int nx = x + dx[k], ny = y - dy[k];
            if (ni < 0 || ni >= H || nj < 0 || nj >= W || A[ni][nj] == '#') continue;
            if (nx < 0 || nx >= H || ny < 0 || ny >= W || B[nx][ny] == '#') {
                nx = x, ny = y;
            }
            if ((A[ni][nj] == '%' && B[nx][ny] != '%') || (A[ni][nj] != '%' && B[nx][ny] == '%')) continue;
            if (vis[ni][nj][nx][ny]) continue;
            vis[ni][nj][nx][ny] = true;
            que.push({ni, nj, nx, ny});
        }

        // Bが動く
        REP(k, 4) {
            int ni = i + dx[k], nj = j + dy[k];
            int nx = x + dx[k], ny = y - dy[k];
            if (ni < 0 || ni >= H || nj < 0 || nj >= W || A[ni][nj] == '#') {
                ni = i, nj = j;
            };
            if (nx < 0 || nx >= H || ny < 0 || ny >= W || B[nx][ny] == '#') continue;
            if ((A[ni][nj] == '%' && B[nx][ny] != '%') || (A[ni][nj] != '%' && B[nx][ny] == '%')) continue;
            if (vis[ni][nj][nx][ny]) continue;
            vis[ni][nj][nx][ny] = true;
            que.push({ni, nj, nx, ny});
        }
    }
    if (vis[gxa][gya][gxb][gyb])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return true;
}

signed main() {
    while (solve())
        ;
}


Measured memory_bytes: 12396
#include"bits/stdc++.h"
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  int sum=0;
    sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  for(int i=0;i<N;i=i+2){
    sum+=S.at(i);}
  int sumw=0;
  for(int i=1;i<N;i=i+2){
    sumw+=S.at(i);}
  cout<<sum-sumw<<endl;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

int ps[200001],n,q,r[200001];
map<int,set<int>> ab;

int main() {
    cin >> n >> q;
    for(int i = 0;i < n-1;i++) {
        int a,b;
        cin >> a >> b;
        ab[a].insert(b);
        ab[b].insert(a);
    }
    for(int  i = 0;i < q;i++) {
        int p,x;
        cin >> p >> x;
        ps[p] += x;
    }
    stack<pair<int,int>> s;
    s.push(make_pair(1,0));
    while(!s.empty()) {
        auto cn = s.top();
        s.pop();
        r[cn.first] = r[cn.second] + ps[cn.first];
        for(auto e:ab[cn.first]) {
            if(e != cn.second) {
                s.push(make_pair(e,cn.first));
            }
        }
    }
    for(int i = 1;i <= n;i++) {
        cout << r[i] << " ";
    }
    cout <<  endl;
}

Measured memory_bytes: 41884
#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;

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 N, std::string S, std::string T){
  string ans="";
  REP(N){
    ans+=S[i];
    ans+=T[i];
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(N, S, T);
    return 0;
}


Measured memory_bytes: 256
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]

def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A

def s():
 print(*d(list(map(int,input().split()))))
 print(c)
if'__main__'==__name__:c=-int(input());s()


Measured memory_bytes: 61648
def main():
    n, x = map(int,input().split())
    a = list(map(int,input().split()))

    a = sorted(a)
    ans = 0
    tmp = 0
    for i in a:
        tmp += i
        if tmp <= x:
            ans+=1

    if n == ans:
        if sum(a) != x:
            ans-=1

    print(ans)




if __name__ == "__main__":
        main()


Measured memory_bytes: 3060
import sys
s=[list(map(int,e.split(',')))for e in sys.stdin]
for i in range(1,len(s)):
 k=len(s[i]);b=k>len(s[i-1])
 for j in range(k):
  t=j-b
  s[i][j]+=max(s[i-1][t*(j>0):t+2])
print(*s[-1])


Measured memory_bytes: 5608
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
   long long int n,m;
   cin>>n>>m;
   long long int sum=1;

   if(abs(n-m)>=2){
       cout<<"0"<<endl;
       return 0;
   }else{
       for(long long int i=1;i<=n;i++){
           sum *=i%1000000007;
           sum = sum%1000000007;
         
       }
       for(long long int i=1;i<=m;i++){
           sum *=i%1000000007;
           sum = sum%1000000007;
       }
       if(n==m){
           sum = (sum*2)%1000000007;
       }else{
           sum = sum%1000000007;
       }
   }
 
   cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = sorted([int(input()) for _ in range(N)])

B = list(reversed(A))
result = abs(A[0] - B[0])

for _, (a, b) in enumerate(zip(A[1:N//2], B[1:N//2])):
    value = abs(A[0]-b) + abs(B[0]-a)
    result += value
    A[0], B[0] = a, b

if N % 2 != 0:
    x = A[N//2]
    result += max(abs(A[0]-x), abs(B[0]-x))

print(result)

Measured memory_bytes: 8516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7;

int main(){
  ll N;
  cin>>N;
  
  vector<ll>X(N);
  vector<pair<ll,ll>>Y(N);
  
  
  for(ll i=0;i<N;i++){
   cin>>X[i];
    Y.at(i).first=X[i];
    Y.at(i).second=(i+1);
   
  }
  
  
  sort(Y.begin(),Y.end());
  
  
  for(ll i=0;i<N;i++){
    ll tmp=Y.at(i).second;
   Y.at(i).first=tmp;
    Y.at(i).second=i;
  }
  
  sort(Y.begin(),Y.end());
  sort(X.begin(),X.end());
  
  

  ll B=X[(N/2)];
  ll A=X[(N/2)-1];
  
  for(ll i=0;i<N;i++){
if(Y.at(i).second>=(N/2)){
  cout<<A<<endl;
}
else{
  cout<<B<<endl;
}
  }
  

}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
int a,b,c,x,y;
int main()
{
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	int ans=0;
	int k=min(x,y);
	ans+=min(c*2*k,a*k+b*k);
	x-=k,y-=k;
	if(x>0) ans+=min(c*2*x,a*x);
	else ans+=min(c*2*y,b*y);
	printf("%d\n",ans);
	return 0;
}

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

#include <climits>
#include <cmath>
#include <cstring>

#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int main()
{
	FAST;
	int n,m;
	cin >> n >> m;
	pair<int,pair<int,int>> arr[m];
	vector<string> ans(m);
	int id[n+1] = {0};

	for(int i=0 ; i<m ; i++)
	{
		cin >> arr[i].first >> arr[i].second.first;
		arr[i].second.second = i;
	}
	
	sort(arr , arr+m);

	for(int i=0 ; i<m ; i++)
	{
		string temp = to_string(arr[i].first);
		while(temp.size() < 6)
			temp  = '0' + temp;
		
		string temp1 = to_string(id[arr[i].first]+1);
		id[arr[i].first]++;
		while(temp1.size() < 6)
			temp1 = '0' + temp1;

		ans[arr[i].second.second] = (temp+temp1);
	}

	for(int i=0 ; i<m ; i++)
		cout << ans[i] << "\n";
	return 0;
}

Measured memory_bytes: 8576
// -*- coding:utf-8-unix -*-

use proconio::input;
// use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        s: [char; n],
    }

    if s.iter().any(|&a| a == 'Y') {
        println!("Four");
    } else {
        println!("Three");
    }
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
//#define int long long 

using namespace std;
int dp[1000001][3];
int arr[10000001][3];
int solve(int n,int i)
{
    if(n < 0 )
        return 0;
    if(dp[n][i]!=-1)
        return dp[n][i];
    return dp[n][i]=max(arr[n][i%3]+solve(n-1,(i+1)%3),arr[n][i%3]+solve(n-1,(i+2)%3));
}

int main()
{
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    int mx = max(solve(n-1,0),max(solve(n-1,1),solve(n-1,2)));
    cout<<mx<<endl;


}

Measured memory_bytes: 22700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int cnt;
vector<int> ch(10010);
vector<int> v[10010];

void dfs(int x, int p){
  ch[x] = cnt;
  cnt++;
  for(auto to:v[x]){
    if(to==p) continue;
    dfs(to,x);
  }
}

int main(){
  int n;
  cin >> n;
  
  rep(i,n-1){
    int a,b; cin >> a >> b; a--; b--;
    v[a].emplace_back(b);
    v[b].emplace_back(a);
  }
  vector<int> c(n);
  int ans = 0;
  rep(i,n){
    cin >> c[i];
    ans += c[i];
  }
  sort(c.rbegin(),c.rend());
  ans -= c[0];

  cnt = 0;
  dfs(0,-1);

  cout << ans << endl;
  rep(i,n){
    cout << c[ch[i]] << (i!=n-1?" ":"");
  }
  cout << endl;
  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

ll n, m, fact[maxN];


int main() {
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	fact[0] = 1;
	RI(i, 100000) {
		fact[i] = (fact[i - 1] * i) % inf;
	}
	if (abs(n - m) > 1) cout<<0<<endl;
	else {
		ll ans = (fact[n] * fact[m]) % inf;
		if (n == m) ans *= 2;
		cout<<ans % inf;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
typedef vector<Int> veci;
typedef vector<double> vecd;
typedef vector<int> veci;
typedef vector<double> vecd;
typedef vector<veci> mati;
typedef vector<vecd> matd;
#define A first
#define B second
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(auto i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
template<typename T> vector<T> getVector(const int n) { return vector<T>(n); }
template<typename T> vector<T> getVector(const int n, const T a) { return vector<T>(n, a); }
template<typename T> vector<T> getEmptyVector() { return vector<T>(); }
template<typename T> void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); }
// #define X first
// #define Y second
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const ll MOD = 1000000007;
const int MAXN = 1<<17;
const int inf = 1<<28;
const int NIL = -inf;
int popcount(int x)  { return __builtin_popcount(x); }
#define DUMP(a) \
    do { std::cout << #a " = " << (a) << ", "; } while(false)
#define DUMPLN(a) \
    do { std::cout << #a " = " << (a) << std::endl; } while(false)

int N, M;
mati G;

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

    cin >> N >> M;
    G.resize(N);
    FORO(i, M) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].PB(v);// G[v].PB(u);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;

    mati d(N, veci(3, -1));
    queue<pii> Q;
    Q.push(pii(s, 0));
    d[s][0] = 0;
    while(!Q.empty()) {
        pii p = Q.front(); Q.pop();
        int u = p.A, q = p.B;
        int nq = (q + 1) % 3;
        //DUMP(u); DUMPLN(ud);
        FORIT(it, G[u]) {
            int v = *it;
            if(d[v][nq] != -1) continue;
            Q.push(pii(v, nq));
            d[v][nq] = d[u][q] + 1;
        }
    }

    int ans = d[t][0];
    if(ans > -1) ans /= 3;
    cout << ans << endl;

    return 0;
}


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

int f(int x)
{
	if(x<3)
		return 1;
		
	return(f(x-1)+f(x-2));
	
} 
int main()
{
	int x,a[4]={0};
	char c[4];
	cin>>x;
	while(x--){
	std::cin>>c;
	if(c[0]=='A')
		a[0]++;
	else if(c[0]=='W')
		a[1]++;
	else if(c[0]=='T')
		a[2]++;
	else
		a[3]++;
}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl;
}















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

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int num = 0;
    for (int i = 0; i < s.size(); i++) {
        switch (s[i]) {
        case 'A':
        case 'C':
        case 'G':
        case 'T':
            num++;
            break;
        default:
            ans = max(ans, num);
            num = 0;
            break;
        }
    }
    ans = max(ans, num);
    num = 0;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) {
    def checkSorted: Unit = {
      val i = readLine()
      if(i != "0 0") {
        println(i.split(" ").map(_.toInt).sorted.mkString(" "))
        checkSorted
      }
    }

    checkSorted
  }
}

Measured memory_bytes: 47048
import java.util.*;
import java.io.*;
class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine(),",");
        System.out.print(st.nextToken()+" "+st.nextToken()+" "+st.nextToken());
    }
    
}


Measured memory_bytes: 8144