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

// clang-format off
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
#define forn(i, x, y) for(int i = x; i < y; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using VI = vector<int>;
using VVI = vector<VI>;
// clang-format on

int dfs(int u, VVI &graph, VI &cache)
{
  if (cache[u] >= 0)
    return cache[u];
  int r = 0;
  for (auto v : graph[u])
    chmax(r, 1 + dfs(v, graph, cache));
  cache[u] = r;
  return r;
}

int main()
{
  IOS;
  int N, M;
  cin >> N >> M;

  VVI graph(N + 1, VI());
  int x, y;
  forn(i, 0, M)
  {
    cin >> x >> y;
    graph[x].push_back(y);
  }

  VI cache(N + 1, -1);
  int res = 0;
  forn(u, 1, N + 1)
      chmax(res, dfs(u, graph, cache));
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 11824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int fact(int n) { 
    int res = 1; 
    for (int i = 2; i <= n; i++) {
        res = res * i;    
    }
    return res; 
}

int nCr(int n, int r) { 
    return fact(n) / (fact(r) * fact(n - r)); 
} 

int main() {
    SPEED;
    int testCases = 1;
    //cin >> testCases;
    while (testCases--) {
        int n,m;
        cin >> n >> m;
        int x = n*(n-1) + m*(m-1);
        cout << x/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
LL max(LL a, LL b){
  if (a > b) {
    return a;
  }else return b;
}

int main(void)
{
  int a, b, h, m;
  scanf("%d %d %d %d", &a, &b, &h, &m);
  double the1=((double)h*60+(double)m)/2;
  double the2=(double)m*6;
  double the=ABS(the1-the2);
  if (the > 180.0) {
    the = 360.0 - the;
  }

  //printf("%lf\n" ,the );
  double a2 = (double)a * (double)a;
  double b2 = (double)b * (double)b;
  the = the * M_PI /180;
  //printf("%lf\n", cos(the));
  double c = sqrt(a2+b2 - 2 * (double)a * (double)b *cos(the));
  printf("%.15lf\n", c);
  return 0;
}


Measured memory_bytes: 2588
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int S[100000];
int d[100000];
int ds;
int dl;
int n;
int s[100000];
int main(){
  int i, j, k, x;
  long long res, tmp;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  N--;
  ds = 1;
  d[0] = 1;
  res = 0;
  for(dl=0;dl<ds;dl++){
    n = N / d[dl];
    for(i=0;i<n;i++){
      s[i] = S[i*d[dl]];
    }
    s[n] = 0;
    for(x=1;x<n;x++){
      i = 0;
      j = n;
      tmp = 0;
      for(;;){
        i += x;
        j -= x;
        if(i==j || i+x > n || j-x < 0){
          break;
        }
        if(N%x==0 && i > j){
          break;
        }
        tmp += s[i] + s[j];
        chmax(res, tmp);
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// int N, S[1d5];
// 
// int d[1d5], ds, dl;
// int n, s[1d5];
// {
//   int i, j, k, x;
//   ll res, tmp;
// 
//   rd(N, S(N));
//   N--;
// 
//   ds = 1;
//   d[0] = 1;
//   
//   res = 0;
// 
//   rep(dl,ds){
//     n = N / d[dl];
//     rep(i,n) s[i] = S[i*d[dl]];
//     s[n] = 0;
// 
//     rep(x,1,n){
//       i = 0;
//       j = n;
//       tmp = 0;
//       for(;;){
//         i += x;
//         j -= x;
//         if(i==j || i+x > n || j-x < 0) break;
//         if(N%x==0 && i > j) break;
//         tmp += s[i] + s[j];
//         res >?= tmp;
//       }
//     }
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 1024
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
l = [1]
for i in range(n):
    l.append(a[l[i] - 1])
 
p = l.index(l[n])
 
if k <= n:
    print(l[k])
else:
    x = (k - n + 1) % (n - p)
    if x == 0:
        print(l[n - 1])
    else:
        print(l[x + p - 1])

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> count(13, 0);
	REP(i, N){
		ll D;
		cin >> D;
		count[D]++;
	}

	if(count[12]>1||count[0]>0){
		cout << 0 << endl;
		return 0;
	}
	vector<ll> ones, twos;
	for(int i=1;i<=12;i++){
		if(count[i]>2){
			cout << 0 << endl;
			return 0;
		}else if(count[i]==2){
			twos.push_back(i);
		}else if(count[i]==1){
			ones.push_back(i);
		}
	}
	//vprint(ones);
	//vprint(twos);
	ll M = ones.size();
	ll ma = -1;
	REP(mask, 1<<M){
		vector<ll> nums;
		nums.push_back(0);
		REP(i, twos.size()){
			nums.push_back(twos[i]);
			nums.push_back(24-twos[i]);
		}
		REP(j, M){
			if(mask>>j&1==1){
				nums.push_back(ones[j]);
			}else{
				nums.push_back(24-ones[j]);
			}
		}
		ll tmp = 100;
		sort(nums.begin(), nums.end());
		REP(i, nums.size()){
			tmp = min(tmp, (nums[(i+1)%nums.size()]-nums[i]+24)%24);
		}
		//vprint(nums);
		//dump(tmp)
		ma = max(ma, tmp);
	}
	cout << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

struct point
{
    int x;
    int y;
};

int main()
{
    int N;
    if (scanf("%d", &N) < 1) return 0;

    // 赤
    vector<point> vR;
    for (int i = 0; i < N; i++)
    {
        int a, b;
        if (scanf("%d", &a) < 1) return 0;
        if (scanf("%d", &b) < 1) return 0;
        vR.push_back({a, b});
    }

    // 青
    vector<point> vB;
    for (int i = 0; i < N; i++)
    {
        int c, d;
        if (scanf("%d", &c) < 1) return 0;
        if (scanf("%d", &d) < 1) return 0;
        vB.push_back({c, d});
    }

    // 青のx座標が小さなもの順
    sort(vB.begin(), vB.end(),
         [](const point& x, const point& y) { return x.x < y.x; } );

    // 赤のy座標が大きなもの順
    sort(vR.begin(), vR.end(),
         [](const point& x, const point& y) { return y.y < x.y; } );
    
    int cnt = 0;
    vector<bool> B(N, false);
    vector<bool> R(N, false);

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (vB[i].x <= vR[j].x) continue;
            if (vB[i].y <= vR[j].y) continue;
            if (B[i] || R[j]) continue;

            cnt++;
            B[i] = true;
            R[j] = true;
        }
    }

    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iterator>
#include <iomanip>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>
#include <limits>
#include <functional>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#define fore(i,a,b) for(ll i = (a),_b = (b); i < (_b); i++)
#define fort(i,a,b) for(ll i = (a),_b = (b); i <= (_b); i++)
#define ford(i,a,b) for(ll i = (a),_b = (b); i >= (_b); i--)
//#define LOCAL
using namespace std;

typedef long long ll;

template<class A,class B> bool maxi(A &a,const B b){return a < b ? (a = b,true):false;};
template<class A,class B> bool mini(A &a,const B b){return a > b ? (a = b,true):false;};

const ll maxN = 1e5 + 5;
const ll inf = 1e10;

ll n,k;
ll dp[maxN],h[maxN];

int main(){
    #ifdef LOCAL
        freopen("b.INP","r",stdin);
    #endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    fort(i,1,n)
        cin >> h[i];
    dp[n] = 0;
    ford(i,n - 1,1){
        dp[i] = inf;
        fort(j,i + 1,min(i + k,n))
            mini(dp[i],dp[j] + abs(h[j] - h[i]));
    }
    cout << dp[1] << '\n';
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <vector>

const int MN = 55;

int N, ap[MN], bp[MN], ad[MN];
std::vector<int> A[MN], B[MN];
void DFS(int u, int pa, std::vector<int> *H, int *p) {
	p[u] = pa;
	for (int v : H[u]) if (v != pa) DFS(v, u, H, p);
}

int op[MN], in[MN], que[MN], l, r;
std::vector<int> G[MN];
inline int Calc() {
	int cnt = 0;
	for (int i = 1; i <= N; ++i) cnt += op[i] = ap[i] != bp[i];
	for (int i = 1; i <= N; ++i) if (!op[i] && op[ap[i]]) return -1;
	for (int i = 1; i <= N; ++i) G[i].clear(), in[i] = 0;
	for (int i = 1; i <= N; ++i) if (op[i]) {
		if (op[ap[i]]) G[i].push_back(ap[i]), ++in[ap[i]];
		if (op[bp[i]]) G[bp[i]].push_back(i), ++in[i];
	}
	l = 1, r = 0;
	for (int i = 1; i <= N; ++i) if (op[i] && !in[i]) que[++r] = i;
	while (l <= r) {
		int u = que[l++];
		for (int v : G[u]) if (!--in[v]) que[++r] = v;
	}
	return r != cnt ? -1 : cnt;
}

int main() {
	int Tests;
	scanf("%d", &Tests);
	while (Tests--) {
		scanf("%d", &N);
		int Ans = N + 1;
		for (int i = 1; i <= N; ++i) A[i].clear(), B[i].clear(), ad[i] = 0;
		for (int i = 1, x, y; i < N; ++i)
			scanf("%d%d", &x, &y), A[x].push_back(y), A[y].push_back(x), ++ad[x], ++ad[y];
		for (int i = 1, x, y; i < N; ++i)
			scanf("%d%d", &x, &y), B[x].push_back(y), B[y].push_back(x);
		DFS(1, 0, A, ap), DFS(1, 0, B, bp);
		int ok = 1;
		for (int i = 1; i <= N; ++i) if (ap[i] != bp[i]) ok = 0;
		if (ok) { puts("0"); continue; }
		for (int i = 1; i <= N; ++i) if (ad[i] == 1) {
			DFS(i, 0, B, bp);
			for (int j = 1; j <= N; ++j) if (j != i) {
				DFS(j, 0, A, ap), ap[j] = i, ap[i] = 0;
				int ans = Calc();
				if (~ans) Ans = std::min(Ans, ans + 1);
			}
		}
		printf("%d\n", Ans > N ? -1 : Ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define REP(i,x) for(ll i=0;i<(ll)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ull> A_v(N, 0);
    REP(i, N)
    {
        cin >> A_v.at(i);
    }

    sort(A_v.begin(), A_v.end());
    auto it_uniq = unique(A_v.begin(), A_v.end());

    if(it_uniq == A_v.end())
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}

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

#define gc getchar
int scan(int*N)
{
	int c,n=0;
	for(c=gc();'0'<=c&&c<='9';c=gc())
	    n=(n*10)+(c&0xf);
	if(N!=NULL)*N=n;
	return n;
}

/*設問用*/
#define N_MAX 3000
typedef struct
{
    int x;
    int y;
}Point;

/*グローバル変数*/
int N;          //座標平面上の点の数
int K;          //同じ直線上にあってはならない点の数
Point P[N_MAX]; //点の座標データ
Point C[N_MAX]; //ある点P[i]を中心にした座標データ

/*クイックソート用比較関数*/
int comp(const void *a, const void *b)
{
    return ((Point *)b)->x * ((Point *)a)->y - ((Point *)a)->x * ((Point *)b)->y;
}

int cnt(int n)
{
    Point c;
    c = C[0];
    int L=2;    //直線上にある点の数
    int M=2;    //上記の最大数
    
    /*傾きが近い順にソート*/
    qsort(C, n, sizeof(Point), comp);
    
    /*同じ傾きの数え上げ*/
    for(int i=1; i<n; i++){
        L += (c.x * C[i].y) == (C[i].x * c.y);//等傾
        if(L > M) M=L;//最大数更新
        else{ L=2, c=C[i]; }
    }
    return M;
}

int main()
{
    int i,j;//ループ用
    int n;//i番目以降の残りの点の数
    int v;//縦に並んでいる点の数
    int ans=0;//回答
    
    /*読込*/
    scan(&N);
	scan(&K);
    for(i=0; i<N; i++){
        scan(&P[i].x);
    	scan(&P[i].y);
    }
    
    /*P[i]中心の座標にして数える*/
    for (i=0; i<=(N-K); i++){
        v=1,n=0;
        for (j=i+1; j<N; j++){
            if ( P[i].x == P[j].x ){
                v++;
            }else{
                C[n] = P[j];
                C[n].x -= P[i].x;
                C[n].y -= P[i].y;
            	n++;
            }
        }
        if ( v>=K || cnt(n)>=K ){
            ans=1;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <iomanip>
#include <vector>


#define debug(x) cout << #x << "==" << x << endl;
const int INF = 1e+9 + 7;
typedef long long ll;

//??\???
#define MAX_N 10000


using namespace std;

class UnionFind {

private:
  int N;
  vector<int> par;
  vector<int> rank;

  void init(int n)  {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }

public:
  UnionFind(int n) {
    N = n;
    par.resize(n);
    rank.resize(n);
    init(n);
  }


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

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

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

    if( x == y) return;

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

  }

};






int main() {
  ios::sync_with_stdio(false);


  int n, q;
  cin >> n >> q;

  UnionFind uf = UnionFind(n);

  int com, x, y;
  for(int i = 0; i < q; i++) {
    cin >> com >> x >> y;

    if( com == 0 ) {
      uf.unite(x,y);
    }

    if( com == 1 ) {
      cout << ( uf.same(x, y) ? 1 : 0 )  << endl;
    }

  }



  return 0;
}

Measured memory_bytes: 3212
from itertools import accumulate

N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for i in range(Q)]

flg=[]
for i in range(N-1):
    s = S[i:i+2] 
    if s == 'AC':
        flg.append(1)
    else:
        flg.append(0)

flg2 = list(accumulate([0]+flg))

for a in A:
    print (flg2[a[1]-1]-flg2[a[0]-1])

Measured memory_bytes: 33144
#include <cstdio>
using namespace std;

int main(void){
    int H, A, B, res = 0;
    scanf("%d %d %d", &H, &A, &B);
    for (int i = A; i <= B; i++) if (H % i == 0) res++;
    printf("%d\n", res);
    return 0;
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define mp make_pair
#define pii pair<int,int>

using namespace std;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin>>n;
    vector<pii> a;
    for(int i=1;i<=n;i++)
    {
        int x,y; cin>>x>>y;
        a.pb(mp(x,y));
    }
    sort(a.begin(),a.end());
    int ans = 0;
    int pop_min = a[0].st + a[0].nd;
    for(int i=1;i<n;i++)
    {
        int akt = a[i].st + a[i].nd;
        ans = max(ans,akt - pop_min);
        pop_min = min(pop_min,akt);
    }

    pop_min = a[0].st - a[0].nd;
    for(int i=1;i<n;i++)
    {
        int akt = a[i].st - a[i].nd;
        ans = max(ans,akt - pop_min);
        pop_min = min(pop_min,akt);
    }

    cout<<ans;



    return 0;

}



Measured memory_bytes: 5228
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int n = inint();
		int[] ar = inintar(n);
		int count = 0;
		
		for (int i=0; i<n-2; i++) {
			if (check(ar[i], ar[i+1], ar[i+2]) == true) count++;
		}
		
		out.println(count);

	}
	
	public boolean check(int L, int M, int R) {
		if ((L > M && M > R) || (L < M && M < R)) return true;
		else return false;
	}
	

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}

	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21844
import math
import sys
input = sys.stdin.readline

Q = int(input())
AB = [list(map(int, input().split())) for _ in range(Q)]

for A, B in AB:
    P = A*B-1
    b = int(math.sqrt(P))
    if b <= 1:
        if P <= 1:
            print(0)
        else:
            print(1)
        continue
    K = []
    for n in [b-1, b, b+1]:
        if P//n > n:
            border = n
        K.append(min(n, P//n))
    ans = 2*border
    if P//(border+1) == border+1:
        ans += 1
    if min(A, B) <= max(K):
        ans -= 1

    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a;
  cin >> a;
  cout<<3*a*a<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s,t;
  cin >> s >> t;
  
  int sl = s.size();
  int tl = t.size();
  int cnt = 0;
  
  if(sl + 1 == tl){
    for(int i = 0; i < sl; i++){
      if(s.at(i) == t.at(i)){
        cnt++;
      }
    }
  }
  
  if(cnt == s.size()){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

    if (a- b * 2 < 0){
        cout << 0 << endl;
    } else {
        cout << a - b * 2 << endl;
    }

	return 0;
}

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

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

int main(){
    int N;
    cin >> N;
    vector<pair<long long, long long> > pairs(N);

    // 入力
    long long x;
    for(int i = 0; i< N; i++){
        cin >> x;
        pairs[i] = make_pair(i, x);
    }

    sort(pairs.begin(), pairs.end(), compare_by_b);

    //初期状態の中央値
    int medL = N/2 - 1;
    int medR = N/2;

    vector<pair<long long, long long> > res(N);
    for(int i = 0; i< N; i++){
        if(i<=medL){
            res[i] = make_pair(pairs[i].first, pairs[medR].second);
        }else{
            res[i] = make_pair(pairs[i].first, pairs[medL].second);
        }
    }
    sort(res.begin(), res.end());
    for(int i = 0; i< N; i++){
        cout << res[i].second << endl;
    }
}

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

int n;

int search(int *A, int w);

int main(int argc, char *argv[])
{
  int i, j, k, l, t;
  int *A, *R, *g, tmp, g_minj, minj, change, g_minw;
  int cost = 0;

  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  R = (int *)malloc(sizeof(int) * n);
  g = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    R[i] = A[i];
    g[i] = 0;
  }

  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j < n; j++) {
      if (R[minj] > R[j]) minj = j;
    }
    tmp = R[minj];
    R[minj] = R[i];
    R[i] = tmp;
  }

  for (i = 0; i < n; i++) {
    if (A[i] == R[i]) continue;

    g_minj = i;
    g[0] = i;
    k = 1;
    j = i;
    while (A[j] != R[i]) {
      j = search(R, A[j]);
      if (A[j] < A[g_minj]) g_minj = j;
      g[k++] = j;
    }
    g_minw = A[g_minj];
    l = search(g, g_minj);

    minj = search(A, R[0]);

    if (k >= 4) {
      if ((k+1) * A[minj] < (k-3) * A[g_minj]) change = 1;
      else change = 0;
    } else change = 0;

    if (change == 1) {
      cost += A[g_minj] + A[minj];
      tmp = A[g_minj];
      A[g_minj] = A[minj];
      A[minj] = tmp;
    }

    for (j = k; j > 1; j--) {
      t = (l + j - 1) % k;
      cost += A[g[t]] + A[g[t+1]];
      tmp = A[g[t+1]];
      A[g[t+1]] = A[g[t]];
      A[g[t]] = tmp;
    }

    if (change == 1) {
      g_minj = search(A, g_minw);
      minj = search(A, R[0]);
      cost += A[g_minj] + A[minj];
      tmp = A[g_minj];
      A[g_minj] = A[minj];
      A[minj] = tmp;
    }
  }

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

  return 0;
}

int search(int *A, int w)
{
  int i;
  int found;

  found = 0;
  for (i = 0; i < n; i++) {
    if (A[i] == w) {
      found = 1;
      break;
    }
  }

  if (found == 1) return i;
  else return -1;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};




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

  
string s;
cin>>s;
string p(s.length(),'x');
cout<<p;






}

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

int main()
{
    long long x,y;
    cin>>x>>y;
    if(y>x) swap(x,y);
    if(x-y>=2) cout<<"Alice"<<endl;
    else cout<<"Brown"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using pii = pair<int,int>;
using ll = long long;

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

    if (N == 0){ outl(0); return 0; }

    vector<char> ans;

    int n = N;

    while (n != 0) {
        int div = n / -2;
        if (div * -2  > n) div++;

        //printf("%d %d %d\n", n, div, n - (div * -2));

        ans.push_back('0' + n - (div * -2));
        n = div;
    }

    reverse(ans.begin(), ans.end());

    rep(i, ans.size()) {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}



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

int main(){

  string a, b, c;
  cin >> a >> b >> c;


  if(b[0]==a[a.size()-1] && c[0]==b[b.size()-1]){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}


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

int main() {
    string s;

    cin >> s; 

    if(s == "SUN"){
        cout << "7";
    }
    else if(s == "SAT"){
        cout << "1";
    }
    else if(s == "FRI"){
        cout << "2";
    }
    else if(s == "THU"){
        cout << "3";
    }
    else if(s == "WED"){
        cout << "4";
    }
    else if(s == "TUE"){
        cout << "5";
    }
    else if(s == "MON"){
        cout << "6";
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
A = list(i for i in range(1,N+1))
#print(A)
if P == A:
    print('YES')
    exit()
for i in range(0, N-1):
    for j in range(i+1, N):
        B = A
        B[i], B[j] = B[j], B[i]
        if P == A:
            print('YES')
            exit()
        B[i], B[j] = B[j], B[i]
print('NO')

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

int main(){
  constexpr int N= 3;

  set<int> colors;
  int buf;
  for(int i=0; i<N; i++){
    cin >> buf;
    colors.insert(buf);
  }
  int64_t ans= colors.size();

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] a = new int[n];

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

            xor_All = xor_All ^ a[i];
        }

        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < n-1; i++) {
            pw.print((xor_All ^ a[i]) + " ");
        }
        pw.println((xor_All ^ a[n-1]));
        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 59388
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1145141919
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int n,m,i,a[262144],b[262144],f[262144]={0};
    scanf("%d%d",&n,&m);
    for(i = 1;i <= m;i++){scanf("%d%d",&a[i],&b[i]);}
    for(i=1;i<=m;i++){
        if(a[i]==1){f[b[i]]++;}
    }
    for(i=1;i<=m;i++){
        if(f[a[i]] != 0 && b[i] == n){printf("POSSIBLE\n");return 0;}
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>

int main()
{
	int i, N;
	long long A[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld", &(A[i]));
	
	int j, k, p, next[200001] = {}, sur[200001] = {};
	long long sum[2][200001] = {}, tmp;
	for (i = N - 1, p = N; i >= 1; i--) {
		if (A[i+1] >= A[i] * 4) {
			for (j = 2, tmp = A[i] * 4; tmp * 4 <= A[i+1]; j += 2) tmp *= 4;
			sur[i] = j;
			next[i] = p;
			p = i;
		}

		for (j = 0, tmp = A[i+1]; tmp < A[i]; j += 2) tmp *= 4;
		sum[0][i] = sum[0][i+1] + j * (p - i);
		for (; j > 0 && p < N; p = next[p]) {
			if (j < sur[p]) {
				sur[p] -= j;
				break;
			} else j -= sur[p];
			sum[0][i] += j * (next[p] - p);
		}
	}
	for (i = 2, p = 1; i <= N; i++) {
		if (A[i-1] >= A[i] * 4) {
			for (j = 2, tmp = A[i] * 4; tmp * 4 <= A[i-1]; j += 2) tmp *= 4;
			sur[i] = j;
			next[i] = p;
			p = i;
		}

		for (j = 0, tmp = A[i-1]; tmp < A[i]; j += 2) tmp *= 4;
		sum[1][i] = sum[1][i-1] + j * (i - p);
		for (; j > 0 && p > 1; p = next[p]) {
			if (j < sur[p]) {
				sur[p] -= j;
				break;
			} else j -= sur[p];
			sum[1][i] += j * (p - next[p]);
		}
	}
	
	long long ans = (sum[0][1] < sum[1][N] + N)? sum[0][1]: sum[1][N] + N;
	for (i = 2; i <= N; i++) {
		tmp = sum[0][i] + sum[1][i-1] + i - 1;
		if (tmp < ans) ans = tmp;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 7960
<?php
$input_line = trim(fgets(STDIN));
$input_line = str_replace(array("\r\n","\r","\n"), '', $input_line);
$input_line = explode(" ", $input_line);
  
  $s = trim(fgets(STDIN));
  $s = str_replace(array("\r\n","\r","\n"), '', $s);
  $s = explode(" ", $s);
  $work = 0;

for ($i = 0; $i < $input_line[1]; $i++) {

  $work += $s[$i];
}

$output = $input_line[0] -  $work;
if ($output >= 0) {
	echo $output;
} else {
	echo -1;
}
?>

Measured memory_bytes: 16920
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> p(n);
	int cnt = 0;
	
	for(int i = 0; i < n; ++i) {
		cin >> p[i];
		p[i]--;
	
		if( p[i] != i ) cnt++;
	}
	
	if( cnt <= 2 ) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
   int N;
   cin>>N; 
   int a[N];
   for(int i=0; i<N; i++){
       cin>>a[i];
   }
   
   sort(a,a+N);
   
   cout<<a[N-1]-a[0]<<endl;
   return 0;
}


Measured memory_bytes: 256
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N, K = inp_list()
ans = 0
for k in range(K, N + 2):
    # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1
    M = ( N * (N + 1) - (N - k) * (N + 1 - k) ) // 2
    m = k * (k - 1) // 2
    ans += (M - m + 1) % mod

print(ans % mod)


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

ll cmb(ll n) {
  if(n < 0)
    return 0;
  else
    return n * (n - 1) / 2;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> cnt;
  rep(i, n) {
    cin >> a[i];
    a[i]--;
    cnt[a[i]]++;
  }

  // map<int, ll> ans;
  // rep(i, cnt.size()) {
  //   int q = cnt[i];
  //   if(q == 0)
  //     continue;
  //   ll aa = cmb(q - 1);
  //   if(ans[q] == 0) {
  //     rep(j, cnt.size()) {
  //       if(j == i)
  //         continue;
  //       aa += cmb(cnt[j]);
  //     }
  //     ans[q] = aa;
  //   }
  // }

  // rep(i, n) cout << ans[cnt[a[i]]] << endl;

  ll ans = 1;
  rep(i, cnt.size()) ans += cmb(cnt[i]);
  rep(i, n) cout << ans - cnt[a[i]] << endl;
}


Measured memory_bytes: 13544
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    for(int i = 0; i < n; ++i)  cin >> x[i] >> y[i] >> h[i];
    int id = -1;
    for(int i = 0; i < n; ++i){
        if(h[i] != 0){
            id = i;
            break;
        }
    }
    int res_x = -1, res_y = -1, height = -1;
    for(int cx = 0; cx <= 100; ++cx){
        bool flag = false;
        for(int cy = 0; cy <= 100; ++cy){
            flag = true;
            int tmp = h[id] + abs(x[id] - cx) + abs(y[id] - cy);
            for(int i = 0; i < n; ++i){
                if(i == id) continue;
                if(max(tmp - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]){
                    flag = false;
                    break;
                }
            }
            if(flag){
                res_x = cx, res_y = cy, height = tmp;
                break;
            }
        }
        if(flag)    break;
    }
    cout << res_x << " " << res_y << " " << height << "\n";
}

Measured memory_bytes: 256
import math
import itertools

N = int(input())
a = []
for i in range(N):
  x, y = list(map(lambda x: int(x), input().split()))
  a.append((x, y))

# 二次元配列を用意してa→bの全てのパターンの経路を計算する
min_load_map = []
for i in range(N):
  arr = []
  for t in range(N):
    min_i_to_t = math.sqrt((a[i][0] - a[t][0])**2 + (a[i][1] - a[t][1])**2)
    arr.append(min_i_to_t)
  min_load_map.append(arr)

ans = float()

# 順列を用意
patterns = itertools.permutations(range(N))
count = 0
for pat in patterns:
  count += 1
  pat = list(pat)
  tmp = 0
  for p in range(1, len(pat)):
    tmp += min_load_map[pat[p-1]][pat[p]]
  ans += tmp

ans /=  count
  
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
 public static void main(String args[]){
  boolean flag=false;
  Scanner scan=new Scanner(System.in);
  String s;

  s=scan.next();
  double n=Long.parseLong(s);
  s=scan.next();
  double a=Long.parseLong(s);
  s=scan.next();
  double b=Long.parseLong(s);

  if(Math.abs(a-b)%2==0)System.out.println("Alice");
  else System.out.println("Borys");
 }
}


Measured memory_bytes: 35716
#include<stdio.h>
#include<string.h>
int main(void){
  char str[100];
  int length,out=0;
  scanf("%s",str);
  length=strlen(str);
  for(int i=0;i<length/2;i++){
    if(str[i]!=str[length-1-i]) out++;
  }
  printf("%d",out);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int dp[3005][3005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string a, b;
	cin >> a >> b;
	repn(i, 1, a.length() + 1) repn(j, 1, b.length() + 1){
		dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		if(a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);	
	}
	int x = a.length();
	int y = b.length();
	string ans = "";
	while(x && y){
		if(a[x - 1] == b[y - 1]){
			ans += a[x - 1];
			x--, y--;
		}	
		else if(dp[x - 1][y] > dp[x][y - 1]) x--;
		else y--;
	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first 
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1e9 + 7;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n<0)return 0;if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(),x.end()
#define Return(x) {cout << x << endl; return 0;}

const int nax = 2e5 + 10;

int__ main() {
    int k,n; cin >> k >> n;

    int a[nax]; for(int i=0;i<n;i++) {cin >> a[i];}

    int mx = 0;

    for(int i=1;i<n;i++) mx = max(mx, a[i] - a[i-1]);

    mx = max(mx , a[0] + (k - a[n-1]));

    cout << k - mx << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    string N;
    cin>>N;
    int res=0;
    REP(i,SZ(N))res+=N[i]-'0';
    res=max(res,9*(SZ(N)-1)+(N[0]-'1'));
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		double phi = n;
		Set<Integer> set = new HashSet<Integer>();

		for (int i=2; i*i<=n; i++) {
			while (n%i == 0) {
				n /= i;
				set.add(i);
			}
		}
		if (n > 1)
			set.add(n);

		Iterator it = set.iterator();
		while (it.hasNext()) {
			int p = (Integer)it.next();
			phi *= 1-(double)1/p;
		}

		System.out.println((int)phi);

		br.close();
	}
}

Measured memory_bytes: 17028
N=int(input())
num=['3','5','7']
ans=0

def solve(str):
    if not str:
        solve(str+'3')
        solve(str+'5')
        solve(str+'7')
    else:
        if int(str)<=N:
            if '3' in str and '5' in str and '7' in str:
                global ans
                ans+=1
            solve(str+'3')
            solve(str+'5')
            solve(str+'7')
        else:
            return
solve('')
print(ans)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		sc.close();

		long ans = a * c;
		ans = Math.max(ans, a * d);
		ans = Math.max(ans, b * c);
		ans = Math.max(ans, b * d);
		System.out.println(ans);
	}
}


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

int main()
{
   int n;

   while(cin>>n)
   {

       if(n==0) return 0;
       int arr[n];
       for(int i=0;i<n;i++)
       cin>>arr[i];

        int mx = arr[0];
        int mx2 = arr[0];
        for(int i=1;i<n;i++)
        {
           mx = max( arr[i], mx+arr[i] );
           mx2 = max( mx,mx2);

        }
         cout<<mx2<<endl;
   }

}



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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;
const int MN = 1'000'000;

vector<int> get_primes(int num){
    vector<int> primes;
    for(int i = 2; i*i <= num; i++){
        if(num % i == 0){
            primes.push_back(i);
            while(num % i == 0){
                num /= i;
            }
        }
    }
    if (num > 1) primes.push_back(num);

    return primes;
}

int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i,0,N) cin >> a[i];
    set<int> primes;
    int set_gcd = a[0];
    bool is_coprime = true;
    for(int i = 0; i < N; i++){
        vector<int> num_primes = get_primes(a[i]);
        for(int p : num_primes){
            if(primes.count(p) > 0){
                is_coprime = false;
                goto setprime;
            }
            primes.insert(p);
        }
    }
    if(is_coprime) goto show;
    setprime:
    for(int i = 0; i < N; i++){
        set_gcd = __gcd(set_gcd, a[i]);
        if(set_gcd == 1) break;
    }
    show:
    if(is_coprime) cout << "pairwise coprime" << endl;
    else if(set_gcd == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 7320
#include <stdio.h>

int main() {
	char b;
	scanf("%c", &b);
	if (b == 'A')
		b = 'T';
	else if (b == 'T')
		b = 'A';
	else if (b == 'C')
		b = 'G';
	else
		b = 'C';
	printf("%c", b);
}

Measured memory_bytes: 128
array = []

for i in range(2):
    val = input()
    array.append(val.split())

kinds = int(array[0][0])
populars = int(array[0][1])
votes_sum = 0

for vote in array[1]:
    votes_sum = votes_sum + int(vote)

winning = votes_sum / (4 * populars)
numbers = 0

for vote in array[1]:
    if int(vote) >= winning:
        numbers = numbers + 1

if numbers >= populars:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
#define REVS(v) reverse(v.begin(),v.end())
#define PI 3.14159265359
using namespace std;
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n,d,count,ans,sosuucount;
  count = 0,ans = 0;
  sosuucount = 1;
  IN2(n,d);
  vector<vector<int>> data(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
  for (int j = 0; j < d; j++) {
    cin >> data.at(i).at(j);
    }
  }
  FOR(i,n-1){
    FORS(j,i+1,n){
      FOR(k,d){
        count += pow(abs(data[i][k] - data[j][k]),2);
      }
      while (sosuucount <= count)
      {
        if (count == pow(sosuucount,2)){
          ans++;
          break;
        }
        sosuucount++;
      }
      sosuucount = 1;
      count = 0;
    }
  }
  OUT(ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

const int N = 1e6 + 1;
int dp[N][2];

int calc(int pos , int n , string &s , int carry){

	//debug(pos , n , s , carry);
	if(pos==n)
		return carry;

	int &ans = dp[pos][carry];

	if(ans!=-1)
		return ans;

	int val = s[pos]-'0';

	val += carry;
	ans = 0;
	int ans1 = val + calc(pos+1 , n , s , 0);
	int ans2 = 10 - val + calc(pos+1 , n , s , 1);

	//debug(ans1 , ans2 , pos);
	ans = min(ans1 , ans2);

	return ans;

}

void solve(){
	
	string s;
	cin>>s;
	int ans = 0;

	reverse(s.begin(),s.end());

	memset(dp , -1 , sizeof dp);

	ans = calc(0 , (int)s.size() , s , 0);

	cout<<ans<<endl;

}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 79516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k,cnt;
	cin>>n>>k;cnt=0;
	while(n!=0){
		cnt++;
		n/=k;
	}
	cout <<cnt;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256