akhauriyash/Code-Regression huggingface dataset:
K = int(input())


def dfs(d, n, buf):
    buf.append(n)

    if d == 10:
        return

    lsd = n % 10

    if lsd != 0:
        dfs(d + 1, n * 10 + lsd - 1, buf)

    dfs(d + 1, n * 10 + lsd, buf)

    if lsd != 9:
        dfs(d + 1, n * 10 + lsd + 1, buf)


buf = []

for n in range(1, 10):
    dfs(1, n, buf)

print(sorted(buf)[K - 1])


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

int main(){
    string s;
    cin >> s;
    int frag = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]==s[i+1]) {
            cout << "Bad";
            frag++;
            break;
        }
    }
    if(frag == 0)
        cout << "Good";
}

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

using namespace std;

using ll = long long;

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

    int N, Q;
    cin >> N >> Q;
    int ac_num[N + 1];
    memset(ac_num, 0, sizeof(ac_num));

    string S;
    cin >> S;
    for (unsigned long i = 1; i < N; ++i) {
        ac_num[i + 1] = ac_num[i];
        ac_num[i + 1] += S.substr(i - 1, 2) == "AC";
    }

    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        cout << ac_num[r] - ac_num[l] << '\n';
    }

    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 100000000000000000;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s ;
  
  bool OK = false ;
  rep(i,s.size()){
    if(s.at(i) == 'C') OK = true ;
    if(OK && s.at(i) == 'F'){
      cout << "Yes" <<endl;
      return 0 ; 
    }
  }
  
    cout << "No" <<endl ;
  
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,m,k,ans=0;
	cin>>n>>m>>k;
	vector<ll> a(n), b(m), aSum(n+1), bSum(m+1);
	for (ll i=0;i<n;i++)
	{
		cin>>a[i];
		aSum[i+1]=aSum[i]+a[i];
	}
	for (ll i=0;i<m;i++)
	{
		cin>>b[i];
		bSum[i+1]=bSum[i]+b[i];
	}
	//for (int i=0;i<=n;i++)cout<<aSum[i]<<" ";cout<<"\n";
	//for (int i=0;i<=m;i++)cout<<bSum[i]<<" ";cout<<"\n";
	for (ll i=0;i<=n;i++)
	{
		ll dif=k-aSum[i];
		if (dif<0)continue;
		if (dif==0)
		{
			ans = max(ans,i);
			continue;
		}
		ll j = upper_bound(bSum.begin(),bSum.end(),dif)-bSum.begin()-1;
		ans = max(ans,i+j);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 9588
N,M = gets.split(' ').map(&:to_i)
#maze = readlines.map { |line| line.split(' ').map(&:to_i)}
#puts maze[0][0]
As = gets.split(' ').map(&:to_i).sort
#ope = M.times.map{|line| line.split(' ').map(&:to_i)}
bc = M.times.map{ gets.split(' ').map(&:to_i)}
#bc.sort_by!{|x| -x[1] }
#↑↓二番目の要素について降順でソート
bc.sort!{|a,b| b[1]<=>a[1]}

n_cnt = 0
m_cnt = 0
c_cnt = bc[0][0]

while n_cnt<N && m_cnt<M

  if As[n_cnt]>=bc[m_cnt][1]
    n_cnt += 1
  else
    As[n_cnt] = bc[m_cnt][1]
    c_cnt -= 1
    n_cnt += 1
  end
  if c_cnt == 0
    m_cnt+=1
  #  c_cnt = bc[m_cnt][0]
  #  if m_cnt >= M? c_cnt = 0:bc[m_cnt][0]
  if m_cnt >= M
    c_cnt = 0
  else
    c_cnt = bc[m_cnt][0]
  end
end
end
ans = 0
for i in 0..N-1
  ans += As[i]
end
puts ans


Measured memory_bytes: 18288
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) break;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if ((i + j) % 2 == 0) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 34488
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;


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

Measured memory_bytes: 256
import Data.List

main = do
 getLine
 as <- map read . words <$> getLine
 putStrLn $ unwords $ map show (cl as)

cl as = [max 1 r1, r1+r2]
 where
  r1 = length $ filter (not.null) $ map (intersect as) lb
  r2 = length $ filter (>=3200) as

lb = [[1..399],[400..799],[800..1199],[1200..1599],[1600..1999],[2000..2399],[2400..2799],[2800..3199]]

Measured memory_bytes: 1148
# ABC 132: B – Ordinary Number
n = int(input())
p = [int(s) for s in input().split()]

count = 0

for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i -1] > p[i] > p[i + 1]:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / LINF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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

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

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

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<int> h(N); REP(i, N) cin >> h[i];
    sort(ALL(h));
    int min = INF;
    for (int i = 0; i+K-1 < N; ++i) {
        chmin(min, h[i+K-1] - h[i]);
    }
    cout << min << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }


int main() {
    int n,t;
    cin>>n>>t;
    vector<pair<int,int>> sm(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        sm[i].first=a;
        sm[i].second=b;
    }
    sort(sm.begin(),sm.end());

    int dp[3001];
   rep(j,3001)dp[j]=0;

    for(int i=0;i<n;i++){
        for(int j=t-1;j>=0;j--){
            dp[min(t,j+sm[i].first)] = max(dp[min(t,j+sm[i].first)],dp[j]+sm[i].second);

            }
        }



    cout<<dp[t]<<endl;


    return 0;
}


Measured memory_bytes: 256
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

b = S()
t = ""
lis = []
for e in b:
    if e in "ATGC":
        t += e
    else:
        lis.append(t)
        t = ""
if e in "ATGC":
    lis.append(t)
ans = 0
for e in lis:
    ans = max(ans,len(e))
print(ans)

Measured memory_bytes: 3316
N, A, B, C, D = map(int, input().split())
N-=1
A-=1
B-=1
C-=1
D-=1
S = input()

massesExist = True
overtakeFlag = False if C > D else True
proceedableFlag = True

if max(A, B, C, D) > N:
    massesExist = False

if not overtakeFlag:
    for i in range(B, D+1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            overtakeFlag = True

for i in range(A, max(C, D)-1):
    if S[i]=="#" and S[i+1]=="#":
        proceedableFlag = False

if overtakeFlag and proceedableFlag and massesExist:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9388
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	char a;
	cin>>a;
	if(a == 'z')cout<<'a'<<endl;
	else cout<<char(a+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
# aの倍数の総和をbで割ったあまりがcになる
# aの倍数の総和はaの倍数なので
# c = na % b を満たすnがあるかどうか調べる

a, b, c = map(int, input().split())
for i in range(1, b+1):
  if i * a % b == c:
    print('YES')
    exit()
print('NO')

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

int main(){
  
  double d1, d2;
  
  cin>>d1>>d2;
  
  double A=(d1+d2)/2.0;
  double B=A+180;
  double ans;
  
  if(B>=360) B-=360;
  
  double com1=abs(A-d1);
  double com2=abs(B-d1);
  
  if(com1>=180) com1=360-com1;
  if(com2>=180) com2=360-com2;
  
  if(com1<com2) ans=A;
  else ans=B;
  
  printf("%.8f\n", ans);
  
  return 0;
}

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

int main() {
  int n, d; cin >> n >> d;
  int x[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }
  int dist[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dist[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = 0; k < d; k++) {
        dist[i][j] += (x[j][k]-x[i][k])*(x[j][k]-x[i][k]);
      }
    }
  }
  int ans = 0;
  
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = 0; k < 200; k++)
      if (dist[i][j] == k*k) {ans++;}
    }
  }
  
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pb push_back
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define mod 1000000007
#define mod1 998244353
#define ff first
#define ss second
#define MAX 500005
#define N 200005
#define INF 1000000009
#define all(v) v.begin(), v.end()
#define sbit(a) __builtin_popcount(a)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0)
        return 0;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }

    return res;
}
ll par[N], rnk[N];
void makeset(ll v)
{
    par[v] = v;
    rnk[v] = 1;
}
ll findset(ll v)
{
    if (par[v] == v)
        return v;
    return par[v] = findset(par[v]);
}
void makeuni(ll a, ll b)
{
    a = findset(a);
    b = findset(b);
    if (a != b)
    {
        if (rnk[a] < rnk[b])
            swap(a, b);

        //  if (rnk[a] == rnk[b])
        rnk[a] += rnk[findset(b)];
        par[b] = a;
    }
}
void solve()
{
    ll n, m;
    cin >> n >> m;
    for (ll i = 1; i <= n; i++)
    {
        makeset(i);
    }
    set<pll> se;
    for (ll i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        if (se.find({x, y}) == se.end() && se.find({y, x}) == se.end())
        {
            makeuni(x, y);
            se.insert({x, y});
        }
    }
    ll mx = 0;
    set<ll> see;
    for (ll i = 1; i <= n; i++)
    {
        mx = max(mx, rnk[i]);
       // cout << rnk[i] << endl;
    }
    cout << mx << endl;
}

int main()
{

    speed;

    ll kk;
    kk = 1;
    // cin >> kk;
    while (kk--)
    {

        solve();
    }
    return 0;
}


Measured memory_bytes: 19236
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 205
#define MAX_M 205

int N,M;
vector<int> t[MAX_N];
vector<int> u[MAX_N];

double dp[MAX_N][MAX_M];

double mem[MAX_N][MAX_M];
double calc(int id,int num){
  if(mem[id][num]!=-1e9)
    return mem[id][num];

  double res=0;
  int sum=0;
  for(int i=0;i<(int)t[id].size();i++){
    int V=t[id][i]*u[id][i];
    res+=u[id][i];
    sum+=V;
    if(sum>num){
      int d=sum-num;
      res-=(double)d/(double)t[id][i];
      break;
    }
  }
  return mem[id][num]=res;
}

int main(){
  cin>>N>>M;
  for(int i=1;i<=N;i++){
    int k;
    cin>>k;
    t[i].resize(k);
    u[i].resize(k);
    for(int j=0;j<k;j++){
      cin>>t[i][j]>>u[i][j];
    }
  }

  fill( mem[0],mem[MAX_N], -1e9);
  fill( dp[0],dp[MAX_N],-1e9);
  dp[0][0]=0;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=M;j++){
      dp[i][j]=dp[i-1][j];
      for(int k=0;k<=j;k++){
        double cost = calc(i,k);
        dp[i][j]=max(dp[i][j],dp[i-1][j-k]+cost);
      }
    }
  }
  printf("%.10f\n",dp[N][M]);
  return 0;
}

Measured memory_bytes: 3852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		
		
		String ns = s.nextLine();
		String str = s.nextLine();
		int n = Integer.parseInt(ns);
//		String str = "2 3 1";
		int[] arr = new int[n+1]; 
		arr[0] = 0;
		String sss[] = str.split("\\s");
		for(int i=1;i<=n;i++) {

			arr[i] = Integer.parseInt(sss[i-1]);
			
		}
		
		int[] a = new int[n+1];
		
		a[0] = 0;
		
		for(int i=1;i<=n;i++) {
			a[(arr[i])] = i;
		}
		for(int i=1;i<=n;i++) {
			System.out.print(a[i]+" ");
		}
	}

}

Measured memory_bytes: 54620
import java.util.Scanner
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val as = Array.fill(n)(sc.nextLong)
  val counts = new Array[Long](60)
  val Mod = 1000000007L

  for (a <- as; no <- 0 until 60) counts(no) += (if ((a & (1L << no)) != 0) 1 else 0)
  println(counts.zipWithIndex.foldLeft(0L){case (z, (c, i)) => (z + (c * (n - c) % Mod) * ((1L << i) % Mod)) % Mod})
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;


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

    map<string, priority_queue<pair<int, int>>> m;
    string s;
    int p;
    for (int i = 0; i < n; i++) {
        cin >> s >> p;
        if (m.count(s) == 0) {
            priority_queue<pair<int, int>> pq;
            pq.emplace(p, i + 1);
            m[s] = pq;
        } else{
            m[s].emplace(p, i + 1);
        }
    }

    for (const auto pp : m) {
        auto q = pp.second;
        while (q.size() > 0) {
            auto x = q.top(); q.pop();
            cout << x.second << endl;
        }
    }

}


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

using namespace std;

int main(){
  float X;
  cin >> X; 
  float root;
  for(float i=X;i>0;i--){
    for(float j=10;j>1;j--){
	  root = pow(i,1/j);
      //cout<<"i:"<<i<<endl;
      //cout<<"root:"<<root-(int)root<<endl;
	  if((root-(int)root)<1.0e-05){
	    cout<<i<<endl;
		return 0;
      }
      //cout<<"i:"<<i<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll H, W;
ll cnt[26]={};

ll cnt4() {
    ll res=0;
    for(ll i=0; i<26; i++) {
        res+=cnt[i]/4*4;
        cnt[i]=cnt[i]%4;
    }
    return res;
}

ll cnt2() {
    ll res=0;
    for(ll i=0; i<26; i++) {
        res+=cnt[i]/2*2;
        cnt[i]=cnt[i]%2;
    }
    return res;
}

ll cnt1() {
    ll res=0;
    for(ll i=0; i<26; i++) {
        res+=cnt[i]/1*1;
        cnt[i]=cnt[i]%1;
    }
    return res;
}

int main(void) {
    cin >> H >> W;
    ll i, j;
    
    for(i=0; i<H; i++) {
        for(j=0; j<W; j++) {
            char t;
            cin >> t;
            cnt[t-'a']++;
        }
    }
    
    ll t=0;
    if(H%2==0) {
        
        if(W%2==0) {
            t+=cnt4();
            
            if(t==H*W) pt("Yes");
            else pt("No");
            
        }else {
            t+=cnt4();
            if(t<H*(W-1)) {
                pt("No");
                return 0;
            }
            
            t+=cnt2();
            
            if(t==H*W) pt("Yes");
            else pt("No");
        }
        
    }else {
        
        if(W%2==0) {
            t+=cnt4();
            if(t<(H-1)*W) {
                pt("No");
                return 0;
            }
            
            t+=cnt2();
            
            if(t==H*W) pt("Yes");
            else pt("No");
        }else {
            t+=cnt4();
            if(t<(H-1)*(W-1)) {
                pt("No");
                return 0;
            }
            
            t+=cnt2();
            if(t<H*W-1) {
                pt("No");
                return 0;
            }
            
            t+=cnt1();
            
            if(t==H*W) pt("Yes");
            else pt("No");
        }
        
    }
    
    
    
    
}


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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long holidays, hw;
  cin >> holidays >> hw;
  long long sum = 0, get;
  for(int i = 0; i < hw; i++){
    cin >> get;
    sum += get;
  }
  if(holidays < sum)
    cout << -1;
  else
    cout << holidays - sum;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define MAXN 100005
#define mod 1000000007
typedef long long ll;
using namespace std;
vector<ll> arr,book,dp;
int main(){
    ll n;
    cin >> n;
    arr.assign(n,0);
    book.assign(MAXN,0);
    dp.assign(MAXN,0);
    char x;
    for(ll i=0;i<n;i++){
        cin >> x;
        arr[i]=x-'a'+1;
    }
    sort(arr.begin(),arr.end());
    for(ll i=1;i<=n;i++){
        if(!book[arr[i-1]]){
            dp[i]=(2*dp[i-1]+1)%mod;
        }
        else{
            int t=book[arr[i-1]];
            dp[i]=(dp[i-1]*2%mod+mod-dp[t-1]%mod)%mod;
        }
        book[arr[i-1]]=i;
    }
    cout << dp[n]%mod << '\n';
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

int power(int x, int y)
{
    int res = 1;      // Initialize result

     // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);
    }
    return res;
}

int32_t main(){
	string s;
	cin>>s;
	int n = s.size();
	int idxa=INT_MAX;
	int idxz = -1;
	for(int i=0; i<n; i++){
		if(s[i]=='A') idxa = min(idxa, i);
		if(s[i]=='Z') idxz = max(idxz, i);
	}
	cout<<max(0, idxz-idxa+1);
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
    int n, a, b;
    int plan1;
    int plan2;
    scanf("%d %d %d", &n, &a, &b);
    plan1 = a*n;
    plan2 = b;
    if(plan1 > plan2){
        printf("%d\n", plan2);
    }else{
        printf("%d\n", plan1);
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  int N; cin >> N;
  vector<vector<int> > G(N);
  vector<P> vp;
  for(int i = 1; i < N; i++){
    int a, b; cin >> a >> b; --a; --b;
    G[a].push_back(b); G[b].push_back(a);
    vp.push_back(P(a, b));
  }
  int MAX_COLOR = 0;
  vector<int> used(N, 0), color(N, 0);
  queue<int> que; que.push(0);
  map<P, int> MAP;
  used[0] = 1;
  while(que.size()){
    int v = que.front(); que.pop();
    int num = 1;
    for(int i = 0; i < G[v].size(); i++){
      int u = G[v][i];
      if(used[u] != 0) continue;
      if(color[v] == num) num++;
      used[u] = 1;
      color[u] = num;
      MAP[P(u, v)] = num;
      MAP[P(v, u)] = num;
      num++;
      que.push(u);
    }
    MAX_COLOR = max(MAX_COLOR, int(G[v].size()));
  }
  cout << MAX_COLOR << '\n';
  for(auto p : vp) cout << MAP[p] << '\n';
}

Measured memory_bytes: 20084
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] holeIndices = new int[M];

        for (int i=0; i<M; i++) {
            holeIndices[i] = sc.nextInt() - 1;
        }

        boolean[] holes = new boolean[N];
        for (int i=0; i<N; i++) {
            holes[i] = false;
        }
        for (int index : holeIndices) {
            holes[index] = true;
        }

        if (holes[0] && holes[1]) {
            System.out.println(0);
            return;
        }

        List<Integer> dp = new ArrayList<>();
        dp.add(1);
        if (!holes[0]) {
            dp.add(2);
        } else {
            dp.add(1);
        }

        for (int i=2; i<N; i++) {
            if (holes[i]) {
                if (holes[i-1]) {
                    System.out.println(0);
                    return;
                } else {
                    dp.add(dp.get(i-1));
                }
            } else {
                if (!holes[i-1] && !holes[i-2]) {
                    dp.add((dp.get(i-1) + dp.get(i-2)) % 1000000007);
                } else {
                    dp.add(dp.get(i-1));
                }
            }
        }
        System.out.println(dp.get(N-1));
    }
}



Measured memory_bytes: 49684
#include <cstdio>
#include <vector>

const int MN = 100005;

int N;
std::vector<int> G[MN];

int Ans, siz[MN];
void DFS(int u, int p) {
	siz[u] = 1;
	int s = 0;
	for (int v : G[u]) if (v != p) {
		DFS(v, u);
		s += siz[v];
		siz[u] ^= siz[v]; 
	}
	if (s >= 2) Ans = 1;
}

int main() {
	scanf("%d", &N);
	if (N & 1) return puts("First"), 0;
	for (int i = 1, x, y; i < N; ++i) {
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	DFS(1, 0);
	puts(Ans ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define watch(x) cerr << (#x) << " is " << (x) << endl;
using namespace std;
const int MAXN = 100001;
const int INF = 1234567890;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int k; string s; cin >> k >> s;
	for (int i = 0; i < min((int)s.size(), k); ++i){
		cout << s[i];
	}
	if ((int)s.size() > k){
		cout << "...";
	}
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int dp[105][10];

int main(){
  int h, w, n;
  cin >> h >> w >> n;
  dp[0][0] = 1;
  for(int i=1; i<=h; ++i) for(int j=0; j<(1<<(w-1)); ++j){
    bitset<8> bs(j);
    bool b = false;
    for(int k=0; k<w-1; ++k){
      if(bs.test(k) && bs.test(k+1)) b = true;
    }
    if(b) continue;
    bool frag = true;
    for(int k=0; k<w; ++k){
      if(bs.test(k)){
        dp[i][k] += dp[i-1][k+1];
        dp[i][k] %= MOD;
        dp[i][k+1] += dp[i-1][k];
        dp[i][k+1] %= MOD;
        frag = false;
      }
      else if(frag){
        dp[i][k] += dp[i-1][k];
        dp[i][k] %= MOD;
      }else{
        frag = true;
      }
    }
  }
  cout << dp[h][n-1] << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(void){
    int a,b,i;
    scanf("%d%d",&a,&b);
    for(i=1;i<=1100;i++){
        if((int)i*8/100==a && (int)i/10==b){
            printf("%d",i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


Measured memory_bytes: 128
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__


          
void solve(void){
  
  int N, X, Y;
  cin >> N >> X >> Y;
  
  vector<int> M(N,0);
  
  REP2(i,1,N){
    REP2(j,i+1,N+1){
      int tmp = j-i;
      chmin(tmp, abs(X-i)+1+abs(j-Y));
      chmin(tmp, abs(Y-i)+1+abs(j-X));
      M[tmp]++;
    }
  }
  
  REP2(k,1,N){
    cout << M[k] << endl;
  }
  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {

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

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}


Measured memory_bytes: 256
s = input()
h = "Heisei"
t = "TBD"
els =  s.split("/")
y = int(els[0])
m = int(els[1])
d = int(els[2])
if y < 2019:
    print(h)
elif m < 4:
    print(h)
elif m == 4 and d <= 30:
    print(h)
else:
    print(t)


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


int power(int n){
    if (n==0) return 1;
    return 100*power(n-1);
}

inline void solve(){
    int a,b;
    cin >> a>>b;
    cout << (power(a)*b+((b>99)*power(a))) << endl;
}

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


Measured memory_bytes: 3612
#標準入力
N = int(input())
A = list(map(int, input().split()))

#累積和
S = [0]*N
for n in range(N):
  S[n] = S[n-1] + A[n]

_sum = int(0)
for i in range(N-1):
  _sum = _sum + (A[i] * (S[-1] - S[i]))

#modulo
_sum = _sum % (1000000000+7)
  
print(_sum)

Measured memory_bytes: 31760
#include<stdio.h>

int main() {
  int n;
  int a[1010] = {};
  int i;
  int min = 1000;
  int max = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (min >= a[i]) {
      min = a[i];
    }
    if (max <= a[i]) {
      max = a[i];
    }
  }
  printf("%d\n", max - min);
  return 0;
}
  

Measured memory_bytes: 128
#include<iostream>
#include<functional>
#include<map>
#include<string>
#include<vector>
#include<climits>
#include<algorithm>
#include<cmath>
#include<utility>
#include<queue>
using namespace std;
bool ispal(string s){
	int n = s.length();
	for(int i=0;i<n/2;i++){
		if(s[i] != s[n-1-i]) return false;
	}
	return true;
}
int main(){
	string S;
	cin >> S;
	int N = S.length();
	if(ispal(S)&&ispal(S.substr(0,(N-1)/2))&&ispal(S.substr((N+3)/2-1,(N-3)/2+1))) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int INF = 1001001001;
const ll LINF = 1e18;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}

ll twoMod(ll in){
    ll count = 0;
    while(in % 2 == 0){
        count++;
        in /= 2;
    }
    return count;
}

int main() {
    ll N; cin >> N;
    ll a, idx = 0; vl as(N, 0);
    while (cin >> a) {
        as[idx] = a;
        idx++;
    }
    
    ll res = 0;
    for (ll i = 0; i < N; i++) {
        res += twoMod(as[i]);
    }
    
    cout << res << endl;
    return 0;
}



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

int main() {
  long N,P;
  cin>>N>>P;
  long ans=1;
  for(long i=2;i*i<=P;i++){
    long cnt=0;
    while(P%i==0){
      P /=i;
      cnt++;
    }
    while(cnt>=N){
      ans *= i;
      cnt -= N;
    }
  }
  if(N==1) cout<<P*ans<<endl;
  else cout<<ans<<endl;
}


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

int main(int argc, char *argv[]) {

  char S[5];
  char s1[3], s2[3];

  scanf("%s", S);

  s1[0] = S[0];
  s1[1] = S[1];
  s2[0] = S[2];
  s2[1] = S[3];

  s1[2] = 0;
  s2[2] = 0;

  int a, b;
  a = atoi(s1);
  b = atoi(s2);

  if (a == 0 || a > 12) {
    if (b == 0 || b > 12 ) {
      printf("NA");
    } else {
      printf("YYMM");
    }
  } else {
    if (b == 0 || b > 12 ) {
      printf("MMYY");
    } else {
      printf("AMBIGUOUS");
    }
  }

}


Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Long[] t = new Long[n];
        Arrays.setAll(t, i -> Long.parseLong(sc.next()));
        sc.close();

        // 主処理
        long result = t[0];
        for (int i = 1; i < n; i++) {
            result = lcm(result, t[i]);
        }

        // 出力
        System.out.println(result);
    }

    public static long lcm(long a, long b) {
        long gcd = gcd(a, b);
        return a / gcd * b;
    }

    public static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }
}


Measured memory_bytes: 26836
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){    
  
  ll N,T; 
  cin >> N;
  vector<ll> vec(N);
  for(ll i = 0; i < N; i++){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end(), greater<ll>());
  T = 0;
  
  for(ll i = 1; i < N; i++){
    T += vec[i/2];
  }
  cout << T << endl; 
  
}


Measured memory_bytes: 4828
from bisect import bisect_left

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

edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

order = []
parent = [-1] * (N + 1)
st = [1]
while st:
    now = st.pop()
    order.append(now)
    if now > 0:
        st.append(-now)
        for to in edges[now]:
            if to == parent[now]:
                continue
            st.append(to)
            parent[to] = now

L = [-10**18]
ans = [-1] * (N + 1)
st = [(-1, -1)] * (N + 1)

for now in order:
    if now < 0:
        val, idx = st[-now]
        if val == -1:
            L.pop()
        if val > 0:
            L[idx] = val
        continue

    a = A[now - 1]
    i = bisect_left(L, a)

    if len(L) == i:
        L.append(a)
    else:
        st[now] = (L[i], i)
        if L[i] > a:
            L[i] = a

    ans[now] = len(L) - 1

print(*ans[1:], sep='\n')


Measured memory_bytes: 154496
#include<iostream>
#include<stdio.h>
#include <string>
using namespace std;
/*int main() {
	int n, i, j, k,c,d,e,f;
	c = 0;
	d = 0;
	char a[1000], b[1000];
	cin >> n;
	for (i = 0; i < n; i++) {
		k = 0;
		e = 0;
		f = 0;
		for (j = 0; j < 1000; j++) {
			scanf_s("%c", &a[j]);
			if (a[j] == ' ')break;
			e++;
		}
		for (j = 0; j < 1000; j++) {
			scanf_s("%c", &b[j]);
			if (b[j] == '\n')break;
			f++;
		}
		if (e < f) {
			for (j = 0; j < e; j++) {
				if (a[j] < b[j]) {
					c += 3;
					k = 1;
					break;
				}
				if (a[j] > b[j]) {
					d += 3;
					k = 1;
					break;
				}
			}
			if (k == 0) {
				c += 3;
			}
		}
		if (e >= f) {
			for (j = 0; j < f; j++) {
				if (a[j] < b[j]) {
					c += 3;
					k = 1;
					break;
				}
				if (a[j] > b[j]) {
					d += 3;
					k = 1;
					break;
				}
			}
			if (k == 0) {
				if (e > f) {
					d += 3;
				}
				else {
					c++; 
					d++;
				}
			}
		}
		
	}
	cout << d << " " << c << endl;
	return 0;
}
*/
/*int main() {
	string a, b, c;
	int n, i, j,s,t,p,q;
	p = 0; q = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> c;
		s = c.find(" ");
		a = c.substr(0, s);
		b = c.substr(s + 1);
		if (a > b) {
			p += 3;
		}
		if (a < b) {
			q += 3;
		}
		if (a == b) {
			p += 1;
			q += 1;
		}
	}
	cout << p << ' '<< q << endl;
	return 0;
}
*/
int main() {
	string a, b, c;
	int n, i, j, s, t, p, q;
	p = 0; q = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a>>b;
		if (a > b) {
			p += 3;
		}
		if (a < b) {
			q += 3;
		}
		if (a == b) {
			p += 1;
			q += 1;
		}
	}
	cout << p << ' ' << q << endl;
	return 0;
}

Measured memory_bytes: 3176
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int*p,n,s,r,a[20000],i;
	while(scanf("%d%d",&n,&s),n)
	{
		for(i=0;i<n;++i)scanf("%d",a+i);
		sort(a,a+n);
		for(r=i=0;i<n;++i)
		{
			p=lower_bound(a+i+1,a+n,s-a[i]+1);
			if(p-a-n)
				r+=a+n-p;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 808
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

constexpr int64 MOD = 1000000007;




int main()
{
    int n, k, pRock, pScissor, pPaper;
    cin >> n >> k >> pRock >> pScissor >> pPaper;
    string t;
    cin >> t;
    
    string tmp(k, ' ');

    int64 score = 0;
    Rep(i, n)
    {
        if (t[i] == tmp[i % k])
        {
            tmp[i % k] = ' ';
        }
        else
        {
            tmp[i % k] = t[i];
            switch (t[i])
            {
                case 'r':
                    score += pPaper;
                    break;
                case 's':
                    score += pRock;
                    break;
                case 'p':
                    score += pScissor;
                    break;
                default:
                    break;

            }
        }
    }

    cout << score << endl;



    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<string>
#include<cstdio>

using namespace std;

int main(){
    //ここ
    int A ,B ;
    cin >> A >> B ;
    if (A==1 && B==2) cout << 3 << endl;
    else if (A==1 && B==3) cout << 2 << endl;
    else if (A==2 && B==1) cout << 3 << endl;
   // else if (A==2 && B==3) cout << 1 << endl;
    else if (A==3 && B==1) cout << 2 << endl;
    else cout << 1 << endl;

    return 0;
} 

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

using namespace std;

int n;
vector<int> v;
vector<int> used;
int ans = 0;

void dfs(int x){
	if(used[x]){
		if(used[x]==1){
			while(used[x]==1){
				used[x] = 2;
				ans++;
				(x += v[x])%=n;
			}
		}
		return;
	}
	used[x] = 1;
	dfs((x+v[x])%n);
	if(used[x] == 1) used[x] = 3;
}

int main(){
	cin >> n;
	v.assign(n,0);
	for(int i=0;i<n;i++){
		cin>>v[i];
		v[i] %= n;
	}
	used.assign(n,0);
	for(int i=0;i<n;i++){
		dfs(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <string.h>
#define MAXN 100000
#define MAXL 10000000
int prime[MAXN];
int c[MAXN];
int check[MAXL];
int main(void)
{
    int N, count,L,R;
        memset(check, 0, sizeof(check));
        check[1]=1;
        count = 0;
        for (int i = 2; i <= 100010; i++)
        {
            if (!check[i])
                prime[count++] = i;
            for (int j = 0; j < count; j++)
            {
                if (i*prime[j] > MAXL)
                    break; // 过大的时候跳出
                check[i*prime[j]] = 1;
                if ((i%prime[j]) == 0) // 如果i是一个合数，而且i % prime[j] == 0
                    break;
            }

        }
      for(int i=3;i <=100000;i+=2)
        if(!check[i]&&!check[(i+1)/2])
            c[i]++;
    for(int i=3;i <=100000;i++)
        c[i]+=c[i-1];
    scanf ("%d",&N);
    while(N--)
    {
        scanf ("%d%d",&L,&R);
        printf ("%d\n",c[R]-c[L -1]);
    }

    return 0;
}


Measured memory_bytes: 40064
n = int(input())
number_list = list(map(int, input().split()))
count = 0
for i in range(n-2):
    if number_list[i] > number_list[i+1] > number_list[i+2]:
        count += 1
    elif number_list[i] < number_list[i+1] < number_list[i+2]:
        count += 1
print(count)

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val map = LinkedHashMap<String, Long>()
    for (i in 0 until n) {
        val s = readLine()!!.toCharArray().sorted().joinToString { it.toString() }
        if (map.contains(s)) {
            map[s] = map[s]!! + 1
        } else {
            map[s] = 1
        }
    }
    println(map.values.map { it * (it - 1) / 2L }.sum())
}

Measured memory_bytes: 81308
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while(left < right) {
		mid = (left + right) / 2;
		if(key == A[mid]) return 1; /* key を発見 */
		if(key > A[mid]) left = mid + 1; /* 後半を探索 */
		else if(key < A[mid]) right = mid; /* 前半を探索 */
	}
	return 0;
}

int main(void) {
	int i, q, k, sum = 0;
	scanf("%d",&n);
	for(i=0; i<n; i++) {
		scanf("%d",&A[i]);
	}
	
	scanf("%d",&q);
	for(i=0;i<q;i++) {
		scanf("%d",&k);
		if(binarySearch(k)) sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 980
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
map<int,int>mp; 
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		mp[x]++;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
		if(it->second>=it->first)
			ans+=it->second-it->first;
		else
			ans+=it->second;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>

int main()
{
    int x, y;
    while(1) {
        scanf("%d%d", &x, &y);
        if(x==0 && y==0) break;
        if(x<=y) printf("%d %d\n", x, y);
        else printf("%d %d\n", y, x);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    using namespace std;
    inline int gi() {
        int x=0,o=1;
        char ch=getchar();
        while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
        if(ch=='-') o=-1,ch=getchar();
        while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
        return x*o;
    }
    int main() {
        int n,A,B,C,D;
        cin>>n>>A>>B>>C>>D,--n;
        long long L=A+1LL*n*C,R=A+1LL*n*D;
        for(int i=0;i<=n;i++) {
    	if(L<=B&&B<=R) return puts("YES"),0;
    	L-=C+D,R-=C+D;
        }
        puts("NO");
        return 0;
    }

Measured memory_bytes: 256
;;;; union find tree
(defpackage :union-find-tree
  (:nicknames :uft)
  (:use :cl)
  (:shadow :find :union :set)
  (:export :make :find :union :same))
(in-package :union-find-tree)

(defun make (n)
  (let ((parent (make-array (list (1+ n))))
        (rank (make-array (list (1+ n)))))
    (loop :for i :from 0 :to n
          :do (setf (aref parent i) i))
    (cons parent rank)))

(defun parent (uft x)
  (aref (car uft) x))

(defun set (uft x r)
  (setf (aref (car uft) x) r))

(defun rank (uft x)
  (aref (cdr uft) x))

(defun rank-up (uft x)
  (incf (aref (cdr uft) x)))

(defun find (uft x)
  (loop :with (p . stack) := '(nil . nil)
        :while (/= (parent uft x) x)
        :do (push x stack)
        :do (setf x (parent uft x))
        :finally (return (prog1 (setf p x)
                           (loop :for y :in stack
                                 :do (set uft y p))))))

(defun union (uft x y)
  (let* ((x-root (find uft x))
         (y-root (find uft y))
         (x-rank (rank uft x-root))
         (y-rank (rank uft y-root)))
    (cond ((< y-rank x-rank)
           (set uft y-root x-root))
          ((< x-rank y-rank)
           (set uft x-root y-root))
          ((/= x-root y-root)
           (set uft y-root x-root)
           (rank-up uft x-root)))))

(defun same (uft x y)
  (= (find uft x) (find uft y)))

(in-package :cl-user)

;;;; main
(let* ((n (read))
       (m (read))
       (uft (uft:make n)))
  (loop :for _ :from 1 :to m
        :for a := (read)
        :for b := (read)
        :do (uft:union uft a b))
  (loop :with cnt := 0
        :for i :from 1 :to n
        :if (= (uft:find uft i) i)
        :do (incf cnt)
        :finally (format t "~A~%" (1- cnt))))


Measured memory_bytes: 78796
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    int x;
    vector<int> k(m);
    vector<vector<int>> s(m,vector<int>(0));
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            cin>>x;
            x --;
            s[i].emplace_back(x);
        }
    }
    vector<int> p(m,0);
    rep(i,m) cin>>p.at(i);
    int ans=0;

    for(int tmp = 0;tmp< (1<<n); tmp++){
        bitset<10> y(tmp);
        bool flag=true;
        rep(i,m){
            int cnt=0;
            rep(j,k[i]){
                if(y.test(s[i][j])) cnt ++;
            }
            if(cnt%2!=p[i]){
                flag=0;
                break;
            }
        }
        if(flag) ans ++;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]
ans=True
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            ans=False
            for k in range(4):
                nx = i+dx[k]
                ny = j+dy[k]
                if nx>=0 and nx <h and ny>=0 and ny<w and s[nx][ny]=='#':
                    ans = True
                    break
            if ans ==False:
                print('No')
                exit()
if ans:
    print('Yes')
            
                

Measured memory_bytes: 3064
o = input()
e = input()
n = len(o)
m = len(e)
st = [0]*(n+m)
for i in range(0,n):
  try:
    st[i*2]=o[i]
  except:
    pass
  try:
    st[i*2+1]=e[i]
  except:
    pass
string = "".join(map(str,st)) 
print(string)

Measured memory_bytes: 3064
import java.util.*;

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

    int n = sc.nextInt();
    int[] x = new int[n];
    double sum = 0;
    double ave;
    int ans = 0;

    for(int i = 0; i < n; i++){
      x[i] = sc.nextInt();
      sum += x[i];
    }

    ave = sum / n;

    if(ave - Math.floor(ave) < 0.5){
      for(int i = 0; i < n; i++){
        ans += (x[i] - Math.floor(ave)) * (x[i] - Math.floor(ave));
      }
    } else {
      for(int i = 0; i < n; i++){
        ans += (x[i] - Math.ceil(ave)) * (x[i] - Math.ceil(ave));
      }
    }

    System.out.println(ans);
  }
}


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s, n) s, s + n
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define pii pair <int, int>
#define pll pair <ll, ll>
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
using namespace std;

int n, z, ans;
string s;
int main () {
	IOS;
	
	cin >> n >> s;
	while (true) {
		int x;
		x = s.find("ABC", z);
		if (x >= 0 && x < n) {
			z = x + 2; ans++;
		} else {
			break;
		}
	}
	cout << ans << '\n';
	return 0; 
}


Measured memory_bytes: 256
#pragma GCC optimze("Ofast")

#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define vp(x,y) vector< pair<x,y> >
#define mp make_pair
#define all(x) x.begin(),x.end()
#define Sort(x) sort(all(x));
#define DSort(x) sort(all(x), greater<>());
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define l_b lower_bound
#define u_b upper_bound
#define u_set unordered_set
#define u_map unordered_map
#define ff first
#define sc second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)

const ll M=1e9+7;
const ld PI=3.14159265;

using namespace std;

int main(){
    fast_io;
    ll t,x,k,d,y;
    t=1;
    while(t--){
        cin>>x>>k>>d;
        x=abs(x);
        if((x/d)>=k){
            x-=(k*d);
            cout<<x;
        }
        else{
            y=x/d;
            x-=(y*d);
            k-=(y);
            if(k%2==0) cout<<x;
            else cout<<min(abs(x-d),abs(x+d));
        }
    }
}




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

int main() {
	while (true) {
		string s;
		int m, h;
		int sum = 0;
		cin >> s;
		if (s == "-")break;
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			sum += h;
		}
		int num = sum % s.size();

		string s2 = s.substr(0, num);
		s.erase(0, num);
		s = s + s2;

		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
a=list(input().strip())
for i in range(len(a)):
  if i >=1:
    if a[i]==a[i-1]:
      print(i,i+1)
      break
  if i>=2:
    if a[i]==a[i-2]:
      print(i-1,i+1)
      break
else:
  print(-1,-1)
      

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

int main() {
  //int n, m;
  string S;
  cin >> S;
  //int ans = 0;

  if (S.substr(2,1) == S.substr(3,1) && S.substr(4,1) == S.substr(5,1)) {
      cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }
  //ans += n*(n-1)/2;
  //ans += m*(m-1)/2;
  //cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

typedef long long ll;
using namespace std;

int main(){
    int n = 0;
    cin >> n;
    vector<ll> a(n); 
    rep(i, n) cin >> a[i];

    ll ans = 0;
    for(int i = 1; i < n; ++i){
        if(a[i] < a[i-1]){
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4764
#include <stdio.h>
#include <iostream>

using namespace std;

    int main(){
    int n;
    cin >> n;
    int problems[n+5];
    int sum = 0;

    for (int i=1; i<=n; i++){
        cin >> problems[i];
        sum += problems[i];
    }

    int m;
    cin >> m;
    int drinks[m+5];
    int times[m+5];

    for (int i=1; i<=m; i++){
        cin >> drinks[i] >> times[i];
    }

    for (int i=1; i<=m; i++){
        int ans = sum;
        ans -= problems[drinks[i]];
        ans += times[i];
        printf("%d\n", ans);
    }

}


Measured memory_bytes: 3656