akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer groupA[] = {1, 3, 5, 7, 8, 10, 12};
        Integer groupB[] = {4, 6, 9, 11};
        Integer groupC[] = {2};
        int x = scanner.nextInt(), y = scanner.nextInt();

        if ((Arrays.asList(groupA).contains(x) && Arrays.asList(groupA).contains(y)) ||
                (Arrays.asList(groupB).contains(x) && Arrays.asList(groupB).contains(y)) ||
                (Arrays.asList(groupC).contains(x) && Arrays.asList(groupC).contains(y))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23380
/**
 * author: Behradm
 * Created: 2020.08.29 16:57:28
 * In The Name of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<int> mark(n, false);
  vector<int> color(n, 0);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }

  auto bfs = [&](int s, int c) {
    queue<int> q;
    q.push(s);
    int ans = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      mark[u] = true;
      ans += 1;
      color[u] = c;
      for (int i = 0; i < (int) g[u].size(); i++) {
        int v = g[u][i];
        if (!mark[v])
          q.push(v);
      }
    }
    return ans;
  };

  int c = 0;
  for (int u = 0; u < n; u++) {
    if (!mark[u]) {
      bfs(u, c);
      c += 1;
    }
  }

  vector<int> cnt(n, 0);
  for (int u = 0; u < n; u++) {
    cnt[color[u]] += 1;
  }

  cout << *max_element(cnt.begin(), cnt.end()) << '\n';
  return 0;
}

Measured memory_bytes: 16812
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n, m;
    cin >> n >> m;

    vector<int> x;
    REP(i, m) {
        int input;
        cin >> input;
        x.push_back(input);
    }

    SORT(x);

    vector<int> len;
    REP(i, m-1) {
        len.push_back(x[i+1] - x[i]);
    }
    sort(len.rbegin(), len.rend());

    int ans = abs(x.back() - x[0]);
    REP(i, min(len.size(), (unsigned long)(n-1))) {
        ans -= len[i];
    }
    P(ans);

    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>

using namespace std;

const int M_MAX = 1000000; 

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

int solve()
{
    int a[M_MAX];
    cin >> a[0];

    for(int i=1; i<=M_MAX; i++) {
        a[i] = f(a[i-1]);
        for(int j=0; j<i; j++) {
            if(a[i] == a[j]) {
                return i;
            }
        }
    }
}

int main()
{
    int i = solve();
    cout << i+1 << endl;    
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  string s; cin >> s;
  if(n%2 == 1){cout << "No" << endl;return 0;}
  if(s.substr(0,n/2) == s.substr(n/2, n)){cout << "Yes" << endl;}
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
T = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
TT = {}
for i,t in enumerate(T):
  i+=N
  TT[t] = T[i%26]

ss = []
for s in S:
  ss.append(TT[s])
print("".join(ss))

Measured memory_bytes: 39152
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()

def calc(x,y,z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

ans = [0]*(N+1)

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            val = calc(x,y,z)
            if val <= N:
                ans[val] += 1

for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 75260
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int a, b, c;
int main() {
  cin >> a >> b >> c;
  if ((b * 10 + c) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main(){
    long long a , b , c , k , ans ;
    
    cin >> a >> b >> c >> k;
    
    ans = min(a , k);
    k = max( (long long) 0 , k-a);
    k = max( (long long) 0 , k-b);
    ans -= k;
    
    cout << ans << endl;
    return(0);
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	int flag[10];
	memset(flag, 0, sizeof(flag));
	cin >> a >> b >> c;
	flag[a]++;
	flag[b]++;
	flag[c]++;
	if (flag[5] == 2 && flag[7] == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

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

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

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> a(0, vector<char>(w));

    rep(i, h) {
        bool white_flg = true;
        vector<char> tmp_a(w);
        rep(j, w) {
            cin >> tmp_a[j];
            if ( tmp_a[j] == '#' ) {
                white_flg = false;
            }
        }
        if ( !white_flg ) {
            a.push_back(tmp_a);
        }
    }


    vector<int> ignore_num;
    rep(i, w) {
        bool white_flg = true;
        rep(j, a.size()) {
            if ( a[j][i] == '#' ) {
                white_flg = false;
            }
        }
        if ( white_flg ) {
            ignore_num.push_back(i);
        }
    } 

//    rep(i, ignore_num.size()) {
//        cout << ignore_num[i] << endl;
//    }

    rep(i, a.size()){
        rep(j, w) {
            bool ignore_flg = false;
            if ( !ignore_num.empty() ) {
                rep(k, ignore_num.size()) {
                    if ( j == ignore_num[k] ) {
                        ignore_flg = true;
                    }
                }
            }
            if ( !ignore_flg ) printf("%c", a[i][j]);
        }
        printf("\n");
    }

    return 0;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

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

ll dp[3001][3001][4];
ll vals[3001][3001];
void solve(ll testnum)
{
    ll r,c,k;
    cin >> r >> c >> k;
    for(ll i = 0; i < k; i++) {
    	ll x,y,z;
    	cin >> x >> y >> z;
    	vals[x-1][y-1] = z;
    }
    dp[r-1][c-1][0] = dp[r-1][c-1][1] = dp[r-1][c-1][2] = vals[r-1][c-1];
    for(ll i=r-1;i>=0;i--) {
    	for(ll j=c-1;j>=0;j--) {
    		for(ll k=0;k<3;k++) {
    			if(j!=c-1) {
	    			if(k < 3) dp[i][j][k] = max(dp[i][j+1][k+1] + vals[i][j], dp[i][j][k]);
	    			dp[i][j][k] = max(dp[i][j+1][k], dp[i][j][k]);
	    		}
	    		if(i!=r-1) {
	    			if(k < 3) dp[i][j][k] = max(dp[i][j][k], dp[i+1][j][0] + vals[i][j]);
	    			dp[i][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
	    		}
	    		// cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n";
    		}
    	}
    }
    cout << dp[0][0][0] << "\n";
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 355220
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[32]={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;
  k-=1;
  cout<<a[k]<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int week;
	int n = 100000;
	cin >> week;
	for (int i = 0; i < week; i++) {
		n = n*105/100;
		if (n%1000)
			n = (n/1000+1)*1000;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 0
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
//use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;

////////////////////////////////////////////////


fn main(){
    read_line();
    let y = read_ints()
        .into_iter()
        .fold(0,|s,i| s + (i-1));
    
    println!("{}",y);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
int main(){
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int h, a;
    cin >> h >> a;

    int ans = h / a;
    
    if (h%a!=0) ++ans;

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

Measured memory_bytes: 256
function Main(input) {
  input = input.trim().split(" ");
  var A = parseInt(input[0], 10);
  var B = parseInt(input[1], 10);
  var C = parseInt(input[2], 10);
  var X = parseInt(input[3], 10);
  var Y = parseInt(input[4], 10);
  var roop = Math.max(X, Y);
  var ans = Infinity;
  var total = 0;
  for (var i = 0; i <= roop; i++) {
    var xa = 0;
    var yb = 0;
    if (i < X) {
      xa = X - i;
    }
    if (i < Y) {
      yb = Y - i;
    }
    total = 2 * i * C + A * xa + B * yb;
    ans = Math.min(ans, total);
    total = 0;
  }
  console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int th = n / 1000;
  int ha = n % 1000 / 100;
  int te = n % 100 / 10;
  int on = n % 10;
  if(ha == te && (ha == th || te == on)){
    cout << "Yes" << endl;
  }else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
void print(int p[]){
    int j = 0;
    for(int i=39;i>=0;i--){
        if(p[i] != 0)  break;
        j++;
    }
    for(int i= 39 - j; i>= 0;i--){
        cout << p[i];
    }
}
int gcd(int a,int b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}
    
int main(){
    int a,b;
    cin >> a >> b;
    int cm=gcd(a,b);
    a/=cm;
    b/=cm;
    int xa[10]={0};
    for(int i=0;;i++){
        if(a<10){
            xa[i]=a%10;
            break;
        }
        xa[i]=a%10;
        a/=10;
    }
    int xb[10]={0};
    for(int i=0;;i++){
        if(b<10){
            xb[i]=b%10;
            break;
        }
        xb[i]=b%10;
        b/=10;
    }
    int p[20]={0};
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            p[i+j]+=xa[j]*xb[i];
        }
    }
    for(int i=0;i<19;i++){
        p[i+1]+=p[i]/10;
        p[i]%=10;
    }
    int xc[20]={0};
    for(int i=0;;i++){
        if(cm<10){
            xc[i]=cm%10;
            break;
        }
        xc[i]=cm%10;
        cm/=10;
    }
    int ans[40]={0};
    for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
            ans[i+j]+=xc[j]*p[i];
        }
    }
    for(int i=0;i<39;i++){
        ans[i+1]+=ans[i]/10;
        ans[i]%=10;
    }
    print(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const LL mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
int cx,cy;

LL qpow(LL a, LL b ,LL mod)
{
    LL res=1;
    while(b!=0)
    {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

const int M = 1e9+7;
LL ff[2*maxn+5];  //打表，记录n!，避免重复计算
void init()
{
    ff[0]=1;
    for(int i=1; i<=2*maxn; i++) //预计算n!
        ff[i]=(ff[i-1]*i)%M;
}
//求最大公因数
LL gcd(LL a,LL b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
 
//解线性同余方程，扩展欧几里德定理
LL x,y;
void Extended_gcd(LL a,LL b)
{
    if(b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        Extended_gcd(b,a%b);
        LL t=x;
        x=y;
        y=t-(a/b)*y;
    }
}
 
//计算不大的C(n,m)
LL C(LL a,LL b)
{
    if(b>a)
        return 0;
    b=(ff[a-b]*ff[b])%M;
    a=ff[a];
    LL c=gcd(a,b);
    a/=c;
    b/=c;
    Extended_gcd(b,M);
    x=(x+M)%M;
    x=(x*a)%M;
    return x;
}
 
//Lucas定理
LL Combination(int n, int m)
{
    LL ans=1;
    LL a,b;
    while(m||n)
    {
        a=n%M;
        b=m%M;
        n/=M;
        m/=M;
        ans=(ans*C(a,b))%M;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>cx>>cy;
    if((cx+cy)%3!=0)
    {
        cout<<0;
        return 0;
    }
    int res=(cx+cy)/3;
    int n=cx-res;
    int m=cy-res;
    if(n<0||m<0)
    {
        cout<<0;
        return 0;
    }
    if(n<m)
        swap(n,m);
    init();
    cout<<Combination(m+n,m)<<endl;
    return 0;
}

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

using namespace std;
#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()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)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()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c;
	cin >>a >>b >>c;
	
	int sm = a+b+c;
	int mx = max({a,b,c});
	rep(i,10000){
		if((sm + 2*i)%3 ==0 && mx*3 <= sm + 2*i ){
			cout << i <<"\n";
			return 0;
		}
	}
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define max(a,b) (a>b?a:b)
int n, k, ans, i, j;
string s;
int main(){
	vector<int> a;
	cin >> n >> k >> s;
	while (i < n)
	{
		while (i < n && s[i] == '1')
			i++;
		ans = max(ans, i-j);
		while (i < n && s[i] == '0')
			i++;
		k--;
		if (k <0 )
		{
			
			while (j < n && s[j] == '1')
				j++;
			while (j < n && s[j] == '0')
				j++;
		}
		ans = max(ans, i - j);
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
//#include <algorithm>
#include<set>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  int n;
  string s;
  cin>>n>>s;
  if(n>=3200){
    cout<<s;
  }else{
    cout<<"red";
  }
	return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int D, E;
  while(cin >> D >> E, D||E){
    double ans = INF;
    for(int i = 0; i <= D; i++){
      int j = D - i;
      ans = min(ans, abs(sqrt(pow(i, 2) + pow(j, 2)) - E));
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3124
h,w=map(int,input().split())
s=[input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            continue
        if not i==0:
            if s[i-1][j]=='#':
                continue
        if not j==0:
            if s[i][j-1]=='#':
                continue
        if not i==h-1:
            if s[i+1][j]=='#':
                continue
        if not j==w-1:
            if s[i][j+1]=='#':
                continue
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 9172
/********************************
*MAHBUBCSEJU                    *
*CSE 22                         *
*JAHANGIRNAGAR UNIVERSITY       *
*TIMUS:164273FU                 *
*UVA>>LIGHTOJ>>HUST:mahbubcseju */
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())
//#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) {
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e) {
    ll ret = 1;
    for(; e > 0; e >>= 1) {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
template <class T>string NTS ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template <class T>T stringtonumber ( const string &Text ) {
    istringstream ss(Text);
    T result;
    return ss >> result ? result : 0;
}
template <class T>bool ISLEFT ( T a,T b,T c) {
    if(((a.xx-b.xx)*(b.yy-c.yy)-(b.xx-c.xx)*(a.yy-b.yy))<0.0)return 1;//Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
#define mx 10000
#define md 1000000007
#define maxp 2050180000

typedef pair<int ,int > P;

////////define value/////

    int main()
    {
        int n,m;
        I2(n,m);
        int ar[10];
        SET(ar);
        for(int i=0;i<m;i++){
            int x;
            I(x);
            ar[x]++;

        }

        for(int i=n;;i++)
        {
            int x=i;
            bool fl=0;
            while(x)
            {
                if(ar[x%10]==1)fl=1;
                x/=10;
            }
            if(!fl){
                PI(i);
                return 0;
            }
        }

        return 0;
    }


Measured memory_bytes: 256
/*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!
                                 
             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।
             
*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    int n;
    cin >> n;
    vi p(1000,1);
    int m=1e9 +1;
    for(int i=0;i<=1000;i++){
    	loop(j,5){
    		p[i]*=i;
    		p[i]%=m;
    	}
    }
    int f=0;
    for(int i=0;i<=1000;i++){
    	for(int j=i;j<=1000;j++){
    		int x;
    		if(p[j]-p[i]<0)
    		x=p[j]-p[i]+m;
    		else
    		x=(p[j]-p[i])%m;
    		int y = (p[j]+p[i])%m;
    		if(x==n){
    			f=1;
    			cout<<j<<" "<<i<<endl;
    			break;
    		}
    		else
    	    if(y==n){
    	    	f=1;
    	    	cout<<j<<" "<<-1*i<<endl;
    	    	break;
    	    }
    	}
    	if(f==1) break;
    }
    return 0;
}

/* Pooja Yadav */

Measured memory_bytes: 3664
def pay?(price, numbers_str)
  price.to_s.each_char do |n_str|
    return false if numbers_str.include?(n_str)
  end
  return true
end

price, _ = gets.split(/\s/).map{ |str| str.to_i }
numbers_str = gets
price += 1 while !pay?(price, numbers_str)
puts price


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void EducationalDP_H()
{
	constexpr ll MOD = 1000000007;
	int H, W;
	cin >> H >> W;
	vvi grid(H, vi(W));
	for (int i = 0; i < H; ++i)
	{
		string str;
		cin >> str;
		for (int j = 0; j < W; ++j)
		{
			grid[i][j] = str[j] == '.' ? 0 : 1;
		}
	}
	vvl dp(H + 1, vl(W + 1));
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			dp[i + 1][j + 1] = (i == 0 && j == 0) ? 1 : grid[i][j] == 1 ? 0
				: dp[i][j + 1] + dp[i + 1][j];
			if (dp[i + 1][j + 1] >= MOD)
				dp[i + 1][j + 1] %= MOD;
		}
	}
	cout << dp[H][W] << endl;
}


int main()
{
	EducationalDP_H();
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int acc[n+1];
  acc[0] = 0;
  for (int i=0; i<n; i++) {
    int a;
    cin>>a;
    acc[i+1] = acc[i] + a;
  }
  int ans = 100000;
  for (int i=0; i<=n; i++) {
    ans = min(ans, abs(acc[i] - acc[n] + acc[i]));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;

int main()
{
    char a[100005];
    scanf("%s",a);
    int l=strlen(a);
    int i;
    bool flag;
    int op=l;
    int max1;
    for( i=0; i<l-1; i++)
    {
        if(a[i]!=a[i+1])
        {
            if(i+1>=l-i-1)
            {
                flag=1;
                max1=i+1;
            }
            else
            {
                flag=0;
                max1=l-i-1;
            }
            op=op>max1?max1:op;
            if(flag)
            {

                for(int j=0; j<max1; j++)
                {
                    if(a[j]=='1')
                        a[j]=='0';
                    else
                        a[j]=='1';
                }
            }
            else
            {
                for(int j=i+1; j<l; j++)
                {
                    if(a[j]=='1')
                        a[j]=='0';
                    else
                        a[j]=='1';
                }
            }
        }
    }
    printf("%d\n",op);
    return 0;
}


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


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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<deque>//double-ended-queue
using namespace std;
int main()
{ 
    int n,m;
    cin>>n>>m;
    long long int a[n];
    long long int sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum=sum+a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    //操作用キュー
    deque<long long int> q;
    for(int i=0;i<n;i++){
        q.push_back(a[i]);
    }
    //キュー配列
    vector<deque<long long int> > v;
    v.push_back(q);

    int num=1;
    long long int max;
    int memory;
    for(int i=0;i<m;i++){
        //初期段階
        if(num==1){
            q.clear();
            q.push_back(v[0][0]/2);
            sum=sum-v[0][0]+v[0][0]/2;
            v[0].pop_front();
            v.push_back(q);
            num++;
        }
        //queueの個数が2個以上
        else{
            //queue先頭の最大値判定
            max=-1;
            for(int j=0;j<num;j++){
                if (!v[j].empty()){
                    if(v[j][0]>max){
                        max=v[j][0];
                        memory=j;
                    }
                }
            }
            //最大値のqueueについて割引券を使用
            v[memory].pop_front();
            if(v.size()==memory+1){
                if(num<31){
                q.clear();
                q.push_back(max/2);
                v.push_back(q);
                sum=sum-max+max/2;
                num++;
                }
                else{
                    cout<<sum<<endl;
                    return 0;
                }
            }
            else{
                v[memory+1].push_back(max/2);
                sum=sum-max+max/2;
            }
        }        
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 2688
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 10**9 + 7

memo = [-1] * (1 << n)
memo[(1 << n) - 1] = 1

def dfs(s, count):
    if memo[s] != -1:
        return memo[s]
    res = 0
    for i in range(n):
        if (s >> i) & 1 == 0 and a[count][i]:
            res += dfs(s | (1 << i), count+1)
    memo[s] = res % mod
    return memo[s]

print(dfs(0, 0))



Measured memory_bytes: 63964
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int k = Integer.parseInt(s[1]);
    s = br.readLine().split(" ");
    int[] arr = new int[n];
    for (int i=0; i<n; i++) {
      arr[i] = Integer.parseInt(s[i]);
    }
    TreeSet<Integer> window = new TreeSet<>();
    int tail = 1;
    boolean noChangeSeen = false;
    for (int i=0; i<k; i++) {
      window.add(arr[i]);
    }
    for (int i=k-1; i>0; i--) {
      if (arr[i]>arr[i-1]) {
        tail++;
      } else {
        break;
      }
    }
    if (tail==k) {
      noChangeSeen = true;
    }
    int count = 1;
    for (int i=k; i<n; i++) {
      if (arr[i]>arr[i-1]) {
        if (tail<k) {
          tail++;
        }
      } else {
        tail = 1;
      }
      if (tail==k && !noChangeSeen) {
        count++;
        noChangeSeen = true;
      }
      if (tail!=k) {
        if (!(arr[i]>window.last() && arr[i-k]==window.first())) {
          count++;
        }
      }
      window.remove(arr[i-k]);
      window.add(arr[i]);
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 55676
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n; string s;
	while (cin >> n) {
		if (n == 0)break;
		int bef = 0;
		int lnow = 0; int rnow = 0;
		int count = 0;
		for (int i = 0; i < n; i++) {
			cin >> s;
			if (s == "lu")lnow = 1;
			else if (s == "ru")rnow = 1;
			else if (s == "ld")lnow = 0;
			else rnow = 0;
		    if ((bef == 0 && rnow + lnow == 2) || (bef == 1 && rnow + lnow == 0)) {
			    count++; bef = (bef + 1) % 2;
		    }
		}
		cout << count << endl;
	}
	return 0;
}


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

int main(){
  string s,a;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0')
      a += '0';
    if(s[i]=='1')
      a += '1';
    if(s[i]=='B'&&a.size()>0)
      a.pop_back();
  }
  cout << a << endl;
}


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

int main()
{
  int H, W;
  int mas[15][10005];
  
  while(cin >> H >> W, W || H) {
    Rep(i, H) Rep(j, W) cin >> mas[i][j];
    int maxv = 0;
    Rep(i, 1 << H) {
      int cnt = 0;
      Rep(j, W) {
	int cnts = 0;
	Rep(k, H) {
	  if((i >> k) & 1) cnts += 1 - mas[k][j];
	  else cnts += mas[k][j];
	}
	cnt += max(cnts, H - cnts);
      }
      maxv = max(maxv, cnt);
    }
    
    cout << maxv << endl;
  }
  return 0;
}

Measured memory_bytes: 3364
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
int n,m;
vector<vector<char>> s(21,vector<char>(21));
int sx=0,sy=0,gx=0,gy=0;
int d[21][21];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int bfs(int x){
  queue<P> que;
  rep(i,n){rep(j,m){d[i][j]=-1;}}
  que.push(P (sx,sy));
  d[sx][sy]=0; 
  while(que.size()){
    P p=que.front();que.pop();    
    rep(i,4){
      int nx=p.first+dx[i],ny=p.second+dy[i];
      if(nx>=0&&nx<n&&ny>=0&&ny<m&&
         s[nx][ny]=='.'&&d[nx][ny]==-1){
        que.push(P(nx,ny));
        d[nx][ny]=d[p.first][p.second]+1;}
    }
  }
  return d[gx][gy];
}
int main(){
  cin>>n>>m;
  rep(i,n){rep(j,m){cin>>s[i][j];}}
  int t=0;
  rep(i,n){rep(j,m){rep(k,n){rep(l,m){
    if(s[i][j]=='.'&&s[k][l]=='.'){
      sx=i,sy=j,gx=k,gy=l;
      int u=bfs(1);
      t=max(t,u);}}}}}
  cout<<t<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353

// size_t f= str.find(string s,0); find s in str from start
// if found then (f != string::npos)
// m.insert({x,y}); m[x]=y;

int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}

signed main(){
    IOS
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int x,y;
  cin>>x>>y;
  vi v(y,0);
  rep(i,0,y){
    cin>>v[i];
  }
  int l=0;
  sort(all(v));
  while(1){
    if(find(all(v),x-l)==v.end()){
      cout<<x-l;
      break;
    }
    else if(find(all(v),x+l)==v.end()){
      cout<<x+l;
      break;
    }
    l++;
  }
    return 0;
}

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

using namespace std;

int main() {
    // Input
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    // Process
    int ans;
    if (K <= A) {
        ans = K;
    } else if (K <= A + B) {
        ans = A;
    } else {
        ans = A - (K - A - B);
    }

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
n = gets.chomp.to_i
sum = 0

x = []
u = []
n.times do
  line = gets.chop.split(" ")
  x << line.shift
  u << line.shift  
end

(0 .. n-1).each do |i|
  if u[i] == "JPY"
    sum += x[i].to_i
  else
    sum += x[i].to_f * 380000.0
  end
end

puts sum



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

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



n,m = m()

print("Yes" if 500 * n >= m else "No")






Measured memory_bytes: 3316
#!/usr/bin/env python

n = int(input())
d = [[0 for _ in range(2)] for _ in range(n)]
for i in range(n):
    d[i][0], d[i][1] = map(int, input().split())

for i in range(n+1-3):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        print('Yes')
        exit()
print('No')


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

int main() {
    long long n;
    cin >> n;
    long long com=1e9;
    string s1,s2;
    long long a,b;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
            s1=to_string(i);
            s2=to_string(n/i);
            a=s1.size();
            b=s2.size();
            com=min(com,max(a,b));
        }
    }
    cout << com << endl;
}

Measured memory_bytes: 256
n, ma, mb = list(map(int, input().split()))

a, b, c = [], [], []

for i in range(n):
    aa,bb,cc = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)

dp = [[float("inf")]*(sum(b)+1) for i in range(sum(a)+1)]
dp[0][0] = 0
max_a = 0
max_b = 0
for i in range(n):
    max_a += a[i]
    max_b += b[i]
    for ai in range(a[i], max_a+1)[::-1]:
        for bi in range(b[i], max_b+1)[::-1]:
            dp[ai][bi] = min(dp[ai][bi], dp[ai-a[i]][bi-b[i]] + c[i])

ans = float("inf")
for i in range(1, min(max_a//ma, max_b//mb)):
    ans = min(ans, dp[i*ma][i*mb])
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3956
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; } return x; }
long lcm(long x, long y) { return (x / gcd(x, y) * y); }

int main(void) {

	long N; cin >> N;
	vector<long> d(N); for (int i = 0; i < N; i++) cin >> d[i];

	long sum = 0; for (int i = 0; i < N; i++) sum += d[i];

	long res = sum * sum;

	for (int i = 0; i < N; i++) res -= d[i] * d[i];

	res /= 2;

	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    char c;
    cin >> c;
    cout << char(c+1) << endl;
}

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

int n, m, s = 0;
int a[30];

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

	memset(a, 0, sizeof(a));

	for (int i = 0; i < n; i++) {
		int k, t;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> t;
			a[t - 1]++;
		}
	}

	for (int i = 0; i < m; i++)
		if (a[i] == n)
			s++;
	
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
#include<bits/stdc++.h>
using namespace std;


lli max_v=1000000;

vector<int> par(max_v);/*親*/
vector<int> Rank(max_v);/*根の深さ*/
/*n要素で初期化*/
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        Rank[i]=0;
    }
}
/*木の根を求める*/
int find(int x){
    if(par[x]==x){/*親が自分自身＝根*/
        return x;
    }
    else{
        return par[x]=find(par[x]);/*一つ上の階層へ*/
    }
}
/*ｘとｙの集合を併合*/
void unite(int x,int y){
    x=find(x);
    y=find(y);
    /*根を求める*/
    if(x==y) return;/*同じ集合に属していたら終了*/
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
/*同じ集合に属するか調べる*/
bool same(int x,int y){
    return find(x)==find(y);
}
/*利用方法はparのそれぞれの要素に対応させる形で別の配列を用意し、そこに入力する。*/

//入力par,Rankの配列数にノードの最大数を入力(max_v)
//使用時、初期化を忘れずに！init
int main(){
    lli n,m;
    cin>>n>>m;
    init(n+1);
    vvi edge(n+1);
    queue<pii> que;
    vi ans(n+1,0);
    rep(i,m){
        lli a,b;
        cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    rep(i,edge[1].size()) que.push(pii(1,edge[1][i]));
    while(!que.empty()){
        pii p=que.front();
        que.pop();
        rep(i,edge[p.second].size()){
            if(same(p.second,1)) continue;
            else{
                ans[p.second]=p.first;
                unite(p.second,p.first);
                rep(j,edge[p.second].size()){
                    if(!same(edge[p.second][j],1)) que.push(pii(p.second,edge[p.second][j]));
                }
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(ans[i]==0){
        out("No");
        return 0;
        }
    }
    out("Yes");
    for(int i=2;i<=n;i++){
        out(ans[i]);
    }
}

Measured memory_bytes: 20948
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int
main(void)
{
	int i, j, n;
	int *a;
	int max = INT_MIN;
	int ans = INT_MIN;

	scanf("%d", &n);
	if (n < 2)
		return 1;

	a = (int *)malloc(sizeof(int) * n);
	if (a == NULL)
		return 1;

	for (i = 0;i < n; i++) {
		scanf("%d", a + i);
	}

	for (i = n - 2; i >= 0 ; i--) {
		if (a[i + 1] > max)
			max = a[i + 1];
		if (ans < max - a[i])
			ans = max - a[i];
	}

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

	return 0;
}



Measured memory_bytes: 2564
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

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


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

void check(char ch)
{

    if (ch >= 'A' && ch <= 'Z')
        cout<<"A"<<endl;

    else if (ch >= 'a' && ch <= 'z')
    cout<<"a"<<endl;

} int main()
{
    char ch;


cin>>ch;
check(ch);

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int ton(string s){
  return atoi(s.c_str());
}
string tos(int N){
  stringstream ss;
  ss<<N;
  string s = ss.str();
  while(s.size() < 4) s = "0" + s;
  return s;
}
int solve(string s){
  if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]) return -1;
  int ans = 0;
  while(true){
    if(s == "6174") break;
    sort(s.begin(), s.end());
    int S = ton(s);
    reverse(s.begin(), s.end());
    int L = ton(s);
    int N = L - S;
    s = tos(N);
    ans += 1;
  }
  return ans;
}

int main(){
  string s;
  while( cin>>s && s != "0000"){
    int ans = solve(s);
    if(ans == -1) cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    long long N,smallest=1000000,sum=0;
    
    cin >> N;
    vector<int> a(N);
    REP(i,N)cin>> a[i];
    sort(a.rbegin(),a.rend());
    ll ans = 0;
    int t = N-1;
    REP(i,N){
        int lim = 2;
        if(i==0)lim = 1;
        REP(j,lim){
            if(t>0){
                ans +=a[i];
                t--;
            }
        }
    }
    // long long A[N];
    // for (long long  i = 0; i < N; i++)
    // {
    //     cin >> A[i];
    //     sum +=A[i];
    //     if(smallest>A[i]){
    //         smallest=A[i];
    //     }
    // }
    // cout << sum-smallest << endl;

    cout << ans << endl;

    return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> P(N);
  for(int i=0; i<N; i++){
    cin>>P.at(i);
  }
  int ans=0;
  int count=1e9;
  for(int i=0; i<N; i++){
    count=min(count,P.at(i));
    if(count==P.at(i)){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4064
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn cmp_2(a:i64, b:i64) -> std::cmp::Ordering {
    let (xi, yi) = (a % 10, b % 10);

    if xi == yi {
        std::cmp::Ordering::Equal
    } else if xi == 0 && yi != 0 {
        std::cmp::Ordering::Greater
    } else if xi != 0 && yi == 0 {
        std::cmp::Ordering::Less
    } else if xi > yi {
        std::cmp::Ordering::Greater
    } else {
        std::cmp::Ordering::Less
    }
}

fn main() {
    let mut r:Vec<i64> = Vec::new();
    r.push(get_input().parse().unwrap());
    r.push(get_input().parse().unwrap());
    r.push(get_input().parse().unwrap());
    r.push(get_input().parse().unwrap());
    r.push(get_input().parse().unwrap());

    r.sort_by(|&a, &b| cmp_2(b, a));

    let mut ans = 0;
    for i in r {
        let a = ans % 10;
        ans += if a == 0 { 0 } else { 10 - a };
        ans += i;
    }
    println!("{}", ans);
}


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

M = A[-1]
m = A[0]

ans = []
for i, a in enumerate(A[1:-1]):
    if a > 0:
        ans.append([m, a])
        m -= a
    else:
        ans.append([M, a])
        M -= a

print(M - m)
ans.append([M, m])
for a1, a2 in ans:
    print(a1, a2)


Measured memory_bytes: 23208