akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int H,W;
int i,j;

main(){
	while(1){
	scanf("%d%d",&H,&W);
	if(H != 0 && W != 0 ){
		for(i=0 ;i<H; i++){
			for(j=0 ;j<W; j++){
				if(i==0 || i==(H-1) || j==0 || j==(W-1)){
				printf("#");
				}else{
					printf(".");
				}
			}
			printf("\n");
		}
	}else{
		break;
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <algorithm>
#define INF 0x3f3f3f3f
#define SI(a) scanf("%d",&a)
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long ll;
const int mod = 998244353;
const int maxn = 110;
using namespace std;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
ll quick_pow(ll x,ll n,ll mod){
	ll res = 1;
	while(n > 0){
		if(n & 1)	res = res * x % mod;
		x = x * x % mod;
		n >>= 1;//相当于n=n/2.详情请参考位移运算符。
	}
	return res;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string str;
    char ans[10];
    cin>>str;
    int len = str.length();
    int pos1 = 0,pos2 = 0;
    while(pos1!=len)
    {
        if(str[pos1]=='B'&&pos2==0){pos1++;continue;}
        else if(str[pos1]=='B'&&pos2!=0){pos2--;pos1++;continue;}
        else{
            ans[pos2] = str[pos1];
            pos1++;pos2++;
        }
    }
    ans[pos2]='\0';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<ll>l(n);
  rep(i,n) cin >> l[i];


  ll ans = 0;

  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      for(int k = j+1; k < n; k++){
        ll l1 = l[i];
        ll l2 = l[j];
        ll l3 = l[k];
        if(l1 == l2 || l2 == l3 || l3 == l1) continue;
        if(l1 < l2+l3 && l2 < l1+l3 && l3 <l2+l1) ans++;    
      }
    }
  }

  cout <<ans << endl;
  
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	for0(i,s.length()){
		cout << "x";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    int ans = 0;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    for (int i = 0; i < n-1; i++)
    {
        for (int j = i+1; j < n; j++)
        {
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a,T2 b){if (b>a) a=b;}
template <class T1, class T2>inline void gmin(T1 &a,T2 b){if (b<a) a=b;}
int n,a[2][105],dp[2][105];
int main(){
    read(n);
    for (int i=1;i<=2;i++){
        for (int j=1;j<=n;j++){
            read(a[i][j]);
        }
    }
    for (int i=1;i<=2;i++){
        for (int j=1;j<=n;j++){
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
        }
    }
    cout<<dp[2][n]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long long int a,b,c;
    scanf("%lld %lld %lld",&c,&a,&b);

    {
        if( b <= a )
        {
            printf("delicious");
        }
        else if ( b > a + c )
        {
            printf("dangerous");
        }
        else
        {
            printf("safe");
        }
    }

return 0;
}

Measured memory_bytes: 1728
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

# https://img.atcoder.jp/arc085/editorial.pdf
# (1900M + 100(N − M)) × 2**M

N, M = map(int, input().split())
print( (1900*M + 100*(N-M)) * 2**M )


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll h,n,a[100000],i;
	cin>>h>>n;
	ll sum=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		}
	if(h>sum)
	{cout<<"No"<<endl;}
	else
	{
		cout<<"Yes"<<endl;
		}
	


return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long n;
long long minx=5201314;

long long work(long long x)
{
	long long ans=0,a=10,b=1;
	long long k=x,m=0;
	while(k)
	{
		ans++;
		k/=10;
	}
	for(int j=1;j<=ans;j++)
	{
	m+=x%a/b;	
	a*=10;
	b*=10;
	}
	return m;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n-i;i++)
	{
		minx=min(minx,work(i)+work(n-i));
	}
	cout<<minx<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <type_traits>
#include <utility>

template <typename T, typename F>
struct SegmentTree {
	int n;
	F& f;
	T ti;
	std::vector<T> dat;
	SegmentTree(F&& f, T ti) : f(std::forward<F>(f)), ti(ti) {}
	void init(int n_) {
		n = 1;
		while (n < n_)
			n <<= 1;
		
		dat.assign(n << 1, ti);
	}
	void build(const std::vector<T> &v) {
		int n_ = v.size();
		init(n_);
		for (int i = 0; i < n_; i++)
			dat[n + i] = v[i];
		for (int i = n - 1; i; i--)
			dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
	}
	void set_val(int k, T x) {
		dat[k += n] = x;
		while (k >>= 1)
			dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
	}
	T query(int a, int b) {
		T vl = ti, vr = ti;
		for (int l = a + n, r = b + n; l<r; l >>= 1, r >>= 1) {
			if (l & 1)
				vl = f(vl, dat[l++]);
			if (r & 1)
				vr = f(dat[--r], vr);
		}
		return f(vl, vr);
	}
	template<typename C>
	int find(int a, int b, C &check, int k, int l, int r) {
		if (!check(dat[k]) || r <= a || b <= l)
			return -1;

		if (k >= n)
			return k - n;

		int m = (l + r) >> 1;
		int vl = find(a, b, check, (k << 1) | 0, l, m);
		if (~vl)
			return vl;

		return find(a, b, check, (k << 1) | 1, m, r);
	}
	template<typename C>
	int find(int a, int b, C &check) {
		return find(a, b, check, 1, 0, n);
	}
};

template <typename F, typename T>
auto helper(F&& f, T ti) {
	return SegmentTree<T, F>(std::forward<F>(f), ti);
}

int gcd(int a, int b) {
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

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

	std::vector<int> dat(n);
	for (auto&& e : dat)
		std::cin >> e;

	auto seg = helper(gcd, 0);
	seg.init(2*n+1);
	
	for (int i = 0; i < 2 * n; ++i)
		seg.set_val(i + 1, dat[i % n]);

	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int tmp = seg.query(i, i + n - 1);
		if (tmp > ans)
			ans = tmp;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 2688
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

a.sort()
key = 0
cnt = 0
b = []
for i in range(n):
    if a[i] != key:
        key = a[i]
        b.append(cnt)
        cnt = 1
    else:
        cnt += 1
b.append(cnt)
del b[0]

b.sort()
if len(b) < k:
    print(0)
else:
    print(sum(b[:len(b)-k]))

Measured memory_bytes: 25644
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<setprecision(10);
    double pi=3.14159265359;

    double a,b,x;cin>>a>>b>>x;
    x/=(a*a);
    if(x<=(b/2)){
        double rad=0.5*pi-atan((2*a*x)/(b*b));
        double ans=180.0*rad/pi;
        cout<<ans<<endl;
    }
    else{
        double y=b-x;
        double rad=atan(2*y/a);
        double ans=180.0*rad/pi;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	ll x;
	cin>>x;
	ll res = x%11;
	if(res>0) res = (res<=6?1:2);
	cout<<(x/11)*2+res<<endl;
	return 0;
}

Measured memory_bytes: 256
//
// Created on 2020/08/22.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    ll ans = 0;
    ll now;
    ll last;
    cin>>last;
    for (int i = 1; i < n; ++i) {
        cin>>now;
        if(now < last){
            ans += abs(last-now);
        }else{
            last = now;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
vector<int> b={'a','i','u','e','o'};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;cin >> x;
	int ans=0,n=0;
	for(int i=1;n<x;++i){
		n+=i;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
//cout<<fixed<<setprecision(6)<<n<<endl;
// transform(s.begin(), s.end(), s.begin(), ::tolower);
//double PI=3.14159265359,c=0;
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ll long long
//#define f(n) for(int i=;i<n;i++)
double PI = acos(-1);
using namespace std;
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll n,arr[100000][4];
ll mem[100000][4];
ll sum(int i,int last)
{
    if(i==n)
     return 0;
    if(mem[i][last])
     return mem[i][last];
    ll ans=0;
    if(last!=0)
     ans=max(ans,arr[i][0]+sum(i+1,0));
    if(last!=1)
     ans=max(ans,arr[i][1]+sum(i+1,1)); 
    if(last!=2)
     ans=max(ans,arr[i][2]+sum(i+1,2)); 
    
   return mem[i][last]=ans;     
}
int main()
{
    fast();
    cin>>n;
    for(int i=0;i<n;i++)
     cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    
    cout<<sum(0,-1)<<endl;



    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
#include<deque>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;




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

	int N, M;
	cin >> N >> M;
	vector<VI> G(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	deque<int> Q;
	vector<bool> vis(N, false);
	Q.push_front(0);
	Q.push_back(G[0][0]);
	vis[0] = true;
	vis[G[0][0]] = true;
	
	bool F = true;
	int s = 0;

	while (F) {
		bool f = true;
		REP(i, G[s].size()) {
			if (!vis[G[s][i]]) {
				Q.push_front(G[s][i]);
				s = G[s][i];
				vis[s] = true;
				f = false;
				break;
			}
		}
		if (f)F = false;
	}

	F = true;
	s = G[0][0];
	while (F) {
		bool f = true;
		REP(i, G[s].size()) {
			if (!vis[G[s][i]]) {
				Q.push_back(G[s][i]);
				s = G[s][i];
				vis[s] = true;
				f = false;
				break;
			}
		}
		if (f)F = false;
	}

	cout << Q.size() << endl;
	while (!Q.empty()) {
		cout << Q.front()+1;
		Q.pop_front();
		if (!Q.empty())cout << " ";
		else cout << endl;
	}
	return 0;
}



Measured memory_bytes: 7168
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 300009
ll m,a,b,c,d,n,arr[sz],i,k,j,x,y;
int main()
{
string cc,dd;
cin >> cc >> dd;
n=cc.size();
m=dd.size();
if(n+1!=m)
{
    printf("No\n");
    return 0;
}
for(i=0;i<n;i++)
{
    if(cc[i]!=dd[i])
    {
        printf("No\n");
        return 0;
    }
}
printf("Yes\n");
return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define MuhammedAly ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define popc(x) __builtin_popcount(x)
#define LLMX 1e18
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x));
#define sz(a) (int)(a).size()
#define inFile(s) freopen((s),"r",stdin)
#define	outFile(s) freopen((s),"w",stdout)
#define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a))
#define pi (2 * acos(0))
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define ll long long
typedef long double ld;
typedef complex<double>point;
typedef tuple<int, int, int> line;
typedef pair<point, point>segment;
typedef vector<point>polygon;
const int N = 21, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353;
const double EPS = 1e-9;

int n, memo[23][(1<<21) + 2];
bool comp[23][23];

int solve(int i = 0, int mask = 0)
{
	if(mask == (1 << n) - 1)
		return 1;
	if(i == n)
		return 0;
	int &ret = memo[i][mask];
	if(~ret)
		return ret;
	ret = 0;
	for(int j = 0 ; j < n ; j++)
		if(comp[i][j] && !((mask >> j) & 1))
			ret = (ret + solve(i + 1, (mask | (1 << j)))) % mod;
	return ret % mod;
}
int main()
{
	MuhammedAly
	mem(memo, -1);
	cin >> n;
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; j < n ; j++)
			cin >> comp[i][j];
	cout << solve();
	return 0;
}


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

long long dp[110][100100];
int v[110];
int w[110];

int main() {
	int n, sz;
	cin >> n >> sz;

	for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sz; j++) {
			if (j - w[i] >= 0) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
				dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			} else dp[i][j] = dp[i - 1][j];
		}
	}

	long long ans = 0;
	for (int i = 0; i <= sz; i++) ans = max(ans, dp[n][i]);

	cout << ans;

	return 0;
}

Measured memory_bytes: 79360
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct P {
  int S,y,x;
  int t;
  P(int S, int y, int x, int t) : S(S),y(y),x(x),t(t) {}
  P() {}
};

struct Sale {
  int d,s,e;
  Sale(int d, int s, int e) : d(d),s(s),e(e) {}
  Sale() {}
};

bool visited[1<<8][20][20][101];           // dp[S][i][j][k] = 商品Sを買って(i,j)に時間kにいることができる
char ba[20][20];
Sale sale[10];
int can[20][20][101];                // 購入可能な商品集合
int get[1<<8];

int main() {
  int w,h;
  while(cin>>w>>h,w||h) {
    int sy,sx;

    REP(i,h) {
      REP(j,w) {
        cin >> ba[i][j];
        if(ba[i][j] == 'P') {
          ba[i][j] = '.';
          sy = i;
          sx = j;
        }
      }
    }
    int n;cin >> n;
    int id[n],rid[n];
    REP(i,n) {
      int d,s,e;
      cin>>id[i]>>d>>s>>e;
      sale[i] = Sale(d,s,e);
      rid[id[i]] = i;
    }
    REP(S,1<<n) {
      get[S] = 0;
      REP(i,n) {
        if (S>>i&1) {
          get[S] += sale[i].d;
        }
      }
    }
    
    const int dy[] = {-1,0,1,0,0};
    const int dx[] = {0,1,0,-1,0};
    
    REP(i,h){
      REP(j,w) {
        if (ba[i][j] != '.') continue;
        REP(l,101) {
          can[i][j][l] = 0;
          REP(k,4) {
            int yy=i+dy[k];
            int xx=j+dx[k];
            if (yy<0||yy>=h||xx<0||xx>=w) continue;
            if (isdigit(ba[yy][xx])) {
              int a = ba[yy][xx]-'0';
              if (sale[rid[a]].s <= l && l < sale[rid[a]].e) {
                can[i][j][l] |= 1<<rid[a];
              }
            }
          }
          // if (l<10) {
          //   cout << i << "," << j << " " << l << " " << bitset<5>(can[i][j][l]) << endl;
          // }
        }
      }
    }
    
    REP(S,1<<n) REP(i,h)REP(j,w)REP(k,101)
      visited[S][i][j][k] = 0;
    queue<P> Q;
    Q.push(P(can[sy][sx][0],sy,sx,0));
    visited[can[sy][sx][0]][sy][sx][0] = 1;
    int ans = 0;
    while(!Q.empty()) {
      P p = Q.front(); Q.pop();

      ans = max(ans, get[p.S]);
      // if (p.t<=10) 
      //   cout << p.y << "," << p.x << " " << bitset<5>(p.S) << " " << p.t << endl;
      if (p.t == 100) continue;
      REP(i,5) {
        int yy=p.y+dy[i];
        int xx=p.x+dx[i];
        if (yy<0||yy>=h||xx<0||xx>=w) continue;
        if (ba[yy][xx] != '.') continue;
        int nS = p.S|can[yy][xx][p.t+1];
        if (!visited[nS][yy][xx][p.t+1]) {
          visited[nS][yy][xx][p.t+1] = 1;
          Q.push(P(nS,yy,xx,p.t+1));
        }
      }
    }
    cout << ans << endl;
  }
}

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

int main(){
	int n;
	cin >> n;
	vector<int> s;
	for ( int i = 0; i < n; i++ ) {
		s.push_back(i);
		cin >> s[i];
	}
	sort(s.begin(),s.end());
	int q;
	cin >> q;
	vector<int> t;
	for ( int i = 0; i < q; i++ ) {
		t.push_back(i);
		cin >> t[i];
	}
	sort(t.begin(),t.end());
	int c = 0;
	for ( int j = 0; j < q; j++ ) {
		for ( int i = 0; i < n; i++ ) {
			if ( s[i] == t[j] ) c++;
			if ( s[i] >= t[j] ) break;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1324
import java.util.*;

// ABC 62-D
// http://abc062.contest.atcoder.jp/tasks/arc074_b

public class Main {
	
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		long[] nums = new long[3 * N];
		
		for (int i = 0; i < 3 * N; i++) {
			nums[i] = in.nextLong();
		}
		
		// Store the maximum sum by picking N from left array
		long[] maxLeft = new long[3 * N];
		PriorityQueue<Long> pq = new PriorityQueue<Long>();
		long sum = 0;
		
		for (int i = 0; i < N; i++) {
			pq.add(nums[i]);
			sum += nums[i];
		}
		
		maxLeft[N] = sum;
		
		for (int i = N; i < 2 * N; i++) {
			pq.add(nums[i]);
			sum += nums[i];
			sum -= pq.poll();
			maxLeft[i + 1] = sum;
		}
		
		// Store the minimum sum by picking N from right array
		long[] minRight = new long[3 * N];
		pq = new PriorityQueue<Long>(Collections.reverseOrder());
		
		sum = 0;
		for (int i = 3 * N - 1; i >= 2 * N; i--) {
			pq.add(nums[i]);
			sum += nums[i];
		}
		
		minRight[2 * N] = sum;
		for (int i = 2 * N - 1; i >= N; i--) {
			pq.add(nums[i]);
			sum += nums[i];
			sum -= pq.poll();
			minRight[i] = sum;
		}
		
//		for (int i = 0; i < 3 * N; i++) {
//			System.out.printf("%3d ", maxLeft[i]);
//		}
//		System.out.println();
//		for (int i = 0; i < 3 * N; i++) {
//			System.out.printf("%3d ", minRight[i]);
//		}
//		System.out.println();
		
		// Determine the answer
		long answer = Long.MIN_VALUE;
		for (int i = N; i <= 2 * N; i++) {
			answer = Math.max(answer, maxLeft[i] - minRight[i]);
		}
		
		System.out.println(answer);
	}
}

Measured memory_bytes: 100128
#include<iostream>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;


int main(){
	int n,k;
	int a[100];
	while(cin>>n>>k,n|k){
		for(int i=0;i<k;i++)cin>>a[i];
		for(int i=0;i<n;i++){
			for(int j=0;j<k;j++){
				int b;
				cin>>b;
				a[j]-=b;
			}
		}
		bool ans=find_if(a,a+k,bind2nd(less<int>(),0))==a+k;
		cout<<(ans?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	LL X,A,B;
	cin>>X>>A>>B;

	if (A-B>=0){
		cout<<"delicious"<<endl;
		return 0;
	}
	if (B-A<=X ){
		cout<<"safe"<<endl;
		return 0;
	}
	cout<<"dangerous"<<endl;

	return 0;
}

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

int main(){
  int n[10002],a,k,kk,nn,min1=111111111 ,min2=111111111 ,min3=111111111 ;
  cin>>a;
  for(int j=0;j<a;j++)cin>>n[j];
  kk=0;
  for(int i=0;i<a;i++){
    for(int j=0;j<a;j++){
      if(i==j)continue;
      k=1;
      nn=n[i];
      while(nn>=10){
	k++;
	nn=nn/10;
      }
      kk=n[j]*(int)pow(10,k)+n[i];
      //      cout<<kk<<endl;/////////
      if(min1>kk){
	min3=min2;
	min2=min1;
	min1=kk;
      }else if(min2>kk){
	min3=min2;
	min2=kk;
      }else if(min3>kk)min3=kk;
    }
    //cout<<"llllllll"<<endl;///
  }
  cout<<min3<<endl;
  return 0;
}

Measured memory_bytes: 3236
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<P> node[305];
struct P2{
  ll a,b,c;
};
bool operator > (const P2 &p1,const P2 &p2){
  if(p1.b==p2.b){
    return p1.c>p2.c;
  }
  else return p1.b<p2.b;
}
bool operator < (const P2 &p1,const P2 &p2){
  if(p1.b==p2.b){
    return p1.c<p2.c;
  }
  else return p1.b>p2.b;
}
ll n,m,l;
ll ans[305][305]={0};
P2 mk_P(ll a,ll b,ll c){
  P2 ret;
  ret.a=a;
  ret.b=b;
  ret.c=c;
  return ret;
}
void dijkstra(int pos){
  vector<P> bans(305);
  for(int i=0;i<=n;i++) bans[i]=P(17441744174417,0);
  bans[pos]=P(0,l);
  priority_queue<P2> pque;
  bool used[305];
  //used[pos]=true;
  for(int i=0;i<=n;i++) used[i]=false;
  pque.push(mk_P(pos,0,l));

//cout<<"DIJKSTRA "<<pos<<endl;
  while(!pque.empty()){
    P2 p=pque.top();
    pque.pop();
    if(used[p.a]) continue;
    int now_pos=p.a;
    used[now_pos]=true;
  //  cout<<p.a<<" "<<p.b<<" "<<p.c<<" ";

    for(int i=0;i<node[now_pos].size();i++){
      int to=node[now_pos][i].first;
  //    cout<<"to:"<<to<<" ";
      if(used[to]) continue;
      ll cost=node[now_pos][i].second;
      ll nc=p.c-cost,nb=p.b;
      if(cost>p.c) {
        nc=l-cost;
        nb++;
      }

      P2 a1=mk_P(to,nb,nc),a2=mk_P(0,bans[to].first,bans[to].second);
      if(a1>a2){
        bans[to].first=nb;
        bans[to].second=nc;
        pque.push(a1);
      }
    }
  //  cout<<endl;
  }

  for(int i=1;i<=n;i++){
    if(i!=pos) ans[pos][i]=(bans[i].first==17441744174417?-1:bans[i].first);
  }
}
int main(){
  cin>>n>>m>>l;
  for(int i=0;i<m;i++){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c>l) continue;
    node[a].push_back(P(b,c));
    node[b].push_back(P(a,c));
  }
  //cout<<"N"<<node[2].size()<<endl;
  for(int i=1;i<=n;i++) dijkstra(i);

/*  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++) cout<<ans[i][j]<<" ";
    cout<<endl;
  }*/
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    ll s,t;
    cin>>s>>t;
    cout<<ans[s][t]<<endl;
  }
}


Measured memory_bytes: 4940
#include<iostream>
#include<cstdio>
#include <set>
using namespace std;
long long ans1,ans2,x,y,A,B,C,D,t;
set<long long> s;
bool check(long long a,long long b,long long c,long long d) {
	if(d<b)return false;
	if(a<b)return false;
	if(b<c)return true;
	a= a-((a-c+b-1)/b)*b;
	if(a<0||a>c)return false;
	if(d%b==0)return true;
	s.clear();
	while(!s.count(a)){
		//cout << a << endl;
		if(a<0||a>c)return false;
		s.insert(a);
		a=a+((c-a)/(d%b)+1)*(d%b)-b;
	}
	return true;
}
int main() 
{	
	scanf("%d",&t);
	while(t--){
		scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
		if(check(A,B,C,D))printf("Yes\n");
		else printf("No\n");
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
long long n,m;
int main()
{
	scanf("%lld%lld",&n,&m);
	if (n==1 || m==1) printf("1\n");
	else if (n&1) printf("%lld\n",n/2*m+(m+1)/2);
	else printf("%lld\n",(n/2)*m);
return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;


int main(){
    ll n,x; cin>>n>>x;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;
    rep(i,n-1){
        if(a[i]+a[i+1]<=x)continue;
        ll mn=a[i]+a[i+1]-x;
        ans+=mn;
        if(a[i+1]>=mn)a[i+1]-=mn;
        else {
            a[i]-=a[i]-x;
            a[i+1]=0;
        }
    }
    cout<<ans<<endl;
}








Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class MyProgram
{	

    public static void Main()
	{
	    int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = n[0];
        n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        
        bool can = true;
        int max = 0;
        int cnt = 0;
        for(int i = 0 ; i < N ; i++)
        {
            //cnt = 0;
            can = true;
            while(can)
            {
                if(n[i] % 2 ==0)
                {
                    n[i] /= 2;
                    cnt++;
                }
                else
                {
                    can = false;
                }
            }
          
        }
        Console.WriteLine(cnt);
	}
}

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

typedef long long ll;
 
int main(){
  string s,t;
  cin >> s;
  cin >> t;
  int n = s.length(), l = t.length();
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  bool ok = false;
  for(int i=0; i<n; i++){
    bool match = true;
    if(ok){
      if(s[i]=='?') s.replace(i, 1, "a");
      continue;
    }
    for(int j=0; j<l; j++){
      if(i+j>=n){
        match=false;
        continue;
      }
      if(s[j+i]=='?'||!match) continue;
      if(s[j+i]!=t[j]) match=false;
    }
    if(match){
      ok = true;
      s.replace(i, l, t);
    }
    if(s[i]=='?') s.replace(i, 1, "a");
  }
  reverse(s.begin(), s.end());
  if(ok) cout << s << endl;
  else cout << "UNRESTORABLE" << endl;
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

ll mod = 1000000007;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

ll inv(ll x){
  ll res = 1;
  ll k = mod - 2;
  ll y = x;
  while(k){
    if(k&1)res = (res*y)%mod;
    y = (y*y) % mod;
    k /= 2;
  }
  return res;
}

struct Square {
  int h,w,cnt;
  Square(int _h,int _w,int _cnt){
    h = _h;
    w = _w;
    cnt = _cnt;
  }
};

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

  string s,t;
  cin >> s >> t;
  int ret = s.length();
  rep(i,s.length() - t.length() + 1){
    int cnt = 0;
    rep(j,t.length()){
      if(s[i+j] != t[j])cnt++;
    }
    ret = min(ret,cnt);
  }
  cout << ret << endl;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <unordered_set>

using namespace std;

typedef long long ll;

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

  unordered_multiset<ll> s(a.begin(), a.end());
  sort(a.rbegin(), a.rend());

  int result = 0;
  for (int x : a) {
    auto it = s.find(x);
    if (it == s.end()) continue;
    s.erase(it);

    for (ll d = 1; d <= 2 * x; d *= 2) {
      if (d < x) continue;
      ll r = d - x;
      auto it = s.find(r);
      if (it == s.end()) {
        continue;
      }
      s.erase(it);
      result++;
      break;
    }
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 9600
open System

[<EntryPoint>]
let main argv =
    let K = stdin.ReadLine() |> int
    let [|A; B|] = stdin.ReadLine().Split() |> Array.map int

    let range = [|A..B|]
    let count = range |> Array.filter(fun x -> x % K = 0) |> Array.length
    if count > 0 then "OK" else "NG"
    |> printfn "%s"

    0

Measured memory_bytes: 30328
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	int ans = s.size();
	for(int i = 0; i < s.size() - 1; i++) if(s[i] != s[i + 1]) ans = std::min(ans, std::max(i + 1, (int)s.size() - i - 1));
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

bool check(string s, string t){
  int n = s.size();
  bool ok = true;
  rep(i,n){
    if (s[i]=='?' || s[i]==t[i]) continue;
    else {
      ok = false;
      break;
    }
  }

  return ok;
}

int main(){
  string s, t; cin >> s >> t;
  vector<int> d;

  int n = t.size();
  rep(i,s.size()-n+1){
    if (check(s.substr(i,n),t)) d.push_back(i);
  }


  if (d.size()==0) cout << "UNRESTORABLE" << endl;
  else {
    int idx = d[d.size()-1];
    rep(i,n) {
      s[idx+i] = t[i];
    }
    rep(i,s.size()){
      if (s[i]=='?') s[i] = 'a';
    }
    cout << s << endl;

  }



  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

bool isSquare(Int a){
  bool flag = false;
  double z = double(sqrt(a));
  if(ceil(z)==floor(z)) flag = true;
  return flag;
}

int main(){
  int n;cin >> n;
  int ans = 0;
  for(int i=1;i<=sqrt(n);i++){
    if(i*i<=n) ans = max(ans,i*i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <time.h>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>
#define print_time()cout<<clock()/CLOCKS_PER_SEC<<" s"<<endl;

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int main(){
    ll n,m;cin>>n>>m;
    if(n>m)swap(n,m);
    if(m-n<2)cout<<"Brown\n";
    else cout<<"Alice\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int L =sc.nextInt();
    L=L+sc.nextInt();
    int R =sc.nextInt();
    R=R+sc.nextInt();
    String q ="";
    if(L<R){
      q="Right";
    }else if(L==R){
      q="Balanced";
    }else{
      q="Left";
    }
    System.out.println(q);
  }
  

  
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool rev = false;
    string head = "", tail = "";
    rep(i,q){
        int t;
        cin >> t;
        if(t == 1) rev = !rev;
        else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(!rev) head = c + head;
                else tail += c;
            }
            else{
                if(rev) head = c + head;
                else tail += c;
            }
        }
    }
    if(!rev){
        cout << head << s << tail << endl;
    }
    else{
        for(int i = tail.size()-1; i >= 0; i--){
            cout << tail[i];
        }
        for(int i = s.size()-1; i >= 0; i--){
            cout << s[i];
        }
        for(int i = head.size()-1; i >= 0; i--){
            cout << head[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1104
#include<stdio.h>
int main(){
	long n,a[10000],i;
	scanf("%ld",&n);
	for(i=0;i<n;i++) scanf("%ld",&a[i]);
	
	int j;
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			int t;
			if(a[i]>a[j]){
				t=a[i];
				a[i]=a[j];
				a[j]=t;
			}
		}
	}
	long s=0;
	for(i=0;i<n;i++) s+=a[i];
	printf("%ld %ld %ld\n",a[0],a[n-1],s);
	return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n, m;
    cin >> n >> m;
    vector<int> v(m,0);
    int k,tmp;
    REP(i,n){
        cin >> k;
        REP(j,k){
            cin >> tmp;
            v[tmp-1]++;
        }
    }
    int result = 0;
    REP(i,m){
        if(v[i]==n){
            result++;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VL A(N);
  rep(i,N) cin>>A[i];
  sort(all(A),greater<ll>());
  ll ans=0;
  if(N%2){
    ans+=A[0];
    rep(i,N/2-1) ans+=A[i+1]*2;
    ans+=A[N/2];
  }else{
    ans+=A[0];
    rep(i,N/2-1) ans+=A[i+1]*2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		final int N = scanner.nextInt();
		final int M = scanner.nextInt();

		boolean[] flag = new boolean[N];
		boolean judge = true;
		int[] number = new int[N];

		int s, c;
		for (int i = 0; i < M; i++) {
			s = scanner.nextInt();
			c = scanner.nextInt();

			if (N > 1 && s == 1 && c == 0)
				judge = false;

			if (flag[s - 1]) {
				if (number[s - 1] != c)
					judge = false;
			} else {
				flag[s - 1] = true;
				number[s - 1] = c;
			}
		}

		if (judge) {

			if (N == 1) {
				System.out.println(number[0]);
			} else if (N == 2) {
				System.out.print(number[0] > 1 ? number[0] : 1);
				System.out.println(number[1]);
			} else if (N == 3) {
				System.out.print(number[0] > 1 ? number[0] : 1);
				System.out.print(number[1]);
				System.out.println(number[2]);
			}

		} else {
			System.out.println(-1);
		}

	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
 
 int main() {
 int S,W;
 cin>>S>>W;
 if(S>W){cout<<"safe";}
 else{cout<<"unsafe";}
}

Measured memory_bytes: 3636
#include <cmath>
#include <iostream>
using namespace std;
int n, f[100], a[100], t[100], x[100], y[100];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> f[i] >> a[i] >> t[i] >> x[i] >> y[i];
	int r1 = -1, r2 = -1, r3 = -1, r4 = -1;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] == a[i] || t[i - 1] != t[i]) continue;
		int dist = (x[i] - x[i - 1]) * (x[i] - x[i - 1]) + (y[i] - y[i - 1]) * (y[i] - y[i - 1]); 
		if (t[i] == 0) {
			if (dist > r1) r1 = dist, r2 = f[i] - f[i - 1];
			else if (dist == r1 && f[i] - f[i - 1] < r2) r2 = f[i] - f[i - 1];
		}
		else {
			if (dist > r3) r3 = dist, r4 = f[i] - f[i - 1];
			else if (dist == r3 && f[i] - f[i - 1] < r4) r4 = f[i] - f[i - 1];
		}
	}
	printf(r1 != -1 ? "%.9f %.9f\n" : "-1 -1\n", sqrt(r1), r2 / 60.0);
	printf(r3 != -1 ? "%.9f %.9f\n" : "-1 -1\n", sqrt(r3), r4 / 60.0);
	return 0;
}

Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vi a(n);
    ffor(i,n) cin >> a[i];
    vector<bool> ok(k + 1);
    
    for(int i = 1; i <= k; ++i)
    {
        for(int j = 0; j < n; ++j)
        {
            if(i >= a[j] && !ok[i - a[j]])
            {
                ok[i] = true;
            }
        }
    }
    // for(auto x : ok)
    // {
    //     cout << x << ' ';
    // }
    if(!ok[k])
    {
        cout << "Second";
    }
    else
    {
        cout << "First";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

int main(void) {
    int q{};
    std::cin >> q;

    std::set<int> my_set{};
    for (int i = 0; i < q; ++i) {
        int kind{};
        std::cin >> kind;

        int x{};
        switch (kind) {
            case 0:
                /// insert
                std::cin >> x;
                my_set.insert(x);
                std::cout << my_set.size() << std::endl;
                break;
            case 1:
                /// find
                std::cin >> x;
                if (my_set.find(x) != my_set.end())
                    std::cout << 1 << std::endl;
                else
                    std::cout << 0 << std::endl;

                break;
            case 2:
                /// delete
                std::cin >> x;
                my_set.erase(x);
                break;
            case 3:
                /// dump
                int l{}, r{};
                std::cin >> l >> r;
                auto iter_begin = my_set.lower_bound(l);
                auto iter_end = my_set.upper_bound(r);
                for (auto iter = iter_begin; iter != iter_end; ++iter)
                    std::cout << *iter << std::endl;

                break;
        }
    }
}


Measured memory_bytes: 12444
#include <stdio.h>

int main()
{
    int a, b;
    int add, sub, mult;
    int max;
    scanf("%d %d", &a, &b);
    add = a + b;
    sub = a - b;
    mult = a * b;
    max = add;
    if(max<sub) max = sub;
    if(max<mult) max = mult;
    printf("%d", max);

    return 0;
}

Measured memory_bytes: 256
s=list(input())
s.reverse()
mod=2019

n=[0]*len(s)
n[0]=1
cnt=[0]*len(s)
cnt[0]=int(s[0])
ans=[0]*2019
answer=0

for i in range(1,len(s)):
  n[i]+=(n[i-1]*10)%mod

for i in range(1,len(s)):
  cnt[i]=(cnt[i-1]+int(s[i])*n[i])%mod

for i in cnt:
  ans[i]+=1

for i in range(len(ans)):
  answer+=(ans[i]*(ans[i]-1))//2

answer+=ans[0]

print(answer)

Measured memory_bytes: 86188
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n,i,j,k,s=0,c=1,x=1,t;
   cin>>n>>k;
   ll a[n+1];
   for(i=0;i<n;i++)
          cin>>a[i];
   sort(a,a+n);
   for(i=0;i<k;i++)
          s+=a[i];
   cout<<s;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
const string MININF = "-INF";
int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[MAXN]; // i本のマッチ棒を使ったときの最大数

void chmax(string &a, string b)
{
  if (a == MININF)
  {
    a = b;
  }
  else if (a.size() < b.size())
  {
    a = b;
  }
  else if (a.size() == b.size())
  {
    if (a < b)
    {
      a = b;
    }
  }
}

int main()
{
  int N, M, a;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 0; i < MAXN; i++)
  {
    dp[i] = MININF;
  }
  dp[0] = "";
  for (int i = 0; i <= N; i++)
  {
    if (dp[i] == MININF)
      continue;
    for (int a : A)
    {
      chmax(dp[i + match[a]], dp[i] + (char)(a + '0'));
    }
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 54756
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
	if A[i] >= B[i]:
		ans += B[i]
	else:
		ans += A[i]
		ch = B[i] - A[i]
		if ch > A[i+1]:
			ans += A[i+1]
			A[i+1] = 0
		else:
			ans += ch
			A[i+1]-=ch
print(ans)


Measured memory_bytes: 18476
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left

import sys
# sys.setrecursionlimit(1000000)
# list(map(int, input().split()))
mod = 10 ** 9 + 7
# https://atcoder.jp/contests/abc141/tasks/abc141_d

N,M = getNM()
# mapをlambdaで改造
A = list(map(lambda x:int(x) * (-1), input().split())) #-1倍してからリストに格納
heapq.heapify(A) #優先度付きキューに変換

for _ in range(M):
    max_value = heapq.heappop(A) * (-1) #最大値の取得
    heapq.heappush(A, (max_value // 2) * (-1)) #半額にして-1倍してからキューに戻す

print((-1)*sum(A)) #最後に-1倍を忘れずに

Measured memory_bytes: 76876
S = input()
L = 0
max_L = 0
 
for i in range(len(S)):
  s = S[i]
  TF = any(['A' in s, 'C' in s, 'G' in s, 'T' in s])
  if TF:
    L += 1
    if L >= max_L:
        max_L = L
  elif L >= max_L:
    max_L = L
    L = 0

print(max_L)

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b/a<=c)cout<<b/a<<endl;
  else cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

double d;

int main()
{
	scanf("%lf",&d);
    double hoge = d*d;
    int t = 0;
    while(t*t <= hoge){
        t++;
    }
    double res = 0;
    if(hoge - (t-1)*(t-1) < 1.0){
        res = t;
    }
    res = max(res,sqrt(2*d*d));
    printf("%.10f\n",res);
	return 0;
}

Measured memory_bytes: 3164