akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<char> = s.trim().chars().collect();
    let mut x: isize = 0;
    let mut y: isize = 0;
    for c in &v {
        if *c == 'I' {x += 1;}
        else if *c == 'D' {x -= 1;}
        if x > y {y = x;}
    }
    println!("{}", y);
}



Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>
int main()
{
    int N,x[200000],y[200000],t[200000],flag=1,i;
    scanf("%d",&N);
    t[0]=x[0]=y[0]=0;
    for(i=1; i<=N; i++)
    {
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
        if((abs(x[i]-x[i-1]+y[i]-y[i-1])%2==abs(t[i]-t[i-1])%2)&&abs((x[i]-x[i-1]+y[i]-y[i-1])<=abs(t[i]-t[i-1])))
            flag=1;
        else
        {
            flag=0;
            break;
        }
    }
    if(flag==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

int main(int argc, char const* argv[])
{
	int n, a[100];
	cin >> n;

	for (int i=n-1; i>=0; i--) {
		cin >> a[i];
	}

	int i=0;
	while (1) {
		cout << a[i];
		if (i == n-1) {
			break;
		} else {
			cout << " ";
		}
		i++;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
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; }
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int n; cin >> n;
    string s1,s2;
    cin >> s1 >> s2;
    int i = 0;
    bool which;
    ll cnt = 1;
    if(s1.at(0) == s2.at(0)){
        cnt *= 3;
        i++;
        which = true;
    }
    else{
        cnt *= 6;
        i += 2;
        which = false;
    }
    while(i<n){
        if(s1.at(i) == s2.at(i)){
            if(which) cnt *= 2;
            cnt %= mod;
            i++;
            which = true;
        }
        else{
            if(which) cnt *= 2;
            else cnt *= 3;
            cnt %= mod;
            i += 2;
            which = false;
        }
    }
    cout << cnt << endl;
    return 0;   

}


Measured memory_bytes: 256
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long

using namespace std;
int a,b;
//#define LOCAL_DEFINE
int main()
{
	#ifdef LOCAL_DEFINE      
    freopen("test1.txt", "rt", stdin);      
	#endif
	cin>>a>>b;
	if(a>b)
		cout<<a-1<<endl;
	else {
		cout<<a<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pb push_back
#define pq priority_queue
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vvll vector<vector<ll>>
#define vvi vector<vector<int>>
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define MODNUM 1000000007
#define lp(i,a,b) for(ll i=a; i<b; i++)
#define all(v) v.begin(), v.end()

using namespace std;
 
ll mex(ll a, ll b, ll m) {
	if(b==0) return 1;
	if(b%2) return a*mex((a*a)%m,(b-1)/2,m)%m;
	else return mex((a*a)%m,b/2,m);
}
 
int x,y;
void exteu(ll a, ll m) {
	if(m==0) { x=1;y=0; }
	else {
		exteu(m,a%m);
		ll temp = x;
		x=y;
		y=temp-(a/m)*y;
	}
}
 
ll fact(ll n) 
{	ll prod=1;
	for(ll i=2; i<=n; i++) {
		prod*=i;
	}
	return prod;
}
 
ll gcd(ll a, ll b) {
	if(b==0) return a;
	return gcd(b, a%b);
}
 
// bool isprime[100001];
// void makesieve() {
// 	memset(isprime, true, sizeof(isprime));
// 	for (int i = 2; i <= sqrt(200000); ++i)
// 	{
// 		if(isprime[i]) {
// 			for (int j = i*i; j <= 200000; j+=i)
// 			{
// 				isprime[j]=false;
// 			}
// 		}
// 	}
// }
// 
// 1 2 4 5 8
vvll D = {{-1,-1}, {1,1}, {1,-1}, {-1,1}};
void solve() {
	ll n; cin>>n;
	ll o=0;
	vll a(n); lp(i,0,n) {cin>>a[i]; if((i+1)%2 && a[i]%2)o++;}
	cout<<o;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin >> TESTS;
	// makesieve();
	while(TESTS--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3640
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Character> slime = new ArrayList<>();
		int N = sc.nextInt();
		String S = sc.next();
		slime.add(S.charAt(0));
		int j = 1;

		for(int i = 1; i < N; i++) {
			char c = S.charAt(i);
			if(slime.get(j - 1) != c) {
				slime.add(c);
				j++;
			}
		}

		System.out.println(slime.size());
		sc.close();
	}
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong K, X;
	cin >> K >> X;

	for (int i = X - K + 1; i <= X + K - 1; ++i)
		cout << i << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,a[200005];
pair<int,int>b[200005];
map<int,int>M;
int maximum_profit(){
	int z1=-2000000000,z2=a[1];
	for(int i=2;i<=n;i++){
		z1=max(z1,a[i]-z2);
		z2=min(z2,a[i]);
	}
	return z1;
}
int main(){
	cin>>n>>t;for(int i=1;i<=n;i++){cin>>a[i];M[a[i]]=i;}
	int G=maximum_profit(),counts=0;
	for(int i=1;i<=n;i++){
		if(M[a[i]+G]>=1 && M[a[i]]>=1 && M[a[i]]<M[a[i]+G])counts++;
	}
	cout<<counts<<endl;
	return 0;
}

Measured memory_bytes: 10112
n = int(input())
Alist = list(map(int, input().split()))

def buy(N, A):
    m = N[0]
    n = N[1]
    
    num = m//A
    N[0] = m%A
    N[1] = n + num
    return N

def sell(N, A):
    m = N[0]
    n = N[1]
    N[1] = 0
    N[0] = m + A * n
    return N


for i in range(n-1):
    if Alist[i] == Alist[i+1]:
        up = None
        continue
    if Alist[i] > Alist[i+1]:
        up = True
        break
    if Alist[i] < Alist[i+1]:
        up = False
        break

if up == None:
    print(1000)
else:
    poplist = []
    for i in range(1, n):
        if up:
            if Alist[i] >= Alist[i-1]:
                poplist.append(i-1)
            else:
                up = False
        
        else:
            if Alist[i] <= Alist[i-1]:
                poplist.append(i-1)
            else:
                up = True

    for idx in poplist[::-1]:
        Alist.pop(idx)

    if Alist[0] > Alist[1]:
        Alist.pop(0)
    
    if len(Alist) == 1:
        print(1000)
    else:
        if Alist[-1] < Alist[-2]:
            Alist.pop(-1)
        
        money = 1000
        nums = len(Alist)//2
        for i in range(nums):
            kabu = money // Alist[2*i]
            money = money%Alist[2*i] + kabu * Alist[2*i+1]
        print(money)

Measured memory_bytes: 9312
using System;

namespace ITP1_11_A
{
    class Dice
    {
        private int top = 0, btm = 5, front = 1, back = 4, left = 3, right = 2;
        private int[] vals = new int[6];
        public int Top { get { return vals[top]; } }
        public Dice(int[] values)
        {
            Array.Copy(values, vals, 6);
            top = 0;
            front = 1;
        }

        public void N()
        {
            int tmp = top;
            top = front;
            front = btm;
            btm = back;
            back = tmp;
        }

        public void W()
        {
            int tmp = left;
            left = top;
            top = right;
            right = btm;
            btm = tmp;
        }
        public void S()
        {
            int tmp = front;
            front = top;
            top = back;
            back = btm;
            btm = tmp;
        }
        public void E()
        {
            int tmp = right;
            right = top;
            top = left;
            left = btm;
            btm = tmp;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Dice dice = new Dice(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
            string cmd = Console.ReadLine();
            foreach (var c in cmd)
            {
                switch (c)
                {
                    case 'N': dice.N(); break;
                    case 'W': dice.W(); break;
                    case 'S': dice.S(); break;
                    case 'E': dice.E(); break;
                    default: break;
                }
            }
            Console.WriteLine(dice.Top);
        }
    }
}

Measured memory_bytes: 9116
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int A, B, C;

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

  printf( "%d\n", std::min( B/A, C ) );

  return 0;
}

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

int fanc(vector<int> &a, int in, int lv, int n, int sum){
	static int fin_ans = 0;
	if(lv == n-1){
		if(sum == in || sum+a.at(n-1) == in) return 1;
		else return 0;
	}else{
		int a1 = fanc(a, in, lv+1, n, sum);
		int a2 = fanc(a, in, lv+1, n, sum+a.at(lv));
		if(a1 == 1 || a2 == 1) return 1;
		else 0;
	}
}

int main(){
	int n, q, in;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);
	cin >> q;
	rep(i, q){
		cin >> in;
		bool ans = fanc(a, in, 0, n, 0);
		if(ans) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll A,B,C,k;
    cin >> A >> B >> C;
    cin >> k;
    rep1(i,k){
        rep0(a,i){
            rep0(b,i-a){
                rep0(c,i-a-b){
                    if(A*pow(2,a) < B*pow(2,b) && B*pow(2,b) < C*pow(2,c)){
                        cout << "Yes" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3288
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    A,B=mi()
    if B % A == 0:
        print(A+B)
    else:
        print(B-A)




if __name__ == "__main__":
    main()

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("in.txt","r",stdin);
    int n,k;
    cin >> n;
    ll sum = 0,sq = 0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        sum += x;
        sq += x*x;
    }
    ll p1 = sum/n;
    ll p2 = ceil(sum*1.0/n);
    ll ans1 = sq - 2*p1*sum + p1*p1*n;
    ll ans2 = sq - 2*p2*sum + p2*p2*n;

    cout << min(ans1,ans2) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define double long double
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
typedef pair<P,P> PP;
double eps=1e-8;
int mod=1e9+7;
int inf=1LL<<55;

priority_queue<P,vector<P>,greater<P> > pq;
bool p[2][100000];

signed main(){
  int n,m,a[100000],ans=0;
  vector<PP> v;

  cin>>n>>m;
  
  for(int i=0;i<n;i++){
    cin>>a[i];
    v.push_back(PP(P(a[i],i),P(i,0)));
    v.push_back(PP(P(i,a[i]),P(i,1)));
    ans+=abs(a[i]-i);
  }
  sort(v.begin(),v.end());

  for(int i=0;i<n;i++){
    int fi=v[i].second.first,se=v[i].second.second;
    p[se][fi]=1;
  }

  vector<int> x,y;
  for(int i=0;i<n;i++){
    if(p[0][i]&&p[1][i])y.push_back(max(a[i],i));
    if(!p[0][i]&&!p[1][i])x.push_back(min(a[i],i));
  }

  sort(x.begin(),x.end());
  reverse(x.begin(),x.end());
  sort(y.begin(),y.end());

  for(int i=0;i<min((int)x.size(),m);i++) ans+=(x[i]*2-y[i]*2);
  cout<<ans<<endl;  
  
  return 0;
}



Measured memory_bytes: 11732
N = int(input())
A = list(map(int,input().split()))

Q = int(input())
for _ in range(Q):
    b,e,t = map(int,input().split())
    for k in range(e-b):
        A[b+k],A[t+k] = A[t+k],A[b+k]

print(*A)


Measured memory_bytes: 5832
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

  map<int, int> dp;

  dp[0] = 0;

  int xs = 0;

  const int n = s.size();

  vector<int> opt(n, 1e9);
  for (int i = 0; i < n; i++) {
    xs ^= 1 << s[i] - 'a';

    for (int j = 0; j < 26; j++) {
      if (dp.count(xs ^ 1 << j)) {
        opt[i] = min(opt[i], dp[xs ^ 1 << j] + 1);
      }
    }
    if (!dp.count(xs)) dp[xs] = 1e9;
    dp[xs] = min(dp[xs], opt[i]);
  }
  if (xs == 0) {
    opt[n - 1] = 1;
  }

  cout << opt[n - 1] << endl;
}

Measured memory_bytes: 10628
sub f{$$_=my$t=pop;grep$$_?$$_&$t:f(3-$t),@$_}print$c*(2*(map{map{push@{-$_},-$a[--$|]for@a=split}<>;$$_||${@$_?f(1)?b:a:c}++}-<>..-1)-$c)+($a+$b)**2+$a*$a

Measured memory_bytes: 131936
#include <iostream>

using namespace std;

inline int min(int x, int y){
	return x < y ? x : y;
}

int main(){
	int n;
	string cardTaro, cardHanako;
	unsigned int ctsize, chsize;
	int lim, pointTaro = 0, pointHanako = 0;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> cardTaro >> cardHanako;
		ctsize = cardTaro.size();
		chsize = cardHanako.size();
		lim = min(ctsize, chsize);

		int j;
		for(j = 0; j < lim; j++){
			if(cardTaro[j] > cardHanako[j]){
				pointTaro += 3;
				break;
			}else if(cardTaro[j] < cardHanako[j]){
				pointHanako += 3;
				break;
			}
		}

		if(j == lim){
			if(ctsize > chsize){
				pointTaro += 3;
			}else if(ctsize < chsize){
				pointHanako += 3;
			}else{
				pointTaro += 1;
				pointHanako += 1;
			}
		}
	}

	cout << pointTaro << " " << pointHanako << endl;

	return 0;
}

Measured memory_bytes: 3184
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	var vs = ReadIntArray();

	var h0 = new Dictionary<int, int>();
	var h1 = new Dictionary<int, int>();

	for(int i = 0; i < n; i += 2)
	{
	    int v0 = vs[i];
	    if (!h0.ContainsKey(v0)){ h0[v0] = 0; }
	    h0[v0] += 1;

	    int v1 = vs[i + 1];
	    if (!h1.ContainsKey(v1)){ h1[v1] = 0; }
	    h1[v1] += 1;
	}

	int mfv0 = 0, mfv1 = 0; // most frequent values
	int maxf0 = 0, secondf0 = 0, maxf1 = 0, secondf1 = 0;
	
	foreach (int v0 in h0.Keys)
	{
	    int f = h0[v0];
	    if (f > maxf0){
		secondf0 = maxf0;
		mfv0 = v0;
		maxf0 = f;
	    }
	    else if (f > secondf0)
	    {
		secondf0 = f;
	    }
	}

	foreach (int v1 in h1.Keys)
	{
	    int f = h1[v1];
	    if (f > maxf1)
	    {
		secondf1 = maxf1;
		mfv1 = v1;
		maxf1 = f;
	    }
	    else if (f > secondf1)
	    {
		secondf1 = f;
	    }
	}

	int ans;
	
	if (mfv0 != mfv1)
	{
	    ans = n - maxf0 - maxf1;
	}
	else
	{
	    int ans0 = n - maxf0 - secondf1;
	    int ans1 = n - maxf1 - secondf0;
	    ans = Math.Min(ans0, ans1);
	}
    
	WriteLine(ans);
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair

const int INF = INT_MAX;

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	vi arr(n);
	int ans = 0;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		ans ^= arr[i];
	}
	int temp;
	for(int i = 0; i < n; i++){
		temp = arr[i] ^ ans;
		cout << temp << " ";
	}
	cout << "\n";


	return 0;
}

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

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

    if(A+B > 16 || A > 8 || B > 8){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }
    
   
}
 



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

namespace ConsoleApp32 {
    class Program {
        static void Main(string[] args) {
            var x = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();

            int N = x[0];
            int A = x[1];
            int B = x[2];

            if (B <= A * N) {
                Console.WriteLine(B);
            } else {
                Console.WriteLine(A * N);
            }
        }
    }
}


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

lint n, m;
priority_queue<lint> q;

int main() {
    cin >> n >> m;
    for(lint i = 0; i < n; i++) {
        lint a;  cin >> a;
        q.push(a);
    }

    while(m--) {
        lint ma = q.top();  q.pop();
        ma /= 2;
        q.push(ma);
    }

    lint ans = 0;
    while(!q.empty()) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int w,h;
	while(cin>>w>>h){
		if(w==0&&h==0) break;
		int a[h+1][w+1],b[h+1][w+1];
		for(int i=1;i<=h-1;i++){
			for(int j=1;j<=w-1;j++){
				cin>>a[i][j];
			}
			for(int j=1;j<=w;j++){
				cin>>b[i][j];
			}
		}
		for(int i=1;i<=w-1;i++){
			cin>>a[h][i];
		}
		for(int i=0;i<=h;i++){
			a[i][0]=1;
			a[i][w]=1;
		}
		for(int i=0;i<=w;i++){
			b[0][i]=1;
			b[h][i]=1;
		}
		int door[h+1][w+1][4];
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				door[i][j][0]=b[i-1][j];
				door[i][j][1]=a[i][j];
				door[i][j][2]=b[i][j];
				door[i][j][3]=a[i][j-1];
			}
		}
		int map[h+1][w+1];
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				map[i][j]=0;
			}
		}
		map[1][1]=1;
		int ct=1,kai=0;
		while(map[h][w]==0&&ct>0){
			kai++;
			ct=0;
			for(int i=1;i<=h;i++){
				for(int j=1;j<=w;j++){
					if(map[i][j]==kai){
						if(door[i][j][0]==0&&map[i-1][j]==0){
							map[i-1][j]=kai+1;
							ct++;
						}
						if(door[i][j][1]==0&&map[i][j+1]==0){
							map[i][j+1]=kai+1;
							ct++;
						}
						if(door[i][j][2]==0&&map[i+1][j]==0){
							map[i+1][j]=kai+1;
							ct++;
						}
						if(door[i][j][3]==0&&map[i][j-1]==0){
							map[i][j-1]=kai+1;
							ct++;
						}
					}
				}
			}
		}
		if(ct==0){
			cout<<0<<endl;
		}
		else{
			cout<<map[h][w]<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1188
import java.util.*

fun main() {
    val snukes = mutableSetOf<Int>()
    val jin = Scanner(System.`in`)
    val n = jin.nextInt()
    val k = jin.nextInt()
    snukes.addAll(1..n)
    for (j1 in 1..k) {
        val d = jin.nextInt()
        for (j2 in 1..d) {
            snukes.remove(jin.nextInt())
        }
    }
    println(snukes.size)
}

Measured memory_bytes: 48040
import sys
iN,iT = [int(_) for _ in input().split()]
aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
aData = [x for x,y in aData if y <= iT]
if aData:
    print(min(aData))
else:
    print("TLE")


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

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> ss(h);
	for (auto &&s : ss)
	{
		cin >> s;
	}

	vector<bool> jr(h, false), jc(w, false);
	for (int i = 0; i < h; i++)
	{
		bool f = true;
		for (int j = 0; j < w; j++)
		{
			f &= (ss[i][j] == '.');
		}

		jr[i] = f;
	}
	for (int j = 0; j < w; j++)
	{
		bool f = true;
		for (int i = 0; i < h; i++)
		{
			f &= (ss[i][j] == '.');
		}

		jc[j] = f;
	}

	for (int i = 0; i < h; i++)
	{
		if (jr[i])
		{
			continue;
		}

		for (int j = 0; j < w; j++)
		{
			if (jc[j])
			{
				continue;
			}

			cout << ss[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <bitset>

using namespace std;

int main() {
  int64_t X;
  cin >> X;
  bitset<10000001> b;
  for (int64_t i = 3; i <= 10000000; i += 2) {
    for (int64_t j = i + i; j <= 10000000; j += i) {
      b.set(j);
    }
  }
  int result = X | (X != 2);
  while (b[result]) result += 2;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1408
//  ©   ___MRX___

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

#define ll long long int

int main()
{
    int n, i, flag = 0;
    cin >> n;
    vector<int> vec(n);
    for(i = 0; i < n; i++) {
        cin >> vec[i];
    }
    for(i = 0; i < n; i++) {
        if(vec[i] != i + 1) flag++;
    }

    if(flag <= 2) cout << "YES" << "\n";
    else cout << "NO" << '\n';

    return 0;
}


Measured memory_bytes: 3552
#include <stdio.h>
#define MAX 100
 
void push(int);
int pop();
 
int top = 0, S[MAX];
 
int main()
{
  int  x, y, z;
  char a[MAX];
 
  while(scanf("%s",a) != EOF){
    if(a[0] == '+'){
      x = pop();
      y = pop();
      push(y+x);
    }
    else if(a[0] == '-'){
      x = pop();
      y = pop();
      push(y-x);
    }
    else if(a[0] == '*'){
      x = pop();
      y = pop();
      push(y*x);
    }
    else{   
      push(atoi(a));
    }
  }
   
  printf("%d\n",pop());
 
  return 0;
}
 
void push(int x)
{
  top++;
  S[top] = x;
}
 
int pop()
{
  top--;
  return S[top+1];
}

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

int d[209][100009], a[209];
long long md = 1000000007;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, x; cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n); 
	for (int i = 0; i <= x; i++)
		d[0][i] = i % a[0];
	for (int i = 1; i < n; i++)
		for (int j = 0; j <= x; j++)
			d[i][j] = (1LL * d[i - 1][j % a[i]] + 1LL * d[i - 1][j] * i) % md;
	cout << d[n - 1][x] << '\n';
	return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <stack>
#include <map>
using namespace std;

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

    int ans;
    bool check(true);
    stack<int> s;
    map<int,int> mp;

    for(int i=0;i<l;i++){
        int c;  cin >> c;
        if(c<0){
            if(s.empty()){
                ans = i+1;
                check = false;
                break;
            }else if(c*(-1)!=s.top()){
                ans = i+1;
                check = false;
                break;
            }else{
                s.pop();
                mp[c*(-1)] = 0;
            }
        }else{
            if(mp[c]==1){
                ans = i+1;
                check = false;
                break;
            }else{
                mp[c]++;
                s.push(c);
            }
        }
    }

    if(check){
        cout << "OK" << endl;
    }else
        cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3120
import java.util.Scanner;

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

		int tLife = scanner.nextInt();
		int tAttack = scanner.nextInt();
		int aLife = scanner.nextInt();
		int aAttack = scanner.nextInt();

		while (true) {
			aLife -= tAttack;

			if (aLife <= 0) {
				System.out.println("Yes");
				break;
			}

			tLife -= aAttack;
			if (tLife <= 0) {
				System.out.println("No");
				break;
			}
		}
	}
}

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

int main(){
    int N;
    ll x;
    cin >> N >> x;
    vector<ll> a(N);
    rep (i,N){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<ll> sum(N+1);
    sum[0]=0;
    rep (i,N){
        sum[i+1]=sum[i]+a[i];
    }
    rep (i,N+1){
        if (i<N&&sum[i]<=x&&x<sum[i+1]){
            cout << i << endl;
            break;
        }
        else if (i==N&&sum[i]==x){
            cout << N << endl;
        }
        else if (i==N){
            cout << N-1 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1000000000;

int main() {FIN
    
    int a, b, h;
    cin >> a;
    cin >> b;
    cin >> h;
    
    cout << ((h / 2) * (a + b)) << "\n";
    
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;

typedef long long ll;

vector<vector<int>> graph;

int n;
map<int, int> d; // d[dist] := 距離が dist のものを数える
void bfs(int start) {
  vector<int> dist(n, -1);
  dist[start] = 0;
  queue<int> q;
  q.push(start);
  while (!q.empty()) {
    auto cur_v = q.front();
    q.pop();
    for (int i = 0; i < graph[cur_v].size(); i++) {
      int nxt_v = graph[cur_v][i];
      if (dist[nxt_v] != -1) {
        continue;
      }
      dist[nxt_v] = dist[cur_v] + 1;
      q.push(nxt_v);
    }
  }
  for (int i = 0; i < n; i++) {
    d[dist[i]]++;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  graph.resize(n);

  for (int i = 0; i < n - 1; i++) {
    graph[i].push_back(i + 1);
    graph[i + 1].push_back(i);
  }
  graph[x].push_back(y);
  graph[y].push_back(x);

  for (int i = 0; i < n; i++) {
    bfs(i);
  }

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


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;


int N;
V<int> t, x ,y;

int main(){
    INIT;
    cin >> N;
    REP(i,N) {
        int ti, xi, yi; cin >> ti >> xi >> yi;
        t.push_back(ti);
        x.push_back(xi);
        y.push_back(yi);
    }
    V<int> z(N);
    std::iota(ALL(z), 0);
    std::sort(ALL(z), [](int& x, int& y) {
        return t[x] < t[y];
    });

    bool ok = true;
    int ct = 0, cx = 0, cy = 0;
    REP(i,N) {
        int nt = t[z[i]], nx = x[z[i]], ny = y[z[i]];
        int cost = abs(cx-nx) + abs(cy-ny);
        if(nt < ct+cost) { ok = false; break; }
        if((nt-ct)%2 != cost%2) { ok = false; break; }
        ct = nt; cx = nx; cy = ny;
    }
    cout << (ok ? "Yes" : "No");
}

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

int main()
{
  while(1){
    int N;
    cin >> N;
    if(N == 0) break;
    int t[N][N+1];
    for(int i = 0; i < N; i++)
      for(int j = 0; j < N+1; j++)
        cin >> t[i][j];
    int dp[1<<N];
    fill(dp,dp+(1<<N),INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < 1<<N; i++){
      for(int j = 0; j < N; j++){
        if((i & (1<<j)) != 0) continue;
        int cost = t[j][0];
        for(int k = 0; k < N; k++){
          if((i & (1<<k)) != 0)
            cost = min(t[j][k+1], cost);
        }
        int n = (i | (1<<j));
        dp[n] = min(dp[n], dp[i]+cost);
      }
    }
    cout << dp[(1<<N)-1] << endl;
  }
}

Measured memory_bytes: 1416
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N ; 
    string cap;
    ll r = 0, b = 0;

    cin >> N ;
    cin >> cap;

    rep(i, cap.size()){
        if(cap[i] == 'R') r++;
        else b ++;
    }

    if(r > b) cout <<"Yes" << endl;
    else cout << "No" << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    string S;
    cin >> S;
    vector<char> T(500010,'#');
    rep(i,S.size()){
        T[i+250000] = S[i];
    }
    ll l = 250000,r = 250000 + S.size();
    ll Q;
    cin >> Q;
    ll t = 0;
    rep(i,Q){
        ll q;
        cin >> q;
        if(q == 1){
            if(t == 1) t = 0;
            else t = 1;
        }else{
            ll F;
            char C;
            cin >> F >> C;
            if(F == 1){
                if(t == 0){
                    T[l-1] = C;
                    l--;
                }
                else{
                    T[r] = C;
                    r++;
                }

            }else{
                if(t == 0){
                    T[r] = C;
                    r++;
                }
                else{
                    T[l-1] = C;
                    l--;
                }
            }
        }
    }
    string ans = "";
    rep(i,500010){
        if(T[i] != '#'){
            ans += T[i];
        }
    }
    if(t) reverse(ALL(ans));
    cout << ans << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0,cnt2=0,i;
    string x;
    cin>>x;
    for(i=0;i<x.size();i++)
    {
        if(x[i]!='T')
            break;
    }
    int ck=0,ans=0;
    for(;i<x.size();i++)
    {
        if(x[i]=='S'&&ck==1)
        {
            int l=min(cnt,cnt2);
         ans+=l;
         cnt=cnt-l;
         cnt2=0;
         ck=0;
        }
        if(x[i]=='S'&&ck==0)
            {
                cnt++;
            }
        else if(x[i]=='T')
        {
            cnt2++;
            ck=1;
        }
        //cout<<cnt<<" "<<cnt2<<" "<<ans<<endl;
    }
    if(ck!=0)
    {
        ans+=min(cnt,cnt2);
    }
    printf("%d\n",x.size()-(ans*2));
}


Measured memory_bytes: 640
ks = list(map(int, input().split()))
K = ks[0]
S = ks[1]

c = 0

for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if K >= z and z >= 0:
            c += 1
print(c)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

Measured memory_bytes: 3316
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
count = 0
for d1, d2 in D:
    if d1 == d2:
        count += 1
    else:
        count = 0
    if count == 3:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 62268
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define dump(x)      cerr << #x << " = " << (x) << endl;

void sortVecPair(vector<auto>& X, VI& idx, auto comparator) {
    VI idx2(SZ(idx));
    iota(ALL(idx2), 0);
    stable_sort(ALL(idx2), comparator);
    REP(i, SZ(idx)) idx2[i] = idx[idx2[i]];
    REP(i, SZ(idx)) idx[i] = idx2[i];
}

int main() {
    LL N;
    cin >> N;
    vector<pair<string, LL>> X(N);
    REP(i, N) {
        string s;
        LL x;
        cin >> s >> x;
        X[i] = make_pair(s, x);
    }

    VI idx(SZ(X));
    iota(ALL(idx), 0);
    sortVecPair(X, idx, [&] (auto& i, auto& j) {return X[i].second > X[j].second;});
    SRSORT(X);

    sortVecPair(X, idx, [&] (auto& i, auto& j) {return X[i].first < X[j].first;});
    FSORT(X);

    REP(i, N) {
        cout << idx[i] + 1 << endl;
    }
    
    return 0;
}


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

int main() {
	string S,T;
	cin>>S>>T;
	int A,B;
	cin>>A>>B;
	string U;
	cin>>U;
	if(U==S) cout<<A-1<<" "<<B<<endl;
	else     cout<<A<<" "<<B-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dp[2][110][50];  /* dp[id][i+1][j] : 先頭からi桁目までで0でない数がj個現れるs以下の数の個数。
                                       ただし、id = 0 のとき現時点でsと等しい。
                                       id = 1 のとき現時点でsより小さいことが確定。 */
int main() {
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    
    dp[0][0][0] = 1;
    rep(id, 2) {
        rep(i, n) {
            rep(j, 4) {
                ll lim = s[i] - '0';  //  先頭からi桁目にはlim以下の数を置ける
                if(id) {
                    lim = 9;
                }
                exrep(x, 0, lim) {  // 先頭からi桁目にxを置くとする
                    dp[id || x < lim][i+1][j + (x != 0)] += dp[id][i][j];
                }
            }
        }
    }
    
    ll ans = 0;
    rep(id, 2) {  
        ans += dp[id][n][k];
    }
    
    out(ans);
    re0;
}

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

int main(){
	ll a,b;
	ll arr[200005];
	cin >> a >> b;
	for(int i=0;i<a;i++){
		cin >> arr[i];
	}
	for(int i=0;i<a-b;i++){
		if(arr[i]<arr[i+b]) cout << "Yes\n";
		else cout << "No\n";
	}
}

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

vector<vector<int>> dp(100005, vector<int>(4,-1));

int rec(int day, int type, vector<vector<int>>& a)
{
    int n = a.size();
    if(day == n) return 0;

    if(dp[day][type] != -1) return dp[day][type];

    int points = 0;

    if(type == 3)
    {
        points = max( points, rec(day+1, 0, a) + a[day][0]);
        points = max( points, rec(day+1, 1, a) + a[day][1]);
        points = max( points, rec(day+1, 2, a) + a[day][2]);
    }

    if(type == 0)
    {
        points = max( rec(day+1, 1, a) + a[day][1], rec(day+1, 2, a) + a[day][2] );
    }
    else if(type == 1)
    {
        points = max( rec(day+1, 0, a) + a[day][0], rec(day+1, 2, a) + a[day][2] );
    }
    else if(type == 2)
    {
        points = max( rec(day+1, 1, a) + a[day][1], rec(day+1, 0, a) + a[day][0] );
    }

    return dp[day][type] = points;
}

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> act(N, vector<int>(3));
    for(int i = 0 ; i < N ; i++)
    for(int j = 0 ; j < 3 ; j++)
       cin >> act[i][j];

    cout << rec(0,3,act);
}

Measured memory_bytes: 19980
#include<iostream>

using namespace std;

int main(){
    int n, p[200009];
    cin >> n;
    for(int i=0;i<n;i++)cin >> p[i];
    int mn=p[0], cnt=0;
    for(int i=0;i<n;i++){
        if(p[i]<=mn)cnt++;
        mn = min(mn, p[i]);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> cnt_vec(M + 1, 0);
  for (int i = 1; i <= N; ++i) {
    int ki;
    cin >> ki;
    for (int j = 1; j <= ki; ++j) {
      int ai;
      cin >> ai;
      ++cnt_vec[ai];
    }
  }

  int ans = 0;
  for (int i = 1; i <= M; ++i) {
    if (cnt_vec[i] == N) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

int main() {
    ll N, min_ans, ans;
    cin >> N;
    min_ans = sqrt(N);
    ans = 11;
    for (ll i = min_ans; i >= 1; i--) {
        if (N % i == 0) {
            ll digit = N / i;
            int count = 0;
            while (digit != 0) {
                digit /= 10;
                count++;
            }
            if (min_ans > count) min_ans = count;
        }
    }
    cout << min_ans << endl;
    return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n; cin >> n;
		if( n == 0) break;
		int ans = 0;
		for(int i = 1; i < n; ++i){
			int nsum = 0;
			for(int j = i; nsum < n; ++j){
				nsum += j;
			}
			if(nsum == n) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define ll long long

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M+1);
    vector<ll> R(M+1);
    for(int i = 1; i <= M; ++i) cin >> L[i] >> R[i];
    if(*min_element(R.begin()+1, R.end())-*max_element(L.begin()+1, L.end()) >= 0)cout << *min_element(R.begin()+1, R.end())-*max_element(L.begin()+1, L.end()) +1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 4844
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long int *a;
  int n, i, j, s;
  long long int m;
  long long int ma;  // minimum a value
  int mi;            // minimum a index;
  cin >> n;
  a = (long long int *)malloc(sizeof(long long int) * n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  s = 0;
  ma = abs(a[0]);
  mi = 0;
  for (i = 0; i < n; i++) {
    if (abs(a[i]) < ma) {
      ma = abs(a[i]);
      mi = i;
    }
    if (a[i] < 0) {
      s++;
    }
  }
  // cout << mi << " " << ma << endl;
  for (i = 0; i < n; i++) {
    if (a[i] < 0) {
      a[i] = -a[i];
    }
  }
  if (s % 2 == 1) {
    a[mi] = -ma;
  }
  m = 0;
  for (i = 0; i < n; i++) {
    // cout << "A:" << a[i] << " ";
    m += a[i];
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int N; long long L; char S[100100];
int cnt,tr[100100][2],dp[100100],chk[100100];

int main()
{
	scanf ("%d %lld",&N,&L);
	while (N--){
		scanf ("%s",S);
		int now = 0;
		for (int i=0;S[i];i++){
			int &nxt = tr[now][S[i]-'0'];
			if (!nxt){
				nxt = ++cnt;
				dp[nxt] = dp[now] + 1;
			}
			now = nxt;
		}
	}

	long long win = 0;
	for (int i=0;i<=cnt;i++) if ((!tr[i][0]) ^ (!tr[i][1])){
		long long x = L - dp[i];
		win ^= x & (-x);
	}
	puts(win?"Alice":"Bob");

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <utility>
#include <cmath>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c; s = "";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	for (int x, h; x = in(), h = in(), x || h;)
		printf("%lf\n", (x + sqrt(x * x + 4 * h * h)) * x);
}


Measured memory_bytes: 2504
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};

ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}

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

  int n, m;
  cin >> n >> m;
  int ans = 0;
  ans += com(n,2);
  ans += com(m,2);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;
string str[50];
string strIn[50];
string strbubble[50];
int n;
void bubbleSort(){
	for (int i = 0; i < n; ++i){
		for (int j = n - 1; j >= i; --j){
			if (j-1>=0 && str[j][1] < str[j - 1][1]) swap(str[j], str[j - 1]);
		}
	}
}
void selectionSort(){
	for (int i = 0; i < n; ++i){
		int Min = i;
		for (int j = i; j < n; ++j){
			if (str[j][1] < str[Min][1]) Min = j;
		}
		swap(str[i], str[Min]);
	}
}

int main(){
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> strIn[i];
	for (int i = 0; i < n; ++i) str[i] = strIn[i];
	bubbleSort();
	for (int i = 0; i < n; ++i){
		if (i != 0) cout << ' '; cout << str[i] ;
	}
	cout << '\n';
	cout << "Stable\n";
	for (int i = 0; i < n; ++i) strbubble[i] = str[i];
	for (int i = 0; i < n; ++i) str[i] = strIn[i];
	selectionSort();
	for (int i = 0; i < n; ++i){
		if (i != 0) cout << ' '; cout << str[i];
	}
	cout << '\n';
	bool isSame = true;
	for (int i = 0; i < n; ++i) if (str[i] != strbubble[i]){ isSame = false; break; }
	if (!isSame) cout << "Not stable\n"; else cout << "Stable\n";
}

Measured memory_bytes: 1212