akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    s = input()

    print("Yes" if s[:n // 2] == s[n // 2:] else "No")


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  
  cout << accumulate(a.begin(), a.end(), 0) << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*dijkstra(G, w, s)
    initializeSingleSource(G, s)
    while true
        mincost = inf
        for each i in G
            if color[i] != BLACK and d[i] < mincost
                mincost = d[i]
u=i
if mincost == inf
            break
        color[u] = BLACK
        for each v in Adj[u]
            if color[v] != BLACK and d[u] + w(u, v) < d[v]
                pi[v] = u
                d[v] = d[u] + w(u, v)*/
#include<stdio.h>
#define N 100
#define MAX 2000
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2


int A[N][N], n;

void dijkstra(){
  int i, u, v, minv, sum = 0;
  int d[N], color[N];

  for(i = 0; i < n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;

  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }

    if(u == -1) break;
    color[u] = BLACK;

    for(v = 0; v < n; v++){
      if(color[v] != BLACK && A[u][v] != INFTY){
        if(d[v] > d[u] + A[u][v]){
          d[v] = d[u] + A[u][v];
          color[v] = GRAY;
        }
      }
    }

  }

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

}


int main(){
  int i, j, s;
  int u, v, c, k;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      A[i][j] = INFTY;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d%d", &v, &c);
      A[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}



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

int solve(vector<int> v, int count) {
    sort(v.begin(), v.end());
    if (v[0] == v[1] && v[1] == v[2]) {
    	return count;
    }
    else if (v[1] == v[2]) {
    	v[0] += 2;
    }
    else {
    	++v[0];
    	++v[1];
    }
    //cout << "(" << v[0] << " " << v[1] << " " << v[2] << ")" << endl;
    return solve(v, count+1);
}

int main() {
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    cout << solve(v, 0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 10 ;
typedef long long ll ;
pair<ll , ll> a[N] ;
ll c[N] ;
ll dp[32] ;
bool cmp(pair<ll , ll> a , pair<ll , ll> b)
{
  return a.first * (b.second + 1) > b.first * (a.second + 1) ;
}
int main()
{
  ll n , t ;
  scanf("%lld%lld" , &n , &t) ;
  ll cnt1 = 0 , cnt2 = 0 ;
  for(ll i = 1 , x , y ; i <= n ;i ++)
   {
     scanf("%lld%lld" , &x , &y) ;
     if(x == 0) c[++ cnt2] = y + 1;
     else a[++ cnt1] = {x , y} ;
   }
   sort(c + 1 , c + cnt2 + 1) ;
   sort(a + 1 , a + cnt1 + 1 , cmp) ;
   for(int i = 1; i <= 30 ;i ++) dp[i] = t + 1 ;
   dp[0] = 0 ;
   int cnt = 0 ;
   for(int i = 1; i <= cnt2 ;i ++) c[i] += c[i - 1] ;
   for(int i = 1; i <= cnt1 ;i ++)
   {
     for(int j = 30 ;j >= 1 ;j --)
      dp[j] = min(dp[j] , (dp[j - 1] + 1) * (a[i].first + 1)+ a[i].second) ;
   }

   int ans = 0 ;
   for(int i = 0 ;i <= 30 ;i ++)
    {
      if(dp[i] > t) continue ;
      int j = 0 ;
      if(cnt2)
       j = upper_bound(c + 1 , c + cnt2 + 1 , t - dp[i]) - c - 1;
      ans = max(ans , i + j) ;
    }
  cout << ans << endl ;
  return 0 ;
}


Measured memory_bytes: 3584
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    if (B- A - 1) % 2 == 1:
        print "Alice"
    else:
        print "Borys"


if __name__ == '__main__':
    main()


Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

template <int M> class ModInt {
    int x;

  public:
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using modint = ModInt<mod>;

int n;
vector<int> e[200009];

modint num, den;

bool used[200009];

int dfs(int x) {
    used[x] = true;
    int re = 0;
    for(const auto &y : e[x]) {
        if(!used[y]) {
            int z = dfs(y);
            den += (modint(2).pow(z) - modint(1)) *
                   (modint(2).pow(n - z) - modint(1));
            re += z;
        }
    }
    return re + 1;
}

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

    cin >> n;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    num = modint(2).pow(n);

    dfs(1);

    den += num - modint(1);
    den -= num * modint(n) / modint(2);

    cout << den / num << endl;
}

Measured memory_bytes: 18048
#include <stdio.h>

#define NUM_ITEMS 100

void selectionSort(int *, int array_size);
void swap(int *,int*);

int main()
{
  int i,j,num;
  int a[100];

  scanf("%d",&num);

  // fill array with random integers
  for (i=0;i<num;i++) {
    scanf("%d",&a[i]);
  }

  // perform selection sort on array
  selectionSort(a, num);

  return 0;
}

void selectionSort(int *a, int array_size)
{
  int i; // ??????????????????????????????????????????
  int j,k; // ?????????????´????????????????????????????
  int min; // ????°?????????????????´??????????????????????
  int temp; // ????????¨??????????????°
  int step=0;

  for (i = 0; i < array_size-1; i++) {
    min = i; // ??????????????????????°???????????´???¨??????

    for (j = i+1; j < array_size; j++) { // ??????????????????

      if (a[j] < a[min]) {
        min = j; // ????°?????????????????´??????´??°
      }
    }
//  for(k=0;k<array_size;k++){
//    printf("%d ",a[k]);

//  }
//    printf("\n");
    // ????°?????????????????´?????????????????´???¨??????
    swap(&a[i],&a[min]);
if(i!=min)    step++;


  }

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

}

void swap(int *a,int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
  }

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

int f(int k){
	for(int r=7%k, i=0; i<k; ++i, r=(r*10+7)%k) if(r == 0) return i+1;
	return -1;
}

int main(){
	int k; cin>>k;
	cout<< f(k) <<endl;
}


Measured memory_bytes: 3600
n, y = map(int, input().split())
y /= 1000
res10, res5, res1 = -1, -1, -1
for a in range(n+1):
  if res1 != -1:
    break
  for b in range(n-a+1):
    c = n - a - b
    total = 10*a + 5*b + c
    if total == y:
      res10, res5, res1 = a, b, c
    if res1 != -1:
      break
print(str(res10) + " " + str(res5) + " " + str(res1))

Measured memory_bytes: 3064
#include <iostream>

 

using namespace std;

 

int main() 
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && y-r >= 0 && x+r <= w && y+r <= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3104
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;
	vector<bool> AC(N, false);
	vector<int> WA(N, 0);
	for (int i = 0; i < M; ++i) {
		int p;
		string S;
		cin >> p >> S;
		--p;
		if (AC[p] == false) {
			if (S == "WA") {
				WA[p]++;
			}
			else {
				AC[p] = true;
			}
		}
	}
	int ansAC = 0;
	int ansWA = 0;
	for (int i = 0; i < N; ++i) {
		if (AC[i]) {
			ansAC++;
			ansWA += WA[i];
		}
	}
	cout << ansAC << endl;
	cout << ansWA << endl;

}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 640
N,K=map(int,input().split())
td=[[int(a) for a in input().split()]for i in range(N)]

td=sorted(td,key=lambda x:-x[1])

ans=0
eat=set([])
noteat=[]
for t,d in td[:K]:
  ans+=d
  if t not in eat:
    eat.add(t)
  else:
    noteat.append(d)
temp_result=ans+len(eat)**2
max_result=temp_result

for t,d in td[K:]:
  if not noteat:
    break
  if t not in eat:
    temp_result+=2*len(eat)+1
    temp_result+=d-noteat.pop()
    eat.add(t)
    max_result=max(max_result,temp_result)
print(max_result)
 

Measured memory_bytes: 26880
//Radhe Radhe
#include<bits/stdc++.h>//157B
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
using namespace std;

int main()
{
    ll i,j,n;
    cin>>n;
   // ll a[n];
    ll x,cnt=0,sum=0,mini=INT_MAX;
    for(i=0; i<n; i++){
        cin>>x;
        if(x<0) cnt++;
        mini=min(mini,abs(x));
        sum+=abs(x);
    }
    if(cnt%2)
    sum-=(2*mini);
    cout<<sum<<endl;
    return 0;
}





Measured memory_bytes: 3644
import math

a,b,x = map(int,input().split())

V = a*a*b

if x >= V/2:
  t = (V-x)*2/a/a
  print(math.atan(t/a)/math.pi*180)
  
else:
  t = x*2/a/b
  print(math.atan(b/t)/math.pi*180)

Measured memory_bytes: 38384
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        boolean[] mustSwap = new boolean[N + 1];
        for (int i = 0; i < N; i++) {
            mustSwap[i] = sc.nextInt() - 1 == i ? true : false;
        }
        mustSwap[N] = false;
        int n = 0;
        for (int i = 0; i < N; i++) {
            if (mustSwap[i]) {
                mustSwap[i] = false;
                mustSwap[i + 1] = false;
                n++;
            }
        }
        System.out.println(n);
    }
}


Measured memory_bytes: 49496
import qualified Data.IntMap as M
import Data.List
 
main = do
  (n:k:as) <- map read . words <$> getContents
  let dict = mkDict as
  print $ solve k dict
 
mkDict :: [Int] -> M.IntMap Int
mkDict = foldr (\x y -> M.insertWith (+) x 1 y) M.empty
 
solve :: Int -> M.IntMap Int -> Int
solve k dict = sum . drop k . sortOn negate $ M.elems dict

Measured memory_bytes: 36220
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#ifdef DAIJOBU
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int main(){
	FIO

	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;cin >> k;
	cout << a[k - 1];
	
	#ifdef DAIJOBU
	cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

def main():
    n = int(input())
    s = [input() for _ in range(n)]
    C = Counter(s)
    mx = max(C.values())
    ans = []
    for k,v in C.items():
        if v == mx:
            ans.append(k)
    ans.sort()
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 35936
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 3;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long X = inputArray[0];
			long K = inputArray[1];
			long D = inputArray[2];
			var absX = Math.Abs(X);
			var comp = Math.Log10(K) + Math.Log10(D) > 20 ? long.MaxValue : K * D;//桁あふれ対応
			if (absX >= comp) {
				Console.WriteLine(absX - K*D);
				return;
			}

			var consume = absX / D;
			var current = absX % D;

			var remain = K - consume;


			//答えの出力
			var ans = remain %2==0 ? current : D-current;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}

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

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

int main()
{
    int n, _d;
    scanf("%d %d", &n, &_d);

    ll d = 1LL * _d * _d;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ll x, y;
        scanf("%lld %lld", &x, &y);

        if (x * x + y * y <= d)
            ans++;
    }

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

    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

struct LazySegTree {
  vector<ll> seg, lazy;
  int size;
  LazySegTree() {}
  LazySegTree(int n) {
    init(n);
  }
  void init(int n) {
    size = 1;
    while (size < n) size *= 2;
    seg.resize(size * 2);
    lazy.resize(size * 2);
    for(int i = 0; i < size*2; i++)seg[i]=INF;
  }
  void update(int k,ll v){
    k += size-1;
    seg[k] = v;
    while(k > 0){
      k = (k - 1)/2;
      seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  void push(int k, int l, int r) {
    seg[k] += lazy[k];
    if (r - l > 1) {
      lazy[k * 2 + 1] += lazy[k];
      lazy[k * 2 + 2] += lazy[k];
    }
    lazy[k] = 0;
  }
  void add(int a, int b, ll v, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] += v;
      push(k, l, r);
    } else {
      add(a, b, v, k * 2 + 1, l, (l + r) / 2);
      add(a, b, v, k * 2 + 2, (l + r) / 2, r);
      seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
    }
  }
  void add(int a, int b, ll v) {
    add(a, b, v, 0, 0, size);
  }
  ll query(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return INF*100; // caution
    if (a <= l && r <= b) return seg[k];
    ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl,vr);
  }
  ll query(int a, int b) {
    return query(a, b, 0, 0, size);
  }
};

int N,Q;
string s;
set<int> ngidx;
int a[300010],sum[300010];
LazySegTree sgt;

int main(){
  cin>>N>>Q;
  cin>>s;
  rep(i,N){
    if(s[i]=='('){
      sum[i+1]=sum[i]+1;
      a[i]=1;
    }
    if(s[i]==')'){
      ngidx.insert(i);
      sum[i+1]=sum[i]-1;
      a[i]=-1;
    }
  }
  sgt.init(N+1);
  rep(i,N+1)sgt.update(i,sum[i]);

  while(Q--){
    int q;
    cin>>q;
    q--;
    if(a[q]==1){
      a[q]=-1;
      ngidx.insert(q);
      sgt.add(q+1,N+1,-2);
      int res=*ngidx.begin();
      ngidx.erase(ngidx.begin());
      a[res]=1;
      sgt.add(res+1,N+1,+2);
      cout<<res+1<<endl;
    }else if(a[q]==-1){
      a[q]=1;
      ngidx.erase(q);
      sgt.add(q+1,N+1,+2);
      int lb=-1,ub=q+1;
      while(ub-lb>1){
        int mid=(lb+ub)/2;
        if(sgt.query(mid,q+1)>=2)ub=mid;
        else lb=mid;
      }
      int res=ub-1;
      a[res]=-1;
      ngidx.insert(res);
      sgt.add(res+1,N+1,-2);
      cout<<res+1<<endl;
    }
  }

  return 0;
}



Measured memory_bytes: 29028
#include <bits/stdc++.h>
// #include <iostream>
// #include <utility>
// #include <string>
// #include <array>
using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

// x^y%p
long long modpow(long long x, long long y, long long p=1) {
    long long res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0) {
        if (y & 1) res = res * x % p;
        y = y>>1;
        x = x * x % p;
    }
    return res;
}

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

  int N;
  cin >> N;
  vector<vector<int>> D(N, vector<int>(2));
  for(int i = 0; i < N; i++) {
    cin >> D[i][0] >> D[i][1];
  }

  for(int i = 0; i < N-2; i++) {
    if(D[i][0] == D[i][1] && D[i+1][0] == D[i+1][1] && D[i+2][0] == D[i+2][1]) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>

int main(void){
  int A,B;
  scanf("%d%d",&A,&B);

  if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) printf("Possible\n");
  else printf("Impossible\n");

  return 0;
}

Measured memory_bytes: 128
L = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())

if A % C == 0 :
    Kokugo = A // C
else :
    Kokugo = A // C + 1
if B % D == 0 : 
    Math = B // D
else :
    Math = B // D + 1
print(L - max(Kokugo, Math))


Measured memory_bytes: 5592
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <random>
#include <complex>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll gcd(ll a, ll b) {
    if (!a) return b;
    return gcd(b%a, a);
}

const int MN = 1010;
const ll MD = 1e9+7;

ll m;

ll powt[MN][MN];
ll fact[MN];
ll comb[MN][MN];
ll gcdm[MN];
ll get2[MN];
void init() {
    for (int i = 0; i < MN; i++) {
        powt[i][0] = 1;
        for (int j = 1; j < MN; j++) {
            powt[i][j] = powt[i][j-1]*i % MD;
        }
    }
    fact[0] = 1;
    for (int i = 1; i < MN; i++) {
        fact[i] = fact[i-1] * i % MD;
    }
    comb[0][0] = 1;
    for (int i = 1; i < MN; i++) {
        comb[i][0] = 1;
        for (int j = 1; j < MN; j++) {
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
            comb[i][j] %= MD;
        }
    }
    for (int i = 0; i < MN; i++) {
        gcdm[i] = gcd(m, i);
    }
    get2[0] = 1;
    get2[1] = 1;
    for (int i = 2; i < MN; i++) {
        get2[i] = get2[i-1] + (i-1) * get2[i-2];
        get2[i] %= MD;
    }
}


ll dp[3][MN][MN];
ll calc(int f, int n, int k) {
    if (k < 0) return 0;
    if (!k) return 1;
    if (dp[f][n][k] != -1) return dp[f][n][k];
    ll res = 0;
    if (!f) {
        for (int i = 1; i <= k; i++) {
            if (n*i / gcdm[n*i] != n) continue;
            ll r = calc(0, n, k-i);
            r *= comb[n*k-1][n*i-1]; r %= MD;
            r *= fact[n*i-1]; r %= MD;
            res += r; res %= MD;
        }
    } else {
        res += (n%2)*calc(1, n, k-1); res %= MD;
        res += (k-1)*n*calc(f, n, k-2); res %= MD;
    }
    return (dp[f][n][k] = res);
}
ll solve(int n, int m) {
    if (!n) return 1;
    if (n < m) return 0;
    if (dp[2][n][m] != -1) return dp[2][n][m];
    ll res = solve(n, m+1);
    for (int i = 1; i <= n/m; i++) {
        ll r = comb[n][i*m];
        r *= calc(0, m, i); r %= MD;
        r *= calc(1, m, i); r %= MD;
        r *= solve(n-i*m, m+1); r %= MD;
        res += r; res %= MD;
    }
    return (dp[2][n][m] = res);
}


int main() {
    memset(dp, -1, sizeof(dp));
    ll n, x, y, z;
    cin >> n >> x >> y >> z;
    x += z;
    m = abs(x-y);
    init();
    if (!x && !y) {
        cout << powt[n][n] * get2[n] % MD << endl;
        return 0;
    }
    if (x == y) {
        cout << fact[n] * get2[n] % MD << endl;
        return 0;
    }
    cout << solve(n, 1) << endl;
    return 0;
}

Measured memory_bytes: 41144
#!usr/bin/env python3
import math

a,b = list(map(int,input().split()))
s = input()

flg = 0
for i in range(len(s)):
    if i == a:
        if s[i] != '-':
            flg = 1
    else:
        if s[i] == '-':
            flg = 1
if flg == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x,i,ans=0;
  cin>>n>>x;
  int l[n],d[n+1]={0};
  for(i=0;i<n;i++)cin>>l[i];
  for(i=1;i<=n;i++)d[i]=d[i-1]+l[i-1];
  for(i=0;i<=n;i++)if(d[i]<=x)ans++;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n,val;
        cin>>n;

        vi v;
        int ans=0;

        rep(i,n)
        {
            cin>>val;
            if(i%2==0 && val%2)
            {
                ans++;
            }
        }

        cout<<ans<<endl;

    }
}   


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
#
# a = list(map(int, input().split('/')))
#
# # print(a)
#
# if a[0] <= 2018:
#     print('Heisei')
# else:
#     if a[0] == 2019 and a[1] <= 4:
#         print('Heisei')
#     else:
#         print('TBD')
#
#

S = input()

S = int(S[5:7])

if S <= 4:
    print('Heisei')
else:
    print('TBD')


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst<<": "; dbg(rst...); }

int main()
{
	const double PI = acos(-1);
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, q;
	cin >>n;
	VI a(n),  z(100100);
	ll sm = 0;
	rep(i, n){
		cin >>a[i];
		z[a[i]]++;
		sm += a[i];
	}
	cin >>q;
	rep(g, q){
		ll b, c;
		cin >>b >>c;
		ll wa = (c - b) * z[b];
		sm += wa;
		cout << sm <<"\n";
		z[c] += z[b];
		z[b] = 0;
	}
		
	return 0;
}


Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)
using Graph = vector<vector<int>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a,ma,mi,maa,mii;
  ma=-10000000;
  mi=10000000;
  cin>>a;
  ll arr[a];
  fr(i,a){
    ll b;
    cin>>b;
    ma=max(b,ma);
    if(ma==b) maa=i+1;
    mi=min(b,mi);
    if(mi==b) mii=i+1;
    arr[i]=b;
  } 
  cout<<2*a-1<<"\n";
  if(ma+mi>0){
  fr(i,a){
    cout<<maa<<" "<<i+1<<"\n";
  }
  fr(i,a-1){
    cout<<i+1<<" "<<i+2<<"\n";
  }
  }
  if(ma+mi<=0){
  fr(i,a){
    cout<<mii<<" "<<i+1<<"\n";
  }
  ifr(i,a-1){
    cout<<i+2<<" "<<i+1<<"\n";
  }
  }
}


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    vector<int> p(n);
    int ans = 0;
    rep(i, n) cin >> p[i];
    int m = INT_MAX;
    rep(i, n) {
        if(m > p[i])
            ans++;
        m = min(m, p[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4056
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

#define f first
#define s second

typedef pair<int, int> P;
typedef pair<int, P> P2;

int main(){
  int a, b;
  while(cin >> a >> b){
    if(a == 0 && b == 0) break;
    P2 tmp;
    vector<P> aa;
    for(int i = 1 ; i <= a ; i++){
      if(a % i == 0){
	aa.push_back(make_pair(i, a/i));
      }
    }
    vector<P> bb;
    for(int i = 1 ; i <= b ; i++){
      if(b % i == 0){
	bb.push_back(make_pair(i, b/i));
      }
    }

    int ans = (1<<29);
    int res[4];
    for(int i = 0 ; i < aa.size() ; i++){
      for(int j = 0 ; j < bb.size() ; j++){
	res[0] = aa[i].f, res[1] = aa[i].s;
	res[2] = bb[j].f, res[3] = bb[j].s;
	sort(res, res+4);
	int t = 0;
	for(int i = 0 ; i < 3 ; i++){
	  t += (res[i]-res[i+1]) * (res[i]-res[i+1]);
	}
	ans = min(ans, t);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int FUNC(int input);

int main(void){
   
   int s;
   
   scanf("%d",&s);
   
   int max = 1000000 + 1;
   int ans = -1;
   int count;
   int *Array = malloc(sizeof(int)*max);
   int i,j;
   
   Array[1] = s;
   count = 0;
   for(i = 2;i <= max;i++){
      Array[i] = FUNC(Array[i-1]);
      for(j = 1;j < i;j++){
         if(Array[j] == Array[i]){
            ans = i;
            count = 1;
            break;
         }
      }
      if(count == 1){
         break;
      }
   }
   
   printf("%d\n",ans);
   
   return 0;
}

int FUNC(int input){
   
   if(input%2 == 0){
      return input/2;
   }
   else {
      return 3*input + 1;
   }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#ifdef LOCAL
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#else
#define D(x)
#define R(X, l)
#endif
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
inline int _max(int cnt, ...);
inline int _min(int cnt, ...);
signed main(void)
{
	#ifdef LOCAL
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = next<int>(), ans = 0;
	hrp(i, 1, n) hrp(j, 1, n) hrp(k, 1, n) ans += __gcd(__gcd(i, j), k);
	cout<<ans<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}
inline int _max(int cnt, ...)
{
	int mx = -1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mx = max(mx, va_arg(l, int));
	va_end(l);
	return mx;
}
inline int _min(int cnt, ...)
{
	int mn = 1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mn = min(mn, va_arg(l, int));
	va_end(l);
	return mn;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
//#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
//#define EXIST(s, e) ((s).find(e)!=(s).end())
//#define SORT(c) sort(begin(c),end(c))
//#define pb emplace_back
//#define MP make_pair
//#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

vector<vector<ll>> ope(vector<ll> v, ll low) {
    vector<vector<ll> > ret;
    vector<ll> tmp;
    rep(i, 0, v.size()) {
        if (v[i] >= low) {
            tmp.push_back(v[i]);
        }
        if (v[i] < low || i == v.size() - 1) {
            ret.push_back(tmp);
            tmp.clear();
        }
    }
    return ret;
}

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

    int N, K, Q;
    cin >> N >> K >> Q;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];

    auto B = A;
    sort(all(B));

    ll ans = INFl;
    rep(i, 0, N) {
        ll low = B[i];
        vector<vector<ll>> hya = ope(A, low);

        vector<ll> kouho;

        for (auto vl : hya) {
            auto vt = vl;
            sort(all(vt));
            rep(j, 0, vt.size() - K + 1) {
                kouho.push_back(vt[j]);
            }
        }
        sort(all(kouho));
        if (kouho.size() >= Q) {
            ans = min(ans, kouho[Q - 1] - low);
        }

    }

    cout << ans << endl;


    return 0;
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char arr[6];
    cin>>arr;
    if(arr[2]==arr[3]&&arr[4]==arr[5]){
    	cout<<"Yes";
	}
	else{
		cout<<"No";
	}
    return 0;
}

Measured memory_bytes: 256
import sys


def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    Adjrev = [[] for i in range(nvertices)]
    for i in range(nedges):
        s, t = map(int, input().split())
        Adj[s].append(t)
        Adjrev[t].append(s)

    ordering = []
    visited = [False] * nvertices
    for u in range(nvertices):
        if not visited[u]:
            dfs1(u, Adj, visited, ordering)

    ordering.reverse()
    component_ids = [-1] * nvertices
    id = 0
    visited = [False] * nvertices
    for u in ordering:
        if visited[u]:
            continue
        dfs2(u, Adjrev, id, visited, component_ids)
        id += 1

    Q = int(input())
    for i in range(Q):
        s, t = map(int, input().split())
        if component_ids[s] == component_ids[t]:
            print(1)
        else:
            print(0)


def dfs1(u, Adj, visited, ordering):
    visited[u] = True
    for v in Adj[u]:
        if visited[v]:
            continue
        dfs1(v, Adj, visited, ordering)
    ordering.append(u)


def dfs2(u, Adj, id, visited, component_ids):
    visited[u] = True
    component_ids[u] = id
    for v in Adj[u]:
        if not visited[v]:
            dfs2(v, Adj, id, visited, component_ids)


main()

Measured memory_bytes: 19772
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl
using namespace std;
using ll = long long;
const int INFINT = 1 << 30;
const ll INFLL = 1LL << 60;
const int MOD = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}

int main() {

	int n, k;
	ll ans;

	cin >> n >> k;
	ans = pow(k - 1, n - 1) * k + 0.5;
	cout << ans NL;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;

int main() {
long long n,k;
cin>>n>>k;
long long a[n];

for(long long i=0;i<n;i++){
	cin>>a[i];
}

long long dp[n];

dp[0]=0;
dp[1]=abs(a[0]-a[1]);
long long min1;
for(long long i=2;i<n;i++){
	min1=INT_MAX;
	for(long long j=1;j<=k&&j<n&&(i-j)>=0;j++)
	min1=min(dp[i-j]+abs(a[i]-a[i-j]),min1);
	
dp[i]=min1;	
}

cout<<dp[n-1];
return 0;
}

Measured memory_bytes: 1792
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



while True:
    N,X = map(int,input().split())
    if N == 0 and X == 0:
        break
    ans = 0
    for a in range(1,N+1):
        for b in range(1,N+1):
            if b <= a:
                continue
            c = X-(a+b)
            if c > b and c <= N:
                ans += 1
    print("%d"%(ans))



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


int main(){

    ll a,b;
    cin>>a>>b;
    if(a%2!=b%2)
    {
        cout<<"IMPOSSIBLE"<<endl;
    }
    else
    {
        cout<<(a+b)/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

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

		int[] food=new int[M];

		for(int i=0;i<N;i++) {
			int J=sc.nextInt();
			for(int j=0;j<J;j++) {
				int inputFood=sc.nextInt()-1;
				food[inputFood]++;
			}
		}

		int cnt=0;

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

		System.out.println(cnt);

		sc.close();

	}

}


Measured memory_bytes: 23508
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    String S = sc.next();
    String T = sc.next();
    long g = gcd(N,M);
    boolean is_ok = true;
    long n = N/g;
    long m = M/g;
    long L = n*m*g;
    for(int l=0;l<g;l++){
      if(S.charAt((int)(l*n))!=T.charAt((int)(l*m))){
        is_ok = false;
        break;
      }
    }
    if(is_ok){
      System.out.println(L);
    }else{
      System.out.println(-1);
    }
  }

  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

}


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

int main() {
	int n;cin>>n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	a.push_back(0);
	vector<pair<long long,int>> v(n),v2(n);
	pair<long long,int> p;
	for(int i=0;i<n;i++){
		p.first=-a[i];
		p.second=i;
		v[i]=p;
	}
	vector<int> num;
	vector<long long> sum;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		v[i].first*=-1;
	}
	num.push_back(v[0].second);
	sum.push_back(0);
	int highest=v[0].second;
	for(int i=1;i<n;i++){
		if(v[i].second<highest){
			num.push_back(v[i].second);
			highest=v[i].second;
		}

	}
	num.push_back(n);
//	for(int i=0;i<num.size();i++){
//		cout<<num[i]<<' ';
//	}
//	cout<<endl;
	vector<long long> ans(n,0);
	int j=0;
	int numsum=0;
//	for(int i=0;i<n;i++){
//		cout<<v[i].first<<' '<<v[i].second<<endl;
//	}
	for(int i=0;i<num.size()-1;i++){
		long long sum=0;
		sum+=numsum*(a[num[i]]-a[num[i+1]]);
		while(v[j].second!=num[i+1]){
			sum+=v[j].first-a[num[i+1]];
			numsum++;
			j++;
			if(j==n)break;
		}
		ans[num[i]]=sum;
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}

	return 0;
}

Measured memory_bytes: 8560
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    cout << (a > 8 || b > 8 ? ":(" : "Yay!") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    
    if(A+B>=C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}




Measured memory_bytes: 256
# 135 B

def swap(k, a, b):
    k[a], k[b] = k[b], k[a]
    return k

n = int(input())
l = list(map(int, input().split()))
num = 0
k = []
ans = []

for i in range(len(l)):
    k.append(l[i])

k.sort()

for i in range(n):
    if k[i] != l[i]:
        num += 1
        ans.append(i)

if num == 2 :
    swap(l, ans[0], ans[1])
    if k == l:
        print("YES")
    else:
        print("NO")
elif num == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9152
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<map>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int N,M;
int fie[5005][5005];
int rui[5005][5005];
ll xy[2][5001];
ll X[5001],Y[5001];

int W,H;

int compress(int id,ll *x){
  vector<ll> xs;
  for(int i=0;i<N;i++){
    xs.push_back(xy[id][i]);
  }

  sort(xs.begin(),xs.end());
  xs.erase(unique(xs.begin(),xs.end()),xs.end());

  for(int i=0;i<N;i++){
    ll a = find(xs.begin(),xs.end(),xy[id][i]) - xs.begin();
    a++;
    x[a] = xy[id][i];
    xy[id][i] = a;
  }

  x[0] = -10000000000;

  return (int)xs.size();

}

int nibun(ll a,ll *b,int wh,bool f){

  /*
  cout << a << " :: wh = " << wh << endl;
  for(int i=0;i<=W;i++)
    cout << b[i] << " ";
  cout << endl;
  */  
  int res = lower_bound(b,b+wh+1,a) - b;

  //  cout << res << endl;

  if(b[res] > a && !f) res--;

  return res;
}

void view(){
  for(int y=0;y<=H+1;y++){
    for(int x=0;x<=W+1;x++){
      cout << rui[x][y] << " ";
    }
    cout << endl;
  }
}

int main(){
  cin >> N >> M;
  for(int i=0;i<N;i++){
    cin >> xy[0][i] >> xy[1][i];
  }

  W = compress(0,X);
  H = compress(1,Y);
  /*
  cout << "W = " << W << endl;
  for(int i=1;i<=W;i++)
    cout << X[i] << " ";
  cout << endl;
  cout << "H = " << H << endl;
  for(int i=1;i<=H;i++)
    cout << Y[i] << " ";
  cout << endl;
  */

  for(int i=0;i<N;i++){
    fie[xy[0][i]][xy[1][i]]++;
  }




  for(int y=1;y<=H+1;y++){
    for(int x=1;x<=W+1;x++){
      rui[x][y] = rui[x-1][y] + fie[x][y];
    }
  }
  for(int y=1;y<=H+1;y++){
    for(int x=1;x<=W+1;x++){
      rui[x][y] += rui[x][y-1];
    }
  }

  for(int i=0;i<M;i++){
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1 = nibun(x1,X,W,true);
    y1 = nibun(y1,Y,H,true);
    x2 = nibun(x2,X,W,false);
    y2 = nibun(y2,Y,H,false);
    /*
    cout << x1 << " "  << y1 << " " << x2 << " " << y2 << endl;
    cout << rui[x2][y2] << " - " << rui[x2][y1-1] << " - " << rui[x1-1][y2] << " + " << rui[x1][y1] << endl;
    */  
    int res = rui[x2][y2] - rui[x2][y1-1] - rui[x1-1][y2] + rui[x1-1][y1-1];
    cout << res << endl;
  }


}

Measured memory_bytes: 196116
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pi 3.141592653589
#define rep(i,n) for(int i=0;i<n;i++)
int n,y;
signed main(){
	cin>>n>>y;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			int sum=10000*i+5000*j+1000*(n-i-j);
			if(sum==y){
				cout<<i<<" "<<j<<" "<<n-i-j<<endl;
				return 0;
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    lint x, y;
    cin >> x >> y;
    int ans = 1;
    while(x<y){
        x *= 2;
        ans++;
        if(x>y){
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256