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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N, W;
vector<vector<int>> bg;

ll addbg(int a, int b, int c, int d)
{
    ll sum = 0;
    REP(i, a)
    {
        sum += bg[0][i];
    }
    REP(i, b)
    {
        sum += bg[1][i];
    }
    REP(i, c)
    {
        sum += bg[2][i];
    }
    REP(i, d)
    {
        sum += bg[3][i];
    }
    return sum;
}

int main()
{
    cin >> N >> W;
    vector<ll> w(N), v(N);
    bg.resize(4);
    REP(i, N)
    {
        cin >> w[i] >> v[i];
        bg[w[i] - w[0]].push_back(v[i]);
    }
    REP(i, 4)
    {
        sort(bg[i].begin(), bg[i].end(), greater<int>());
    }
    ll ans = 0;
    REP(i, bg[0].size() + 1)
    {
        REP(j, bg[1].size() + 1)
        {
            REP(k, bg[2].size() + 1)
            {
                REP(l, bg[3].size() + 1)
                {
                    ll weight = w[0] * i + (w[0] + 1) * j + (w[0] + 2) * k + (w[0] + 3) * l;
                    if (weight <= W)
                    {
                        ans = max(ans, addbg(i, j, k, l));
                    }
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int f(int n){
    int ret;

    if(n%2==0){
        ret = n/2;
    }else{
        ret = (3*n)+1;
    }

    return ret;
}

int main(){
    int s,ans,tmp;
    vector<int> vec;

    cin >> s;
    vec.push_back(s);
    while(1){
        int tmp = f(vec.back());
        auto itr = find(vec.begin(),vec.end(),tmp);
        size_t index = std::distance( vec.begin(), itr );
        if (index != vec.size()) {
            ans = vec.size()+1;
            break;
        }
        else { 
            vec.push_back(tmp);
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int x;
    cin >> x;
    int ans = 0;
    for (int i = 1; i <= 33; i++) {
        for (int j = i*i; j <= x; j *= i) {
            ans = max(ans, j);
            if (j == 1) break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3548
n = int(raw_input())
ais = map(int,raw_input().split(' '))
res = [0] * n

c = 0
sign = 1
for ai in ais:
	c += ai * sign
	sign *= -1
res[0] = c/2
for i in range(1, len(ais)): res[i] = ais[i-1] - res[i-1]
print ' '.join(map(str,[e*2 for e in res]))

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

#define ll long long 
ll mincost(ll n,ll h[])
{
	ll dp[n+1],a,b;
	
	dp[1]=0;
	
	for(ll step=2;step<=n;step++)
	{
	   a=abs(h[step]-h[step-1])+dp[step-1];
	  if(step!=2)
	   {b=abs(h[step]-h[step-2])+dp[step-2];}
	  else
	  	{b=INT_MAX;}
	  dp[step]=min(a,b);
	}
	return(dp[n]);
}
int main()
{
   
    
    ll n;
    cin>>n;
    ll h[n+1],i;

    for(i=1;i<=n;i++)
    {
    	cin>>h[i];
    }
    cout<<mincost(n,h)<<endl;
	
}

Measured memory_bytes: 1792
n=int(input())
s=input()
ans=0

for i in range(10):
  x=s.find(str(i))
  if x!=-1:
    for j in range(10):
      y=s.find(str(j),x+1,n)
      if y!=-1:
        for k in range(10):
          z=s.find(str(k),y+1,n)
          if z!=-1:
            ans+=1
print(ans)

Measured memory_bytes: 3188
N, A, B = map(int, input().split())
t_a = True
t_b = False
while True:
    if t_a:
        if A - 1 == B or A - B <= -1:
            A += 1
        elif A + 1 == B or A - B >= 1:
            A -= 1

        if A == B or A < 0 or A > N:
            print("Borys")
            break
        t_a = False
        t_b = True
    elif t_b:
        if B - 1 == B or B - A <= -1:
            B += 1
        elif B + 1 == B or B - A >= 1:
            B -= 1

        if A == B or B < 0 or B > N:
            print("Alice")
            break
        t_a = True
        t_b = False

Measured memory_bytes: 3064
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,m ; cin>>n>>m; 
    vi digit(n+1,-1); 
    bool ok=true;
    for (int i=0;i<m;i++){ 
        int  a, b; cin >> a >> b ; 
        if (digit[a] > -1 and digit[a] != b) ok=false; 
        digit[a]=b;
    }
    if ((!ok) or (digit[1]==0 and n>1)) cout << -1 << endl, exit(0);
    int c=1;
    if (n==1) c=0;
    for (int i=1;i<=n;i++) {
        digit[i] = max(digit[i],c);
        c=0;
    }
    if (n>1 and digit[1]==0) cout << -1 ;
    else for (int i=1;i<=n;i++) cout << digit[i] ; 
    cout << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

string str;

int prin(int a, int b){
	string p;
	p = str.substr(a, b-a+1);
	cout << p << "\n";
	
	return 0;
}

int revers(int a, int b){
	string rev = str.substr(a, b-a+1), rev2 = str.substr(a, b-a+1);
	for (int i = 0; i < b-a+1; i++){
		rev2[i] = rev[b-a-i];
	}
	str = str.replace(a, b-a+1, rev2);

	return 0;
}

int replac(int a, int b, string p){
	str = str.replace(a, b-a+1, p);

	return 0;
}

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

	for (int j = 0; j < n; j++){
		string adj;
		cin >> adj;

		if (adj == "replace"){
			int a, b;
			cin >> a >> b;
			string p;
			cin >> p;

			replac(a, b, p);
		}
		else if (adj == "reverse"){
			int a, b;
			cin >> a >> b;
			
			revers(a, b);
		}
		else if (adj == "print"){
			int a, b;
			cin >> a >> b;
			
			prin(a, b);
		}
		else cout << "ばなな\n";
	}

	return 0;
}


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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n; cin >> n;
  int ans = 1;
  for (int i = 1; i <= n; ++i){
    int x; cin >> x;
    if (ans == x) ++ans;
  }
  cout << (ans - 1 == 0 ? -1 : n - ans + 1);
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  vector<int>a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int N;
  cin>>N;
  cout<<a[N-1]<<endl;
  return 0;
}


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

int main()
{
  int k;
  cin >> k;
  vector<int64_t> as(k);
  for (int i = 0; i < k; i++)
  {
    cin >> as.at(i);
  }
  int64_t a = 2;
  for (int i = k - 1; i >= 0; i--)
  {
    a = ((a + as.at(i) - 1) / as.at(i)) * as.at(i);
  }
  auto ok = [&](int64_t x) {
    for (int i = 0; i < k; i++)
    {
      x = x - (x % as.at(i));
    }
    return x == 2;
  };
  if (!ok(a))
  {
    cout << -1 << endl;
    return 0;
  }
  int64_t l = a, r = 1LL << 62;
  while (r - l > 1)
  {
    int64_t m = (r + l) / 2;
    if (ok(m))
      l = m;
    else
      r = m;
  }
  cout << a << ' ' << l << endl;
}

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

int main() {
  int n,judge;
  cin >> n;
  vector<char> s(n);

  judge = 0;
  for(int i=0;i<n;i++){
    cin >> s.at(i);
    if(s.at(i) == 'Y'){
      judge = 1;
      break;
    }
  }

  if(judge){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    int a[3][100005];
    for(int i=0; i<n; i++) cin >> a[0][i] >> a[1][i] >> a[2][i];

    int dp[3][100005];
    for(int i=0; i<3; i++){
        for(int j=0; j<100005; j++) dp[i][j] = -1e9;
    }
    dp[0][0] = 0;
    dp[1][0] = 0;
    dp[2][0] = 0;

    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(j != k) dp[j][i+1] = max(dp[k][i] + a[j][i], dp[j][i+1]);
            }
        }
    }

    int ans = max({dp[0][n], dp[1][n], dp[2][n]});
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long long N;
	cin >> N;
	int sqN = sqrt(N);
	long long temp1,temp2;
	long long ans = 0;
	for (long  long i = 1; i <= sqN; ++i)
	{
		if (N % i == 0)
		{
			if (i != 1)
			{
				temp1 = i - 1;
				if ((N / temp1) == (N % temp1))
				{
					ans += temp1;
				}
			}

			if (N != i * i)
			{
				temp2 = N / i - 1;

				if ((N / temp2) == (N % temp2))
				{
					ans += temp2;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i = 0; i <= 9; i++){
    for(int j = 0; j <= 9; j++){
      for(int k = 0; k <= 9; k++){
        queue<int> q;
        q.push(i);
        q.push(j);
        q.push(k);
        rep(si,n){
          if(s[si]=='0'+q.front()) q.pop();
          if(q.empty()){
            ans++;
            break;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3680
A,B,H,M = (int(x) for x in input().split())
import math
Angle = (H*30+0.5*M)-M*6
if 180<Angle<=360:
    Angle = 360-Angle
Rad = math.radians(Angle)
Length = math.sqrt(A*A + B*B -2*A*B*math.cos(Rad))
print(Length)

Measured memory_bytes: 9452
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

anntena = [a, b, c, d, e]

flag = False

for i in range(5):
    for j in range(i, 5):
        if anntena[j] - anntena[i] > k:
            flag = True
            print(":(")
        if flag:
            break
    if flag:
        break

if not flag:
    print("Yay!")


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

#define key int





int partition(key *A,int p,int r){
  key x,swap;
  x=A[r];
  int i,j;
  i=p;
  for(j=p;j<=r;j++){
    if(A[j] <= x){
       swap=A[i];
       A[i]=A[j];
       A[j]=swap;
       i++;
    }
  }
  return i-1;
}



int main(){
  int n;
  scanf("%d",&n);
  int *A;
  int i,k;
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  k=partition(A,0,n-1);
  for(i=0;i<k;i++) printf("%d ",A[i]);
  printf("[%d] ",A[k]);
  for(i=k+1;i<n-1;i++)  printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  return 0;
}

Measured memory_bytes: 992
#include <iostream>
#include <stack>

using namespace std;

char S[2000][2000];
int cnt[1999][1999];

int main(){
    int H, W;
    
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> S[i][j];
        }
    }
    
    
    for(int i = 0; i < H-1; i++){
        for(int j = 0; j < W-1; j++){
            if((S[i][j] == S[i+1][j+1] && S[i][j+1] == S[i+1][j]) || (S[i][j] == S[i][j+1] && S[i+1][j] == S[i+1][j+1]) || (S[i][j] == S[i+1][j] && S[i][j+1] == S[i+1][j+1])){
                if(i == 0) cnt[i][j] = 1;
                else cnt[i][j] = cnt[i-1][j]+1;
            }else{
                cnt[i][j] = 0;
            }
        }
    }
    int ans = max(H, W);
    int l[1999], r[1999];
    for(int i = 0; i < H-1; i++){
        stack<int> st;
        for(int j = 0; j < W-1; j++){
            while(!st.empty()){
                int top = st.top();
                if(cnt[i][top] >= cnt[i][j]) st.pop();
                else break;
            }
            //cout << "size:" << st.size() << endl;
            if(st.empty()) l[j] = -1;
            else l[j] = st.top();
            st.push(j);
        }
        while(!st.empty()){
            st.pop();
        }
        for(int j = W-2; j >= 0; j--){
            while(!st.empty()){
                int top = st.top();
                if(cnt[i][top] >= cnt[i][j]) st.pop();
                else break;
            }
            //cout << "size:" << st.size() << endl;
            if(st.empty()) r[j] = W-1;
            else r[j] = st.top();
            st.push(j);
        }
        for(int j = 0; j < W-1; j++){
            ans = max(ans, (cnt[i][j]+1)*(r[j]-l[j]));
            //cout << (cnt[i][j]+1)*(r[j]-l[j]) << endl;
            //cout << l[j] << ' ' << r[j] << ' ' << cnt[i][j] << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19840
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int Q, l, r;
bool is_prime[100000];
int c_sum[100000];

int main() {
    fill(is_prime + 2, is_prime + 100000, true);
    FOR(i, 2, 100000) {
        if (is_prime[i]) {
            for (int j = i * 2; j < 100000; j += i) {
                is_prime[j] = false;
            }
        }
    }

    for (int i = 3; i < 100000; i += 2) {
        c_sum[i] = c_sum[i - 2];
        if (is_prime[i] && is_prime[(i + 1) / 2])
            c_sum[i]++;
    }

    cin >> Q;
    REP(i, Q) {
        cin >> l >> r;
        cout << c_sum[r] - c_sum[max(0, l - 2)] << endl;
    }
    return 0;
}

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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

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

  ll a,b;
  cin >> a >> b;
  b++;
  ll ans = 0;
  for (ll i = 0; i < 60; i++) {
    ll num = (1LL<<i);
    if (b < num) break;
    ll tmp = 0;
    tmp += b/(num*2)*num;
    tmp += b%(num*2);
    if (b%(num*2) != 0) tmp -= min(num, b%(num*2));

    ll tmp1 = 0;
    tmp1 += a/(num*2)*num;
    tmp1 += a%(num*2);
    if (a%(num*2) != 0) tmp1 -= min(num, a%(num*2));

    ll tmp2 = tmp - tmp1;
    ans += (tmp2&1) * num;
  }
  cout << ans << endl;
  return 0;
}


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


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll x;
	cin >> x;

	for (ll a = 0; a <= 3000; a++)
	{
		ll b5 = (a * a * a * a * a) - x;
		if (b5 >= a*a*a*a*a)
			continue;
		for (ll b = -3000; b <= a; b++)
		{
			if (b * b * b * b * b == b5)
			{
				cout << a << " " << b << endl;
				ret;
			}
		}
		
	}

	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
 
int main(void)
{
  int X;
  int i;
  int ans = 1;
  
  scanf("%d", &X);
  
  if(X == 1) {
    printf("1\n");
    return 0;
  }
  for(i = 2; i * i <= X; i++) {
    int tmp = i * i;
    while(tmp <= X) tmp *= i;
    tmp /= i;
    if(tmp > ans) ans = tmp;    
  }
  printf("%d\n", ans);
  
  return 0;
}

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

int main(){
    int N;
    int i, j, k;
    int count=0, max = 0;

    cin >> N;
    char s[N];
    cin >> s;

    for(i = 0; i < N; i++){
        int check[26] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        for(j = 0; j <= i ; j ++){
            for(k = i + 1; k < N ; k++ ){
                if(s[j] == s[k] && check[(int)(s[j]) - 'a'] == 0){
                    count ++;
                    check[(int)(s[j]) - 'a'] = 1;
                }
            }
        }
        if(count > max){
            max = count;
        }
        count = 0;
    }

    cout << max << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
        for (int i = 0; i < n; i++) {
            double x1 = scanner.nextDouble();
            double y1 = scanner.nextDouble();
            double x2 = scanner.nextDouble();
            double y2 = scanner.nextDouble();
            double x3 = scanner.nextDouble();
            double y3 = scanner.nextDouble();
            double x4 = scanner.nextDouble();
            double y4 = scanner.nextDouble();

            
            if (isParallel(x1, y1, x2, y2, x3, y3, x4, y4)) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
    
    public static boolean isParallel(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
        if ( (y2-y1)/(x2-x1) == (y4-y3)/(x4-x3) ) {
            return true;
        } else {
            return false;
        }
    }
}

Measured memory_bytes: 18760
#include<stdio.h>
#include<math.h>
int main()
{
    int a;
    int b,c;
    scanf("%d",&c);
    a=sqrt(c);
    if((int)a==a )
        printf("%d\n",a*a);
    else
        printf("%d\n",(a-1)*(a-1));
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int s;
  cin >> s;
  int i = 1;
  set<int> as;
  while (true) {
    as.insert(s);
    if (s & 1) s = 3 * s + 1;
    else s >>= 1;
    i++;
    if (as.find(s) != as.end()) {
      cout << i;
      return 0;
    }
  }
}
#endif


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

int main(){
    int n;
    cin >> n;
    map<string, int> s;
    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        s[tmp] = 0;
    }

    auto ans = s.size();
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()

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

    int x,a;
    cin>>x>>a;
    if(x<a)cout<<0;
    else cout<<10;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    long long N,b,ans=0,i;
    cin>>N;
    vector<long long> a(N);
	for(i=0;i<N;++i)
	{
		cin>>a[i];
		a[i]= a[i]-(i+1);
	}
	sort(a.begin(),a.end());
	b=a[(N)/2];
	for(i=0;i<N;++i){
	    ans+=abs(a[i]-b);
    }
    cout<<ans<<endl;
	return 0;
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
int n = 100005,k;
vector<int> h(n);
vector<int> dp(n,-1);

int dfs(int i){
  int res = INF;
  for(int j=1;j<=k;j++){
    if(i-j>=0){
      if(dp.at(i-j) == -1) dp.at(i-j) = dfs(i-j);
      res = min(res,dp.at(i-j)+abs(h.at(i)-h.at(i-j)));
    }
  }
  return res;
}
  

 
int main() {
  cin >> n >> k;
  rep(i,n) cin >> h.at(i);
  dp.at(0) = 0;
  cout << dfs(n-1) << endl;  
  return 0;
}




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

int main(void)
{
    long long  K;
    cin >> K;
    string ans;
    for (long long i = 0; i < K; i++)
    {
        ans.push_back('A');
        ans.push_back('C');
        ans.push_back('L');
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string L="ABCDEFGHIJKLMNOPQRSTUVWXYZ",A=" ',-.?"+L,C=L+" .,-'?";
string B[]={"101","000000","000011","10010001","010001","000001","100101","10011010",
	"0101","0001","110","01001","10011011","010000","0111","10011000",
	"0110","00100","10011001","10011110","00101","111","10011111","1000",
	"00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
int bin2dec(string s){
	int x=0,i=0;
	for(;i<s.size();i++)x=x*2+s[i]-'0';
	return x;
}
int main(){
	string s,s1;
	int i,n;
	while(getline(cin,s)){
		s1="";
		for(i=0;i<s.size();i++)s1+=B[A.find(s[i])];
		n=s1.size()%5;
		if(n!=0)s1+=string(5-n,'0');
		s="";
		for(i=0;i<s1.size();i+=5)s+=C[bin2dec(s1.substr(i, 5))];
		cout<<s<< endl;
	}
}

Measured memory_bytes: 1196
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    n, m = map(int, input().split())
    tree = [[] for _ in range(n)]
    for _ in range(m):
        i, j, k = map(int, input().split())
        i -= 1
        j -= 1
        tree[i].append((k, j))
        tree[j].append((k, i))

    # dijkstra
    import heapq

    ans = 0
    for i in range(n):
        for j in tree[i]:
            seen = [0] * n
            goal = j[1]
            base = j[0]
            seen[i] = 1
            todo = []
            heapq.heapify(todo)
            for k in tree[i]:
                if k[0] < base and k != j:
                    heapq.heappush(todo, k)
            while len(todo) > 0:
                k = heapq.heappop(todo)
                if k[1] == goal:
                    if k[0] < base:
                        ans += 1
                    break
                seen[k[1]] = 1
                for l in tree[k[1]]:
                    if seen[l[1]] == 0 and k[0] + l[0] < base:
                        heapq.heappush(todo, (k[0] + l[0], l[1]))

    print(ans // 2)

main()

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

#define ll long long
#define endl "\n"

int main ()
{
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int ll
	int x, y;
	cin >> x >> y;

	int low = 0;
	int high = x;
	int middle;
	
	//cout << low << " " << high << endl;
	while (low <= high){
		int middle = low + (high - low)/2;
		//cout << low << " " << high << " " << middle*2 + (x-middle)*4 << endl;
		if (middle*2 + (x-middle)*4 == y){
			cout << "Yes" << endl;
			return 0;
		}

		else if (middle*2 + (x-middle)*4 > y){
			low = middle + 1;
		}

		else high = middle - 1;

		 
	}

	cout << "No" << endl;
	return 0;

	return 0;
}

Measured memory_bytes: 3668
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#define re register
using namespace std;
int n,m;
int mp[2052][2052];
inline void work(re int x,re int y,re int X,re int Y){
    if(x==X&&y==Y){
        mp[x][y]=1;
        return;
    }
    mp[x+X>>1][y+Y>>1]=1;
    int midx=x+X>>1,midy=y+Y>>1;
    work(x,y,midx-1,midy-1);
    work(midx+1,y,X,midy-1);
    work(x,midy+1,midx-1,Y);
    work(midx+1,midy+1,X,Y);
}
signed main(){
    int tmp=0;
    scanf("%d%d",&n,&m);
    if(n<m){
        for(re int i=1;i<=(1<<m);i+=(1<<n)){
            work(1,i,(1<<n)-1,i+(1<<n)-2);
        }
    }
    else{
        for(re int i=1;i<=(1<<n);i+=(1<<m)){
            work(i,1,i+(1<<m)-2,(1<<m)-1);
        }
    }
    for(re int i=1;i<(1<<n);++i){
        for(re int j=1;j<(1<<m);++j)
        printf("%d",mp[i][j]);
        putchar('\n');
    }
}

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

int main()
{
    int N,ans=0;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N);
    for(int i=1;i<=N-1;i++) {
        cin >> B[i];
    }
    for(int i=0;i<=N;i++) {
        A[i] = 0;
    }
    A[1] = B[1];
    for(int i=1;i<=N-1;i++) {
        A[i+1] = B[i];
        if(!(B[i]>=max(A[i],A[i+1]))) {
            A[i] = B[i];
        }
    }
    for(int i=1;i<=N;i++) {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  int main() {
 int N,K,X,Y;
 cin>>N>>K>>X>>Y;
 if(N<=K){
 cout<<X*N<<endl;
 }
 else{
 cout<<X*K+Y*(N-K)<<endl;
 }
  }


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

using namespace std;

unsigned long long n, p;

unsigned long long power(unsigned long long x, int y) {
    if (y == 0) return 1;
    if (y & 1) return power(x, y - 1) * x;
    unsigned long long res = power(x, y / 2);
    return res * res;
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> p;
    map <unsigned long long, unsigned long long> d;
    unsigned long long div = 2;
    while (div * div <= p) {
        if (p % div == 0) {
            d[div]++;
            p /= div;
        } else {
            div++;
        }
    }
    if (p != 1) {
        d[p]++;
        p = 1;
    }
    unsigned long long ans = 1;
    for (auto x : d) {
        if (x.second >= n) {
            ans *= power(1ll * x.first, x.second / n);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
gcd_set = set()

def do_gcd(a, b) :
    if a % b == 0 :
        return b 
    else :
        return do_gcd(b, a % b)

if n == 2 :
    a, b = map(int, input().split())
    gcd = do_gcd(max(a, b), min(a, b))

    for i in range(1, int(math.sqrt(gcd) + 1)) :
        if gcd % i == 0 :
            gcd_set.add(i)
            gcd_set.add(int(gcd / i))
else :
    a, b, c = map(int, input().split())
    _gcd = do_gcd(max(a, b), min(a, b))
    gcd = do_gcd(max(_gcd, c), min(_gcd, c))
    
    for i in range(1, int(math.sqrt(gcd) + 1)) :
        if gcd % i == 0 :
            gcd_set.add(i)
            gcd_set.add(int(gcd / i))

            
for i in sorted(gcd_set) :
    print(i)


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

void linersearch(int *, int *, int, int);
void printArray(int *, int);

int main() {
    int slen, tlen, *SArray, *TArray;
    
    scanf("%d", &slen);
    SArray = (int *)malloc(slen * sizeof(int)+1);
    for(int i=0; i<slen; ++i) 
        scanf("%d", (SArray+i));

    scanf("%d", &tlen);
    TArray = (int *)malloc(tlen * sizeof(int)+1);
    for(int i=0; i<tlen; ++i) 
        scanf("%d", (TArray+i));

    //printArray(SArray, slen);
    //printArray(TArray, tlen);
    linersearch(SArray, TArray, slen, tlen);
    return 0;
}


void linersearch(int *SArray, int *TArray, int slen, int tlen) {
    int i=0, cnt=0;
    for(int j=0; j<tlen; ++j) {
        SArray[slen] = TArray[j];
        i=0;
        while(SArray[i] != SArray[slen])
            ++i;
        
        if(i==slen) {
            continue;
        }
        ++cnt;
    }
    printf("%d\n",cnt);
}


void printArray(int *Arrayptr, int length) {
    for(int i=0; i<length; ++i) {
        printf("%d ", *(Arrayptr+i));
    }
    printf("\n");
}


Measured memory_bytes: 2776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll k=(a+d-1)/d,r=(c+b-1)/b;
    if(k>=r) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] B = new int[n];
        for (int i = 0; i < (n-1); i++) {
            B[i] = s.nextInt();
        }
        int ans=0;
     for(int i=0;i<n;i++){
         if(i==0){
             ans=B[0];
             continue;
         }
         ans+=B[i];
         if(B[i]>B[i-1]){
             ans-=(B[i]-B[i-1]);
         }
     }

     System.out.print(ans+B[n-2]);
}
}


Measured memory_bytes: 23636
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int x = max(a, max(b, c));
    int y = a + b + c - x;

    for (int i = 0; i < k; i++) {
        x *= 2;
    }

    cout << x + y << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define gc() fgetc(stdin)
ll read() {
	ll a = 0; int b = 1, c;
	while (((c=gc()) > '9' || c <'0') && c != '-');
	if (c=='-') b=-1,c=gc();
	while (c >= '0' && c <= '9') a=a*10+c-'0',c=gc();
	return a*b;
}
#define gs(s) scanf("%s",s)
#define gi(i) i=read()
#define gl(i) i=read()
#define pc(c) putchar(c)
#define ps(s) printf("%s",s)
#define pi(i) printf("%d",i)
#define pl(i) printf("%lld",i)

int n, a[100005];

int main() {
	gi(n);
	for (int i = 0; i < n; i++) gi(a[i]);
	sort(a, a+n);
	if (n == 2) {
		printf("%d %d\n", a[1], a[0]);
		return 0;
	}
	int i, j;
	for (i = 0, j = 0; i < n; i++) {
		while (abs(a[i]/2 - a[j+1]) <= abs(a[i]/2 - a[j])) j++;
//		printf("C(%d, %d)\n", a[j], a[i]);
	}
	printf("%d %d\n", a[i-1], a[j]);
	return 0;
}


Measured memory_bytes: 640
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

doubling = []
lst = []
for i in range(n):
    lst.append(a[i])
doubling.append(lst)

for i in range(59):
    before = doubling[-1]
    after = []
    for j in range(n):
        after.append(before[before[j]])
    doubling.append(after)

sisu = 59
now = 0
while k > 0:
    idx = pow(2, sisu)
    if k < idx:
        sisu -= 1
    else:
        k -= idx
        now = doubling[sisu][now]
print(now+1)

Measured memory_bytes: 217060
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        vll v(5);
        rep(i, 0, 5) cin >> v[i];
        vll ord(5);
        iota(all(ord), 0);

        ll ans = inf;
        do {
                ll sm = 0;
                rep(i, 0, 5) {
                        ll now = v[ord[i]];
                        ll r = now % 10;
                        ll tmp = 10 - r;
                        if (tmp == 10) tmp = 0;
                        if (i != 4) sm += now + tmp;
                        else sm += now;
                }
                chmin(ans, sm);
        } while (next_permutation(all(ord)));
        cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, m; cin >> n >> m;
    map<int, int> ma;
    FOR(i, 0, m) {
        int a, b; cin >> a >> b;
        ++ma[a], ++ma[b];
    }
    bool ok = true;
    each(i, ma)ok &= i.second % 2 == 0;
    cout << (ok ? "YES" : "NO") << "\n";
}

Measured memory_bytes: 4352
from collections import Counter

n = int(input())
s = str(input())
s_count = Counter(list(s))

ans = 1
count = 0

for i, j in s_count.items():
    count += 1
    ans *= j

if count < 3:
    ans = 0
    

for i in range(n):
    k = 1

    while i + 2 * k < n:
        if ans == 0:
            break
        l = []
        l.append(s[i])
        l.append(s[i+k])
        l.append(s[i+2*k])
        if l.count('R') == 1 and l.count('G') == 1 and l.count('B') == 1:
            ans -= 1
        
        k += 1
    
print(ans)

Measured memory_bytes: 68856
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

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

  int n; cin >> n;
  vector<pii> v;
  rep(i, n) {
    int a; cin >> a;
    v.emplace_back(a, i + 1);
  }

  sort(all(v));

  rep(i, n) {
    cout << v[i].second << " ";
  }
  cout << '\n';

  return 0;
}

Measured memory_bytes: 1780
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        while(true){
            int n=s.nextInt();
            int m=s.nextInt();
            if(n==0&&m==0) break;
            int v[]=new int[n];
            for(int i=0;i<n;i++){
                v[i]=s.nextInt();
            }
            int max=0;
            for(int i=0;i<n-1;i++){
                for(int j=i+1;j<n;j++){
                    if(max<v[i]+v[j]&&v[i]+v[j]<=m) max=v[i]+v[j];
                }
            }
            if(max==0) System.out.println("NONE");
            else System.out.println(max);
        }
    }
}


Measured memory_bytes: 51992
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n,0);

  int mx = 0;
  rep(i,n) {
    cin >> a.at(i);
  }

  rep(i,n-1) {
    mx = max(mx,abs(a.at(i)-a.at(i+1)));
  }
  mx = max(mx,k-abs(-a.at(0)+a.at(n-1)));
  cout << k - mx << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

//class
class Baseball{
public:
	int firstbase, secondbase, thirdbase;
	int inningNumber, out, score;

	Baseball(int num){
		inningNumber = num;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		out = 0;
		score = 0;
	}

	void playball(){
		for(int i = 0; i < inningNumber; ++i)
			inning();
	}

	void inning(){
		out = 0;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
		score = 0;

		while(out != 3){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				hit();
			if(str == "HOMERUN")
				homerun();
			if(str == "OUT")
				out++;
		}

		std::cout << score << std::endl;
	}

	void hit(){
		score += thirdbase;
		thirdbase = secondbase;
		secondbase = firstbase;
		firstbase = 1;
	}

	void homerun(){
		score += thirdbase + secondbase + firstbase + 1;
		firstbase = 0;
		secondbase = 0;
		thirdbase = 0;
	}
};
//main
int main(){
	int n;
	std::cin >> n;
	
	Baseball *baseball = new Baseball(n);
	baseball->playball();
	delete baseball;

	return 0;
}


Measured memory_bytes: 3020
#include <stdio.h>

int main() {
    int s;
    scanf("%d", &s);
    int a = 0;
    if (s == 4 || s == 2 || s == 1) {
      printf("%d", 4);
    } else {
      for (int i = 0; i < 1000000; i++) {
        if (s % 2 == 0) {
          s = s/2;
        } else {
          s = 3*s+1;
        }
        if (s == 4) {
          a++;
        }
        if (a == 2) {
          printf("%d", i+2);
          break;
        }
      }
    }
}

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

 int calcNumOfCombination(int n, int r){//nCr
        int num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }

int main(){
    int n,m; cin >> n >> m;
    int a = calcNumOfCombination(n,2);
    int b = calcNumOfCombination(m,2);
    cout << a+b << endl;
    return 0;
}

Measured memory_bytes: 256
program ABC168B
    implicit none
    character(100)::S
    integer(8)::K,Slen
    read*,K,S
    Slen=len_trim(S)
    if(Slen<=K)print'(A)',S(1:Slen)
    if(Slen>K)print'(A,A)',S(1:K),"..."
end program ABC168B

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

#define ALEN 500001 
#define INF 1000000000;

long L[ALEN];
long R[ALEN];

int merge(long Arr[], int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int count = 0;

	for(int i = 0; i < n1; i++){
		L[i] = Arr[left + i];
	}
	for(int i = 0; i <n2; i++){
		R[i] = Arr[mid + i];
	}

	L[n1] = INF;
	R[n2] = INF;

	int i = 0;
	int j = 0;
	for(int k = left; k < right; k++){
		if(L[i] <= R[j]){
			Arr[k] = L[i];
			i = i + 1;
		}else{
			Arr[k] = R[j];
			j = j + 1;
		}
		count++;
	}
	return count;
}

int mergeSort(long arr[], int left, int right){
	int count = 0;
	if(left + 1 < right){
		int mid = (left + right)/2;
		count += mergeSort(arr, left, mid);
		count += mergeSort(arr, mid, right);
		count += merge(arr, left, mid, right);
	}
	return count;
}

void printArr(long arr[], int n){
	for(int i = 0; i < n; i++){
		cout << arr[i];
		if(i != n - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

int main(){
	long n, arr[ALEN];
	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	int count = mergeSort(arr, 0, n);
	printArr(arr, n);
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 10884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

struct UF{
    int n;
    vector<int> par,size;
    
    void init(int n_){
        n=n_;
        par.assign(n,-1);
        size.assign(n,1);
        
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int root(int a){
        if(par[a]==a) return a;
        else return par[a]=root(par[a]);
    }
    
    void unite(int a,int b){
        if(root(a)!=root(b)){
            size[root(a)]+=size[root(b)];
            par[root(b)]=root(a);
        }
    }
    
    bool check(int a,int b){
        return root(a)==root(b);
    }
};

struct edge{
    int a;
    int b;
    ll c;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<edge> E(M),use;
    for(int i=0;i<M;i++){
        cin>>E[i].a>>E[i].b>>E[i].c;
        E[i].a--;E[i].b--;
    }
    
    sort(all(E),[](auto a,auto b){
        return a.c<b.c;
    });
    
    UF uff;
    uff.init(N);
    ll sum=0;
    
    for(int i=0;i<M;i++){
        if(!uff.check(E[i].a,E[i].b)){
            sum+=E[i].c;
            uff.unite(E[i].a,E[i].b);
            use.push_back(E[i]);
        }
    }
    
    pair<ll,ll> ans=mp(0,0);
    
    for(int i=0;i<si(use);i++){
        UF uf;
        uf.init(N);
        ll s=0;
        for(int j=0;j<M;j++){
            if(use[i].a==E[j].a&&use[i].b==E[j].b) continue;
            if(!uf.check(E[j].a,E[j].b)){
                uf.unite(E[j].a,E[j].b);
                s+=E[j].c;
            }
        }
        if(sum<s||uf.size[uf.root(0)]<N){
            ans.fi++;
            ans.se+=use[i].c;
        }
    }
    
    cout<<ans.fi<<" "<<ans.se<<"\n";
}




Measured memory_bytes: 3924