akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {

    int r;
    cin>>r;
    fin(r*r*3);
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc162/tasks/abc162_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> tr, tg, tb;
    bitset<4001> br, bg, bb;
    REP(i, N) {
        if (s[i] == 'R') {
            tr.emplace_back(i);
            br.set(i);
        } else if (s[i] == 'G') {
            tg.emplace_back(i);
            bg.set(i);
        } else {
            tb.emplace_back(i);
            bb.set(i);
        }
    }
    int sum = 0;
    REP(i, N - 2) {
        FOR(j, i + 1, N - 1) {
            if (s[i] == s[j])
                continue;
            int t = 0;
            if (s[i] != 'R' && s[j] != 'R') {
                t = distance(lower_bound(ALL(tr), j + 1), tr.end());
                if (2 * j - i < N && br.test(2 * j - i))
                    t--;
            } else if (s[i] != 'G' && s[j] != 'G') {
                t = distance(lower_bound(ALL(tg), j + 1), tg.end());
                if (2 * j - i < N && bg.test(2 * j - i))
                    t--;
            } else {
                t = distance(lower_bound(ALL(tb), j + 1), tb.end());
                if (2 * j - i < N && bb.test(2 * j - i))
                    t--;
            }
            sum += t;
        }
    }

    cout << sum << endl;

    return 0;
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
using namespace std;
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    string S;
    cin >> S;
    ll ans = LLONG_MAX;
    rep(i, S.length()) {
        rep(j, S.length()) {
            if (j == i + 2) {
                string SS = "";
                for (int k = i; k <= j; k++) {
                    SS += S[k];
                }
                ans = min(ans, abs(stoll(SS) - 753));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

#define int long long int

bool visited[100010] = { 0 };
int dist[100010] = { 0 };
bool flag = true;
std::vector< std::vector< int > > check(100010);
std::vector< std::vector< std::pair<int, int> > > g(100010);

void dfss(int index, int count)
{
	dist[index] = count;
	
	for (int i = 0; i < g[index].size(); ++i)
	{
		int next = g[index][i].first;
		int distance = g[index][i].second;
		
		if (dist[next] == 1e9 + 7)
		{
			dfss(next, count + distance);
		}
		else if (dist[next] != count + distance)
		{
			flag = false;
			return;
		}
	}
}

main()
{	
	int n, m;
	std::cin >> n >> m;
	
	for (int i = 0; i < m; ++i)
	{
		int l, r, d;
		std::cin >> l >> r >> d;
		
		--l;
		--r;
		g[l].push_back(std::make_pair(r, d));
		g[r].push_back(std::make_pair(l, -d));
	}
	
	for (int i = 0; i < n; ++i)
		dist[i] = 1e9 + 7;
	
	for (int i = 0; i < n; ++i)
	{
		if (dist[i] == 1e9 + 7)
		{
			dfss(i, 0);
		}
	}
	
	if (flag)
		std::cout << "Yes";
	else
		std::cout << "No";
	
	
}

Measured memory_bytes: 18816
#include <stdio.h>
#include <cmath>

int main()
{
	double l,a,r,pi = 2.0 * acos(0.0);
	scanf("%lf", &r);
	l =2*r*pi;
	a =r*r*pi;
	printf("%lf %lf\n", a, l);
	return 0;
}


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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        if(i%2==0&&a[i]%2==1){
            ans++;
        }
    }
    std::cout << ans << std::endl;
    
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
using namespace std;
struct node
{
    int x,y;
    int step;
};
int h,w,sx,sy,ex,ey;
deque<node> q;
char s[1005][1005],vis[1005][1005];
int nextx[]={0,-1,0,1},nexty[] = {-1,0,1,0};
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    scanf("%d%d",&h,&w);
    scanf("%d%d",&sx,&sy);
    scanf("%d%d",&ex,&ey);
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j)
            scanf(" %c",&s[i][j]);
    }
    /*
    for(int i=1; i<=h; ++i){
        for(int j=1; j<=w; ++j)
            printf("%c",s[i][j]);
        putchar('\n');
    }*/

    vis[sx][sy] = 1;
    q.push_back((node){sx,sy,0});
    //cout<<q.front().x<<' '<<q.front().y;
    //getchar();
    int ans = -1;
    while(!q.empty()){
        struct node t = q.front();
        q.pop_front();
        vis[t.x][t.y] = 1;
        if(t.x==ex&&t.y==ey){
            ans = t.step;
            break;
        }

        for(int i=0; i<4; ++i){
            int tx,ty;
            tx = t.x + nextx[i];
            ty = t.y + nexty[i];
            if(tx>0&&tx<=h&&ty>0&&ty<=w&&s[tx][ty]=='.'&&!vis[tx][ty]){
                q.push_front((node){tx,ty,t.step});
            }
        }

        for(int tx=t.x-2; tx<=t.x+2; ++tx){
            for(int ty=t.y-2; ty<=t.y+2; ++ty){
                if(tx>0&&tx<=h&&ty>0&&ty<=w&&s[tx][ty]=='.'&&!vis[tx][ty]){
                    if(tx==t.x&&ty==t.y)
                        continue;
                    q.push_back((node){tx,ty,t.step+1});
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 11840
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> ans;
    if(n % 2 == 0)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = i+1; j <= n; j++)
            {
                if(j != n+1-i)
                {
                    ans.push_back(P(i, j));
                }
            }
        }
    }
    else
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = i+1; j <= n; j++)
            {
                if(j != n-i)
                {
                    ans.push_back(P(i, j));
                }
            }
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}


Measured memory_bytes: 384
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
int main()
{
    int n ;
    cin >> n ; vector<int> a (n);
    for (int i =0 ; i < n ;i++)cin >> a[i];
    int ans =0 ;
    for (int i =0 ; i < n ;i++)
        for (int j = i+1 ; j < n ;j++)
            ans += a[i] * a[j];
    cout << ans <<"\n";

}


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

int main()
{
    string S; cin >> S;
    string seeds[] = {"dream", "dreamer", "erase", "eraser"};
    reverse( S.begin(), S.end() );
    for(int i = 0; i < 4; ++i ) reverse(seeds[i].begin(), seeds[i].end());
    string T = "";
    bool ans = true;
    for(int i = 0; i < S.size();){
        bool endflag = true;
        for(int j = 0; j < 4; ++j){
            if(S.substr(i, seeds[j].size()) == seeds[j]){
                endflag = false;
                i += seeds[j].size();
            }
        }
        if(endflag) {
            ans = false;
            break;
        }
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int A, B;
    cin >> A >> B;

    if(A<B) {
        if(A==1) cout << "Alice" << endl;
        else cout << "Bob" << endl;
    } else if(A>B) {
        if(B==1) cout << "Bob" << endl;
        else cout << "Alice" << endl;
    } else cout << "Draw" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;

int main(){
   int s; cin >> s;
   vector<int> v(10000);
   v[0]=s;
   rep(i,1,10000){
      if(v[i-1]%2==0){
         v[i]=v[i-1]/2;
      }else{
         v[i]=v[i-1]*3+1;
      }
   }
   int m=1000000;
   rep(i,0,10000){
      rep(j,i+1,10000){
         if(v[i]==v[j]){
            m=min(m,j);
         }
      }
   }
   cout<<m+1<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <limits>
#include <queue>
#include <utility>
#define rep(i,a) for(int i=0;i<(a);++i)

using P = std::pair<int, std::pair<int, int>>;

constexpr int MAX_N = 5000, INF = std::numeric_limits<int>::max()>>2;

int N, K;
int C[MAX_N], R[MAX_N];
std::vector<int> G[MAX_N];
int d[MAX_N][MAX_N+1];
std::priority_queue<P, std::vector<P>, std::greater<P>> pque;

int main()
{
  scanf( "%d%d", &N, &K );
  rep( i, N )
    scanf( "%d%d", C+i, R+i );
  rep( i, K )
  {
    int A, B;
    scanf( "%d%d", &A, &B );
    --A; --B;
    G[A].push_back( B );
    G[B].push_back( A );
  }

  std::fill( (int*)d, (int*)(d+N), INF );
  d[0][0] = 0;
  pque.push( P( 0, std::make_pair( 0, 0 ) ) );

  while( !pque.empty() )
  {
    P p = pque.top(); pque.pop();
    int dist = p.first, v = p.second.first, remain = p.second.second;

    if( dist > d[v][remain] )
      continue;

    for( auto u : G[v] )
    {
      if( remain > 0 && d[u][remain-1] > d[v][remain] )
      {
        d[u][remain-1] = d[v][remain];
        pque.push( P( d[u][remain-1], std::make_pair( u, remain-1 ) ) );
      }
      if( d[u][R[v]-1] > d[v][remain]+C[v] )
      {
        d[u][R[v]-1] = d[v][remain]+C[v];
        pque.push( P( d[u][R[v]-1], std::make_pair( u, R[v]-1 ) ) );
      }
    }
  }

  printf( "%d\n", *std::min_element( d[N-1], d[N-1]+N+1 ) );

  return 0;
}


Measured memory_bytes: 100816
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n, a, b; cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;
public class Main{

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

		BigInteger A = new BigInteger(stdIn.nextLine());
		BigInteger B = new BigInteger(stdIn.nextLine());

		if(A.compareTo(B) == 1) {
			System.out.println("GREATER");
		}else if(A.compareTo(B)== -1) {
			System.out.println("LESS");
		}else {
			System.out.println("EQUAL");
		}

	}

}


Measured memory_bytes: 23892
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
#define FF first
#define SS second

const ll mod = 1000000007;
int main(){
	FASTIO;
  ll n; cin >> n;
  ll ans = -1e12;
  ll mp, Mp, mm, Mm;
  mp = mm = 1e12;
  Mp = Mm = -1e12;
  for ( int k = 0; k < n; k++ ){
    ll x, y; cin >> x >> y;
    mp = min(mp, x + y);
    Mp = max(Mp, x + y);
    mm = min(mm, x - y);
    Mm = max(Mm, x - y);
    ans = max({ans, Mp - mp, Mm - mm});
  }
  cout << ans << endl;
	return 0;
}

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

int main() {
  int h, w, n;
  scanf("%d %d %d", &h, &w, &n);
  set<pair<int, int>> s, rs;
  for (int i = 0; i < n; ++i) {
    int y, x;
    scanf("%d %d", &y, &x);
    s.emplace(y, x);
    rs.emplace(x, y);
  }
  for (int i = 1; i <= w; ++i) {
    s.emplace(h + 1, i);
    rs.emplace(i, h + 1);
  }
  for (int i = 1; i <= h; ++i) {
    s.emplace(i, w + 1);
    rs.emplace(w + 1, i);
  }
  int uy = 1, ux = 1;
  set<pair<int, int>> reachable;
  int turn = 0;
  while (true) {
    if (turn == 0) {
      if (s.find({uy + 1, ux}) != s.end())
        break;
      ++uy;
    } else {
      if (s.find({uy, ux + 1}) == s.end()) {
        auto p = *rs.lower_bound({ux, uy});;
        reachable.insert(*s.lower_bound({p.second, p.first}));
        ++ux;
      }
    }
    turn ^= 1;
  }
  auto p = *rs.lower_bound({ux, uy});
  reachable.insert(*s.lower_bound({p.second, p.first}));
  int ans = -1;
  for (auto p : s)
    if (reachable.find(p) != reachable.end())
      if (ans == -1 || p.first - 1 < ans)
        ans = p.first - 1;
  printf("%d\n", ans);
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
  return 0;
}

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

void trace(int A[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

int main()
{
    int maxN = 1000;
    int A[maxN];

    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    trace(A, N);

    //insertion sort
    for (int i = 1; i < N; i++)
    {
        int v = A[i];
        int j = i-1;
        while (j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
    
        trace(A, N);
    }
    
    return 0;
}


Measured memory_bytes: 3048
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<stack>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

vector<string> donut(10);
vector<string> lis(200);

int main(){
	int i, j, w, h;
	int d[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	string ans, ins;
	while(1){
		cin >> h >> w;
		if(!h) break;
		ans="0";
		lis.clear();
		donut.clear();
		REP(a,h){
			cin >> ins;
			donut.push_back(ins);
		}
		/*REP(a,h){
			cout << donut[a] << endl;
		}*/
		REP(a,h){
			REP(b,w){
				REP(c,8){
					//cout << a << "," << b << ":" << donut[a][b] << endl;
					ins = donut[a][b];
					//cout << ins << endl;
					int x = a+d[c][0], y = b+d[c][1];
					if(x<0) x = h-1;
					if(x>h-1) x = 0;
					if(y<0) y = w-1;
					if(y>w-1) y = 0;
					while(x!=a||y!=b){
						//cout<<a<<","<<b<<"("<<c<<"):"<<x<<","<<y<<"->";
						//cout<<donut[y][x]<<endl;
						ins += donut[x][y];
						x = x+d[c][0];
						y = y+d[c][1];
						if(x<0) x = h-1;
						if(x>h-1) x = 0;
						if(y<0) y = w-1;
						if(y>w-1) y = 0;
					}
					lis.push_back(ins);
				}
			}
		}
		//REP(a,lis.size()) cout << lis[a] << endl;
		REP(a,lis.size()){
			for(i=a+1;i<lis.size();i++){
				if(lis[a][0]==lis[i][0]){
					//cout << a << "-" << i << endl;
					for(j=max(2,(int)ans.size());j<=min(lis[a].size(),lis[i].size());j++){
						if(lis[a].substr(0,j)==lis[i].substr(0,j)){
							ins = lis[a].substr(0,j);
							if(ins.size() > ans.size()) ans = ins;
							else if(ins.size()==ans.size()&&ins < ans) ans = ins;
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1524
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
	int N, M, X, a, costL=0, costR=0;
	cin >> N >> M >> X;
	for (int i = 0; i < M; i++) {
		cin >> a;
		if (a < X) costL++;
		else costR++;
	}
	cout << min(costL, costR) << endl;
}

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

int main(){
  string player[3];
  cin >> player[0] >> player[1] >> player[2];
  int turn = 0;
  int count[3] = {0};

  while(true){
    count[turn]++;
    if(count[turn] == player[turn].size() + 1) {
      cout << (char)('A' + turn) << endl;
      return 0;
    }
    turn = player[turn][count[turn]-1] - 'a';
    // cout << count[0] << " , " << count[1] << " , " << count[2] << endl;
    // cout << player[0].size() << " , " << player[1].size() << " , " << player[2].size() << endl << endl;
  }
  return 0;
}


Measured memory_bytes: 256
s = int(input())
L = [s]
cnt = 1
while True:
  cnt += 1
  if L[cnt-2]%2 == 0:
    L.append(L[cnt-2]//2)
  else:
    L.append(L[cnt-2]*3+1)
  if not len(set(L)) == cnt:
    print(cnt)
    exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t
//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// {素因数、指数}
vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}


int main(){
    ll N; cin >> N;
    if(isPrime(N)){
        cout << 1 << endl;
        return 0;
    }

    vector<pair<ll,ll>> V = prime_factorize(N);
    ll ans = 0;
    for(auto m : V){
        ll cnt = 1;
        while(1){
            if(m.second >= cnt) {
                m.second -= cnt;
                cnt++;
                ans++;
            }
            else break;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3632
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = [int(input()) for i in range(N)]

ans = aa[0]-1
tmp = 2
for i in range(1,N):
	a = aa[i]
	if a > tmp:
		ans += (a-1)//tmp
	elif a == tmp:
		tmp += 1

print(ans)


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

int main() {
  int n; cin >> n;
  int count=0;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  count = abs(vec.at(n-1)-vec.at(0));
  cout << count << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[1<<10][1<<10];
signed main(){
  Int n;
  while(cin>>n,n){
    string s;
    cin>>s;
    memset(dp,0,sizeof(dp));
    vector<vector<Int> > sp(1<<10);
    dp[0][0]=1;
    sp[0].emplace_back(0);
    bool flg=0;
    for(Int i=0;i<n;i++){
      if(s[i]=='u') continue;
      Int b=0;
      while(s[i+1]!='u'){
	b|=1<<(s[i]-'0');
	Int ne=1<<(s[i+1]-'0');
	if(b&ne) flg=1;
	if(flg) break;
	for(Int x=(1<<10)-1;x>=0;x--){
	  if(x&b) continue;
	  if(sp[x].empty()) continue;
	  
	  for(Int y:sp[x]){
	    if((x&ne)&&((y|b)==b)) flg=1;
	    Int nx=x|b,ny=y|ne;
	    if((y&b)==b) ny^=b;
	    if(!dp[nx][ny]){
	      dp[nx][ny]=1;
	      sp[nx].emplace_back(ny);
	    }
	    if(flg) break;
	  }
	  if(flg) break;
	}
	i++;
      }
      Int ne=1<<(s[i]-'0');
      if(b&ne) flg=1;
      if(flg) break;
    }
    cout<<(flg?"UNSAFE":"SAFE")<<endl;
  }
  return 0;
}



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

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  vector<vector<int>> c(h,vector<int>(w));
  int x=0,y=0;
  rep(i,n){
    rep(j,a[i]){
      c[y][x]=i+1;
      if(y%2==0){
        x++;
        if(x==w){
          x--;
          y++;
        }
      }else{
        x--;
        if(x==-1){
          x++;
          y++;
        }
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << c[i][j] << ' ';
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
ll inf = 1e18;
ll p = 1e9 + 7;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll dp[1001][1001], u2[1001][1001];
char arr[1001][1001];
ll val[1001][1001];
ll  x2, y2, n, m;
void dfs (ll x, ll y, ll v)
{
    u2[x][y] = 1;
    val[x][y] = v;

    ll dx[4] = {1, -1, 0, 0};
    ll dy[4] = {0, 0, 1, -1};
    ll i, j;
    for (i = 0; i < 4; i++)
    {
        ll t1 = x + dx[i];
        ll t2 = y + dy[i];
        if (t1 >= 1 && t1 <= n && t2 >= 1 && t2 <= m)
        {
            if (arr[t1][t2] == '.' && u2[t1][t2] == 0)
                dfs(t1, t2, v);




        }

    }



}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i, j, y, x,  z, w, g, key, l, r, t, k;
    ll a, b, c;
    ll t2, t3, t4, t1;

    string s;
    cin >> n >> m;
    memset(u2, 0, sizeof(u2));
    ll x1, y1;
    cin >> x1 >> y1;
    cin >> x2 >> y2;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
            cin >> arr[i][j];
    }
    ll cur = 0;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            if (u2[i][j] == 0 && arr[i][j] == '.')
            {
                cur++;
                dfs(i, j, cur);
            }

        }
    }
    vector<set<ll>>adj(cur + 1);
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            for (k = -2; k <= 2; k++)
            {
                for (l = -2; l <= 2; l++)
                {
                    t1 = k + i;
                    t2 = l + j;
                    if (t1 >= 1 && t1 <= n && t2 >= 1 && t2 <= m)
                    {
                        if (arr[t1][t2] == '.' && arr[i][j] == '.')
                        {
                            if (val[i][j] != val[t1][t2])
                            {
                                adj[val[i][j]].insert(val[t1][t2]);
                                adj[val[t1][t2]].insert(val[i][j]);
                            }
                        }
                    }

                }
            }

        }
    }
    ll src = val[x1][y1];
    ll end = val[x2][y2];
    vector<ll>d(cur + 1, -1), used(cur + 1, 0);
    queue<ll>q;
    used[src] = 1;
    d[src] = 0;
    q.push(src);
    while (!q.empty())
    {
        auto u = q.front();
        q.pop();
        for (auto v : adj[u])
        {
            if (used[v] == 0)
            {
                d[v] = d[u] + 1;
                used[v] = 1;
                q.push(v);
            }
        }
    }
    cout << d[end];
    return 0;
}

Measured memory_bytes: 45896
n = int(input())
h = list(map(int, input().split()))

higher = [0]
move = [0]

for i in range(1, n):
  if h[i-1] < h[i]:
    m = i - higher[len(higher) - 1] - 1
    move.append(m)
    higher.append(i)

move.append(len(h) - 1 - higher[len(higher) - 1])


print(max(move))

Measured memory_bytes: 20516
N = int(input())
A = [int(i) for i in input().split()]
ans = [0]*N
for i in range(N):
    n = N - i #1~N
    coun = sum(ans[n-1::n])%2
    if A[n-1] != coun:
        ans[n-1] = 1
n = sum(ans)
st = " ".join(["" if n==0 else str(i+1) for i,n in enumerate(ans)])
print(n)
print(st)

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";

int main() {
    ll a;
    string b;
    cin>>a>>b;
    
    ll d=(b[0]-'0')*100+(b[2]-'0')*10+b[3]-'0';
    
    ll ans=a*d;
    ans/=100;
    cout<<ans<<endl;
  

}


Measured memory_bytes: 3628
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <list>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <math.h>
#include <unordered_map>
#include <string>

typedef long long ll;
typedef double db;
const ll mod=1000000007;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* author : hey_it_works(kunal)
 It works, idk how exactly*/

using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

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


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N, M; cin >> N >> M;
  int l, r; ll c;
  vector<vector<int>> G(N);
  vector<vector<ll>> CO(N);
  rep(i,M){
    cin >> l >> r >> c;
    l--; r--;
    G[l].pb(r);
    CO[l].pb(c);
  }
  rep(i,N-1){
    G[i+1].pb(i);
    CO[i+1].pb(0);
  }

  // ここからダイクストラ
  vector<ll> D(N, -1);
  vector<bool> used(N, false);
  priority_queue<pair<ll,int>,
                 vector<pair<ll,int>>,
                 greater<pair<ll,int>>> q;

  q.push({0,0});
  while(!q.empty()){
    ll d = q.top().first; int to = q.top().second; q.pop();
    if(used[to]) continue;
    used[to] = true;
    D[to] = d;
    rep(i, (int)G[to].size()){
      if(D[G[to][i]] != -1 && D[G[to][i]] <= D[to] + CO[to][i]) continue;
      q.push({D[to] + CO[to][i], G[to][i]});
    }
  }
  cout << D[N-1] << endl;
  return 0;
}


Measured memory_bytes: 13812
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func nextFloat64() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func convertMark(m string) int {
	if m == "S" {
		return 1
	} else if m == "H" {
		return 2
	} else if m == "C" {
		return 3
	}
	return 4
}

var marks = []string{"S", "H", "C", "D"}

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

	n, _ := nextInt()
	cards := make([]int, 52)

	for i := 0; i < n; i++ {
		x1 := nextString()
		x2, _ := nextInt()

		i := convertMark(x1)
		cards[13*(i-1)+(x2-1)]++
	}

	for i := 0; i < 52; i++ {
		if cards[i] == 0 {
			mark := i / 13
			j := i%13 + 1

			fmt.Println(marks[mark], j)
		}
	}
}



Measured memory_bytes: 1120
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func submit(line string) int {
	parts := strings.Split(line, " ")
	p, _ := strconv.Atoi(parts[0])
	q, _ := strconv.Atoi(parts[1])
	r, _ := strconv.Atoi(parts[2])

	return min(p+q, min(q+r, r+p))
}

func main() {
	line := nextLine()
	ans := submit(line)
	fmt.Println(ans)
}


Measured memory_bytes: 640
(function (input) {
    var inputs = input.replace(/\r/g, '').split("\n"), str = [], s, l, tmp, count, max;
    while(true) {
        max = 0;
        str[0] = inputs.shift();
        if(str[0] === '') {
            break;
        }
        str[1] = inputs.shift();
        if(str[0].length < str[1].length) {
            s = str[0];
            l = str[1];
        } else {
            s = str[1];
            l = str[0];
        }
        for(var i = 0, len = s.length; i < len; i++) {
            count = max + 1;
            while(s[i + count - 1] && l.indexOf(s.slice(i, i + count)) >= 0) {
                count++;
            }
            if(count > max) {
                max = count - 1;
            }
        }
        console.log(max);
    }
})(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10092
/*
*Bismillahir Rahmanir Rahmin
* @Author: {{Syed Yasir Shahriar
{
/*//*\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\*/
 
//أعوذ بالله من الشيطان الرجيم
//بسم الله الرحمن الرحيم
 
/*//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\*/
 
/*};/* @Date:   {{create_time}}typedef int MyCustomType;
* @Last Modified by:   mrinm
* @Last Modified time: 2020-05-31 20:57:08
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define v vector<ll>
#define st stack<ll>
#define pq  priority_queue <int>
#define q queue<ll>
#define mod 1000000005
using namespace std;

int main(){
      

       ios::sync_with_stdio(0);
        cin.tie(0),cout.tie(0);
         int t;
          int a,x;
          cin>>a>>x;
          int ans=2*x-a;
          cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main(){
    int n,i;
    int num[1000];
    cin >> n;
    for(i=0;i<n;i++){
        cin >> num[i];
    }
    for(i=n-1;i>-1;i--){
        if(i==0){
            cout << num[i] << endl;
            return 0;
        }else{
            cout << num[i] << " ";
        }
    }
    return 0;    
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,k,a[200005]={0};
	cin>>n>>k;
	for(int x=1;x<=n;x++)
	cin>>a[x];
	for(int x=k+1;x<=n;x++)
	{
		if(a[x]>a[x-k])cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 4408
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;

int main () {

    string s;
    cin >> s;
    int n = (int)s.size();

    if (s.front() == '0' || s.back() == '1') {
        cout << -1 << endl;
        return 0;
    }

    REP(i,(s.size() + 1) / 2) {
        int f = (i + 1) - 1;
        int b = (n - (i + 1)) - 1;
        if (s[f] != s[b]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << 1 << " " << 2 << endl;

    int pre = 2;
    for (int i = 2; i < (int)s.size(); i++) {
        int idx = i + 1;
        cout << pre << " " << idx << endl;
        if (s[i - 1] == '1') {
            pre = idx;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
	long long n,m;
	scanf("%lld %lld",&n,&m);
	long long p=m-n*2;
	if(p<0)
	   printf("%lld",m/2);
	else
	   printf("%lld",n+p/4);
	return 0;
}

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    else return gcd(b, a%b);
}

ll count2(ll n)
{
    ll t = n, c = 0;
    while(true) {
        if(t % 2 == 0) {
            t >>= 1;
            ++c;
        }
        else break;
    }
    return c;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    REP(i,0,N) cin >> a[i];

    ll c0 = count2(a[0]), c;
    bool f = true;
    
    REP(i,0,N) {
        c = count2(a[i]); 
        if(c == 0 || c != c0) {
            f = false;
            break;
        }
        else a[i] >>= c;
    }

    if(f) {
        ll L = a[0], ans;
        REP(i,1,N) L *= a[i] / gcd(L, a[i]);
        L *= 1 << (c-1);
        ans = (M / L + 1) / 2;
        _PR(ans);
    }
    else _PR(0);

    return 0;
}

/*



*/

Measured memory_bytes: 1024
program road_of_the_king
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: dp(0:300,301,300) = 0_8
  integer :: n, m, i, j, k
  read(*,*) n, m
  dp(0,1,1) = 1_8
  do i = 0, m-1
    do j = 1, n
      do k = 1, n
        dp(i+1,j+1,k) = mod(dp(i+1,j+1,k)+dp(i,j,k)*int(n-j,8),md)
        dp(i+1,j,k) = mod(dp(i+1,j,k)+dp(i,j,k)*int(j-k,8),md)
        dp(i+1,j,j) = mod(dp(i+1,j,j)+dp(i,j,k)*int(k,8),md)
      end do
    end do
  end do
  write(*,'(i0)') dp(m,n,n)
end program road_of_the_king

Measured memory_bytes: 212608
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == -1:
            break
        else:
            if n != 0:
                hoge = []
                while True:
                    foo = n // 4
                    bar = n % 4
                    if foo >= 4:
                        hoge.append(bar)
                        n = foo
                    elif foo < 4:
                        hoge.append(bar)
                        hoge.append(foo)
                        break
                hoge.reverse()
                hoge = [str(hoge[i]) for i in range(len(hoge))]
                fuga = ""
                for i in range(len(hoge)):
                    fuga += hoge[i]
                print(int(fuga))
            elif n == 0:
                print(n)



if __name__ == "__main__":
    main()

Measured memory_bytes: 7776
#include <cstdio>
#include <cassert>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>

using namespace std;

#define all(c) begin(c), end(c)
#define dump(c) cerr << "> " << #c << " = " << (c) << endl
#define REP(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1001001001;
const double EPS = 1e-10;


template<typename T1,typename T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){
  return os << '(' << p.first << ',' << p.second << ')';
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& a){
  os << '[';
  rep(i,a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

int main() {
  for(int T, P, R; cin >> T >> P >> R, (T | P | R) != 0; ) {
    int ac[51][51] = {}, wa[51][51] = {};
    int nums[51] = {}, times[51] = {};
    rep(i, R) {
      int tid, pid, time;
      string mes;
      cin >> tid >> pid >> time >> mes;
      tid--;
      pid--;
      if(ac[tid][pid]) continue;
      if(mes == "CORRECT") {
        nums[tid]++;
        times[tid] += wa[tid][pid] * 1200 + time;
        ac[tid][pid] = 1;
      }
      else {
        wa[tid][pid]++;
      }
    }

    set<tuple<int, int, int>> sta;
    rep(i, T) {
      sta.insert(make_tuple(-nums[i], times[i], i));
    }

    for(auto i : sta) {
      cout << get<2>(i) + 1 << ' ' << -get<0>(i) << ' ' << get<1>(i) << endl;
    }
  }

  
  
  return 0;
}

Measured memory_bytes: 1244
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> dp(n + 1, M);
    for(int i = 0; i <= n; i++){
        dp[i] = i;
    }
    for(int h = 6; h <= n; h *= 6){
        for(int i = h; i <= n; i++){
            dp[i] = min(dp[i], dp[i - h] + 1);
        }
    }
    for(int h = 9; h <= n; h *= 9){
        for(int i = h; i <= n; i++){
            dp[i] = min(dp[i], dp[i - h] + 1);
        }
    }
    cout << dp[n] << '\n';
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << ((s[0]==s[1] && s[1]!=s[2] && s[2]==s[3] && s.length()==4)? "Yes": "No");
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{

    vector<int> tp;
    int n;
    cin >> n;
    tp.resize(n);
    for(int i = 0; i < n; i++)
        cin >> tp[i];
    sort(tp.begin(),tp.end());
    int r = 10000000000;
    for(int t = 1; t <= 100; t++)
    {
        int z = 0;
        for(int i = 0; i< n; i++)
        {
            z += ((t - tp[i])*(t-tp[i]));
        }
        r = min(r,z);
    }
    cout << r;
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}

module Main where

import qualified Data.ByteString.Char8 as B8
import Data.Maybe (fromJust)
import Data.Char (toUpper,isDigit)
import Data.List
import qualified Data.Map as M
import Data.Array.IO
import Data.IORef
import Data.Ix (range)
import Control.Monad
import Control.Applicative
import Text.Printf
import Data.Time.Calendar
import Debug.Trace

readDigits = map read <$> words <$> getLine :: IO [Int]
readDigits' = map read <$> lines <$> getContents :: IO [Int]

--
main :: IO ()
main = do
    loop 1
    where
    loop cnt = do
        n <- readLn :: IO Int
        when (n /= 0) $ do
            putStrLn $ "Case " ++ (show cnt) ++ ": " ++ (show n)
            loop (cnt+1)

Measured memory_bytes: 4108
N=int(input())
B=list(map(int,input().split()))
answers=[]
while B:
    length=len(B)
    for n in range(len(B)-1,-1,-1):
        if B[n]==n+1:
            answers.append(B[n])
            del B[n]
            break
    if length==len(B):
        break
if len(answers)!=N:
    print(-1)
else:
    for answer in list(reversed(answers)):
        print(answer)
        

Measured memory_bytes: 63628
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    rgb = [None for _ in range(n)]
    rgb_acc = [None for _ in range(n)]
    rgb_st = {"R","G","B"}
    rgb_lst = ["R","G","B"]
    for i, char in enumerate(s):
        if char == "R":
            rgb[i] = [1,0,0]
        elif char == "G":
            rgb[i] = [0,1,0]
        else:
            rgb[i] = [0,0,1]
    
    rgb_acc[0] = rgb[0]
    for i in range(1, n):
        rgb_acc[i] = rgb_acc[i-1][:]
        index = 0 if s[i]=="R" else 1 if s[i]=="G" else 2
        rgb_acc[i][index] += 1
    
    ans = 0
    for i in range(n-2):
        for j in range(i+1,n-1):
           if s[i]!=s[j]:
                ex = rgb_st - {s[i], s[j]}
                ex = ex.pop()
                index = 0 if ex=="R" else 1 if ex=="G" else 2
                cnt = rgb_acc[n-1][index]-rgb_acc[j][index]
                if j+1 <= 2*j-i < n:
                    if s[2*j-i] == ex:
                        cnt -= 1
                ans += cnt

    print(ans)
main()

Measured memory_bytes: 75708
N,K,*A=map(int, open(0).read().split())
x=1
C=[None]*N
C[0]=0
c=0
while c<K:
    x=A[x-1]
    c+=1
    if C[x-1] is None:
        C[x-1]=c
    else:
        a=C[x-1]
        b=c-a
        K=(K-a)%b+a+b
        while c<K:
            x=A[x-1]
            c+=1
        break
print(x)


Measured memory_bytes: 31636
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; ll A[2010];
ll dp[2020][2020];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	vector<int> ord;
	rep(i, 0, N) ord.push_back(i);
	sort(all(ord), [&](int a, int b) { return A[a] > A[b]; });

	rep(tot, 0, N + 1) rep(lft, 0, N + 1) dp[tot][lft] = -inf;
	dp[0][0] = 0;

	rep(tot, 0, N) rep(lft, 0, tot + 1) if(0 <= dp[tot][lft]) {
		int i = ord[tot];

		if (0 <= i - lft) chmax(dp[tot + 1][lft + 1], dp[tot][lft] + A[i] * (i - lft));
		if (0 <= (N - 1 - (tot - lft) - i)) chmax(dp[tot + 1][lft], dp[tot][lft] + A[i] * (N - 1 - (tot - lft) - i));
	}

	ll ans = 0;
	rep(lft, 0, N + 1) chmax(ans, dp[N][lft]);
	cout << ans << endl;
}







Measured memory_bytes: 35260
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define sz(x) (int)(x.size())
#define pb push_back
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (long long)(1e9) + 123;
const int mod = 1000000007;
const double eps = 1e-9;


signed main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    cout << n * n;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
s = input()
l = 0
r = n - 1
cnt = 0
while l < r:
    if s[l] == "R":
        l += 1
    elif s[r] == "W":
        r -= 1
    else:
        cnt += 1
        l += 1
        r -= 1
print(cnt)


Measured memory_bytes: 9468