akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

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

    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

    vector<int> dp(n+1);
    {
        dp[n]=n;
        dp[n-1]=n-1;
        map<int,int> nex;
        nex[a[n-1]]=n-1;
        for(int i=n-2;i>=0;i--){
            if(nex.count(a[i])) dp[i]=dp[nex[a[i]]+1];
            else dp[i]=i;
            nex[a[i]]=i;
            
        }
    }
    map<int,int> mp;
    for(int i=n-1;i>=0;i--) mp[a[i]]=i;
    vector<int> p(n+1);
    p[n]=dp[0];
    for(int i=0;i<n;i++){
        int id=mp[a[i]];
        p[i]=dp[id+1];
        // cerr<<p[i]<<endl;
    }

    vector<int> pre;
    vector<int> loop;
    {   
        set<int> s;
        int v=dp[0];
        // cerr<<dp[0]<<endl;
        while(true){
            s.insert(v);
            pre.push_back(v);
            v=p[v];
            if(s.count(v)) break;
        }
        int id=find(pre.begin(),pre.end(),v)-pre.begin();
        for(int i=id;i<pre.size();i++) loop.push_back(pre[i]);
    }
    // for(int i=0;i<pre.size();i++) cerr<<pre[i]<<" ";
    // cerr<<"#"<<endl;
    int beg=(k-1<=pre.size() ? pre[k-1] : loop[(k-1-pre.size())%loop.size()]);

    // cerr<<beg<<endl;
    // cerr<<"#"<<endl;
    map<int,int> cnt;
    vector<int> res;
    for(int i=beg;i<n;i++){
        if(cnt[a[i]]){
            while(cnt[a[i]]){
                assert(res.size());
                cnt[res.back()]--;
                res.pop_back();
            }
        }
        else{
            cnt[a[i]]++;
            res.push_back(a[i]);
        }
    }
    // cerr<<"#"<<endl;
    for(int i=0;i<res.size();i++){
        cout<<res[i]<<(i+1==n ? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 25692
#include<stdio.h>

#define M 10000
#define N -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[M];
int n,D[M],H[M];

void setDepth(int u,int d){
  if( u == N )
    return;
  D[u]=d;
  setDepth( T[u].left,d+1 );
  setDepth( T[u].right,d+1 );
}

int setHeight(int u){
  int h1=0;
  int h2=0;

  if( T[u].left != N )
    h1=setHeight(T[u].left)+1;

  if( T[u].right != N )
    h2=setHeight(T[u].right)+1;

  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if( T[u].parent == N )
    return N;

  if( T[T[u].parent].left !=
      u && T[T[u].parent].left != N )
    return T[T[u].parent].left;

  if( T[T[u].parent].right !=
      u && T[T[u].parent].right != N )
    return T[T[u].parent].right;

  return N;
}

void p(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));

  int deg=0;

  if( T[u].left != N )
    deg++;

  if( T[u].right != N )
    deg++;

  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if( T[u].parent == N ){
    printf("root\n");
  }
  else if( T[u].left == N && T[u].right == N ){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0;

  scanf("%d",&n);

  for( int i=0; i<n; i++ )
    T[i].parent = N;

  for( int i=0; i<n; i++ ){
    scanf("%d %d %d",&v,&l,&r);

    T[v].left=l;
    T[v].right=r;

    if( l != N )
      T[l].parent = v;

    if( r != N)
      T[r].parent = v;
  }

  for( int i=0; i<n; i++ )
    if( T[i].parent == N )
      root=i;

  setDepth(root,0);
  setHeight(root);

  for( int i=0; i<n; i++ )
    p(i);

  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main(){
  cout << setprecision(10);
  string S;
  cin >> S;
  string ret="Yes";
  for(int i=0; i<S.size(); i++){
    if(i%2==0 && S[i]=='L') ret="No";
    if(i%2==1 && S[i]=='R') ret="No";
  }
  cout << ret << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

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

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    mat X(N), Y(N);
    REP(i,0,N) {
        cin >> A[i];
        REP(j,0,A[i]) {
            ll x, y;
            cin >> x >> y;
            X[i].pb(x-1); Y[i].pb(y);
        }
    }

    ll m = 0;
    vec F(N);
    REP(b,0,1<<N) {
        REP(i,0,N) F[i] = ((b >> i) & 1);
        ll c = 0;
        bool f = true;
        REP(i,0,N) {
            if(F[i]) {
                REP(j,0,A[i]) {
                    if(F[X[i][j]] != Y[i][j]) f = false;
                }
            }
        }
        if(f) {
            REP(i,0,N) c += F[i];
        }
        m = MAX(m,c);
    }

    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 3636
import java.io.*;
public class Main {

	public static void main(String[] args)throws IOException{
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		
		String[] text=str.split(" ");
		int a=Integer.parseInt(text[0]);
		String b=text[1];
		int c=Integer.parseInt(text[2]);
		
		while (b.equals("?") == false){
				if(b.equals("+")){
				System.out.println(a+c);
			}else if(b.equals("-")){
				System.out.println(a-c);
			}else if(b.equals("*")){
				System.out.println(a*c);
			}else if(b.equals("/")){
				System.out.println(a/c);
			}
			str=br.readLine();
			text=str.split(" ");
			a=Integer.parseInt(text[0]);
			b=text[1];
			c=Integer.parseInt(text[2]);
		}
	}
}

Measured memory_bytes: 17104
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> num[202020];
int a[202020],b[202020];
bool de[202020],dp[202020];
char s[202020];
int d[202020][2];
int cnt=0,n,m;
void del_p(int p);
void del_e(int e);
void del_e(int i)
{
	if(de[i])
		return;
	de[i]=true;
	d[a[i]][s[b[i]]-'A']--;
	d[b[i]][s[a[i]]-'A']--;
	if(d[a[i]][s[b[i]]-'A']==0)
		del_p(a[i]);
	if(d[b[i]][s[a[i]]-'A']==0)
		del_p(b[i]);
}
void del_p(int p)
{
	if(dp[p])
		return;
	dp[p]=true;
	cnt++;
	for(int i=0;i<num[p].size();i++)
		del_e(num[p][i]);
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	memset(d,0,sizeof(d));
	for(int i=1;i<=n;i++)
		num[i].clear();
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		d[a[i]][s[b[i]]-'A']++;
		d[b[i]][s[a[i]]-'A']++;
		num[a[i]].push_back(i);
		num[b[i]].push_back(i);
	}
	memset(de,0,sizeof(de));
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
		if(d[i][0]==0||d[i][1]==0)
			del_p(i);
	if(n==cnt)
		printf("No");
	else
		printf("Yes");
	return 0;
}

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

int root(vector<int> &r, int a)
{
    if (r[a] == a) return a;
    else return r[a] = root(r, r[a]);
}

int main()
{
    long long N, K, L;
    scanf("%lld%lld%lld", &N, &K, &L);
    vector<int> road, rail;
    for (int i = 0; i <= N; i++) {
        road.push_back(i);
        rail.push_back(i);
    }
    for (int i = 1; i <= K; i++) {
        int p, q;
        scanf("%d%d", &p, &q);
        road[root(road, p)] = root(road, q);
    }
    for (int i = 1; i <= L; i++) {
        int r, s;
        scanf("%d%d", &r, &s);
        rail[root(rail, r)] = root(rail, s);
    }
    map<pair<int, int>, int> mp;
    for (int i = 1; i <= N; i++) {
        mp[make_pair(root(road, i), root(rail, i))]++;
    }
    for (int i = 1; i <= N; i++) {
        printf("%d ", mp[make_pair(root(road, i), root(rail, i))]);
    }
    printf("\n");
}

Measured memory_bytes: 13548
#include <iostream>

using namespace std;

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

	if (S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I' && S.length() >= 4) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}




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

#define DEBUG if(0)
#define lli long long int
const int maxN = 1e5 + 1, INF = 1e9 + 5;
int cost[maxN], n;

int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &cost[i]);
  vector<int> dp(n, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j : {i + 1, i + 2})
      if (j < n)
        dp[j] = min(dp[j], dp[i] + abs(cost[i] - cost[j]));
  printf("%d\n", dp[n - 1]);      
  return 0;
}

Measured memory_bytes: 1024
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_076_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 R      PIC S9(4).
    01 G      PIC 9(4).
    01 ZS     PIC -(5)9.
    01 ans    PIC X(5).

    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT R.
    ACCEPT G.

    SUBTRACT R FROM G GIVING R.

    ADD G TO R.

    MOVE R TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 636
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	double r;
	cin >> r;
	cout << fixed << setprecision(6);
	cout << r * r * acos(-1) << " " << 2 * r * acos(-1) << endl;

	return 0;
}


Measured memory_bytes: 3280
import collections
import sys
input = sys.stdin.readline
import heapq
from array import array
def solve():
  n = int(input())

  query2 = collections.deque([])
  edge = [[] for _ in range(n)]
  ans = array('I', [ 0 for i in range(n)])
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    query2.append(a)
    query2.append(b)
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
  c = list(int(i) for i in input().split())
  if n == 1:
    print(1)
    print(c[0])
    exit()
  c = collections.deque(sorted(c,reverse =True))
  d = collections.Counter(query2)
  d2 = d.most_common()
  bfs = []
  heapq.heappush(bfs,(-1*d2[0][1],d2[0][0]-1,-1))#回数,場所、親
  ct = 0
  visit = [False]*n
  while bfs:
    times,place,parent = heapq.heappop(bfs)
    if visit[place]:
      continue
    else:
      visit[place] = True

      for i in range(len(edge[place])):
        newp = edge[place][i]
        newtimes = len(edge[newp])
        if not visit[newp]:
          heapq.heappush(bfs,(-1*newtimes,newp,place))
      #print(place,parent,times)
      ans[place] = c.popleft()

      #print(c,place)

  print(sum(ans)-max(ans))
  print(*ans)
  
solve()


Measured memory_bytes: 8528
while True:
    a = input()
    if(a == "#"):
        break
    g,y,m,d = map(lambda x:x,a.split(" "))
    if(int(y) <=30):
        print(g,y,m,d)
    elif(int(y) <= 31 and int(m) <= 4 and int(d) <= 30):
        print(g,y,m,d)
    else:
        print("?",int(y)-30,m,d)


Measured memory_bytes: 5600
N = int(input())
A = list(int(input()) for i in range(N))
B = []
count = 0
maxA = max(A)
for i in A:
  if i == maxA:
    count += 1
  else:
    B.append(i)

if B != []:
  maxB = max(B)

if count > 1:
  for i in range(N):
    print(maxA)
else:
  for i in range(N):
    if A[i] == maxA:
      print(maxB)
    else:
      print(maxA)

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

const int N = 2e5 + 10;
typedef long long ll;
ll n, k, h[N], tot, sum;

int main() {
    cin >> n >> k;
    rep(i, 1, n) scanf("%lld", &h[i]), tot += h[i];
    sort(h + 1, h + n + 1);
    if (n <= k) puts("0");
    else {
        for (int i = n; i >= n - k + 1; i--) sum += h[i];
        printf("%lld\n", tot - sum);
    }
    return 0;
}


Measured memory_bytes: 1792
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, M = sc.nextInt()
    val ans = if (abs(N - M) == 0) {
      2L * permMod(N, N, MOD) * permMod(M, M, MOD) % MOD
    } else if (abs(N - M) == 1) {
      permMod(N, N, MOD).toLong * permMod(M, M, MOD) % MOD
    } else 0

    out.println(ans)
  }

  def permMod(n: Int, k: Int, m: Int): Int = {
    def step(n: Long, k: Long, v: Long): Long = {
      if (k == 0) v
      else step(n - 1, k - 1, n * v % m)
    }
    step(n, k, 1).toInt
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 27436
import copy

def bubble_sort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]

def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i+1, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]

def is_stable(in0, out0):
    for m in '123456789':
        in1 = list(filter(lambda e:e[1]==m, in0))
        out1 = list(filter(lambda e:e[1]==m, out0))
        #print(in1,out1)
        if in1 != out1:
            return 'Not stable'
    return 'Stable'

N = int(input())
C = list(input().split())
C1 = copy.deepcopy(C)
C2 = copy.deepcopy(C)
bubble_sort(C1, N)
selection_sort(C2, N)
print(*C1)
print(is_stable(C, C1))
print(*C2)
print(is_stable(C, C2))



Measured memory_bytes: 6344
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		Obj[] arr = new Obj[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.a = Integer.parseInt(sa[0]);
			o.b = Integer.parseInt(sa[1]);
			arr[i] = o;
		}
		br.close();

		Arrays.parallelSort(arr, new Comparator<Obj>() {
			public int compare(Obj o1, Obj o2) {
				return o1.a - o2.a;
			}
		});

		PriorityQueue<Obj> pq = new PriorityQueue<>(new Comparator<Obj>() {
			public int compare(Obj o1, Obj o2) {
				return o2.b - o1.b;
			}
		});

		int ans = 0;
		int j = 0;
		for (int i = 1; i <= m; i++) {
			for ( ; j < n; j++) {
				if (arr[j].a > i) {
					break;
				}
				pq.add(arr[j]);
			}
			Obj o = pq.poll();
			if (o != null) {
				ans += o.b;
			}
		}
		System.out.println(ans);
	}

	static class Obj {
		int a, b;
	}
}


Measured memory_bytes: 47916
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   int n,m;
   cin>>n>>m;
   int a[m][2];
   rep(i,m){
       cin>>a[i][0]>>a[i][1];
       a[i][0]--;a[i][1]--;
   }
   bool ok[n];
   rep(i,n)ok[i]=true;
   vector<int> must[m][2];
   rep(i,n){
       bool used[n];
       rep(j,n)used[j]=false;
       used[i]=true;
       for(int j=m-1;j>=0;j--){
           if(used[a[j][0]]&&used[a[j][1]]){
               ok[i]=false;
               break;
           }
           if(used[a[j][0]]){
               used[a[j][1]]=true;
               must[j][1].push_back(i);
           }
           if(used[a[j][1]]){
               used[a[j][0]]=true;
               must[j][0].push_back(i);
           }
       }
   }
   bool check[n][n];
   rep(i,n)rep(j,n)check[i][j]=true;
   rep(i,m){
       for(auto x:must[i][0])for(auto y:must[i][1])
       check[x][y]=check[y][x]=false;
   }
   int ans=0;
   rep(i,n)REP(j,i+1,n){
       if(ok[i]&&ok[j]&&check[i][j])ans++;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 6016
# 入力
a, b, c, d = map(int,input().split())

# 処理

if abs(a-b) <= d and abs(b-c) <= d: #abs():絶対値を示す関数
    answer = 'Yes'
elif abs(a-c) <= d:
    answer = 'Yes'
else:
    answer = 'No'

# 出力
print(answer)

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

int main(){
  char s[4];
  int a[26]={0},b=0;
  string ans="Yes";
  for(int i=0;i<4;i++){
    cin>>s[i];
    a[s[i]-'A']++;
  }
  for(int i=0;i<26;i++){
    if(a[i]>2)ans="No";
    if(a[i])b++;
  }
  if(b>2)ans="No";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
S=input()

ans,cnt,rank=[],0,0
for s in S:
  if s=='a':
    if a+b>cnt:
      ans.append('Yes')
      cnt+=1
    else:
      ans.append('No')
  elif s=='b':
    rank+=1
    if a+b>cnt and rank<=b:
      ans.append('Yes')
      cnt+=1
    else:
      ans.append('No')
  else:
    ans.append('No')
print(*ans,sep='\n')

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

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N, 0), dist(N + 1, 0);
    cin >> A[0];
    dist[0] = abs(A[0]);
    ll total = dist[0];
    for (int i = 1; i < N; i++)
    {
        cin >> A[i];
        dist[i] = abs(A[i] - A[i - 1]);
        total += dist[i];
    }
    dist[N] = abs(A[N - 1]);
    total += dist[N];
    for (int i = 0; i < N; i++)
    {
        ll ans = total;
        ans -= (dist[i + 1] + dist[i]);
        if (i == 0)
        {
            ans += abs(A[i + 1]);
        }
        else if (i == N - 1)
        {
            ans += abs(A[N - 2]);
        }
        else
        {
            ans += abs(A[i - 1] - A[i + 1]);
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
  ll x;
  cin >> x;
  ll ans=(x/11)*2;
  if(x%11 == 0){
  }else if(x%11 > 6){
    ans += 2;
  }else if(x%11 <= 6){
    ans++;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
/*input
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=105;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int edge[maxn][maxn];

int main(){
	IOS;
	int n,m;
	cin>>n>>m;
	REP(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		edge[u][v]=edge[v][u]=1;
	}

	vector<int> v;
	REP(i,n) v.pb(i);
	int cnt=0;
	do{
		bool flag = 1;
		REP(i,SZ(v)-1){
			if(edge[v[i]][v[i+1]]==0) flag=0;
		}
		if(flag&&v[0]==0) cnt++;
	}while(next_permutation(ALL(v)));
	cout<<cnt<<'\n';
	return 0;
}


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

using namespace std;

using ll = long long;

int main(){
    string s, s1;
    cin >> s >> s1;
    ll arr[150] = {0}, arr1[150] = {0};
    vector<ll>prvi, drugi;
    for(ll i = 0; i < s.length(); ++i){
        prvi.push_back(arr[s[i]] + 1);
        arr[s[i]]++;
        drugi.push_back(arr1[s1[i]] + 1);
        arr1[s1[i]]++;
    }
    if(prvi == drugi)cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3956
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

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

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, Q;
string s;
P p[100000];
int n[100000];

void solve()
{
    REP(i, N-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            n[i+1] = n[i] + 1;
        }else{
            n[i+1] = n[i];
        }
    }

    REP(i, Q){
        //cout << n[p[i].se] - (p[i].fi-1 >= 0 ? n[p[i].fi-1] : 0) << endl;
        cout << n[p[i].se] - (p[i].fi >= 0 ? n[p[i].fi] : 0) << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Q >> s;
    REP(i, Q){
        cin >> p[i].fi >> p[i].se;
        p[i].fi--;
        p[i].se--;
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

int main() {
	//101とか011などの文字列が入力される
	int s;
  	cin >> s;
  	int s1 = s / 100 % 10,
  		s2 = s / 10 % 10,
  		s3 = s / 1 % 10;
  	cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    ll k;cin >> k;
    int n;cin >> n;
    vl a(n);
    rep(i,n)cin >> a[i];
    ll mx = 0;
    rep(i,n-1){
        chmax(mx,a[i+1]-a[i]);
    }
    chmax(mx,a[0] + (k - a[n-1]));
    cout << k - mx << '\n';
    return 0;
}
/*
 *!!CHECK!! 
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */


Measured memory_bytes: 1792
n = gets.to_i
w = gets.chomp.split
sum_1 = 0
(n+1).times do |i|
    w[i] = w[i].to_i
    sum_1 += w[i]
end

diffs = []
sum_2 = 0
(n+1).times do |i|
    sum_1 -= w[i]
    sum_2 += w[i]
    diffs << (sum_1 - sum_2).abs
end

puts diffs.min

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

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  FOR(i, 1, n + 1) mp[i] = n - i;
  int p = n;
  REP(i, m) {
    int e;
    cin >> e;
    mp[e] = p++;
  }
  vector<P> ans;
  for (auto x : mp) {
    ans.push_back({x.second, x.first});
  }
  sort(rbegin(ans), rend(ans));
  for (auto x : ans) cout << x.second << endl;
}



Measured memory_bytes: 14284
#include<bits/stdc++.h>
using namespace std;
const int N=25;
int b[N],a[N],n,m,c,ans=0;
int main()
{
	cin>>n>>m>>c;
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<n;i++)
	{
		int sum=c;
		for(int j=0;j<m;j++)
		{
			cin>>a[j];
			sum+=a[j]*b[j];
		}
		if(sum>0)ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <cmath>
#include <string.h>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_nested(i, s, n) for (int i = s; i <= n; i++)
#define ll long long
#define ull unsigned long long

const int N = 500;
const ll INF = 1000000007;

using namespace std;

template <class T>
T limit(T n, T k) {
	return (n > k) ? k : n;
}
int cal_time_steps();

int main() {
	cout << cal_time_steps() << endl;
    return 0;
}

int cal_time_steps() {
	int n, m, k;
	
	cin >> n >> m;
	
	vector<ull> v(n + 1, 0);
	vector<bool> a(n + 1, true);
	
	rep(i, n) {
		cin >> k;
		a[k] = false;
	}
	
	v[0] = 1;
	
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= limit(n, i + 2); j++) {
			if (a[j]) {
				v[j] += v[i];
				v[j] %= INF;
			}
		}
	}
	
	return v[n];
}

Measured memory_bytes: 1024
import numpy as np
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

time_array = np.array([A, B, C, D, E])
ten_array = np.ceil(time_array / 10)

tentimes_array = ten_array * 10
sum_time = int(sum(tentimes_array)) 
dif_array = tentimes_array - time_array
max_dif = int(max(dif_array))

print(sum_time - max_dif)


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

int main(){
	int n,l,*ice,buf,prog,over,h=0,sz;
	queue<int> q;
	
	cin >> n >> l;
	
	ice = new int[n+2];
	ice[0] = ice[n+1] = 0;
	for(int i = 1; i < n+1; i++){
		cin >> ice[i];
	}
	
	for(int i = 1; i < n+1; i++){
		if(ice[i]){
			if((ice[i] > ice[i-1]) && (ice[i] > ice[i+1])){
				q.push(i);
			}
		}
	}
	
	while(1){
		buf = q.front();
		prog = (l - ice[buf]) > 0?(l - ice[buf]):0;
		
		sz = q.size();
		for(int i = 0; i < sz; i++){
			buf = q.front();
			q.pop();
			
			ice[buf] += prog;
			over = (ice[buf] - l) >= 0?(ice[buf] - l):-1;
			if(over != -1){
				ice[buf] = 0;
				if(ice[buf-1] > ice[buf-2]){
					ice[buf-1] += over;
					q.push(buf-1);
				}
				if(ice[buf+1] > ice[buf+2]){
					ice[buf+1] += over;
					q.push(buf+1);
				}
			}else{
				q.push(buf);
			}
		}
		h += prog;
		
		if(q.empty()){
			break;
		}
	}
	
	cout << h << endl;
	
	return 0;
}

Measured memory_bytes: 1416
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

int main() {
	string s;
	vector<string> ans;
	int k;
	cin >> s >> k;

	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < s.size(); j++) {
			ans.push_back(s.substr(j, i));
		}
	}

	sort(ans.begin(), ans.end());
	unique(ans.begin(), ans.end());
	
	cout << ans[k - 1] << endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

int lbidx(vector<int> x, int y) {
  auto itr = lower_bound(x.begin(), x.end(), y);
  int idx = itr - x.begin();
  return idx;
};

int upidx(vector<int> x, int y) {
  auto itr = upper_bound(x.begin(), x.end(), y);
  int idx = itr - x.begin();
  return idx;
}

ll n,q;
ll s[200100],t[200100],x[200100];
ll d[200100];
struct road {
	ll sx;
	ll add;
	ll dis;
	road(ll _sx,ll _add,ll _dis){
		sx = _sx;
		add = _add;
		dis = _dis;
	}
	bool operator < (road &r2){
		if (sx != r2.sx){
			return sx < r2.sx;
		} else {
			return add < r2.add;
		}
	}
};
vector<road> rr;
ll ans[200100];
int main(){
	cin >> n >> q;
	rep(i, 0, n) cin >> s[i] >> t[i] >> x[i];
	rep(i, 0, q) cin >> d[i];
	rep(i, 0, n) {
		rr.pb(road(s[i]-x[i],1,x[i]));
		rr.pb(road(t[i]-x[i],-1,x[i]));
	}
	sort(All(rr));

	set<ll> T;
  int t = 0;
	rep(i, 0, q){
		// rep(t, 0, rr.size()) {
    //   if (rr[t].sx > d[i]) break;
		// 	//cout<<i<<" "<<t<<endl;
		// 	if (rr[t].add == 1) {
		// 		T.insert(rr[t].dis);
		// 	} else {
		// 		T.erase(rr[t].dis);
		// 	}
		// 	//cout<<t1.size()<<endl;
		// 	//cout<<i<<" "<<t<<endl;
		// }
    while(t < rr.size() && rr[t].sx <= d[i]) {
      if (rr[t].add == 1) {
        T.insert(rr[t].dis);
      } else {
        T.erase(rr[t].dis);
      }
      t++;
    }
		if(T.empty()) cout << -1 << endl;
		else cout<<*T.begin()<<endl;
	}
	//REP(i,q)cout<<ans[i]<<endl;
	return 0;
}


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

int bubbleSort(int A[], int N) {
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag; i++) {
        flag = 0;
        for(int j = N - 1; j >= i + 1; j--) {
            if(A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

// int bubbleSort(int A[], int N) {
//     int sw = 0;
//     bool flag = 1;
//     for(int i = 0; flag; i++) {
//         flag = 0;
//         for(int j = N - 1; j >= i + 1; j--) {
//             if(A[j] > A[j - 1]) {
//                 swap(A[j], A[j - 1]);
//                 sw++;
//                 flag = 1;
//             }
//         }
//     }
//     return sw;
// }


int main() {
    int A[100], N, sw;

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

    sw = bubbleSort(A, N);

    for(int i = 0; i < N; i++) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  char W = 'a';
  int X = 0, Y = 0, Z = 0;

  while (X <= A.size() && Y <= B.size() && Z <= C.size()) {
    if (W == 'a') {
      if (X == A.size()) W = 'A';
      else W = A.at(X);
      X++;
    }
    if (W == 'b') {
      if (Y == B.size()) W = 'B';
      else W = B.at(Y);
      Y++;
    }
    if (W == 'c') {
      if (Z == C.size()) W = 'C';
      else W = C.at(Z);
      Z++;
    }
  }

  cout << W << endl;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  int sum=0;
  while(M-->0){
   	int A;
    cin >> A;
    sum+=A;
  }
  
  int ans=N-sum;
  if(ans<0)ans=-1;
  cout << ans << endl;
}

Measured memory_bytes: 3644
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        x: usize,
        y: usize,
    }

    fn distance(p: usize, q: usize) -> usize {
        ((p as isize) - (q as isize)).abs() as usize
    }

    let mut d = vec![0; n];
    for i in 1..n {
        for j in i + 1..=n {
            let d0 = j - i; // XYを通らない場合
            let d1 = distance(i, x) + distance(y, j) + 1; // XYを通る場合
            d[min(d0, d1)] += 1;
        }
    }
    for i in 1..n {
        println!("{}", d[i]);
    }
}


Measured memory_bytes: 2116
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int a,b;
bool judge(int a)
{
	for(int i=1;i<=9;i++)
	{
		if(a%i==0&&a/i<=9) return true;
	}
	return false;
}

int main()
{
	scanf("%d",&a);
	if(judge(a)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
if a == b:
    print(0)
elif (a % 2 == 1 and b % 2 == 0) or (a % 2 == 0 and b % 2 == 1):
    print("IMPOSSIBLE")
else:
    k = (a + b) // 2
    print(k)
    

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

using namespace std;

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl

const int maxn = (int)3e5+5;
typedef long long ll;

void solve()
{
    ll n;
    cin >> n;
    string ans = "";
    while (n!=0){
        --n;
        ans += (char)('a' + n % 26);
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main()
{
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //cout << "Fi Amanillah" << endl;


    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define MAX_N 100010



int main()
{
  int N,W;cin>>N>>W;
  vector<ll> w(N+1);
  vector<ll> v(N+1);
  
  for (ll i=1;i<=N;i++)
   cin>>w[i]>>v[i];
  
  //dp[i][w]=i個までで重さの総和がw以下の価値
  vector<vector<ll>> dp(N+1,vector<ll>(W+1));
  
  //初期条件
  for (int j=0;j<=W;j++)
    dp[0][j]=0; 
  
  for (int i=1;i<=N;i++)
  {
    for (int j=1;j<=W;j++)
    {
      //i番目の品物をもらうかどうか
      if (j-w[i]>=0)
      {
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
      }
      
      //i番目を選ばないとき
      dp[i][j] = max(dp[i][j],dp[i-1][j]);
    }
  }
  
  cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 80256
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 200000;

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

	int ans = 0;
	ans += a < b ? a : b;
	ans += c < d ? c : d;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n = int(input())
arr = [int(i) for i in input().split()]
sm = sum(abs(i) for i in arr)
mn = min(abs(i) for i in arr)
nc = sum(i < 0 for i in arr)
if nc % 2 == 0: print(str(sm))
else: print(str(sm - 2 * mn))


Measured memory_bytes: 60272
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int MAXN = 1001;

int n;
int used[MAXN], ind[MAXN], t[MAXN][MAXN], a[MAXN][MAXN];
bool ok = 1;

void sim(int v) {
    if (!ok || used[v] == 1) {
        ok = 0;
        return;
    }
    used[v] = 1;
    int u = a[v][ind[v]];
    while (ok && a[u][ind[u]] != v) {
        sim(u);
    }
    int nw = 1;
    if (ind[u]) nw = max(nw, t[u][ind[u] - 1] + 1);
    if (ind[v]) nw = max(nw, t[v][ind[v] - 1] + 1);
    t[v][ind[v]] = t[u][ind[u]] = nw;
    ind[v]++, ind[u]++;
    used[v] = 0;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            if (t[i][j] == 0) sim(i);
            ans = max(ans, t[i][j]);
        }
    }
    if (!ok) {
        cout << -1;
        return 0;
    }
    cout << ans;
}
/*

*/


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

int main()
{
    int a, b, k;
    scanf("%d %d %d", &a, &b, &k);
    int ans = a>b?b:a;
    while(k--){
        while(a%ans!=0 || b%ans!=0)
            ans--;
        //printf("%d %d\n", k, ans);
        ans--;
    }
    ans++;
    printf("%d\n", ans);
    return 0;
}


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



vector<int> process(vector<int> a) {
    vector<int> res;
    for (int i = 0; i + 1 < a.size(); ++i) {
        res.push_back(abs(a[i] - a[i+1]));
    }
    return res;
}

int naive(string S) {
    vector<int> a;
    for (int i = 0; i + 1 < S.size(); ++i) {
        int x = S[i] - '0';
        int y = S[i+1] - '0';
        a.push_back(abs(x - y));
    }
    while (a.size() > 1) a = process(a);
    return a[0];
}

const int MAX = 1100000;
vector<long long> cnt;
void pre() {
    cnt.assign(MAX, 0);
    for (int i = 1; i < MAX; ++i) {
        int j = i;
        int add = 0;
        while (j % 2 == 0) ++add, j /= 2;
        cnt[i] = cnt[i-1] + add;
    }
}

int N;
string S;

int solve() {
    vector<int> a;
    for (int i = 0; i + 1 < N; ++i) {
        int x = S[i] - '0';
        int y = S[i+1] - '0';
        a.push_back(abs(x - y));
    }

    if (a.size() == 1) return a[0];
    N = (int)a.size() - 1;
    long long parity = 0;
    for (int i = 0; i < a.size(); ++i) {
        long long ex = cnt[N] - cnt[i] - cnt[N-i];
        if (ex > 0) continue;
        parity += a[i];
    }

    if (parity % 2 == 1) return 1;
    else {
        bool exist_one = false;
        for (int i = 0; i < a.size(); ++i) {
            if (a[i] == 1) exist_one = true;
        }
        if (exist_one) return 0;
        else {
            parity = 0;
            for (int i = 0; i < a.size(); ++i) {
                long long ex = cnt[N] - cnt[i] - cnt[N-i];
                if (ex > 0) continue;
                parity += a[i] / 2;
            }
            if (parity % 2 == 1) return 2;
            else return 0;
        }
    }
}

int main() {
    pre();
    while (cin >> N >> S) {
        N = S.size();
        cout << solve() << endl;
    }
}

















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

int main(void){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int w = 0, r=0;
	int p[N]; //W:0, R:1
	rep(i,N) {
		if (S[i] == 'W') {
			w++;
			p[i] = 0;
		}
		else {
			r++;
			p[i] = 1;
		}
	}
	int ans = min(w,r);
	if (ans==0) {
		cout << ans << endl;
		return 0;
	}

	int k = 0;
	int lw = 0, rr = N-1;
	while (1){
		while (lw < N){
			if (p[lw] == 0) break;
			lw++;
		}

		while (rr>=0){
			if (p[rr] == 1) break;
			rr--;	
		}

		if (rr < lw) break;	

		p[lw] = 1; p[rr] = 0;
		k++;
	}	

	ans = min(ans,k);
	cout << ans << endl;
	
return 0;
}


Measured memory_bytes: 4496
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class C {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N;
        int[] X;
        Input(out N);
        InputArray(out X);
        int[] cost = new int[100];
        for(int i = 1; i <= 100; i++) {
            for(int k = 0; k < N; k++) {
                cost[i - 1] += (X[k] - i) * (X[k] - i);
            }
        }
        Console.WriteLine(cost.Min());
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 13396
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        long cnt1 = 0;
        long cnt2 = 0;
        for (int i = 1; i <= n; i++) {
            if (k % 2 == 0) {
                if (i % k == 0) {
                    cnt1++;
                }
                if (i % k == k / 2) {
                    cnt2++;
                }
            } else if (k % 2 == 1) {
                if (i % k == 0) {
                    cnt1++;
                }
            }
        }
        long ans = cnt1 * cnt1 * cnt1 + cnt2 * cnt2 * cnt2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204