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

int main() 
{
    int N, M;
    cin >> N >> M;
    map<string, int>mp;
    for (int i = 0; i < M; i++) {
        string a;
        string b;
        cin >> a >> b;
        mp["1" + a + b]++;
        mp[a + b + to_string(N)]++;
    }
    
    for (auto itr = mp.begin(); itr != mp.end(); itr++){
        if (itr->second > 1) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 43756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
int main(){
    char s;
    cin >> s;
    if (isupper(s)){
        cout << "A" << endl;
    }
    else {
        cout << "a" << endl;
    }
}

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

int main()
{
	int i, H, W, N, a[10001];
	scanf("%d %d", &H, &W);
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int j, color[100][100] = {}, cur = 1;
	for (i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (j = 0; j < W; j++) {
				color[i][j] = cur;
				a[cur]--;
				if (a[cur] == 0) cur++;
			}
		} else {
			for (j = W - 1; j >= 0; j--) {
				color[i][j] = cur;
				a[cur]--;
				if (a[cur] == 0) cur++;
			}
		}
	}
	
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) printf("%d ", color[i][j]);
		printf("\n");
	}
	fflush(stdout);
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("hard1.txt","r",stdin)
#define OUT freopen("hard1.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 1000005

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define INF 1000000000000000000LL
#define alpha 26
#define mod 998244353LL
#define maxn 500005
#define LOG 18

char s[1005][1005] ;

int main()
{
    int n , m , a , b ;

    scanf("%d %d %d %d",&n,&m,&a,&b) ;

    int N = n , M = m ;

    for(int i=0 ; i<n ; i++)
    {
        for(int j=0 ; j<m ; j++) s[i][j] =  '.' ;
        s[i][m] = '\0' ;
    }

    if( n%2==1 )
    {
        for(int i=m-1 ; i-1>=0 ; i-=2)
        {
            if( a==0 ) continue ;
            a-- ;
            s[n-1][i] = '>' ;
            s[n-1][i-1] = '<' ;
        }
        n-- ;
    }
    if( m%2==1 )
    {
        for(int i=0 ; i+1<n ; i+=2)
        {
            if(b==0) continue ;
            b-- ;
            s[i][m-1] = '^' ;
            s[i+1][m-1] = 'v' ;
        }
        m-- ;
    }

//    printf("--- %d %d\n",a,b) ;

    if( n+1 == N && m+1==M && n>=2 && m>=2 && a%2==1 && b%2==1 )
    {
        s[n][0] = 'v' ; s[n-1][0] = '^' ;
        b-- ;
        s[n-2][0] = '<' ; s[n-2][1] = '>' ;
        a-- ;

        for(int j=m-1 ; j>1; j--)
        {
            if(b==0) break ;
            s[n-2][j] = '^' ;  s[n-1][j] = 'v' ;
            b-- ;
        }
        for(int j=2 ; j+1<m ; j+=2)
        {
            if(a==0) break ;
            if( s[n-2][j+1]!='.' || s[n-2][j] !='.' ) break ;
            s[n-2][j] = '<' ; s[n-2][j+1] = '>' ;
            a-- ;
        }
        for(int j=1 ; j+1<m ; j+=2)
        {
            if(a==0) break ;
            if( s[n-1][j]!='.' || s[n-1][j+1]!='.' ) break ;
            s[n-1][j] = '<' ; s[n-1][j+1] = '>' ;
            a-- ;
        }
        n -= 2 ;
    }

  /*  printf("------------ %d %d\n",a,b) ;

    for(int i=0 ; i<N ; i++)
    {
        printf("%s",s[i]) ;
        printf("\n") ;
    }
*/
    for(int j=0 ; j+1<m ; j+=2)
    {
        for(int i=0 ; i<n ; i++)
        {
            if(a==0) continue ;
            s[i][j] = '<' ; s[i][j+1] = '>' ;
            a-- ;
        }
    }

//    printf("-- %d %d\n",a,b) ;

    for(int j=0 ; j<m ; j++)
    {
        for(int i=0 ; i+1<n ; i++)
        {
            if( s[i][j]!='.' ) continue ;
            if(b==0) continue ;
            s[i][j] = '^' ;
            s[i+1][j] = 'v' ;
            b-- ;
            i++ ;
        }
    }

    if(a==0 && b==0)
    {
        printf("YES\n") ;
        for(int i=0 ; i<N ; i++) printf("%s\n",s[i]) ;
        return 0 ;
    }
    else printf("NO\n") ;

    return 0 ;
}


Measured memory_bytes: 4676
n=gets.chomp.to_i
s=gets.chomp.split("").map { |e| e.to_s }

count_w = 0
count_e = 0

n.times do |i|
  if s[i] == "E"
    count_e += 1
  else
    count_w += 1
  end
end

if count_e == 0 || count_w == 0
  puts 0
  exit
end

e_L = 0
w_L = 0
e_R = count_e
w_R = count_w

ans = n+1


n.times do |j|
  count = 0
  if s[j] == "E"
    count = w_L + e_R - 1
    e_L += 1
    e_R -= 1
  else
    count = w_L + e_R
    w_L += 1
    w_R -= 1
  end
 ans = ans > count ? count : ans
end


puts ans

Measured memory_bytes: 31872
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main()
{
    string S;
    cin >> S;

    long sum = 0;
    long count = 0;

    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == 'B')
        {
            count++;
        }
        else
        {
            sum += count;
        }
    }

    cout << sum << '\n';
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int MOD=1e9+7;
vector<int> tree[200005];
int dp[200005][2];

int dfs(int curr,int parent,int color){
    if(dp[curr][color]!=-1) return dp[curr][color];
    dp[curr][color]=1;
    for(auto i : tree[curr]){
        if(i!=parent){
            if(color==0){
                dp[curr][color]=(dp[curr][color]*dfs(i,curr,1))%MOD;
            }
            else{
                dp[curr][color]=(dp[curr][color]*(dfs(i,curr,0)+dfs(i,curr,1)%MOD))%MOD;
            }
        }
    }
    return dp[curr][color];
}

int32_t main(){
    memset(dp,-1,sizeof(dp));
    int n;cin>>n;
    for(int i=0,x,y;i<n-1;i++){
        cin>>x>>y;x--;y--;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    cout<<(dfs(0,-1,0)+dfs(0,-1,1))%MOD<<"\n";
    return 0;
}

Measured memory_bytes: 20864
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] w = new int[n];
		int[] b = new int[n];
		int[] r = new int[n];
		for(int i = 0; i < n; i++) {
			String str = sc.next();
			for(int j = 0; j < m; j++) {
				char c = str.charAt(j);
				if(c == 'W') {
					w[i]++;
				}else if(c == 'B') {
					b[i]++;
				}else {
					r[i]++;
				}
			}
		}
		
		int ans = 100000000;
		
		for(int i = 1; i < n - 1; i++) {
			for(int j = i + 1; j < n; j++) {
				int tmp = 0;
				
				for(int k = 0; k < i; k++) {
					tmp += m - w[k];
				}
				for(int k = i; k < j; k++) {
					tmp += m - b[k];
				}
				for(int k = j; k < n; k++) {
					tmp += m - r[k];
				}
				
				ans = Math.min(ans, tmp);
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 26200
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N;cin>>N;
    int ans=0;
    REP(i,40){
        REP(j,8){
            int d=pow(i,j+2);
            if(d<=N){
                ans=max(ans,d);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	int N;
	cin >> N;
	int A[3] = {};

	rep(i, N) {
		int a;
		cin >> a;
		if (a % 4 == 0) A[2]++;
		else if (a % 2 == 0) A[1]++;
	}

	int ikeru = A[2] * 2;
	if (ikeru && A[1] == 0) {
		ikeru++;
	}
	ikeru += A[1];

	if(ikeru >= N) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int mothernum, mother[20];

int sentaku(int i, int now, int aim)
{
 int back;
 if ( now == aim ) {
   return 1;
 }
 if ( i > mothernum ) {
   return 0;
 }
 back = sentaku(i+1, now, aim) || sentaku(i+1, now+mother[i], aim);
 return back;
}

int main()
{
 int kidsnum, kids[200], i, j, flag;
 
 scanf("%d", &mothernum);
 for (i = 0; i < mothernum; i++) {
   scanf("%d", &mother[i]);
 }
  
 scanf("%d", &kidsnum);
 for(i = 0; i < kidsnum; i++) {
   scanf("%d", &kids[i]);
 }

 for(i = 0; i< kidsnum; i++){
   flag = 0;
   flag = sentaku(0, 0, kids[i]);
   if (flag == 1) {
      printf("yes\n");
   } else {
      printf("no\n");
   }
 }
 
 return 0;
}

Measured memory_bytes: 1788
import Control.Applicative ((<$>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List (unfoldr)
import Data.Char (isSpace)

main :: IO ()
main = solve <$> (B.getLine >> (readil B.readInt <$> B.getLine)) >>= print

solve :: [Int] -> Int
solve = sum . map (f 0)
  where f c x | even x = f (c+1) (x `div` 2)
              | otherwise = c

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')


Measured memory_bytes: 1148
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    a, b = ss()
    sa = a*int(b)
    sb = b*int(a)

    if sa <= sb:
        print(sa)
    else:
        print(sb)

    return

main()


Measured memory_bytes: 9152
n=int(input());a=list(map(int,input().split()));c=0
for i in range(n):
 m=i
 for j in range(i,n):
  if a[j]<a[m]:m=j
 if m!=i:a[i],a[m]=a[m],a[i];c+=1
print(*a)
print(c)


Measured memory_bytes: 5608
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

using int64 = long long;
const int64 kUnreached = 1e+16;

struct Edge {
  int64 to, dist;
};

void Dijkstra(const vector<vector<Edge>>& edges, const int64 k, vector<int64>& dists) {
  dists[k] = 0;
  queue<int64> q;
  q.push(k);
  while (!q.empty()) {
    int64 from = q.front();
    q.pop();
    for (auto& e : edges[from]) {
      int64 to = e.to;
      if (dists[to] < kUnreached)
        continue;
      dists[to] = dists[from] + e.dist;
      q.push(to);
    }
  }
}

int main() {
  int64 n;
  cin >> n;
  vector<vector<Edge>> edges(n);
  for (int64 i = 0; i < n - 1; ++i) {
    int64 a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    edges[a].push_back({b, c});
    edges[b].push_back({a, c});
  }

  int64 q, k;
  cin >> q >> k;
  vector<int64> dists(n, kUnreached);
  Dijkstra(edges, k - 1, dists);
  for (int64 i = 0; i < q; ++i) {
    int64 x, y;
    cin >> x >> y;
    cout << (dists[x - 1] + dists[y - 1]) << "\n";
  }
  return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll a[200005];
int main(){
    ll n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    ll sum=a[1];
    for(int i=3;i<=n;i++){
        sum+=a[(i+1)/2];
    }
    cout<<sum<<endl;
}

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

using namespace std;


int main() {
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k) {
        cout << k << endl;
    }
    else if (a+b >= k) {
        cout << a << endl;
    }
    else {
        cout << a - (k - a - b) << endl;
    }
    return 0; 
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const ll INF = 1001001001;
const ll MOD = 1e9 + 7;

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  int cnt = 0;
  int b[100];
  rep(i, m) cin >> b[i];
  for(int i = 0; i < n; i++){
    int tmp = 0;
    rep(i, m){
      int u; 
      cin >> u;
      tmp += u * b[i];
    }
    if(tmp > -c) cnt++;
  }
  cout << cnt <<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}
/*
ll Integer_factorization(ll n){
    ll num = 0;
    ll ndash = n;
    if(n == 1) return 1;
    ll a = 2;
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    return num;
}
*/

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

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

    for(int i = 0;i < s.size();i++){
        int cur = 0;
        while((s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C' )&& i < s.size()){
            i++;
            cur++;
        }
        ans = max(ans,cur);
        
    }
    cout << ans << endl;
    
    
}




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}



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

int main() {
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  if (a + b < c + d) {
    std::cout << "Right" << std::endl;
  } else if (a + b == c + d) {
    std::cout << "Balanced" << std::endl;
  } else {
    std::cout << "Left" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cfloat>
#include<cmath>
#include<map>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

typedef unsigned int uint;
typedef long long ll;

using namespace std;

int main(){
  int n, m, h, d;
  while(scanf("%d",&n),n){
    scanf("%d%d%d",&m,&h,&d); h--; m--;
    char buff[16];
    int sen[d+1][n-1];
    int memo[d+1][n];
    memset(sen,0,sizeof(sen));
    REP(i,n) memo[0][i] = i;
    REP(i,d){
      REP(j,n) memo[i+1][j] = memo[i][j];
      scanf("%s",buff);
      //puts(buff);
      REP(j,n-1){
        sen[i][j] = buff[j] - '0';
        if(sen[i][j] == 1)
          swap(memo[i+1][j], memo[i+1][j+1]);
      }
      //REP(j,n) printf("%d%c",memo[i][j]+1,(j!=n-1&&sen[i][j]==1?'-':' ')); puts("");
    }
    int atari = memo[d][h];
    //cout << atari << endl;
    if(atari == m){
      puts("0");
    }else{
      bool flag = false;
      REP(dd,d){
        REP(nn,n-1){
          if(sen[dd][nn]==0)
            if(nn==0 || sen[dd][nn-1]==0)
              if(nn==n-2 || sen[dd][nn+1]==0){
                sen[dd][nn] = 1;
                REP(i,n) memo[0][i] = i;
                REP(i,d){
                  REP(j,n) memo[i+1][j] = memo[i][j];
                  //puts(buff);
                  REP(j,n-1){
                    if(sen[i][j] == 1)
                      swap(memo[i+1][j], memo[i+1][j+1]);
                  }
                  if(memo[d][h] == m){
                    printf("%d %d\n",dd+1,nn+1);
                    flag = true;
                    goto end;
                  }
                }
                sen[dd][nn] = 0;
              }
        }
      }
    end:
      if(!flag) puts("1");
      /*
      bool flag = false;
      REP(dd,d){
        int idx;
        REP(i,n){
          if(memo[dd][i] == m){
            idx = i;
            break;
          }
        }
        if(idx != 0 && memo[dd][idx-1] == atari){
          if(sen[dd][idx-1] == 0){
            if(idx == n-1 || sen[dd][idx] == 0){
              if(idx == 1 || sen[dd][idx-2] == 0){
                flag = true;
                printf("%d %d",dd+1,idx);
              }
            }
          }
        }
        if(idx != n-1 && memo[dd][idx+1] == atari){
          if(sen[dd][idx] == 0){
            if(idx == 0 || sen[dd][idx-1] == 0){
              if(idx == n-2 || sen[dd][idx+1] == 0){
                flag = true;
                printf("%d %d\n",dd+1,idx+1);
              }
            }
          }
        }
        if(flag) break;
      }
      if(!flag)
        puts("1");
      */
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e9+7;
const int inf=1e9+7;
const double eps=1e-6;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
const double pi=acos(-1);

int pre[203040][2],suf[203040][2];
char a[203040];
int n;


int main(){
    TB
	cin>>n;
	cin>>(a+1);
	for(int i=1;i<=n;i++){
		pre[i][0]=pre[i-1][0];
		pre[i][1]=pre[i-1][1];
		if(a[i]=='R')pre[i][0]++;
		else pre[i][1]++;
	}
	for(int i=n;i>=1;i--){
		suf[i][0]=suf[i+1][0];
		suf[i][1]=suf[i+1][1];
		if(a[i]=='R')suf[i][0]++;
		else suf[i][1]++;
	}
	int ans=n;
	for(int i=0;i<=n;i++){
		int x=pre[i][1],y=suf[i+1][0];
		ans=min(max(x,y),ans);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6832
def main():
    n, m, x = map(int, input().split())
    a_ = [int(i) for i in input().split()]

    p1 = 0
    for i in range(x - 1, -1, -1):
        if i in a_:
            p1 += 1

    p2 = 0
    for i in range(x + 1, n):
        if i in a_:
            p2 += 1

    print(min([p1, p2]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//People only find me interesting because they can't tell whether I'm serious or not
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
typedef __int128 s128;
typedef __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 100005
#define PI 3.14159265359
#define inf LLONG_MAX
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;
ll dp[22][(1<<22)];
vl adj[22];
void solve(){
    f(i,0,(1<<22)){
        ll p = __builtin_popcount(i);
        adj[p].pb(i);
    }

    ll n;
    cin>>n;
    ll a[n+1][n+1];
    f(i,1,n+1){
        f(j,1,n+1){
            cin>>a[i][j];
        }
    }
    dp[0][0]=1;

    f(i,1,n+1){
        for(auto u:adj[i]){
            f(j,1,n+1){
                if(a[i][j] && (u & (1<<j))){
                    ll s = ~(1<<j);
                    s &= u;
                    (dp[i][u] += dp[i-1][s]) %= P;
                }
            }
        }
    }

    cout<<dp[n][(1<<(n+1)) - 2];

}
signed main() {
    teevra_gati
        
    solve();

    return 0;
}

Measured memory_bytes: 661516
#include <bits/stdc++.h>
 
using namespace std;
 
int N,M,Q;
 
int b[100005],c[100005],d[100005],e[100005],f[100005]; bool g[100005],h[100005];

vector<int> a,v,x;
 
const int INF=1000000009;
 
int main(){
 
	cin>>N>>M>>Q;
 
	for(int i=0; i<Q; i++){
		int x;
		scanf("%d",&x);
		a.push_back(x);
		b[i]=x;
		c[x]++;
	}

	sort(b,b+Q); M=b[Q-1];

	int j=1;
	
	for(int i=Q-1; i>=0; i--){
		if(!g[a[i]]){
			d[j]=a[i]; g[a[i]]=1; j++;
		}
	}

	for(int i=1; i<=M; i++){
		if(g[i]==0){
			v.push_back(i);
		}
	}

	for(int i=j; i<=M; i++){
		d[i]=v[0]; v.erase(v.begin());
	}

	int esize=M; bool no=1;

	for(int i=M-1; i>=1; i--){
		if(d[i]>d[i+1]){
			esize=i; no=0;
			break;
		}
	}

	if(no){
		cout<<"Yes"<<endl; return 0;
	}

	int k=1;

	for(int i=esize; i>=1; i--){
		e[k]=d[i]; k++;
	}

	int count=0,time=0; bool find=0; 

 while(1){

	k=1; find=0; 

	for(int i=0; i<a.size(); i++){

	 if(a[i]==e[k]&&h[i]==0){
	 	h[i]=1;
	 	k++;
	 }
	 
	 if(k==esize+1){
		count++; k=1; find=1;
	 }

	}

	if(!find) break;
	if(count>=N) break;
		
 }

 //cout<<z<<endl;
 //cout<<count<<endl;

	if(count>=N) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
 
}

Measured memory_bytes: 2552
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
int main(){
    int n;
    cin>>n;
    vector<int64_t> t(n),a(n);
    rep(i,n){
        cin>>t[i]>>a[i];
    }
    for(int i=1;i<n;i++){
        if(t[i]<t[i-1]||a[i]<a[i-1]){
            int64_t k = max(t[i-1]/t[i]+(t[i-1]%t[i]!=0),a[i-1]/a[i]+(a[i-1]%a[i]!=0));
            t[i] *= k;
            a[i] *= k;
        }
    }
    /*
    rep(i,n){
        cout<<t[i]<<" "<<a[i]<<endl;
    }
    */
    cout<<a[n-1]+t[n-1]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		int sum = 1;
		for (int i=0;i<D;i++) {
			sum =sum *100;
		}
		if (N==100) {
			System.out.println(101*sum);
			return;
		}
		System.out.println(N*sum);
	}
}

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

int main() {
 string s;
 cin >> s;
 if (s == "AAA" || s == "BBB"){
   cout << "No" << endl;
 }
 else cout <<"Yes" << endl;
 


}

Measured memory_bytes: 256
import sys
import collections
import copy
N = int(input())
H = [int(i) for i in input().split()]
count = 0
ans = 0
for i in range(N-1):
    if H[i] < H[i+1]:
        ans = max(ans,count)
        count = 0
    else:
        count += 1
ans = max(ans,count)
print(ans)


Measured memory_bytes: 64540
#include <stdio.h>
int T[500000];
int size;

void maxHeapify(int i)
{
  int l,r,max=0,tmp;
  l=left(i);
  r=right(i);
  if(l<=size&&T[l]>T[i])
    {
      max=l;
    }
  else
    {
      max=i;
    }
  if(r<=size&&T[r]>T[max])
    {
      max=r;
    }
  if(max!=i)
    {
      tmp=T[i];
      T[i]=T[max];
      T[max]=tmp;
      maxHeapify(max);
    }
}

void buildMaxHeap(void)
{
  int i;
  for(i=size/2;i>=1;i--)
    {
      maxHeapify(i);
    }
}

int right(int i)
{
  return 2*i+1;
}

int left(int i)
{
  return 2*i;
}

main()
{
  int i;
  scanf("%d",&size);
  for(i=1;i<=size;i++)
    {
      scanf("%d",&T[i]);
    }
  buildMaxHeap();
  for(i=1;i<=size;i++)
    {
      printf(" %d",T[i]);
    }
  printf("\n");
  return 0;
}

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

int main(void) {
	string S;
	cin >> S;
	if (S == "abc" || S == "acb" || S == "bac" || S == "bca" || S == "cab" || S == "cba") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 1e9+7;

string S;

ll N, K;
ll d[100005];
ll ans;
bool flag;

long long mod_pow(long long x, long long n) {
	if (n == 0) return 1;
	long long res = mod_pow(x*x % mod, n / 2);
	if (n & 1) res = res * x % mod;
	return res;
}

const int MAX_NUM = 2100;
long long fact[MAX_NUM], inv[MAX_NUM];

long long comb(long long n, long long k) {
	if (n < k || n < 0 || k < 0) return 0;
	if (fact[0] == 0) {
		fact[0] = 1; inv[0] = 1;
		for (int i = 1; i < MAX_NUM; i++) {
			fact[i] = fact[i - 1] * i % mod;
			inv[i] = mod_pow(fact[i], mod - 2);
		}
	}
	return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);


	cin >> N>>K;

	FOR(i, 1, K + 1) {
		if (i == 1)cout << N - K + 1 << endl;
		else cout << (comb(N - K + 1, i)*comb(K - 1, i - 1))%MOD << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll dp[15][1005];
void solve(){
  ll h,w,k,res=pow(10,9);
  cin>>h>>w>>k;
  for(ll i=0;i<h;i++){
    string s;
    cin>>s;
    for(ll j=0;j<w;j++){
        dp[i][j+1]=dp[i][j];
      if(s[j]=='1')
        dp[i][j+1]++;
    }
  }
  for(ll mask=0;mask<pow(2,h-1);mask++){
    vector<ll> g;
    ll cnt=1,x=mask;
    while(x>0){
      if(x&1)
        g.push_back(cnt);
      x>>=1;
      cnt++;
    }
    ll ind=0,sum=ll(g.size());
    g.push_back(h);
    for(ll i=1;i<=w;i++){
      ll hi=0,a=0;
      for(ll j=0;j<ll(g.size());j++){
        ll val=0;
        while(a<g[j]){
          val+=dp[a][i]-dp[a][ind];
          a++;
        }
        hi=max(hi,val);
      }
      if(hi>k){
        if(ind==i-1){
          sum=pow(10,9);
          break;
        }
        ind=i-1;
        sum++;
      }
    }
    res=min(res,sum);
  }
  cout<<res;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q=1;
  for(ll i=1;i<=q;i++)
    solve();
}

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

long long int st[800005];

long long int query(int node, int be, int en, int l, int r){
	if(be >= l && en <= r)return st[node];
	if(be > r || en < l)return 0;
	int mid = (be + en) >> 1;
	long long int p1 = query(2*node, be, mid, l, r);
	long long int p2 = query(2*node + 1, mid + 1, en, l, r);
	return max(p1, p2);
}

void update(int node, int be, int en, int pos, long long int value){
	if(be == en){
		st[node] = value;
		return;
	}
	int mid = (be + en) >> 1;
	if(pos <= mid)update(2*node, be, mid, pos, value);
	else update(2*node + 1, mid + 1, en, pos, value);
	st[node] = max(st[2*node], st[2*node + 1]);
	return;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int n;
	cin >> n;
	long long int a[n], h[n];
	vector<long long int>dp(n + 1, 0);
	//dp[i] -> max beauty that can be obtained if last flower selected has height i
	
	for(int i = 1; i <= n; ++i)cin >> h[i];
	for(int i = 1; i <= n; ++i)cin >> a[i];
		
	for(int flower = 1; flower <= n; ++flower){
		dp[h[flower]] = query(1, 1, n, 1, h[flower]) + a[flower];
		update(1, 1, n, h[flower], dp[h[flower]]);
	}
	
	long long int mx = 0;
	for(int i = 0; i <= n; ++i){
		mx = max(mx, dp[i]);
	}
	cout << mx << endl;
	return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>

int main(void){
   char S[101];
   char T[101];
   int a;
   scanf("%d",&a);
   scanf("%s%s",S,T);
   for(int i = 0; i < a; i++){
      printf("%c%c",S[i],T[i]);
   }
   printf("\n");
}


Measured memory_bytes: 1692
#include<stdio.h>
#include<algorithm>
int main() {
	int n, h, a, ans = 0, amax = 0, b[100000];
	scanf("%d %d", &n, &h);

	for (int i = 0; i < n; ++i) {
		scanf("%d %d", &a, &b[i]);
		amax = (amax < a ? a : amax);
	}
	std::sort(b, b+n); std::reverse(b, b+n);

	for (int i = 0; i < n && h > 0 && b[i] > amax; ++i) {
		h -= b[i];
		++ans;
	}
	if (h > 0) ans += (h + amax - 1) / amax;
	printf("%d\n", ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    while (n != 0) {
        vector<ll> p(n), j(n - 1);
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> p[i];
            sum += p[i];
        }
        for (int i = 0; i < n - 1; i++) {
            cin >> j[i];
        }
        ll ans = n * sum;
        sort(j.begin(), j.end(), greater<int>());
        for (int i = 0; i < n - 1; i++) {
            sum += j[i];
            ans = max(ans, (n - i - 1) * sum);
        }
        cout << ans << "\n";
        cin >> n;
    }
    return 0;
}


Measured memory_bytes: 3820
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    sum=0
    for i in range(x//3+1,n+1):
        for j in range((x-i)//2+1,i):
            if 0<x-i-j<j :   
                sum+=1
    print(int(sum))

Measured memory_bytes: 7516
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        # nを合う数字で割り切れたら、その割った数と商をリストに追加する。
        # nが平方数のとき、同じ数字が2回追加されてしまうので3行したのif文がある
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

yakusuu_list = make_divisors(N)

cnt = 0
for yaku in yakusuu_list[::-1]:
    m = yaku-1
    a = N / yaku
    if a >= m:
        break
    else:
        cnt += m

print(cnt)

Measured memory_bytes: 39152
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k1;cin>>h>>w>>k1;
    vector<string> m(h);
    rep(i,0,h){
        string x;cin>>x;
        m[i] = x;
    }
    int ans = 0;
    rep(i,0,pow(2,h+w)){
        vector<string> m1(h);
        copy(m.begin(),m.end(),m1.begin());
        vector<int> m2(h+w);
        rep(j,0,h+w){
            if (1 & (i>>j)) m2[j] = 1;
        }
        rep(j,0,h){
            if (m2[j]==1){
                rep(k,0,w) m1[j][k] = 'x';
            }
        }
        rep(j,h,w+h){
            if (m2[j]==1){
                rep(k,0,h) m1[k][j-h] = 'x';
            }
        }
        int num = 0;
        rep(j,0,h){
            rep(k,0,w){
                if (m1[j][k]=='#') num++;
            }
        }
        if (num==k1) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4016
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(N, M, A):
    count = 0
    total = sum(A)
    for a in A:
        if a * 4 * M >= total:
            count += 1
    if count >= M:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":

    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    ans = solv(N, M, A)

    print(ans)


Measured memory_bytes: 3060
N = gets.to_i
a = gets.split.map(&:to_i)

b = []

(N - 1).step(0, -2) do |i|
  b << a[i]
end

sp = 0
if N.odd?
  sp = 1
end

sp.step(N - 1, 2) do |i|
  b << a[i]
end

puts b.join(' ')



Measured memory_bytes: 25348
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		sc.nextLine();
		int[] n = new int[4];
		n[0] = 0;
		n[1] = 0;
		n[2] = 0;
		n[3] = 0;
		String StringLine = sc.nextLine();
		StringLine=StringLine.replace(" ", "");
		char[] array = StringLine.toCharArray();
		for (int i = 0; i < num; i++) {
			switch (array[i]) {
			case 'P':
				n[0]++;
				break;
			case 'W':
				n[1]++;
				break;
			case 'G':
				n[2]++;
				break;
			case 'Y':
				n[3]++;
				break;
			}
		}
		int rc = 0;
		for (int i = 0; i < 4; i++) {
			if (n[i] == 0) {
				rc++;
			}
		}
 
		switch (rc) {
		case 0:
			System.out.println("Four");
			break;
		case 1:
			System.out.println("Three");
			break;
		case 2:
			System.out.println("Two");
			break;
		case 3:
			System.out.println("One");
			break;
		}
	}
 
}

Measured memory_bytes: 22996
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
using Int = int64_t;


void calc() {

	Int L; std::cin >> L;
	double len = (double)L / 3.0;
	double ans = len * len * len;
	std::cout << std::setprecision(10) << ans << "\n";

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

//func nextString() string {
//	sc.Scan()
//	return sc.Text()
//}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

//func nextUint64() uint64 {
//	sc.Scan()
//	i, e := strconv.ParseUint(sc.Text(), 10, 64)
//	if e != nil {
//		panic(e)
//	}
//	return i
//}

func main() {
	n := nextInt()

	m := 0
	for ;; {
		m++
		if 1000 * m >= n {
			break
		}
	}

	fmt.Println(1000 * m - n)
}


Measured memory_bytes: 1804
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long

const long double PI = acos(-1);

const int maxn = 2*1e5 + 10;


void solve(){
    int r;
    cin >> r;

    double ans = 2.0*PI*(double)r;

    cout << fixed << setprecision(12) << ans << endl;
    

} 

signed main() 
{   
    //IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 3788
n = int(input())
sp = []
for i in range(n):
  s_, p_,  = input().split()
  sp.append([s_, int(p_)])

sp1 = sp
sp2 = sorted(sp, key=lambda x:(x[0], -x[1]))

for i in range(n):
  print(sp1.index(sp2[i])+1)

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

int main () 
{
  int n, x; cin >> n >> x;
  
  int sum =0;
  int ans = 0;
  
  vector<int> vec(n);
  for (int i=0; i <n; i++) 
  {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
    sort(vec.begin(), vec.end());
  
  if (sum < x )
  {
    ans = (x -sum)/ vec.at(0);
  }
    
  cout << ans + n  << endl;
}

Measured memory_bytes: 256
x = set(list(map(int, input().split())))
a = set([1, 3, 5, 7, 8, 10, 12])
b = set([4, 6, 9, 11])
if len(x & a) == 2 or len(x & b) == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n==0){
		cout<<0<<endl;
		return 0;
	}
	string ans;
	while(n!=0){
		if(n%2!=0){
			ans='1'+ans;
			n--;
		}else
			ans='0'+ans;
		n/=-2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 998244353
S = []
for _ in range(K):
    S.append(tuple(map(int, input().split())))

dp = [0] * (N + 1)
dp[1] = 1
sum_list = [0] * (N + 1)
sum_list[1] = 1

for i in range(2, N+1):
    for L, R in S:
        RR = i - L
        if RR <= 0:
            continue
        LL = max(1, i-R)
        if LL <= RR:
            t = sum_list[RR] - sum_list[LL-1]
            dp[i] += t
    sum_list[i] = (sum_list[i-1] + dp[i]) % MOD
    dp[i] %= MOD

print(dp[N])


Measured memory_bytes: 24408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        if (a == 0) {
            System.out.println(0);
        } else {
            long count = n / (a + b);
            long plus = n - count * (a + b);
            if (plus > a) {
                plus = a;
            }
            System.out.println(count * a + plus);
        }
    }
}


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

int n;
string tab[103];
map <string, bool> present;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> tab[i];
    }
    present[tab[0]] = 1;
    for (int i = 1; i < n; i++) {
        if (tab[i][0] != tab[i - 1][tab[i - 1].size() - 1] || present.count(tab[i])) {
            cout << "No";
            return 0;
        }
        present[tab[i]] = 1;
    }
    cout << "Yes";
}

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

int main(){
	ll n , x;
	cin >> n >> x;

	vector<ll> a(n+1 , 0);
	for(ll i = 1 ; i <= n ; i++){
		cin >> a[i];
	}

	ll counter = 1;
	vector<ll> pos(n+1 , -1);

	ll i = 1;
	ll first = -1 , second = -1;

	while(pos[i] == -1){
		pos[i] = counter;
		counter++;
		i = a[i];
	}

	ll spos = pos[i]-1 , clength = counter - pos[i];
	//cout << "Spos :: " << spos << " clength :: " << clength << endl;

	if(x <= spos){
		x++;
		for(ll i = 0 ; i <= n ; i++){
			if(pos[i] == x){
				cout << i << endl;
			}
		}
	} else {
		ll eff = x - spos;
		ll temp = eff % clength;
		ll ans = spos + temp + 1;
		//cout << "ans :: " << ans << endl;
		for(ll i = 0 ; i <= n ; i++){
			if(pos[i] == ans){
				cout << i << endl;
			}
		}
	}

	//cout << "Cycle :: " ;
	//for (ll i = 0 ; i <= n ; i++){
		//cout << pos[i] << " ";
	//}
	return 0;
}


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int nums[n];
  REP(i,n) {
    cin >> nums[i];
  }
  int ans = nums[0];
  REPS(i,1,n) {
    ans = __gcd(ans, nums[i]);
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1024
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
ll dp[2003][2003];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i,ans=0,x,l,r,j;
    pll a[2005];
    cin>>n;
    for(i=1;i<=n;++i){
    	cin>>a[i].first;
    	a[i].second=i;
	}
	sort(a+1,a+1+n,greater<pll>());
	for(i=1;i<n+1;++i){
		for(j=0;j<i;++j){
			l=j;
			r=i-1-j;
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+abs(l+1-a[i].second)*a[i].first);
			r=j;
			l=i-1-j;
			dp[l][r+1]=max(dp[l][r+1],dp[l][r]+abs(n-r-a[i].second)*a[i].first);
		}
	}
	for(i=0;i<n;++i){
		ans=max(ans,dp[i][n-i]);
	}
	cout<<ans;
}

Measured memory_bytes: 26268
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

(defparameter *hash-memo* (make-hash-table :test #'equal))

(defmacro dp (&body func)
  `(let* ((f (quote func))
          (num (gethash f *hash-memo*)))
     (if num
       num
       (setf (gethash f *hash-memo*) ,func))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(let* ((n (read))
      (pos (loop repeat n collect (read)))
      (ans (expt 10 10)))
  (loop for i below 100
        do
        (setf ans (min ans (loop for p in pos sum (expt (- i p) 2)))))
  (princ ans))



Measured memory_bytes: 18744
// abc151_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    char x;
    cin >> x;
    char ans = x + 1;
    print(ans);


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	 int h,w;
	 cin>>h>>w;
	 char b[100][100];
	 vector<bool> col(h,false),row(w,false);

	 for (int i = 0; i < h; i++){
	 	for (int j = 0; j < w; j++){
	 		cin>>b[i][j];
	 		if(b[i][j]=='#'){
	 			row[i]=1;
	 			col[j]=1;
	 		}
	 	}
	 }

	 for (int i = 0; i < h; i++){
	 	if(row[i]){
	 		for (int j = 0; j < w; j++){
	 			if(col[j]) cout<<b[i][j];
	 		}
	 		cout<<endl;
	 	}
	 }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int n;
  cin >> n;
  double x = 1e2;
  for (int i = 0; i < (int)n; ++i) x = ceil(x * 1.05);
  cout << ll(x * 1000) << endl;

  return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  if((n%2==0&&k<=n/2)||(n%2==1&&k<=n/2+1)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s = iterator.next().unwrap();

    let mut count_w: usize = 0;
    let mut ans: usize = 0;
    for (i, c) in s.chars().enumerate() {
        if c == 'B' {
            continue;
        }
        ans += i - count_w;
        count_w += 1;
    }
    return ans.to_string();
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

int w[100005];
int t[100005];
int main() {
  int n; ll m;
  cin >> n >> m;

  ll wmax = 0;
  for (int i = 1; i <= n; i++){
    cin >> w[i] >> t[i];
    if (w[i] > wmax)
      wmax = w[i];
  }

  sort(t+1, t+n+1);
  ll ans = 0;
  for (int i = n; i > 0; i--){
    if (m > 0){
      if (t[i] > wmax){
        ans++;
        m = m - t[i];
      }
      else 
        break;
    }
  }
  
  if (m > 0){
    ans = ans + m/wmax;
    if (m%wmax != 0)
      ans++;
    m = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4400
let counter = ref 0

let merge array left mid right =
  let init n p = Array.init (n+1) (fun i -> if i=n then max_int else array.(p+i)) in
  let xs = init (mid-left) left in
  let ys = init (right-mid) mid in
  let rec loop i j k =
    if k < right then
      (incr counter;
       if xs.(i) <= ys.(j) then (array.(k) <- xs.(i); loop (i+1) j (k+1))
       else (array.(k) <- ys.(j); loop i (j+1) (k+1)) )
  in loop 0 0 left

let rec msort array left right =
  if left+1 < right then
    let mid = (left+right)/2 in
    msort array left mid;
    msort array mid right;
    merge array left mid right

let () =
  let n = read_int () in
  let (l : int array) = Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x)) in
  msort l 0 n;
  Array.iteri (fun i v -> Printf.printf (if i = n-1 then "%d\n" else "%d ") v) l;
  Printf.printf "%d\n" !counter

Measured memory_bytes: 19496