akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
const int N = 1e7 + 4;
int spf[N];
void sieve()
{
    spf[1] = 1;
    for (int i = 2; i < N; i++)

        // marking smallest prime factor for every
        // number to be itself.
        spf[i] = i;

    // separately marking spf for every even
    // number as 2
    for (int i = 4; i < N; i += 2)
        spf[i] = 2;

    for (int i = 3; i * i < N; i++)
    {
        // checking if i is prime
        if (spf[i] == i)
        {
            // marking SPF for all numbers divisible by i
            for (int j = i * i; j < N; j += i)

                // marking spf[j] if it is not
                // previously marked
                if (spf[j] == j)
                    spf[j] = i;
        }
    }
}

// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
ll getFactorization(int x)
{
    vector<int> ret;
    int o = x;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    ll ans = 1;
    for (int i = 0; o > 1; i++)
    {
        ll cnt = 0;
        while (o % ret[i] == 0)
        {
            cnt++;
            o /= ret[i];
        }
        ans = ans * (cnt + 1ll);
    }
    return ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    sieve();
    int n;
    cin >> n;
    ll ans = 1ll;
    for (int i = 2; i <= n; i++)
    {
        ans = ans + i * getFactorization(i);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 42720
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    auto a = make_vec<int>(n, n);
    rep(i, n) rep(j, n) cin >> a[i][j];
    
    bool ok = true;
    rep(k, n) rep(i, n) rep(j, n) if (chmin(a[i][j], a[i][k] + a[k][j])) ok = false;
    if (!ok) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    rep(j, n) rep(i, j) {
        // path from i to j
        bool flag = true;
        rep(k, n) if (i != k && j != k && a[i][j] == a[i][k] + a[k][j]) flag = false;
        if (flag) ans += a[i][j];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3780
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

a, b = map(int, input().split())
if b >= a:print('unsafe')
else: print('safe')


Measured memory_bytes: 9180
#include<stdio.h>

int arr[10];
int b[10],c[10];
int visited[10]; 
int dfs(int n,int nb,int nc)
{
	int sign=0,sign1=0;
	if(n==10)
		return 1;	
	else
	{
		if(nb==0)
		{
			b[nb]=arr[n];
			sign=dfs(n+1,nb+1,nc);
			
		}
		else 
		{	
			if(arr[n]>b[nb-1])
			{
				b[nb]=arr[n];
				sign=dfs(n+1,nb+1,nc);
				
			}
		}
		if(nc==0)
		{
			c[nc]=arr[n];
			sign1=dfs(n+1,nb,nc+1);
			
		}
		else
		{
			if(arr[n]>c[nc-1])
			{
				c[nc]=arr[n];
				sign1=dfs(n+1,nb,nc+1);
			
			}
		}
	}
	return sign||sign1;
}
int main()
{
	int N;
	scanf("%d",&N);
	while(N--)
	{
		int i,sign=0;
		for(i=0;i<10;i++)
			scanf("%d",&arr[i]);
		sign=dfs(0,0,0);
		if(sign)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 2484
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x,T a,T b){return a<=x&&x<=b;}
template<class T> void amin(T &a,T v){if(a>v) a=v;}
template<class T> void amax(T &a,T v){if(a<v) a=v;}
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<=EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<=EPS*max(1.0,max(fabs(x),fabs(y))); }
double SQSUM(double x,double y) { return x*x+y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

#if 1

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

	for(ll hi=1;;hi++)
	{
		vector <ll> ans;
		ll sum = hi*(hi + 1) / 2;
		if (sum >= N)
		{
			for (ll dec = hi; dec >= 0; dec--)
			{
				if(N==0) break;

				if (N - dec >= 0)
				{
					ans.push_back(dec);
					N -= dec;
				}

			}

			reverse(ans.begin(),ans.end());
			for (ll a : ans)
			{
				cout << a << endl;
			}
			return 0;
		}
	}

	return 0;
}



#else

int main()
{
	int H,W;
	cin >> H >> W;

	for (int y = 0; y < H; ++y)
	{
		for (int x = 0; x < W; ++x)
		{
			string s;
			cin >> s;
			if (s == "snuke")
			{
				char a = 'A'+x;
				char b = 1+y;
				printf("%c%d\n",a,b);
				break;

			}

		}
	}



	return 0;
}

#endif

Measured memory_bytes: 384
#include <stdio.h>
#define INFTY 100001
#define white 0
#define gray 1
#define black 2
#define N 100

int primkansu(void);

int n,M[N][N];

int main(){

  int i,j,e;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e == -1) M[i][j]=INFTY;
      else M[i][j] = e;
    } 
  }

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

  return 0;
}

int primkansu(){
  int u,i,minv,sum,v;
  int d[N],p[N], color[N];

  for(i=0; i<n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = white;
  }

  d[0]=0;

  while(1){
    minv = INFTY;
    u = -1;
    for(i=0; i<n; i++){
      if( minv > d[i] && color[i] != black ){
	u = i;
	minv = d[i];
      }
    }
    if( u == -1 ) break;
    color[u] = black;
    for(v=0; v<n; v++){
      if( color[v] != black && M[u][v] != INFTY ){
	if( d[v] > M[u][v] ){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = gray;
	}
      }
    }
  }
  sum = 0;
  for(i=0; i<n; i++){
    if( p[i] != -1 ) sum += M[i][p[i]];
  }
  
  return sum;
  
}




Measured memory_bytes: 1988
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 r;
  scanf ("%" SCNi32, &r);
  i32 ans = 3 * r * r;
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    
    int n, l;
    cin >> n >> l;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<int> res;
    int flag = 0;
    for (int i = 0; i < n - 1; i++) {
        if (v[i] + v[i + 1] >= l) {
            flag = i + 1;
            break;
        }
    }
    if (flag == 0) {
        cout << "Impossible" << endl;
        return 0;
    }
    for (int i = 1; i < n; i++) {
        if (i != flag) {
            res.push_back(i);
        } else {
            break;
        }
    }
    for (int i = n - 1; i >= 1; i--) {
        if (i != flag) {
            res.push_back(i);
        } else {
            break;
        }
    }
    res.push_back(flag);
    cout << "Possible" << endl;
    for (auto r : res) {
        cout << r << endl;
    }
}


Measured memory_bytes: 4320
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j;
string s,t;
int main()
{
	cin>>s;
	fz0k(i,s.length()){
		if(t.size()&&t[t.length()-1]=='S'&&s[i]=='T'){
			t.erase(t.length()-1);
		}
		else{
			t.push_back(s[i]);
		}
	}
	cout<<t.size()<<endl;
	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int p , q , r;
    cin >> p >> q >> r;
    int ma = -1;
    int sum=p+q+r;

    if (p>ma) ma =p;
    if (q>ma) ma =q;
    if (r>ma) ma =r;

    cout << sum-ma << endl;
    
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}

const ll inf=10000000000;
int main(){
  ll N;cin>>N;
  vector<ll> v(N,0);
  vector<ll> n(N,0);
  ll a;
  ll u=0;
  ll ans=0;
  rep(i,N){
    cin>>n[i];
    v[n[i]-1]++;
  }
  rep(i,N){
    u+=(v[i])*(v[i]-1)/2;
  }
  
  rep(i,N){
    ans=u- (v[n[i]-1]*(v[n[i]-1]-1))/2 + ((v[n[i]-1]-2)*(v[n[i]-1]-1))/2 ;
    cout<<ans<<endl;
    ans=0;
  }
  
}

Measured memory_bytes: 5760
#include<stdio.h>
#define MAX 101
#define WHITE -1
#define GRAY -2
#define BLACK -3

int G[MAX][MAX],d[MAX],color[MAX];
int n,k[MAX],u,v,time;
int head,tail;
int Q[MAX];

int empty(){
  if(head==tail) return 1;
  else return 0;
}

void Enqueue(int x){
  Q[tail] = x;
  
  if(tail==MAX) tail = 0;
  else tail += 1;
  
}

int Dequeue(){
  int x;
  x = Q[head];
  
  if(head == MAX) head = 0;
  else head += 1;
  
  return x;
}


void BFS(int s){
  int i,j;

  for(u=1; u<=n; u++){
    color[u] = WHITE;
  }
  d[s] = 0;
  Enqueue(s);
  while(!empty()){
    u = Dequeue();
    for(i=1; i<=k[u]; i++){
      if(color[G[u][i]] == WHITE){
	color[G[u][i]] = GRAY;
	d[G[u][i]] = d[u]+1;
	Enqueue(G[u][i]);
      }
    }
    color[u] = BLACK;
  }
}
  
int main(){
  int i,j;
  
  scanf("%d",&n);
  
  for(i=1; i<=n; i++){
    scanf("%d%d",&u,&k[i]);
    d[u] = -1;
    for(j=1; j<=k[i]; j++){
      scanf("%d",&G[i][j]);
    }
  } 
  BFS(1);

  for(i=1; i<=n; i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

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

using namespace std;

int val[100005][3];
int n, k;

int dp[100005][3];

int solve(int i, int a){

    if (i == n) return 0;
    
    if(dp[i][a] != -1){
        return dp[i][a];
    }
    
    int ans = 0;

    for(int x=0; x<3; x++){
        if(x != a)
            ans = max(ans, solve(i+1, x) + val[i][a]);
    }
    
    return dp[i][a] = ans;

}


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

}

Measured memory_bytes: 10368
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::*;

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed parsing")
}

fn main() {
  let mut x: u32 = read::<u32>();

  loop {
    if is_prime(x) {
      break;
    }
    x = x + 1;
  }

  println!("{}", x);

}

fn is_prime(n: u32) -> bool {
  if n <= 1 {
    return false;
  }
  for i in 2..n {
    if n % i == 0 {
      return false;
    }
    if i * i > n {
      return true;
    }
  }
  true
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val n = readInt()
    val s = readString()

    var ans = 0
    for (i in 0..n - 3) {
        if ("${s[i]}${s[i + 1]}${s[i + 2]}" == "ABC") ans++
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 33568
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int l[q], r[q];
  for(int i = 0; i < q; i++){
    cin >> l[i] >> r[i];
    --l[i]; --r[i];
  }

  int t[n + 1];
  fill(t, t + n + 1, 0);
  for(int i = 2; i <= n; i++){
    if(s[i - 1] == 'C' && s[i - 2] == 'A'){
      t[i] = t[i - 2] + 1;
    }
    else{
      t[i] = t[i - 1];
    }
  }

  string buf;
  for(int i = 0; i < q; i++){
    int ans = t[r[i] + 1] - t[l[i]];
    if(l[i] - 1 >= 0 && s[l[i] - 1] == 'A' && s[l[i]] == 'C') --ans;
    buf += to_string(ans) + "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 2872
#include <iostream>
using namespace std;
int main(void){
  int H,W,i,j,n;
  cin >> H;
  cin >> W;
     
  while(H != 0 && W != 0){
      for(i = 0; i < H; i++){
          for(j = 0; j < W; j++){
              if((i + j) % 2 == 0){
                  cout << "#";
              }
              else{
                  cout << ".";
              }
          }
          cout << endl;
      }
      cin >> H;
      cin >> W;
      cout << endl;
  }
}


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

namespace AtCorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var x = cin.ReadLong;
            var n = (int)(Sqrt(2 * x) - 1);
            var step = n * (n + 1) / 2;
            if(x <= step)
            {
                WriteLine(n);
                return;
            }
            var IncStep = step;
            while(IncStep < x)
            {
                n++;
                IncStep = n * (n + 1) / 2;
            }
            WriteLine(n);
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

int main(void) {
	string str1, str2;
	int len;
	int ans = 0;
	
	while(cin >> str1) {
		str2 = "";
		len = str1.length();
		char rev[100];
		bool flag = true;
		char a, b;
		
		for(int i = 0; i < len; ++i) {
			rev[i] = str1[len - i - 1];
		}
		
		for(int i = 0; i < len; ++i) {
			str2 += rev[i];
		}
		
		if(str1 == str2)   ++ans;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  string s;
  cin>>s;
  int num=1;
  for(int i=1;i<N;i++){
  if(s.at(i)!=s.at(i-1))
    num+=1;
  }
  if(num-2*K<=1)
    cout<<N-1<<endl;
  else
    cout<<N-(num-2*K)<<endl;
    
  
  
   return 0;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 30001
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

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

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M)  //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

signed main() {
    int N, P;
    cin >> N >> P;
    vector<int> factors;
    if (P == 1) {
        cout << "1" << endl;
        return 0;
    }
    for (int i = 2; i <= sqrt(P); i++) {
        while (P % i == 0) {
            factors.push_back(i);
            P /= i;
        }
        if (P == 1) break;
    }
    if (P != 1) factors.push_back(P);

    int count = 1;
    int ans = 1;
    for (int i = 1; i < factors.size(); i++) {
        if (factors[i - 1] != factors[i]) {
            ans *= pow(factors[i - 1], (count / N));
            count = 1;
        } else {
            count++;
        }
    }
    ans *= pow(factors[factors.size() - 1], (count / N));
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

#define ue 100001

int main()
{
	int64 nn, tmp, ans = 0;
	cin >> nn;
	int64 memo[ue] = {0};
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> tmp;
		memo[tmp]++;
		ans += tmp;
	}
	int64 qq, bb, cc;
	cin >> qq;
	for(int64 ii = 0;ii < qq;ii++)
	{
		cin >> bb >> cc;
		ans += (cc - bb) * memo[bb];
		cout << ans << endl;
		memo[cc] += memo[bb];
		memo[bb] = 0;
	}
	return 0;
}

Measured memory_bytes: 4428
S = input()
ans = [0 for i in range(len(S)+1)]
 
for i in range(len(S)):
    if S[i] == "<":
        ans[i+1] = ans[i]+1

 
for i in range(len(S)):
    if S[len(S)-i-1] == ">":
        ans[len(S)-i-1] = max(ans[len(S)-i-1], ans[len(S)-i]+1)
 
print(sum(ans))

Measured memory_bytes: 24024
<?php

fscanf(STDIN, "%s", $s);

$s_arr = str_split($s);

$len = count($s_arr);

$min = 753;
for ($i = 0; $i < $len - 2; ++$i) {
    $num = (int) ($s_arr[$i] . $s_arr[$i + 1] . $s_arr[$i + 2]);

    $min = min($min, abs(753 - $num));
}

echo $min;


Measured memory_bytes: 4604
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{

	int N = 0;
	cin >> N;

	vector<long long> v(N);

	for (int a = 0; a < N; ++a)
	{
		cin >> v[a];
	}
	
	sort(v.begin(), v.end());

	bool primo= true, secondo = false, completo = true;
	long long primoN= -1, secondoN = -1, completoN = -1;
	for (int a = N - 1; a > 0; --a)
	{
		if (v[a] == v[a - 1] && secondo && v[a] != primoN)
		{
			secondoN = v[a];
			secondo = false;
		}
		if (v[a] == v[a - 1] && primo)
		{
			primoN = v[a];
			primo = false;
			secondo = true;
		}
		if (a >= 3 && completo)
		{
			if (v[a] == v[a - 1] && v[a - 1] == v[a - 2] && v[a - 2] == v[a - 3])
			{
				completoN = v[a];
				completo = false;
			}
		}
	}
	
	if (completoN == -1 && (primoN == -1 || secondoN == -1))
	{
		cout << "0" << endl;
		return 0;
	}


	if (primoN*secondoN > completoN*completoN)
		cout << primoN*secondoN << endl;
	else
		cout << completoN*completoN << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iterator>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <cmath>

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")

using namespace std;

int factorical(int x) {
	return x ? x * factorical(x - 1) : 1;
}

//B - Between a and b ...
//give up
int Main() {
	long long a, b, x;
	long long ans = 0;

	cin >> a >> b >> x;

	auto aDiv = (a - (a % x)) / x;
	auto bDiv = (b - (b % x)) / x;
	ans = bDiv - aDiv;
	if (0 == (a % x)) ans++;

	cout << ans;

	return 0;
}


int main()
{
	Main();
	return 0;
}

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

const int MAXN = 1e6 + 6;


int main()
{
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0; i < S.size(); ++i)
        ans += (S[i] != T[i]);

        cout << ans << endl;

    return 0;
}
/*
4 6 7 5
*/


Measured memory_bytes: 3916
using System;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());
            
            int kumiawase = 0;
            for(int i = 0; i < 1 + x / 500 ; i++)
            {
                if(i > a) break;
                int nokori = x - 500 * i;
                for(int j = 0; j <  1 + nokori / 100 ; j++)
                {
                    if(j > b) break;
                    int coin50s = (nokori - 100 * j) / 50;
                    if( (coin50s <= c) && (500 * i + 100 * j + 50 * coin50s == x))
                        kumiawase += 1;
                }
            }

            Console.WriteLine(kumiawase);
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {
	long long n,a,b,ans;
	scanf("%lld %lld %lld", &n, &a, &b);
	if ((a - b) % 2==0)ans = Ma((a - b) / 2, (b - a) / 2);
	else if (a + b - 1 <= n)ans = (a + b - 1) / 2;
	else ans = n + (1 - a - b) / 2;
	printf("%lld", ans);
}

Measured memory_bytes: 128
function main(input) {
  input=input.trim();
  const n = parseInt(input.split(" ")[0], 10);
  const arrA = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
  console.log(Math.max.apply(null, arrA)-Math.min.apply(null, arrA));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

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

  cout << ((a[a.size() - 1] == b[0] && (b[b.size() - 1] == c[0])) ? "YES" : "NO") << endl;

  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n+1,0);
  vector<int> b(n,0);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  long long ans = 0;
  rep(i,n) 
  if(a[i] > b[i]){
    ans+=b[i];
  }else{
    ans += ((a[i+1] -(b[i]-a[i]))>0)?b[i]:(a[i]+a[i+1]);
    a[i+1] = ((a[i+1] -(b[i]-a[i]))>0)?a[i+1]-(b[i]-a[i]):0;
  }
  cout << ans;
}

Measured memory_bytes: 1024
var=input()
var=var.split()
n=int(var[0])
m=int(var[1])
A=[[0 for i in range(m)]for j in range(n)]
b=[0 for i in range(m)]
c=[0 for i in range(n)]
for i in range(n):
    var=input()
    var=var.split()
    for j in range(m):
        A[i][j]=int(var[j])
for i in range(m):
    var=input()
    var=var.split()
    b[i]=int(var[0])
line=0

for line_A in A:
    line_b=0
    for row in line_A:
        c[line]+=row*b[line_b]
        line_b+=1
    print(c[line])
    line+=1


Measured memory_bytes: 5940
#include<iostream>
#include<string>
#include<vector>
using namespace std;
long long L[9], K[9], c[32], power[33];
char T[17] = "0123456789abcdef";
vector<int>vec;
int main() {
	power[0] = 1; for (long long i = 1; i <= 32; i++)power[i] = power[i - 1] * 2;
	int n; cin >> n;
	for (int t = 0; t < n; t++) {
		vec.clear(); for (long long i = 0; i < 9; i++) { L[i] = 0; K[i] = 0; }
		for (long long i = 0; i < 32; i++)c[i] = 0;
		for (long long i = 0; i < 9; i++) {
			string S; cin >> S; long long b[8];
			while (S.size() < 8)S = '0' + S;
			for (long long j = 0; j < 8; j++) {
				for (long long k = 0; k < 16; k++) {
					if (T[k] == S[j])b[7 - j] = k;
				}
			}
			for (long long j = 0; j < 4; j++)L[i] += power[j * 4] * b[j];
			for (long long j = 0; j < 8; j++)K[i] += power[j * 4] * b[j];
		}
		for (long long j = 0; j < 65536; j++) {
			long long S = 0;
			for (long long k = 0; k < 8; k++) {
				S += j^L[k];
			}
			if (S % 65536 == (L[8] ^ j))vec.push_back(j);
		}
		for (long long i = 0; i < vec.size(); i++) {
			for (long long j = 0; j < 65536; j++) {
				long long W = j * 65536 + vec[i], S = 0;
				for (long long k = 0; k < 8; k++) {
					S += W^K[k];
				}
				if (S%power[32] == (K[8] ^ W)) {
					long long OK = 0;
					for (long long k = 7; k >= 0; k--) {
						char V = T[(W / power[k * 4]) % 16];
						if (V >= '1')OK = 1;
						if (OK == 1 || k == 0)cout << V;
					}
					cout << endl;
					goto E;
				}
			}
		}
	E:;
	}
	return 0;
}

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

int main() {
    int64_t N, K, Q; cin >> N >> K >> Q;
    vector<int64_t> A(N, K);
    for (int i = 0; i < Q; i++) {
        int64_t x; cin >> x;
        A.at(x - 1)++;
    }

    for (int i = 0; i < N; i++) {
        if (1 <= A.at(i) - Q) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 3944
#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#define pb  push_back

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

const ll INF = 999999999;
const ll atcoder = 1000000007;
const int dx[4] = { 1 , 0 , -1 ,0 };
const int dy[4] = { 0 , 1 , 0 , -1 };

int main() {

	string s;
	int cnt = 0;

	cin >> s;

	for (int i = 0; i < 6; i++) {
		if (s[i] == '1')cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    List<Integer> list = new ArrayList<>();
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(in.readLine());
      list.add(a[i]);
    }
    
    Collections.sort(list);
    
    for(int i=0; i<n; i++) {
      System.out.println(list.get(n-1)!=a[i]?list.get(n-1):list.get(n-2));
    }
  }
}

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

int main() {

	vector<vector<int>> c(3, vector<int>(3));

	for (int i= 0;i < 3;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> c.at(i).at(j);
		}
	}

	vector<int> a(3);
	vector<int> b(3);

	for (int i = 0;i < 3;i++) {
		if (i == 0)
			b.at(i) = c.at(0).at(0);
		else
			b.at(i) = c.at(0).at(i);
	}

	for (int i = 0;i < 3;i++) {
		a.at(i) = c.at(i).at(0) - b.at(0);
	}

	bool t = true;
	for (int i = 1;i < 3;i++) {
		for (int j = 1;j < 3;j++) {
			if (c.at(i).at(j) != a.at(i) + b.at(j)) {
				t = false;
				break;
			}
		}
	}
	if (t)
		cout << "Yes";
	else
		cout << "No";
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N, Q;
    cin >> N >> Q;
    dsu d(N);
    REP(i, 0, Q){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0){
            d.merge(u, v);
        }else{
            cout << (d.same(u, v) ? 1 : 0) << endl;
        }
    }
}

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

const int MOD = 1000000007;

int dp[100010];

template<class T> inline void add_mod(T &a, const T b){
	a += b;
	if(a >= MOD) a -= MOD;
}

template<class T> inline void sub_mod(T &a, const T b){
	a -= b;
	if(a < 0) a += MOD;
}

int main(){
	int n, k, up_to;
	scanf("%d%d", &n, &k);
	dp[0] = 1;
	for(int child = 0; child < n; child++) {
		scanf("%d", &up_to);
		int fake[100010] = {0};
		for(int used = k; used >= 0; used--) {
			if(!up_to) break;
			int l = used + 1;
			int r = min(used + up_to, k);
			add_mod(fake[l], dp[used]);
			if(r + 1 <= k) sub_mod(fake[r+1], dp[used]);
		}
		int prefix_sum = 0;
		for(int i = 0; i <= k; i++) {
			add_mod(prefix_sum, fake[i]);
			add_mod(dp[i], prefix_sum);
		}
	}
	printf("%d\n", dp[k]);
}

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

using namespace std;

int main(){
  int n,m,d[200000],t[200000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>d[i];
  sort(d,d+n);
  cin>>m;
  for(int i=0;i<m;i++)cin>>t[i];
  sort(t,t+m);
  int id=0;
  for(int i=0;i<n;i++){
    if(id==m)break;
    if(d[i]==t[id])id++;
  }
  if(id==m)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

int main(void){
    int N;

    scanf("%d", &N);

    char *S = (char *) malloc(sizeof(char) * (N + 1));

    scanf("%s", S);

    char prev = S[0];
    int num = 1;

    for(int i = 1; S[i] != '\0'; i ++){
        if(S[i] != prev){
            prev = S[i];
            num ++;
        }
    }
    printf("%d\n", num);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    const int NUM=1e5+10;
    bool nop[NUM];int prn,prm[NUM],mip[N];
    void pre()
    {
        fo(i,2,NUM-1)
        {
            if(!nop[i]) prm[++prn]=i,mip[i]=i;
            for(int j=1;j<=prn and (ll)prm[j]*i<NUM;j++)
            {
                int t=prm[j]*i;nop[t]=1;mip[t]=prm[j];
                if(i%prm[j]==0) break;
            }
        }
    }
    map<ll,int> a,b;
    ll f[N],lg[N];
    void main()
    {
        pre();
        int n=qread();
        fo(i,1,n)
        {
            ll num=qread();
            for(int i=1;prm[i]<=2200;i++) {ll tmp=1ll*prm[i]*prm[i]*prm[i];while(num%tmp==0)num/=tmp;}
            a[num]++;
        }
        fo(i,2,N-1) lg[i]=lg[i>>1]+1;
        int ans=(a[1]>0);
        fo(i,2,1e5)
        {
            vc<int> tmp;
            int num=i;bool err=0;
            while(num>1) {
                int now=mip[num];tmp.PB(now);
                int ct=0;while(num%now==0)num/=now,ct++;
                if(ct>1) err=1;
            }if(err) continue;

            int m=sz(tmp);
            f[0]=1;fo(t,0,m-1) f[0]*=tmp[t];
            fo(s,1,bin(m)-1)
            {
                int t=s&-s;f[s]=f[s^t]*tmp[lg[t]];
                if(s>((bin(m)-1)^s)) ans+=max(a[f[s]],a[f[(bin(m)-1)^s]]),a[f[s]]=a[f[(bin(m)-1)^s]]=0;
            }
        }
        for(map<ll,int>::iterator t=a.begin();t!=a.end();t++) if(t->FR!=1) ans+=t->SE;write(ans);
    }
};//(ans+MOD)%MOD
int main()
{
    srand(time(0));
    mine::main();
}


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

int main() {
	int N, M, a, b, ans = 0;
	cin >> N >> M;
	vector<vector<bool>> c(N, vector<bool>(N));
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		c[a - 1][b - 1] = true;
		c[b - 1][a - 1] = true;
	}
	vector<int> d(N);
	for (int i = 0; i < N; i++) d[i] = i;
	do {
		bool e = true;
		for (int i = 1; i < N; i++) {
			if (!c[d[i - 1]][d[i]]) {
				e = false;
				break;
			}
		}
		if (e) ans++;
	} while (next_permutation(d.begin() + 1, d.end()));
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

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

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

bool shinobu(string s)
{
  if (s == "/" || s == "*" || s == "+" || s == "-"){
    return (false);
  }

  return (true);
}

signed main()
{
  //ios::sync_with_stdio(false);
  string in;

  while (cin >> in){
    char c;
    stack<double> st;
    bool line = false;
    while (scanf("%c", &c), c == '\n' ? line = true: line = false, true){
      if (shinobu(in)){
        st.push(atoi(in.c_str()));
        //cout << "tst: " << st.top() << endl;
      } else {
        double n1 = st.top(); st.pop();
        double n2 = st.top(); st.pop();
        if (in == "-"){
          st.push(n2 - n1);
        }
        if (in == "+"){
          st.push(n2 + n1);
        }
        if (in == "*"){
          st.push(n2 * n1);
        }
        if (in == "/"){
          st.push(n2 / n1);
        }
        //cout << "calc: " << n2 << in << n1 << "=" << st.top() << endl;
      }
      if (line) break;
      cin >> in;
    }
    printf("%f\n", st.top());
  }

  return (0);
}

Measured memory_bytes: 1268
#include <iostream>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    int x, count=0, sum=1;
    for(x = k; x > 0; x /= 2){
        count++;
        sum *=2;
        if(!(--n)){
            cout << sum << endl;
            return 0;
        }
    }
    
    cout << sum + n*k << endl;
    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
string s;
int n, l[N], r[N], a[N];

struct Dsu {
    int pset[N], szset[N], val[N];
    void init() {
        for (int i = 0; i < N; ++i) pset[i] = i, szset[i] = 1, val[i] = a[i];
    }
    int findset(int i) { return i == pset[i] ? i : pset[i] = findset(pset[i]); }
    bool sameset(int i, int j) { return findset(i) == findset(j); }
    void unionset(int i, int j) {
        if(sameset(i, j) ) return ;
        i = findset(i); j = findset(j);
        if(szset[i] > szset[j]) swap(i, j);
        val[j] = (val[i] + val[j]) % 26;
        szset[j] += szset[i];
        pset[i] = j;
    }
} dsu;

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> n;
    s = 'a' + s; s += 'a';
    for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i];
    for (int i = 0; i < s.size() - 1; ++i) a[i] = (s[i + 1] - s[i] + 26) % 26;

    dsu.init();
    for (int i = 1; i <= n; ++i) {
        dsu.unionset(l[i] - 1, r[i]);
    }
    for (int i = 0; i < s.size() - 1; ++i) dsu.unionset(i, s.size() - 2 - i);

    for (int i = 0; i < N; ++i) if(dsu.val[dsu.findset(i)]) return cout << "NO", 0;

    cout << "YES";

    return 0;
}


Measured memory_bytes: 2796
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
int mod=163577857;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(int a,int n,int m){if(n==0)return 1;int p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC";
    else cout<<"ABC";



    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();

		int[][] A = new int[2][N+2];

		for(int i = 1 ; i <= N ; i++){
			if(String.valueOf(S.charAt(i-1)).equals("E")){
				A[0][i] = A[0][i-1] + 1;
			}
			else{
				A[0][i] = A[0][i-1];
			}
			if(String.valueOf(S.charAt(i-1)).equals("W")){
				A[1][i] = A[1][i-1] + 1;
			}
			else{
				A[1][i] = A[1][i-1];
			}
		}

/*
		for(int i = 0 ; i < 2  ; i++){
			for(int j = 1 ; j <= N ; j++){
				System.out.print(A[i][j] + " ");
			}
			System.out.println(" ");
		}
*/
		int ans = 300001;
		int tmp = 0;
		for(int i = 1 ; i <= N ; i++){
			tmp = (A[0][N] - A[0][i]) + A[1][i-1];
			ans = Math.min(tmp, ans);
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 48492
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let string_fold_left f init str =
  let n = String.length str in
  let rec doit i acc =
    if i >= n then acc
    else doit (i + 1) (f acc str.[i])
  in
  doit 0 init

let swap (a, b) = (b, a)

let make_dice = function
  | a :: b :: c :: d :: e :: f :: _ -> [(a, f); (b, e); (c, d)]
  | _ -> exit 1

let roll dice cmd =
  match dice with
  | [] | [_] | _::_::[] -> exit 1
  | x :: y :: z :: _ ->
      match cmd with
      | 'N' -> [y; swap x; z]
      | 'S' -> [swap y; x; z]
      | 'E' -> [swap z; y; x]
      | 'W' -> [z; y; swap x]
      | _ -> exit 1

let multi_roll dice cmds =
  string_fold_left (fun acc c -> roll acc c) dice cmds

let rotate_clockwise = function
  | [] | [_] | _::_::[] -> exit 1
  | x :: y :: z :: _ -> [x; z; swap y]

let all_rolled_patterns dice =
  let pin_top d =
    [d; roll d 'N'; roll d 'W'; roll d 'E'; roll d 'S'; multi_roll d "SS"]
  in
  let rotate d =
    let d1 = rotate_clockwise d in
    let d2 = rotate_clockwise d1 in
    let d3 = rotate_clockwise d2 in
    [d; d1; d2; d3]
  in
  List.concat (List.map rotate (pin_top dice))

let top = function
  | [] | [_] | _::_::[] -> exit 1
  | (a, _) :: _ -> a

let front = function
  | [] | [_] | _::_::[] -> exit 1
  | _ :: (b, _) :: _ -> b

let right = function
  | [] | [_] | _::_::[] -> exit 1
  | _ :: _ :: (c, _) :: _ -> c

let () =
  let l = read_line () in
  let dice = make_dice (List.map int_of_string (split l ' ')) in
  let q = read_int () in
  let rec doit i =
    if i > q then ()
    else
      let l = read_line () in
      match List.map int_of_string (split l ' ') with
      | [] | [_] -> exit 1
      | n_top :: n_front :: _ -> begin
          let ds = List.filter (fun d ->
            n_top = top d && n_front = front d) (all_rolled_patterns dice) in
          Printf.printf "%d\n" (right (List.hd ds));
          doit (i + 1);
        end
  in
  doit 1

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

const int NOT_FOUND=-1;

int binarySearch(int key,int A[],int n){
	int left=0;
	int right=n;
	
	while(left<right){
		int mid=(left+right)/2;
		
		if(A[mid]==key){
			return mid;
		}
		else if(key<A[mid]){
			right=mid;
		}
		else{
			left=mid+1;
		}
	}

	return NOT_FOUND;
}

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

	int q;
	cin>>q;
	
	int T[50000];
	for(int i=0;i<q;i++){
		cin>>T[i];
	}
	
	int C=0;
	
	for(int i=0;i<q;i++){
		if(binarySearch(T[i],S,n)!=NOT_FOUND){
			C++;
		}
	}

	cout<<C<<endl;
	
	return 0;
}

Measured memory_bytes: 3576
h,w=map(int,input().split())
a=[input() for _ in range(h)]
dp=[[0]*w for _ in range(h)]
dp[0][0]=1
mod=10**9+7
for i in range(h):
    for j in range(w):
        if i<h-1:
            if a[i+1][j]==".":
                dp[i+1][j]+=dp[i][j]
                dp[i+1][j]%=mod
        if j<w-1:
            if a[i][j+1]==".":
                dp[i][j+1]+=dp[i][j]
                dp[i][j+1]%=mod
print(dp[h-1][w-1])

Measured memory_bytes: 49436
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

void solve(void){
    string s;
    cin >> s;
    int n = s.length();
    int b = -1, e = -1;
    Rep(0, n-2, i) {
        if (b != -1) break;
        if (s[i] == s[i+1]) {
            b = i+1; e = i+2;
        }
        else if (i != n-2 and s[i] == s[i+2]) {
            b = i+1; e = i+3;
        }
    }
    cout << b << ' ' << e << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size() 
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)


/****************************** CODE IS HERE ***********************************/


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

    string a, b; cin >> a >> b;
    int n = sz(a);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] != b[i]) ans++;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3816
#include <iostream>

using namespace std;

class Dice{
private:
  int tmp;
public:
  int d[6];

  void rollN(){
    tmp = d[0];
    d[0] = d[1];
    d[1] = d[5];
    d[5] = d[4];
    d[4] = tmp;
  }
 
  void rollE(){
    tmp = d[0];
    d[0] = d[3];
    d[3] = d[5];
    d[5] = d[2];
    d[2] = tmp;
  }

  void rollS(){
    tmp = d[0];
    d[0] = d[4];
    d[4] = d[5];
    d[5] = d[1];
    d[1] = tmp;
  }

  void rollW(){
    tmp = d[0];
    d[0] = d[2];
    d[2] = d[5];
    d[5] = d[3];
    d[3] = tmp;
  }
};

int main(){
  Dice dice;
  string str;

  for(int i = 0 ; i < 6 ; i++){
    cin >> dice.d[i];
  }
  cin >> str;
  for(int i = 0 ; i < str.size() ; i++){
    switch(str[i]){
    case 'N':
      dice.rollN();
      break;
    case 'E':
      dice.rollE();
      break;
    case 'S':
      dice.rollS();
      break;
    case 'W':
      dice.rollW();
    break;
    }
  }
  cout << dice.d[0] << endl;

  return 0;
}

Measured memory_bytes: 1208
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, A, B = MAP()
if (B-A)%2 == 0:
	print((B-A)//2)
else:
	# Aが勝ち続けて調整した後負ける
	win = (A-1)+1
	lose = (N-B)+1
	#print(win, lose, B-win-1, N-A-lose)
	print(min(B-1, win+((B-win)-1)//2, N-A, lose+(N-(A+lose))//2))

Measured memory_bytes: 3064