akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long int;
typedef long double ld;
typedef pair<ll,ll> pll;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll ,null_type,less<ll >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest element(0-based)=> cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X => cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

#define sz(v) (ll)v.size()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	char c;
	cin>>c;
	cout<<(char)(c+1)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
U_MAP mp;
pq que;

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

  cin >> n;
  rep(i, n) cin >> a[i];
  multiset<ll> st;
  st.insert(a[n - 1]);
  mp[a[n - 1]]++;
  st.insert(LINF);
  rrrep(i, n - 2, 0) {
    auto it = st.upper_bound(a[i]);
    ll score = *it;
    if (score == LINF) {
      ans++;
    } else {
      mp[score]--;
      if (mp[score] == 0) {
        st.erase(score);
      }
    }
    st.insert(a[i]);
    mp[a[i]]++;
  }
  Cout(ans + 1);
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d[i];
    }

    sort(d.begin(), d.end(), greater<int>());

    int x=d.at(0);
    int cnt=1;
    for(int i=0; i<n-1; i++){
        if(d.at(i)==d.at(i+1)) continue;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	string S;
	cin >> N >> S;
	vector<vector<int>> a(N+1, vector<int>(128));
	for (int i = N-1; i >= 0; -- i) {
		a[i]['R'] = a[i+1]['R'];
		a[i]['G'] = a[i+1]['G'];
		a[i]['B'] = a[i+1]['B'];
		++ a[i][S[i]];
	}
	ll res = 0;
	for (int i = 0; i+2 < N; ++ i) {
		for (int j = i+1; j+1 < N; ++ j) if (S[i] != S[j]) {
			for (char c : string("RGB")) if (c != S[i] && c != S[j]) {
				int r = a[j+1][c];
				int k = j+(j-i);
				if (k < N && S[k] == c) -- r;
				res += r;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 5700
#include<bits/stdc++.h>
#define ll long long
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 1234567
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

int main()
{
    ll N, M;
    fin(N); fin(M);
    vector <ll> v[N + 1];
    for(ll i = 1; i <= M; i++)
    {
        ll foo, bar;
        fin(foo); fin(bar);
        v[foo].push_back(bar);
        v[bar].push_back(foo);
    }
    for(ll i = 1; i <= N; i++)
    {
        fout((ll) v[i].size());
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define in(x) int x; cin>>x;
#define inn(x, y) int x, y; cin>>x>>y;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}

int32_t main(void){
	IOS;
	
	in(n);
	int arr[n+1];
	mem(arr);
	rep(i, 0, n-1)
	{
		in(temp);
		arr[temp] += 1;
	}
	rep(i,1,n+1) cout<<arr[i]<<endl;
}

Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 205
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,a,b,n;
	cin>>a>>b>>n;
	ll ar[a+1],br[b+1]; k=2e18; l=2e18;
	for(i=1;i<=a;i++){
		cin>>ar[i];
		k=min(k,ar[i]);
	}
	for(i=1;i<=b;i++){
		cin>>br[i];
		l=min(br[i],l);
	}

	ll mn=2e18,x,y,c;
	mn=min(mn,k+l);
	for(i=1;i<=n;i++){
		cin>>x>>y>>c;
		mn=min(mn,ar[x]+br[y]-c);
	}
	cout<<mn;
	return 0;
}

Measured memory_bytes: 1792
import sys
water1,water2,sugar1,sugar2,per_limit,total_limit = map(int,input().split())

max_sugar_per_water = 0
best_total = 0
best_sugar = 0
# waterはfor使うか、、、

if per_limit == 0:
    print(100*water1)
    sys.exit()

for time_water1 in range(30):
    for time_water2 in range(30):
        water = water1*time_water1*100 + water2*time_water2*100
        if water > total_limit:
            break
        if water == 0:
            continue

        sugar_limit = (water//100)*per_limit
        time_sugar1 = 0
        while True:
            time_sugar2 = 0
            while True:
                sugar = sugar1*time_sugar1+sugar2*time_sugar2

                # トータルの重さ判定
                if total_limit < water+sugar:
                    break
                # 溶ける量制限判定
                if sugar_limit < sugar:
                    break

                # 濃度求めて、最大なら更新
                sugar_per_water = sugar/water
                if sugar_per_water >= max_sugar_per_water:
                    max_sugar_per_water = sugar_per_water
                    best_sugar = sugar
                    best_total = sugar+water

                # 砂糖2の量を更新
                time_sugar2 += 1

            # 砂糖1だけで制限超過してたらbreak
            if sugar1*time_sugar1 > sugar_limit or sugar1*time_sugar1 + water > total_limit:
                break
            # 砂糖1を更新
            time_sugar1 += 1

        if water > total_limit:
            break
print(best_total,best_sugar)

Measured memory_bytes: 9140
n=int(input())
s=str(input())
R=[]
B=[]
G=[]
for i in range(n):
  if s[i]=='R':
    R.append(i)
  elif s[i]=='B':
    B.append(i)
  else:
    G.append(i)
ans=len(R)*len(B)*len(G)

for i in range(n-1):
  for j in range(i+1,n):
    char1=s[i]
    char2=s[j]
    if char1==char2:
      pass
    else:
      if n>2*j-i>j and s[2*j-i]!=char1 and s[2*j-i]!=char2:
        ans-=1
print(ans)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int x, y, z; cin >> x >> y >> z;

    cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	static long[] p;
	static long[] pi;
	static long mod = 1000000007;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		int a = Integer.parseInt(sa[2]);
		int b = Integer.parseInt(sa[3]);
		br.close();

		p = new long[h + w];
		p[0] = 1;
		for (int i = 1; i < p.length; i++) {
			p[i] = p[i - 1] * i % mod;
		}
		pi = new long[h + w];
		pi[0] = 1;
		for (int i = 1; i < pi.length; i++) {
			pi[i] = pi[i - 1] * modinv(i) % mod;
		}

		long ans = 0;
		for (int i = 0; i < h - a; i++) {
			long temp = nCr(i + b - 1, i);
			temp *= nCr(h - i - 1 + w - b - 1, h - i - 1);
			temp %= mod;
			ans += temp;
			ans %= mod;
		}
		System.out.println(ans);
	}

	static long nCr(int n, int r) {
		if (n <= 0 || r <= 0) {
			return 1;
		}
		long v = p[n];
		v = v * pi[n - r] % mod;
		v = v * pi[r] % mod;
		return v;
	}

	static long modinv(long a) {
		long b = mod;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= mod;
		if (u < 0) u += mod;
		return u;
	}
}


Measured memory_bytes: 24148
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;
 
void Main()
{
	int N;
    int count = 0;
    string S;
  
  	cin >> N >> S;
  
    if(N % 2 == 1){
      printf("No");
    }
  
    else{
      for(int i = 0; i < N / 2; i++){
        
        if(S[i] == S[N/2+i])
          count++;
      }
      if(count == N/2){
        printf("Yes");
      }
      else
        printf("No");
    }
	
	
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args)  {
        Scanner scan =new Scanner(System.in);
        String s=scan.next();
        long k = Long.parseLong(scan.next());

        long len=Math.min(s.length(),k);
        char ans = '1';
        for(int i=0;i<len;++i){
            if (s.charAt(i)!='1'){
                ans=s.charAt(i);
                break;
            }
        }
        System.out.print(ans);



}
}
//end

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long

signed main() {
  int n;
  cin >> n;
  int a[3 * n];
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  int sumlow[n + 1];
  priority_queue<int, vector<int>, greater<int> > quelow;
  sumlow[0] = 0;
  for (int i = 0; i < n; i++) {
    sumlow[0] += a[i];
    quelow.push(a[i]);
  }
  for (int i = n; i < 2 * n; i++) {
    quelow.push(a[i]);
    sumlow[i - n + 1] = sumlow[i - n] + a[i] - quelow.top();
    quelow.pop();
  }
  int sumhigh[n + 1];
  priority_queue<int> quehigh;
  sumhigh[n] = 0;
  for (int i = 2 * n; i < 3 * n; i++) {
    sumhigh[n] += a[i];
    quehigh.push(a[i]);
  }
  for (int i = 2 * n - 1; i >= n; i--) {
    quehigh.push(a[i]);
    sumhigh[i - n] = sumhigh[i - n + 1] + a[i] - quehigh.top();
    quehigh.pop();
  }
  int ans = sumlow[0] - sumhigh[0];
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sumlow[i] - sumhigh[i]);
  }
  cout << ans << endl;
  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;

#define ForIndex(N) for (size_t index = 0; index < (N); index++)

void calc(const uint64_t n, const uint64_t k)
{
    // 初期得点: 1 から n までのどれか p0 とする
    // 目標: k は 1 以上の値

    // コインを x 回振った時、すべて表の場合の得点は p0 * x
    // p0 * 2^x >= k になるまで振るので、x は log2 (k / p0) を超える最初の値
    // 勝つ確率 = 全て表なので、0.5^x 乗

    double sumP = 0;
    double oneP = 1.0 / static_cast<double>(n);

    for (uint64_t p0 = 1; p0 <= n; p0++)
    {
        if (p0 >= k) {
            // 絶対勝利するケース
            sumP += oneP * (n - p0 + 1);
            break;
        }
        else {
            int requireCount = std::ceil(std::log2(static_cast<double>(k) / static_cast<double>(p0)));
            sumP += std::pow(0.5, requireCount) * oneP;
        }
    }

    printf("%.12f\n", sumP);
}

int main()
{
    uint64_t N, K;
    cin >> N >> K;
    calc(N, K);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int r;
	cin >> r;
	if (r < 1200) cout << "ABC" << endl;
	else if (r >=1200 && r <2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (int argc, const char * argv[]) {
	int count;
	int a,b,c;
	int i;
	int cache;
	
	scanf("%d", &count);
	for (i=0; i<count; i++) {
		scanf("%d%d%d", &a,&b,&c);
		
		if (a > c) {
			cache = c;
			c = a;
			a = cache;
		}
		if (b > c) {
			cache = c;
			c = b;
			b = cache;
		}
		if (a*a+b*b == c*c) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}	
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

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

    int n;
    cin >> n;
    vector<vi> a(n, vi(3));
    for (auto &x : a) for (auto &y : x) cin >> y;

    vector<vi> dp(n, vi(3));
    dp[0] = a[0];
    for (int i = 1; i < n; i++)
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                if (j != k) dp[i][j] = max(dp[i][j], a[i][j] + dp[i - 1][k]);
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}

/*
USE LONG LONG!!!!

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

Measured memory_bytes: 11264
#include "vector"
#include "math.h"
#include "algorithm"
#include "iostream"
#include "string"

using namespace std;
typedef long long ll;

string ans;
string dp[70][70];

string changeCorrectValue(string a){
    if(a.size() > 1){
        if(a[0] == '0') a.erase(a.begin());
        return a;
    }
    return a;
}

string detect(string a, string b){
    a = changeCorrectValue(a);
    b = changeCorrectValue(b);
    if(a.size() > b.size()){
        return a;
    }
    else if(a.size() < b.size()){
        return b;
    }
    // same keta
    for(int i=0; i<a.size(); i++){
        int num = a[i] - '0';
        int num2 = b[i] - '0';
        if(num > num2){
            return a;
        }
        else if(num < num2){
            return b;
        }
    }
    return a;
}


bool isNum(char a){
    if(0 <= a - '0' && a - '0' <= 9) return true;
    return false;
}


string solve(int W, int H, vector<vector<char> > vv){
    if(isNum(vv[0][0])) dp[0][0] = vv[0][0];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(j+1 < W && isNum(vv[i][j+1])) {
                dp[i][j+1] = detect(dp[i][j+1], dp[i][j] + vv[i][j+1]);
            }
            if(i+1 < H && isNum(vv[i+1][j])) {
                dp[i+1][j] = detect(dp[i+1][j], dp[i][j] + vv[i+1][j]);
            }
            // cout << i << "," << j << ":" << dp[i][j] << endl;
            ans = detect(ans, dp[i][j]);
        }
    }
    return ans;
}

int main(){
    while(1){
        int W, H;
        cin >> W >> H;
        if(!W && !H) break;
        vector<vector<char> > vv(H, vector<char>(W));
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cin >> vv[i][j];
                dp[i][j] = "";
            }
        }
        ans = "";
        
        cout << solve(W, H, vv) << endl;
    }
    return 0;
}


Measured memory_bytes: 3388
#include <cstdio>
long long n, p, ans=1, i, u;
int main(){
	scanf("%lld%lld", &n, &p);
	if(n==1) ans = p;
	else for(i=2; i*i <= p; i++){
		for(u=0; !(p%i); u++, p/=i);
		for(u/=n; u; u--, ans*=i);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	cin>>a>>b>>c;
	if(a + b == c || a + c == b || b + c == a){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long

int32_t  main()
{   
    IOS;
    int n,k;
    cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
        cin>>v[i];
    int curr=1;
    int vis[n+1];
    memset(vis,0,sizeof(vis));
    vector<int> ans;
    for(int i=0;i<n+1;i++)
    {
        ans.push_back(curr);
        curr=v[curr];
        if(vis[curr])
            break;
        vis[curr]=1;
    }
    ans.push_back(curr);

    if(k<ans.size())
    {
        cout<<ans[k]<<endl;
        return 0;
    }
    k-=(ans.size()-1);
    int ind=-1;
    for(int i=0;i<ans.size();i++)
    {
        if(ans[i]==curr)
        {
            ind=i;
            break;
        }
    }
    int len=(ans.size()-ind-1);
    k%=len;
    cout<<ans[ind+k]<<endl;
}   

Measured memory_bytes: 8436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	ll k;
	cin>>s>>k;
	if(s[0] == '1')
	{
		ll pos = 0;
		while(s[pos] == '1')
			pos++;
		if(pos == s.size())
		{
			cout<<"1\n";
			return 0;
		}
		else if(pos>=k)
		{
			cout<<"1\n";
			return 0;
		}
		else
		{
			cout<<s[pos]<<endl;
			return 0;
		}
	}
	cout<<s[0]<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
static int N= 0;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		int data[]= {9,900,90000};
				
		ArrayList<Integer> al =new ArrayList<Integer>();
		int count = 0;
		int keta=0;
		int a=N;
		while(true) {
	    int t =a%10;
		a=a/10;
		keta++;
		al.add(t);
		if(a<1) break;
	
		
		}
		
		int j=0;
		for(int i=0;i<keta-1;i+=2) {	
			
			
			count += data[j];
			j++;
		}
		if(keta %2 != 0) {
			
			
			count+= N-Math.pow(10,keta-1)+1;
		}
		
		
		System.out.println(count);
}
}


Measured memory_bytes: 21204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int k = getInt();
		int x = getInt();
		for ( int i = x - k + 1 ; i < x + k ; i++ ) {
			System.out.printf( "%d ", i );
		}
		System.out.println();
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

class unionfind_tree{
    public:
    int N;

    vector<int> par;
    vector<int> size;

    unionfind_tree(int n): N(n){
        par.resize(n);
        size.resize(n);
        rep(i,n){ 
            par[i] = i;
            size[i] = 1;
        }
    }

    int getPar(int x){
        if(par[x] == x) return x;
        return par[x] = getPar(par[x]);
    }

    void unite(int u,int v){
        int pu = getPar(u);
        int pv = getPar(v);
        if(pu == pv) return ;
        par[pu] = pv;
        size[pv] += size[pu];
    }
    
    bool isSame(int u,int v){
        int pu = getPar(u);
        int pv = getPar(v);
        return pu == pv;
    }

    int getSize(int u){
        int par_u = getPar(u);
        return size[par_u];
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    unionfind_tree uf(N);
    vector<ll> ans(M);
    vector<int> a(M),b(M);

    rep(i,M){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    ans[M-1] = 1LL * N*(N-1)/2;
    
    for(int i = M-1; i > 0; i--){
        if(!uf.isSame(a[i],b[i])){
            ans[i-1] = ans[i] - uf.getSize(a[i]) * uf.getSize(b[i]);
        }else{
            ans[i-1] = ans[i];
        }
        uf.unite(a[i],b[i]);
    }

    rep(i,M){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */

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

// #define int long long

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;}
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

/* }}} */

struct UnionFind {
  vi par;
  vi rank;

  UnionFind(int n) : par(n), rank(n, 0) {
    REP(i, n) par[i] = i;
  }

  int root(int x) {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  UnionFind uni(n);

  REP(i, q) {
    bool a;
    int b, c;
    cin >> a >> b >> c;
    if (a) {
      print(uni.same(b, c));
    } else {
      uni.unite(b, c);
    }
  }

  return 0;
}

Measured memory_bytes: 1288
// DSL_1 A
#include<cstdio>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int par[10000], rank[10000];

void init( int n )
{
	rep( i, n )
		par[i] = i, rank[i] = 0;

	return;
}

int find( int x )
{
	if( x == par[x] )
		return x;
	else
		return par[x] = find( par[x] );
}

void unite( int x, int y )
{
	x = find( x );
	y = find( y );
	if( x == y )
		return;

	if( rank[x] > rank[y] )
		par[y] = x;
	else
	{
		par[x] = y;
		if( rank[x] == rank[y] )
			++rank[y];
	}

	return;
}

bool same( int x, int y )
{
	return find( x ) == find( y );
}

int main()
{
	int n, q;
	scanf( "%d%d", &n, &q );
	init( n );

	rep( i, q )
	{
		char com[2];
		int x, y;
		scanf( "%s%d%d", com, &x, &y );

		if( *com == '0' )
			unite( x, y );
		else
			printf( "%d\n", same( x, y ) );
	}

	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    vii a(N);
    vii b(N);
    int x;
    Rep(i,N) Scd(x), a[i]={x,i};
    Rep(i,N) Scd(x), b[i]={x,i};

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    bool OK = true;

    vi p(N); // a_{p_i} = b_i
    Rep(i,N){
        p[a[i].second] = b[i].second;
        if( a[i].first > b[i].first ) OK = false;
    }

    vi t(N);
    int cnt = 0;
    stack<int> s;
    Rep(i,N){
        if( !t[i] ) cnt++, s.push(i);
        while( s.size() ) {
            int from = s.top(); s.pop();
            t[from] = cnt;
            if( !t[p[from]] ) s.push(p[from]);
        }
    }

    if( cnt == 1 ){
        Rep(i,N){
            if( i == N-1 ) {
                OK = false;
                break;
            }
            if( b[i].first >= a[i+1].first ){
                break;
            }
        }
    }

    // Rep(i,N){
    //     printf ("a,%d[%d] : b,%d[%d]\n", a[i].first, a[i].second,
    //             b[i].first, b[i].second );
    // }
    // printf ("cnt:%d\n", cnt );

    YesNo(OK);

    return 0;
}





Measured memory_bytes: 2560
//https://atcoder.jp/contests/agc005/tasks/agc005_b
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main(){
#if LOCAL&01
    std::ifstream in("./test/sample-3.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    vector<ll> an(N+1);
    vector<ll> pos(N+1); //aは1..Nを並べ替えたもの
    FOR(i,1,N+1){
        ll a;
        cin>>a;
        an.at(i)=a;
        pos.at(a)=i; //場所
    }

    ll ans = 0;
    set<ll> used{0,N+1}; //placeがはいる
    //set 追加はO(logN),値はsortされてはいるので、2分探索できる、sortされた順番でiteratorで取得する
    FOR(a,1,N+1){ //aを1から
        auto now_pos=pos[a]; //今の場所
        auto it = used.lower_bound(now_pos); //以上,upper_bound(より上)でもよい
        auto l = *it; //数字が小さい順のplaceを入れていって、その左右をみていく
        auto r = *(--it);
        ans += a*(r-now_pos)*(now_pos-l);
        used.insert(pos[a]);
    }
    cout<<ans<<endl;
    return 0;
}

//tleする
int tle_main() {
    ll N; cin>>N;
    vector<ll> an(N);
    for(auto&& a: an){
        cin>>a;
    }

    ll ans=0;
    for (ll n=N-1;n>=0;--n) {
        ll tmp=INT64_MAX;
        for(ll i=n;i>=0;--i){
            tmp = min(an.at(i), tmp);
            ans += tmp;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
#include <string.h>

typedef struct{
	int taro;
	int hanako;
}score_;

score_ score;

int main(void)
{
	int n;
	scanf("%d",&n);
	
	char card[n][2][100];
	
	for(int i = 0; i < n; i++){
		scanf("%s %s",card[i][0],card[i][1]);
		//printf("%s %s\n",card[i][0],card[i][1]);
	}
	
	for(int i = 0; i < n; i++){
		int res = strcmp(card[i][0],card[i][1]);
		if(res > 0){
			score.taro += 3;
		}else if(res == 0){
			score.taro++;
			score.hanako++;
		}else{
			score.hanako += 3;
		}
	}
	
	
	printf("%d %d\n",score.taro,score.hanako);
	
	return 0;
}
	


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

long long n;

long long calc(long long x) {
    long long ret = x/10;
    for (long long cur = 50; cur < LLONG_MAX/5; cur *= 5) {
        ret += x/cur;
    }
    return ret;
}

int main() {
    cin >> n;
    if (n%2) return !printf("0");
    cout << calc(n);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

    int n, m;
    char c;
    cin>>n>>m;
    vector<ll> w(m, 0ll);
    w[0] = 1ll;

    for (int i=0; i<n; ++i) {
        for (int j=0; j<m; ++j) {
            cin>>c;
            if (c == '#')
                w[j] = 0ll;
            else
                if (j>0) {
                    w[j] += w[j-1]*1ll;
                    w[j] %= MOD;
                }
        }
    }
    cout<<w[m-1]%MOD<<endl;

    return 0;
}

Measured memory_bytes: 3588
import math
a,b,x = map(int, input().split())
if x >= a*a*b/2:
    X = (2*a*a*b-2*x)/(a**3)
    print(math.degrees(math.atan(X)))
else:
    X = (a*b*b)/(2*x)
    print(math.degrees(math.atan(X)))

Measured memory_bytes: 38384
N,K=map(int,input().split())
from collections import defaultdict
data=[]
for n in range(N):
    data.append(tuple(map(int,input().split())))
data.sort(key=lambda x:x[0])
now=0
for i in range(len(data)):
    now+=data[i][1]
    if now>=K:
        print(data[i][0])
        break

Measured memory_bytes: 18484
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  string S;
  cin>>S;

  cout<<S[0];

  cout<<S.length()-2;

  cout<<S[S.length()-1]<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>

int main()
{
	int A, B;
	int ans;
	scanf("%d %d", &A,&B);
	if (A <= 5)
	{
		ans = 0;
	}
	else if (A <= 12)
	{
		ans = B / 2;
	}
	else
	{
		ans = B;
	}
    std::cout << ans; 

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (buf1==buf2&&(buf2=(buf1=buf)+fread(buf,1,1<<23,stdin),buf1==buf2)?-1:*buf1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*buf1=buf,*buf2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=2e5;
typedef int fuko[yuzu|10];
fuko a,l,r;
int main() {
  int i,n=read();
  for (i=1;i<=n;++i) a[i]=read();
  for (i=1;i<=n;++i) {
    for (l[i]=i;l[i]>1&&a[l[i]-1]>a[i];l[i]=l[l[i]-1]);
  } 
  for (i=n;i;--i) {
    for (r[i]=i;r[i]<=n&&a[r[i]+1]>a[i];r[i]=r[r[i]+1]);
  }
  ll llx=0;
  for (i=1;i<=n;++i) llx+=1ll*a[i]*(i-l[i]+1)*(r[i]-i+1);
  write(llx);
}

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

int main()
{
  int a, b , c;
  cin >> a >> b >> c;
  cout << (a + b) * c / 2 << endl;
  return 0;

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
int main(){
  long long i, j, a, b, c;
  cin >> a >> b >> c;
  if(a+b+1>=c) cout << b+c;
  else cout << a+2*b+1;
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
mod = 10 ** 9 + 7
X = [i for i in range(N+1)]
min = 0
max = 0
for i in range(K):
    min += X[i]
    max += X[-1 * (i+1)]
ans = (max - min + 1) % mod
#print(min,max,ans)
for i in range(K,N+1):
    min += X[i]
    max += X[-1 * (i+1)]
    ans += max - min + 1
    ans %= mod
    #print(min,max,ans)
print(ans)

Measured memory_bytes: 16896
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A = [I() for i in range(5)]
k = I()
ans = A[-1]-A[0]
if ans <= k:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 22008
#a, b, m = map(int,input().split())
#a = list(map(int,input().split()))
#bc = 

n, a, b = map(int,input().split())
s = list(input())
x = 0 #予選通過人数
y = 0 #海外の人数

for c in s:
    if c == "a": 
        if x < a+b:
            x += 1
            print("Yes")
        else:
            print("No")
    if c == "b":
        if x < a+b and y < b:
            x += 1
            y += 1
            print("Yes")
        else:
            print("No")
    if c == "c":
        print("No")

Measured memory_bytes: 4712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <numeric>
#include <bitset>
#include <ext/algorithm>
#include <ext/numeric>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL; using namespace std;

int main() {
	LL N, A, B;
	cin >> N >> A >> B;
	if ((N == 1 && A != B) || A > B) {
		cout << 0 << endl;
		return 0;
	}
	LL mmin = (N - 1) * A + B, mmax = A + (N - 1) * B;
	cout << mmax - mmin + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<String, Integer> freq = new HashMap<>();
        int n = sc.nextInt();
        int maxFreq = 0;
        List<String> list = new ArrayList<>();
        String str = "";
        for(int i = 0; i < n; i++) {
          str = sc.next();
          freq.put(str, freq.getOrDefault(str, 0) + 1);
          if(maxFreq == freq.get(str)) {
            list.add(str);
          } else if (maxFreq < freq.get(str)) {
            maxFreq = freq.get(str);
            list = new ArrayList<>();
            list.add(str);
          }
        }
        Collections.sort(list);
        for(String s : list)
          System.out.println(s);
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

const ll MOD = 1e9 + 7;
const int INF = 55;
ll dp [INF] [INF * INF];

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    IOS;

    int n; string s; cin>>n>>s;

    int x = 0, x_m=0;

    loop(i,n)
    {
        if(s[i] == 'I')
        {
            x++;

            if(x_m < x)
            {
                x_m = x;
            }
        }

        else if (s[i] == 'D')
        {
            
                x--;
        
        }
    }

    cout<<x_m<<endl;


}


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

int main(){
   bool is_prime[1000000];
   is_prime[0]=is_prime[1]=false;
   for(int i=2;i<1000000;i++)
      is_prime[i]=true;
   for(int i=2;i*i<1000000;i++){
      if(is_prime[i]){
         for(int j=i*i;j<1000000;j+=i){
            is_prime[j]=false;
         }
      }
   }
   int n[1000000];
   int count=0;
   for(int i=0;i<1000000;i++){
      if(is_prime[i])
         count++;
      n[i]=count;
   }
   while(true){
      int x;
      cin >> x;
      if(cin.eof())
         break;
      cout << n[x] << endl;
   }
   
   return 0;
}

Measured memory_bytes: 7932
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s[s.size()-1]=='2'||s[s.size()-1]=='4'||s[s.size()-1]=='5'||s[s.size()-1]=='7'||s[s.size()-1]=='9')
	{
		cout<<"hon";
		exit(0);
	}
	if(s[s.size()-1]=='0'||s[s.size()-1]=='1'||s[s.size()-1]=='6'||s[s.size()-1]=='8')
	{
		cout<<"pon";
		exit(0);
	}
	cout<<"bon";
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1020000;
int n,p[N],q[N],f[N],t[N];
bool ck(int x, int y, int z){
	return q[x]<q[y]&&q[y]<q[z]||q[y]<q[z]&&q[z]<q[x]||q[z]<q[x]&&q[x]<q[y];
}
int main() {
	read(n);rep(i,1,n)read(p[i]),q[p[i]]=i;
	t[n]=0;
	per(i,n-1,1)
		if(!t[i+1]){
			if(q[i]<q[i+1])t[i]=0;
			else t[i]=1,f[i]=i+1;
		}
		else{
			if(ck(f[i+1],i,i+1))t[i]=t[i+1],f[i]=f[i+1];
			else t[i]=t[i+1]+1,f[i]=i+1;
		}
	printf("%d",t[1]);
	return 0;
}


Measured memory_bytes: 13312
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <functional>

using namespace std;

typedef pair<int, int> P;

struct UF {
	int n;
	vector<int>d;
	UF() {}
	UF(int n) :n(n), d(n, -1) {}

	int root(int v) {
		if (d[v] < 0) { return v; }
		return d[v] = root(d[v]);
	}
	bool unite(int x,int y) {
		x = root(x);
		y = root(y);
		if (x == y) { return false; }
		if (size(x) < size(y)) { swap(x, y); }
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	int size(int v) { return -d[root(v)]; }
};

vector<P>xs;
vector<P>ys;
vector<P>ex;

priority_queue<P, vector<P>, greater<P> > que;

int main(){

	int N;

	scanf("%d",&N);

	UF t(N+5);

	int i;

	for(i=0;i<N;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		xs.push_back(P(x,i));
		ys.push_back(P(y,i));
	}

	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());

	for(i=0;i<N-1;i++){
		ex.push_back(P(xs[i].second,xs[i+1].second));
		que.push(P(abs(xs[i].first-xs[i+1].first),ex.size()-1));
	}
	for(i=0;i<N-1;i++){
		ex.push_back(P(ys[i].second,ys[i+1].second));
		que.push(P(abs(ys[i].first-ys[i+1].first),ex.size()-1));
	}

	int ans=0;

	while(!que.empty()){
		P e = que.top();
		que.pop();
		int a=ex[e.second].first;
		int b=ex[e.second].second;
		if(t.root(a)!=t.root(b)){
			ans+=e.first;
			t.unite(t.root(a),t.root(b));
		}
	}

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

	return 0;
}

Measured memory_bytes: 5524
h,w,k = map(int,input().split())
time1 = [0 for _ in range(h)]
time2 = [0 for _ in range(w)]
raw = []
for _ in range(h):
  raw.append(input())
def nex(time):
  l = len(time)
  for i in range(l):
    if time[i] == 0:
      time[i] = 1
      return time
    else:
      time[i] = 0
  else:
    return 'over'
ans = 0
while time1 != 'over':
  while time2 != 'over':
    cnt = 0
    for i in range(h):
      for j in range(w):
        if raw[i][j] == '#' and time1[i] == 0 and time2[j] == 0:
          cnt += 1
    if cnt == k:
      ans += 1
    time2 = nex(time2)
  time1 = nex(time1)
  time2 = [0 for _ in range(w)]
print(ans)

Measured memory_bytes: 68604
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int N;
int C[10001];
bool visit[10001]={false};
vector<vector<int>> ADJ(10001);
int D[10001]={0};
int score=0;
void dfs(int v,int p)
{
	for (int i = 0; i < ADJ[v].size(); ++i)
	{
		if(ADJ[v][i]!=p)
		{
			dfs(ADJ[v][i],v);
		}
	}
	score+=min(D[v],D[p]);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	

    cin>>N;    
    for (int i = 0; i < N-1; ++i)
    {
    	int x,y;
    	cin>>x>>y;
    	ADJ[x].push_back(y);
    	ADJ[y].push_back(x);	
    }
    int maxin=0;
    for (int i = 0; i < N+1; ++i)
    {
    	if(ADJ[i].size()>ADJ[maxin].size())
    	{
    		maxin=i;
    	}
    }
    for (int i = 1; i <= N; ++i)
    {
    	cin>>C[i];    	
    }
    sort(C+1,C+N+1,greater<int>());
	int x=1;
	queue<int> bfs;
	bfs.push(maxin);
	visit[maxin]=true;
	while(bfs.size()>0)
	{
		int v=bfs.front();
		for (int i = 0; i < ADJ[v].size(); ++i)
		{
			if(!visit[ADJ[v][i]])
			{
				bfs.push(ADJ[v][i]);
				visit[ADJ[v][i]]=true;
			}
		}
		bfs.pop();
		D[v]=C[x];
		x++;
	}
	dfs(1,0);
	cout<<score<<endl;
	for (int i = 0; i < N; ++i)
	{
		cout<<D[i+1]<<" ";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 1408
#Kagami Mochi
N = gets.chomp.to_i
d = []
ans = 1
for i in 0..N-1 do
    d[i] = gets.chomp.to_i
    d.sort!
end
d.uniq!
for i in 1..d.length-1 do 
    if d[0] < d[i] 
        ans = ans + 1
    end
end
puts ans

Measured memory_bytes: 1788