akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


def main():
    N, M = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(M)]
    # 辺を取っ払っても、そのノードに移動出来る時は橋となる？

    ans = 0
    for i in range(M):
        g = Graph()
        for j in range(M):
            if j == i:
                continue
            else:
                g.add_edge(ab[j][0], ab[j][1])
                g.add_edge(ab[j][1], ab[j][0])
        tmp = Dijkstra(g, ab[i][0])
        if tmp.shortest_distance(ab[i][1]) == float('inf'):
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    b = [0 for i in range(n)]
    ans = []

    for i in range(n // 2, n):
        if a[i] == 1:
            b[i] = a[i]
            ans.append(i + 1)

    for i in range(n // 2 - 1, -1, -1):
        cnt = 0
        for j in range(i * 2 + 1, n, i + 1):
            cnt ^= b[j]
        if cnt != a[i]:
            b[i] = 1
            ans.append(i + 1)

    tmp = len(ans)
    print(tmp)
    if tmp > 0:
        print(*ans, sep=" ")


if __name__ == '__main__':
    main()


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

using namespace std;

const int MAX_N = 1e5;

int n;

int a[MAX_N];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#define For(N) for (int i = 0; i < N; i++)

using namespace std;
using ll = long long int;
using vi = vector<int>;

int A(int f, int a) {
	int i;
	for (i = 0; i*f < a; i++);
	return i*f;
}

int main() {
	int N;
	vi C, S, F;
	cin >> N;
	N--;
	For(N) {
		int c, s, f;
		cin >> c >> s >> f;
		C.push_back(c);
		S.push_back(s);
		F.push_back(f);
	}
	For(N) {
		int ans = 0;
		for (int j = i; j < N; j++) {
			if (ans <= S[j])ans = S[j];
			else ans = A(F[j], ans);
			ans += C[j];
		}
		cout << ans << endl;
	}
	cout << "0\n";
	return 0;
}



Measured memory_bytes: 256
N=int(input())
p=[]
r=0

if N%2==0:
  c=0
  while N%2==0:
    N=N//2
    c+=1
  p.append(c)
for i in range(3,int(N**0.5)+1,2):
  if N%i==0:
    c=0
    while N%i==0:
      N=N//i
      c+=1
    p.append(c)
if N!=1:
  p.append(1)
  
while p:
  r+=int(((8*p.pop()+1)**0.5-1)/2)
  
print(r)

Measured memory_bytes: 9376
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    byte k = sc.nextByte();
    sc.nextLine();
    String s = sc.nextLine();
    sc.close();
    if(s.length() > k) {
      s = s.substring(0, k) + "...";
    }
    System.out.println(s);
  }
}

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

int main() {
	int n[3];
	cin >> n[0] >> n[1] >> n[2];
	sort(n, n+3);
	int c = 1;
	for(int i = 1; i < 3; i++){
		if(n[i] != n[i-1]){
			c++;
		}
	}
	cout << c << endl;
	return 0;
}

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

int main()
{
    int r=0,c=0;

    cin>>r>>c;
    int arr[101][101]={{}};

    for(int row=0;row<r;row++)
    {
        for(int col=0;col<c;col++)
        {
            cin>>arr[row][col];
        }
    }
    for(int row=0;row<=r;row++)
    {
        for(int col=0;col<=c;col++)
        {
            if(col==c)
            {
                cout<<arr[row][col]<<"\n";
            }else{
                cout<<arr[row][col]<<" ";
                arr[row][c] += arr[row][col];
                arr[r][col] += arr[row][col];
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int a, b; cin >> a >> b;
  int result = (a+b+1)/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX

int n,r;

int besth[50]={};
int* bh = besth+25;

double sh(double nr,double np){
	np = abs(np);
	return sqrt(nr*nr-np*np)-nr;
}

int main(void){

	for(;;){
		scanf("%d%d",&r,&n);
		if(r==0)break;
		memset(besth,0,sizeof(besth));
		rep(i,n){
			int xl,xr,h;
			scanf("%d%d%d",&xl,&xr,&h);
			reg(j,xl,xr-1){
				bh[j]=max(bh[j],h);
			}
		}
		
		
		double ans = 10000;
		
		reg(i,-r,r-1){
			double nsh = sh(r,i>=0?i:abs(i)-1);
			//printf(" %d .. %lf %d\n",i,nsh,bh[i]);
			ans = min(ans,bh[i]-nsh);
		}
		printf("%lf\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>

int main() {
	int32_t n;
	std::cin >> n;

	int32_t max = -1;
	std::map<std::string, int32_t> votes;
	for(int32_t i = 0 ;i < n; i++) {
		std::string cur;
		std::cin >> cur;

		votes[cur]++;
		max = std::max(max, votes[cur]);
	}

	std::vector<std::string> answer;
	for(auto it = votes.begin(); it != votes.end(); it++)
		if(it->second == max) {
			answer.push_back(it->first);
		}
	std::sort(answer.begin(), answer.end());

	for(int32_t i = 0; i < answer.size(); i++) {
		std::cout << answer[i] << "\n";
	}
	return 0;
}




Measured memory_bytes: 26868
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

print(n**2)


Measured memory_bytes: 38384
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

#define MAX  40002
#define BASE 20000

int a[MAX];
int sum[MAX]; int sz;
int left[MAX];

int main()
{
	int i, j, k, x, h, s, ans;
	int c;

	h = BASE, ans = s = 0;
	for (x = 1; ; x++) {
		c = gc();
		if (c <= ' ') break;
		if (c == '\\') {
			if (s > 0) ans += s, sum[sz++] = s, s = 0;
			a[--h] = x;
		} else if (c == '/') {
			if (a[h] > 0) left[sz] = a[h], s += x-a[h];
			else if (s > 0) ans += s, sum[sz++] = s, s = 0;
			h++;
		}
	}
	if (s > 0) ans += s, sum[sz++] = s;

	printf("%d\n", ans);
	k = sz;
	i = sz-1; while (i > 0) {
		j = i-1; while (j >= 0 && left[j] > left[i]) {
			sum[i] += sum[j], sum[j] = 0, j--, k--;
		}
		i = j;
	}

	printf("%d", k);
	for (i = 0; i < sz; i++) if (sum[i] > 0) printf(" %d", sum[i]);
	putchar('\n');
	return 0;
}



Measured memory_bytes: 2144
package main

import (
	"fmt"
	"strconv"
)

type node struct {
	v int  // value
	g rune // group (S, H, C, D)
}

func bubblesort(a []node) int {
	done := true
	n := len(a)
	c := 0
	for done {
		done = false
		for j := n - 1; j >= 1; j-- {
			if a[j].v < a[j-1].v {
				a[j-1], a[j] = a[j], a[j-1]
				c++
				done = true
			}
		}
	}
	return c
}

func selectsort(a []node) int {
	n := len(a)
	c := 0
	for i := range a {
		minj := i
		for j := i; j < n; j++ {
			if a[j].v < a[minj].v {
				minj = j
			}
		}
		a[i], a[minj] = a[minj], a[i]
		if minj != i {
			c++
		}
	}
	return c
}

func printSlice(a []node) {
	for i, e := range a {
		if i > 0 {
			fmt.Printf(" ")
		}
		fmt.Printf("%c%d", e.g, e.v)
	}
	fmt.Printf("\n")
}

func isStable(a []node, b []node) bool {
	for i, e := range a {
		e2 := b[i]
		if e.g != e2.g || e.v != e2.v {
			return false
		}
	}
	return true
}

func main() {
	n := 0
	fmt.Scan(&n)
	a := make([]node, n)
	var s string
	for i := range a {
		fmt.Scan(&s)
		a[i].g = rune(s[0])
		a[i].v, _ = strconv.Atoi(s[1:])
	}
	b := make([]node, n)
	copy(b, a)

	bubblesort(a)
	selectsort(b)
	printSlice(a)
	fmt.Println("Stable")
	printSlice(b)
	if isStable(a, b) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}



Measured memory_bytes: 1156
N, K = map(int, input().split())
ps = []
for i in range(N):
    a, b = map(int, input().split())
    ps.append([a, b])
ps = sorted(ps)
k = 0
for i in range(N):
    k += ps[i][1]
    if k >= K:
        print(ps[i][0])
        break

Measured memory_bytes: 20872
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main()
{
	char str1[100];
	char str2[100];
	scanf("%s %s",str1,str2);
	int s1,s2;
	scanf("%d %d",&s1,&s2);
	char str[100];
	scanf("%s",str);
	if(strcmp(str1,str))
	{
		s2--;
	}
	else if(strcmp(str2,str))
	{
		s1--;
	}
	printf("%d %d",s1,s2);
	return 0;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

#define MAX_N 100000

int N,M;
vector<int> edge[MAX_N];
int used[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> M;
    REP(i,M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a].pb(b);
        edge[b].pb(a);
    }
    
    // 適当な2辺を作る
    deque<int> path;
    path.pb(0);
    path.pb(edge[0][0]);
    used[0] = 1;
    used[edge[0][0]] = 1;
    while(true) {
        int last = path.back();
        int flag = 1;
        for (auto x: edge[last]) {
            if (used[x] == 0) {
                used[x] = 1;
                path.pb(x);
                flag = 0;
                break;
            }
        }
        int first = path.front();
        for (auto x: edge[first]) {
            if (used[x] == 0) {
                used[x] = 1;
                path.push_front(x);
                flag = 0;
                break;
            }
        }
        if (flag) {
            cout << path.size() << endl;
            for(int i=0;i<path.size()-1;i++) {
                cout << path[path.size()-i-1]+1 << " ";
            }
            cout << path[0]+1 << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 7168
n,q=map(int,input().split())
s=input()
b=[0]*(n+1)
y=0
for x,i in enumerate(s):
    if i=="A" and x!=n-1 and s[x+1]=="C":
        y+=1
    b[x+1]=y
for i in range(q):
    a0,a1=map(int,input().split())
    print(b[a1-1]-b[a0-1])


Measured memory_bytes: 52568
import java.util.*;

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

		while(sc.hasNext()){
			p = (sc.next()+"=").toCharArray();

			flg = true;
			Complex ans = expr(0).val;
			if(flg && ans.correct()){
				System.out.println(ans);
			}
			else{
				System.out.println("overflow");
			}
		}
	}

	private static char[] p;
	private static boolean flg;

	private static Parsed expr(int idx){
		Parsed r = term(idx);
		while(p[r.idx] == '+' || p[r.idx] == '-'){
			char op = p[r.idx];
			Complex tmp = r.val;
			r = term(r.idx+1);
			if(op == '+'){
				r.val = tmp.add(r.val);
				if(!r.val.correct()) flg = false;
			}
			else{
				r.val = tmp.sub(r.val);
				if(!r.val.correct()) flg = false;
			}
		}
		return r;
	}

	private static Parsed term(int idx){
		Parsed r = fact(idx);
		while(p[r.idx] == '*'){
			char op = p[r.idx];
			Complex tmp = r.val;
			r = fact(r.idx+1);
			r.val = tmp.mul(r.val);
			if(!r.val.correct()) flg = false;
		}
		return r;
	}

	static Parsed fact(int idx){
		if(p[idx] == 'i'){
			return new Parsed(new Complex(0,1),idx+1);
		}
		else if(Character.isDigit(p[idx])){
			while(p[idx]=='0') idx++;

			long t = 0;
			int len = 0;

			while(Character.isDigit(p[idx])){
				t = t * 10 + p[idx++] - '0';
				len++;
			}
			if(t >= 10001 || len > 6) flg = false;
			return new Parsed(new Complex(t,0),idx);
		}
		else if(p[idx] == '('){
			Parsed r = expr(idx+1);
			if(!r.val.correct()) flg = false;
			if(p[r.idx]!=')') return null;
			return new Parsed(r.val,r.idx+1);
		}
		else return null;
	}
}

class Parsed{
	Complex val;
	int idx;

	Parsed(Complex val,int idx){
		this.val = new Complex(val.real,val.imag);
		this.idx = idx;
	}
}

class Complex{
	long real;
	long imag;

	Complex(long real,long imag){
		this.real = real;
		this.imag = imag;
	}

	Complex add(Complex c){
		return new Complex(real + c.real, imag + c.imag);
	}

	Complex sub(Complex c){
		return new Complex(real - c.real, imag - c.imag);
	}

	Complex mul(Complex c){
		return new Complex(real * c.real - imag * c.imag,
											 real * c.imag + imag * c.real);
	}

	boolean correct(){
		return Math.abs(real) <= 10000 && Math.abs(imag) <= 10000;
	}

	public String toString(){
		if(real == 0){
			if(imag == 0) return "0";
			return imag + "i";
		}
		else{
			if(imag == 0) return ""+real;
		}

		return String.format("%d%c%di",real,(imag>=0?'+':'-'),Math.abs(imag));
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

struct Point {
    int x;
    int y;
    int count;
};

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> map(h);
    for (int i=0; i<h; i++){
        cin >> map[i];
    }
    queue<Point> q;
    Point p = {0, 0, 1};
    q.push(p);
    int ans = 0;
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            ans += map[i][j] == '.';
        }
    }
    while (!q.empty()){
        p = q.front();
        q.pop();
        int x = p.x, y = p.y, count = p.count++;
        if (map[y][x] == '#')  continue;
        map[y][x] = '#';
        if (x == w-1 && y == h-1){
            cout << ans-count << endl;
            return 0;
        }
        if (x > 0 && map[y][x-1] == '.'){
            p.x--;
            q.push(p);
            p.x++;
        }
        if (y > 0 && map[y-1][x] == '.'){
            p.y--;
            q.push(p);
            p.y++;
        }
        if (x < w-1 && map[y][x+1] == '.'){
            p.x++;
            q.push(p);
            p.x--;
        }
        if (y < h-1 && map[y+1][x] == '.'){
            p.y++;
            q.push(p);
            p.y--;
        }
    }
    cout << -1 << endl;
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

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

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
    int n,k;
    cin >> n>> k;
    if (n  % k == 0) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	ll a[n];
	rep(i,n)cin>>a[i];
	vector<ll> ans(n);
	rep(i,n-1)ans[i+1]=a[i]-ans[i];
	ll diff=a[n-1]-(ans[0]+ans[n-1]);
	diff/=2;
	rep(i,n){
		if(i%2)ans[i]-=diff;
		else ans[i]+=diff;
	}
	rep(i,n)cout<<ans[i]*2<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2816
import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int N = sc.nextInt();
    int M = sc.nextInt();

    int[] likes = new int[M];
    for (int i=0; i<N; i++) {
      int len = sc.nextInt();
      for (int j=0; j<len; j++) {
        likes[sc.nextInt()-1]++;
      }
    }

    int count = 0;
    for (int i=0; i<M; i++) {
      if (likes[i] == N) count++;
    }

    System.out.println(count);

  }
}


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

const int mod = 1000000007;

int a[1010], b[1010];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for (int j = 0; j < m; j++){
		scanf("%d", &b[j]);
	}
	sort(a, a + n), sort(b, b + m);
	if (unique(a, a + n) - a != n || unique(b, b + m) - b != m){
		printf("0\n");
		return 0;
	}
	long long ans = 1;
	int na = n - 1, nb = m - 1;
	for (int p = n * m; p >= 1; p--){
		while (na >= 0 && a[na] >= p) na--;
		while (nb >= 0 && b[nb] >= p) nb--;
		if (a[na + 1] == p && b[nb + 1] == p) continue;
		if (a[na + 1] == p){
			if (m - 1 - nb <= 0){
				printf("0\n");
				return 0;
			}
			ans = ans * (m - 1 - nb + mod) % mod;
		}
		else if (b[nb + 1] == p){
			if (n - 1 - na <= 0){
				printf("0\n");
				return 0;
			}
			ans = ans * (n - 1 - na + mod) % mod;
		}
		else{
			if ((n - 1 - na) * (m - 1 - nb) - (n * m - p) <= 0){
				printf("0\n");
				return 0;
			}
			ans = ans * (((n - 1 - na) * (m - 1 - nb) % mod - (n * m % mod - p) + mod) % mod) % mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();

		if(a.equals(b.substring(0, a.length())) && a.length() + 1 == b.length()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 35696
a_1=list(map(int, input().split()))
a_2=list(map(int, input().split()))
a_3=list(map(int, input().split()))

c=[a_1,a_2,a_3]

N=int(input())

b=[int(input()) for _ in range(N)]

for i in range(3):
    for j in range(3):
        if c[i][j] in b:
            c[i][j]=0
            
            
i=0
if c[0][0]==0 and c[0][1]==0 and c[0][2]==0:
    i+=1
if c[1][0]==0 and c[1][1]==0 and c[1][2]==0:
    i+=1
if c[2][0]==0 and c[2][1]==0 and c[2][2]==0:
    i+=1
if c[0][0]==0 and c[1][0]==0 and c[2][0]==0:
    i+=1
if c[0][1]==0 and c[1][1]==0 and c[2][1]==0:
    i+=1
if c[0][2]==0 and c[1][2]==0 and c[2][2]==0:
    i+=1
if c[0][0]==0 and c[1][1]==0 and c[2][2]==0:
    i+=1
if c[0][2]==0 and c[1][1]==0 and c[2][0]==0:
    i+=1
    
if i>0:
    print("Yes")
else:
  print("No")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int k;
cin>>k;
int arr[n];
for(int i = 0 ; i < n ;i++){
 cin>>arr[i];
}
int dp[n];
  for(int i = 0 ; i < n; i++){
    dp[i] = INT_MAX;
  }
dp[0] = 0;
for(int i = 1;  i< n; i++){
	for(int j = 1 ; j <= k ; j++){
		if(i-j >= 0){
    dp[i] = min(dp[i] , dp[i-j] + abs(arr[i] -arr[i-j]));
  // dp[i] = min(dp[i] , dp[i-j] + abs(arr[i] - arr[i-j]));
}
}
}
cout<<dp[n-1]<<endl;
}



Measured memory_bytes: 1792
n,a,b = map(int, input().split())
# print(n,a,b)
# kakuketa no wa = x, a <= x <= b
def wa(x):
	res = [0,0,0,0,0]
	q = x // 10**4
	if q!=0:
		x = x - 10**4 *q
		res[0]=q
	q = x // 10**3
	if q!=0:
		x = x - 10**3 *q
		res[1]=q
	q = x // 10 **2
	if q!=0:
		x = x - 10**2 *q
		res[2]=q
	q = x // 10 
	if q!=0:
		x=x - 10*q
		res[3]=q
	res[4]=x
	return sum(res)
ans=0
for nn in range(1,n+1):
	wa1 =wa(nn)
	if wa1 >= a:
		if wa1 <= b:
			ans += nn
print(ans)

Measured memory_bytes: 3064
def main():
    N,M=map(int,input().split())
    L=2**N
    dp=[10**10 for i in range(L)]
    dp[0]=0


    for i in range(M):
        a, _ = map(int, input().split())
        key=sum([1<<(int(i)-1) for i in input().split()])
        for j in range(L):
                q=j|key
                dp[q]=min(dp[j]+a,dp[q])


    ans=dp[L-1]
    print(ans if ans<10**10 else -1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

int arr[maxn];
int a, b, c, d, e, f, g;
void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
	}
	return 0;
}

// type below

void solve()
{
	cin >> a >> b;
	cout << (a * (a - 1)) / 2 + (b * (b - 1)) / 2 << '\n';
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();
    
    System.out.println(A*B > C*D ? A*B : C*D);
  }
}

Measured memory_bytes: 23764
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,M,i,j,a[50],b[50],c[50],d[50],min_d,dis,min_p;
inline void solve(){
  IN2(N,M);
  INS2(i,N,a,b);
  INS2(i,M,c,d);
  REP(i,N){
    min_d=INT_MAX;
    REP(j,M){
      dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dis<min_d){
        min_d=dis;
        min_p=j+1;
      }
    }
    OUT(min_p);
  }
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

using namespace std;

#define int long long

int32_t main(){

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int x,y,a,b,c,i,j,k,sum=0,t;

	cin>>x>>y>>a>>b>>c;

	vector<int> r(a), g(b), z(c);

	for(i=0; i<a; i++)
		cin>>r[i];

	for(i=0; i<b; i++)
		cin>>g[i];

	for(i=0;i<c;i++)
		cin>>z[i];

	sort(r.begin(), r.end(), greater<int>());
	sort(g.begin(), g.end(), greater<int>());
	sort(z.begin(), z.end(), greater<int>());
	t=x+y;
	i=j=k=0;
	while(t--){

		if(i<x && j<y){

			if(r[i] >= g[j] && r[i] >= z[k]){

				sum += r[i];
				i++;

			}
			else if(g[j] >= z[k]){

				sum += g[j];
				j++;
				
			}
			else{

				sum += z[k];
				k++;
			}
		}

		else if(i<x){

			if(r[i] >= z[k]){

				sum += r[i];
				i++;
			}
			else{
				sum += z[k];
				k++;
			}
		}

		else if(j<y){

			if(g[j] >= z[k]){

				sum += g[j];
				j++;
			}
			else{
				sum += z[k];
				k++;
			}
		}

		else{

			sum += z[k];
			k++;
		}

	}	

	cout<<sum;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string.h>
using namespace std;

int main () {
  string h;
  cin >> h;
  if (h == "A") {
    cout << "T" << endl;  
  }
  if (h == "T") {
    cout << "A" << endl;  
  }
  if (h == "G") {
    cout << "C" << endl;  
  }
  if (h == "C" ){
    cout << "G" << endl;  
  }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   string s;
           cin>>s;
           if(s.back()=='s'){
            cout<<s<<"es"<<endl; 
           }
           else{
             cout<<s<<"s"<<endl;
           }
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main(void) {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X; --Y;

    WeightedGraph<int> g(N);
    for(int i=0; i<N-1; i++) {
        g[i].emplace_back(i+1, 1);
        g[i+1].emplace_back(i, 1);
    }
    g[X].emplace_back(Y, 1);
    g[Y].emplace_back(X, 1);

    vector<int64_t> ans(N);
    for(int i=0; i<N; i++) {
        auto dist = dijkstra(g, i);
        for(auto e: dist) {
            ans[e]++;
        }
    }

    for(int k=1; k<N; k++) {
        cout << ans[k]/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline long IN(void)
{
  long x=0;int f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=8;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;;
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return OUT(l),0;
}

Measured memory_bytes: 3008
s=input()
n=len(s)
check=0
for i in range (n):
    if s[i]!=s[n-1-i]:
        check+=1
for i in range((n-1)//2):
    if s[i]!=s[(n-3)//2-i]:
        check+=1
if check==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        aa: [i128; n],
    }

    for &a in aa.iter() {
        if a == 0 {
            println!("0");
            return;
        }
    }
    let x = 10i128.pow(18);
    
    let mut mul = 1;
    for a in aa {
        mul *= a;
        if mul > x {
            println!("-1");
            return;
        }
    }

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


Measured memory_bytes: 5336
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;

#define N 3
#define N2 9

struct Puzzle {
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle& p) const {
    for (int i = 0; i < N2; i++) {
      if (f[i] == p.f[i]) {
        continue;
      }
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p) {
  for (int i = 0; i < N2; i++) {
    if (p.f[i] != (i + 1)) {
      return false;
    }
  }
  return true;
}

string bfs(Puzzle s) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    if (isTarget(u)) {
      return u.path;
    }
    int sx = u.space / N;
    int sy = u.space % N;
    for (int r = 0; r < 4; r++) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N) {
        continue;
      }
      v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if (!V[v]) {
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }
  return "unsolvable";
}

int main(){
  Puzzle in;

  for (int i = 0; i < N2; i++) {
    cin >> in.f[i];
    if (in.f[i] == 0) {
      in.f[i] = N2; // set space
      in.space = i;
    }
  }

  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 30556
import sys
s=input()
b=[]
an=0
for i in range(len(s)):
  if s[i]!="x":
    b.append(s[i])
for i in range(len(b)):
  if b[i]!=b[-i-1]:
    print(-1)
    sys.exit()

i=j=0 
while i<=len(s)-1-j:
  if s[i]==s[-1-j]:
    i+=1
    j+=1
  elif s[i]=="x":
    i+=1
    an+=1
  elif s[-1-j]=="x":
    j+=1
    an+=1

print(an)
  

Measured memory_bytes: 9812
import sys
N, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
# print(As)
d = [-1]*(N+1)
i = 1
step = 1
while step <= K:
	# print("step: {}, idx: {}".format(step,i))
	next_i = As[i]
	if d[next_i] != -1:
		freq = step - d[next_i]
		step = step + ((K - step) // freq)*freq
	d[next_i] = step
	step += 1
	i = next_i
 
print(i)

Measured memory_bytes: 32332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
int check(string a,string &b)
{
    int cnt=0;
    for (int i=0;i<a.size();i++)
        cnt+=a[i]!=b[i];
    return cnt;
}
void solve()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int mx=INF;
    for (int i=0;i<n-m+1;i++)
        mx=min(mx,check(s.substr(i,m),t));
    cout<<mx<<'\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
//    cin>>_t;
    _t=1;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3580
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N=int(input())
S = input()

if S.count("R")==0 or S.count("W")==0:
    print(0)
    sys.exit()

tmp = S.count("R")
mae = S[0:tmp]
tmp2 = mae.count("R")

print(tmp-tmp2)

Measured memory_bytes: 73432
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,in;
	cin>>n;
	set<int> s;
	rep(i,n)cin>>in,s.insert(in);
	cout<<s.size()<<endl;
}


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

#define ENDL '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);
#define sayy cout<<"YES"<<ENDL;
#define sayn cout<<"NO"<<ENDL;

string group(string s){
    string result;
    result += s[0];
    for(int i(0); i<s.length() - 1; i++){
        if(s[i] != s[i+1]){
            result += s[i+1];
        }
    }
    return result;
}

int main(){
    io

    int n;
    string s;
    cin >> n >> s;

    string str;
    str = group(s);
    
    cout << str.length() << endl;

    return 0;
}

Measured memory_bytes: 3872
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 n;
vector<i64> a;
int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  i64 ans = 0;
  for (i64 k = 0; k < 60; ++k) {
    i64 cnt = 0;
    for (int i = 0; i < n; ++i) {
      cnt += (a[i] >> k) & 1;
    }
    (ans += (1ll << k) % mod * cnt % mod * (n - cnt) % mod) %= mod;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) { }
    bool unionSet(ll x, ll y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) {
        return root(x) == root(y);
    }
    ll root(ll x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(ll x) {
        return -data[root(x)];
    }
};

#define MAX_COUNT 1000001

string ss;

vector<int> g[MAX_COUNT];
int vv[MAX_COUNT];
int vmi[MAX_COUNT];
int vma[MAX_COUNT];
int mod[MAX_COUNT];

static const int nv = -10000000;

struct Visit
{
    int from;
    int current;
};

string s[10];
int h,w;

char No = '.';

bool dfs(int x, int y)
{
    if(x == w - 1 && y == h - 1 && s[y][x] != No)
    {
        return true;
    }
    bool c = false;
    {
        if(x < w - 1)
        {
            if(s[y][x + 1] != No)
            {
                c |= dfs(x+1, y);
            }
        }
        if(y < h - 1)
        {
            if(s[y + 1][x] != No)
            {
                c |= dfs(x, y + 1);
            }
        }
    }
    return c;
}

int main()
{
    cin >> h >> w;
    for(int i = 0;i < h;i++)
    {
        cin >> s[i];
    }
    int sum = 0;
    for(int y = 0;y < h;y++)
    {
        for(int x = 0; x < w;x++)
        {
            if(s[y][x] != No)
            {
                sum++;
            }
        }
    }
    if(sum > w + h -1)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    if(s[0][0] == No)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    if(dfs(0,0))
    {
        cout << "Possible" << endl;
        return 0;
    }
    cout << "Impossible" << endl;
    return 0;
}

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



int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	long long sum = a+b+c;
	if (sum >= 22)
		cout << "bust\n";
	else
	 cout << "win\n";		
}

Measured memory_bytes: 256
S = list(input())
T = list(input())
ans = 0
#print(type(range(len(S))))

for i in range(len(S)): #→for文で回せるようなiterableなものの例：range,リスト，タプル，集合，辞書，文字列
    #print(S[i])
    #print(T[i])
    if not S[i] == T[i]:
        ans += 1
print(ans)



#print(S)
#print(T)


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

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z  << " " << x << " " << y  << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int c = 0;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    int count = 0;
                    for (int l = 0 ; l < n ; l++) {
                        int t = Integer.valueOf(s.substring(l, l+1));
                        if (count == 0) {
                            if (i == t) count++;
                        } else if (count == 1) {
                            if (j == t) count++;
                        } else if (count == 2) {
                            if (k == t) count++;
                        }
                    }
                    if (count == 3) c++;
                }
            }
        }

        System.out.println(c);
    }

}


Measured memory_bytes: 339116