akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

vector<vector<int> > rot = {
	{0,1,2,3,4,5},
	{0,2,4,1,3,5},
	{0,4,3,2,1,5},
	{0,3,1,4,2,5},
	{1,5,2,3,0,4},
	{1,2,0,5,3,4},
	{1,0,3,2,5,4},
	{1,3,5,0,2,4},
	{2,5,4,1,0,3},
	{2,4,0,5,1,3},
	{2,0,1,4,5,3},
	{2,1,5,0,4,3},
	{3,4,5,0,1,2},
	{3,5,1,4,0,2},
	{3,1,0,5,4,2},
	{3,0,4,1,5,2},
	{4,0,2,3,5,1},
	{4,2,5,0,3,1},
	{4,5,3,2,0,1},
	{4,3,0,5,2,1},
	{5,4,2,3,1,0},
	{5,2,1,4,3,0},
	{5,1,3,2,4,0},
	{5,3,4,1,2,0}
};

vector<vector<vector<int> > > cond = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];

char toggleCase(char c) {
	if (islower(c)) return toupper(c);
	return tolower(c);
}

string solve(int x) {
	if (x == 8) {
		return "YES";
	}
	for (int i=1; i<8; ++i) {
		if ( ! used[i]) {
			for (int j=0; j<24; ++j) {
				pz[x].id = i;
				pz[x].r = j;
				bool ok = true;
				for (int k=0; k<(int)cond[x].size(); ++k) {
					int bloc1 = x;
					int face1 = rot[pz[bloc1].r][cond[x][k][0]];
					int bloc2 = cond[x][k][1];
					int face2 = rot[pz[bloc2].r][cond[x][k][2]];
					if (toggleCase(dice[pz[bloc1].id][face1]) != dice[pz[bloc2].id][face2]) {
						ok = false; break;
					}
				}
				if (ok) {
					used[i] = true;
					if (solve(x+1) == "YES") {
						return "YES";
					}
					used[i] = false;
				}
			}
		}
	}
	return "NO";
}

int main() {
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) {
			cin >> dice[i];
		}
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
import itertools
n,m,q=map(int,input().split())
lis=[i for i  in range(1,m+1)]
lis=list(itertools.combinations_with_replacement(lis,n))
box=[0 for j in range(len(lis))]
for i in range(q):
    que=list(map(int,input().split()))
    for j in range(len(lis)):
        if lis[j][que[1]-1]-lis[j][que[0]-1]==que[2]:
            box[j]+=que[3] 
print(max(box))

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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=2e5 + 5;
const int M=1e5 + 5;

ll s[N],dp[N];
ll arr[N];
int main()
{
	ios_base::sync_with_stdio(false);
	int n,i;
	for(i=0;i<N;i++){
		arr[i]=0;
	}
	cin>>n;
	for(i=0;i<n;i++){
		cin>>s[i];
	}	
	vector <ll> v;
	v.pb(s[0]);
	for(i=1;i<n;i++){
		if(s[i]!=s[i-1]) v.pb(s[i]);
	} 
	n=v.size();

	if(n==1){
		cout << 1 << endl;
		return 0;	
	}

	dp[0]=1;
	
	arr[v[0]]=1;
	for(i=1;i<n;i++){
		dp[i]=(arr[v[i]]+dp[i-1])%mod;
		arr[v[i]]=(arr[v[i]]+dp[i-1])%mod;
	}
	cout << dp[n-1] << endl;

	return 0;
	
}

Measured memory_bytes: 6644
// Author: 23forever
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 2999;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n;
double p[MAXN + 5], dp[MAXN + 5][MAXN + 5];

void init() {
  n = read();
  for (int i = 1; i <= n; ++i) scanf("%lf", &p[i]);
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  //freopen("test.out", "w", stdout);
#endif
  init();

  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    for (int j = 1; j <= i; ++j) {
      dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
    }
  }

  double ans = 0;
  for (int i = n / 2 + 1; i <= n; ++i) ans += dp[n][i];
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 68992
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#include <atcoder/scc>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int n,m;
	std::cin >> n >> m;
	atcoder::scc_graph g(n);
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		g.add_edge(a,b);
	}
	auto scc=g.scc();
	print(scc.size());
	for(auto& e:scc) {
		std::cout << e.size();
		for(auto x:e) std::cout << ' ' << x;
		std::cout << EL;
	}
}


Measured memory_bytes: 40124
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 値 - 取得
	int liN, liM, liD;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &liN, &liM, &liD);

	// ２組比較 - 美しさ獲得が２パターンの数
	int liTCnt = 0;
	if (liD > 0) {
		liTCnt = liN - liD * 2;
		if (liTCnt < 0) {
			liTCnt = 0;
		}
	}

	// ２組比較 - 美しさ獲得が１パターンの数
	int liOCnt = liN;
	if (liD > 0) {
		liOCnt = liD * 2;
		if (liOCnt > liN) {
			liOCnt = liN * 2 - liOCnt;
		}
	}

	// 平均 - 取得
	double ldAvg = (double)(liTCnt * 2 + liOCnt) / (double)liN / (double)liN * (double)(liM - 1);

	// 結果 - セット
	sprintf(lc1Out, "%.7lf\n", ldAvg);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

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

  std::vector<int> a(n);
  for (auto&& ai : a) std::cin >> ai;

  auto b = a;
  std::sort(b.begin(), b.end());
  const auto maxa1 = b[n - 1];
  const auto maxa2 = b[n - 2];

  for (auto&& ai : a) std::cout << (ai == maxa1 ? maxa2 : maxa1) << std::endl;
}

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

int main()
{
	long num, i,dif;
	cin >> num;
	num *= 3;
	long a[num];
	for (i = 0; i < num; i++) cin >> a[i];
	sort(a, a + num, greater<long>());
	dif = 0;
	for (i = 0; i < num*2/3; i++) {
		if (i % 2 == 1) dif += a[i];
	}
	cout << dif;
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int n,k;
int frogA(int ind, int a[],vector<int>&dp){
	if(ind == n-1)return 0;
	if(dp[ind]!=-1)return dp[ind];
		
	int res = INT_MAX;
	for(int i = ind+1;i<=min(n-1,ind+k);i++){
		int s = abs(a[ind] - a[i]) + frogA(i,a,dp);
		res = min(res,s);
	}
	
	return dp[ind] = res;
	
}



int main(){
	

	cin >> n >> k;
	int a[n];
	vector<int>dp(n,-1);
	for(int i = 0;i<n;i++)cin >>a[i];
	
	cout << frogA(0,a,dp);
	
}

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

const int MAX_N = 110;
int par[MAX_N];
int rnk[MAX_N];
int nodeNum[MAX_N];

void init(int n) {
	for(int i = 0; i < n; i++) {
		par[i] = i;
		rnk[i] = 0;
		nodeNum[i] = 1;
	}
}

int find(int x) {
	if(par[x] == x) {
		return x;
	}
	return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
	nodeNum[x] = nodeNum[y] = nodeNum[x] + nodeNum[y];
}

bool same(int x, int y) {
	return find(x) == find(y);
}

struct Edge {
	int u, v, w;
};

bool comp(const Edge& e1, const Edge& e2) {
	return e1.w < e2.w;
}

const int INF = 1 << 28;
Edge e[10000];

int main() {
	int n, m;
	while(cin >> n >> m, n | m) {
		for(int i = 0; i < m; i++) {
			cin >> e[i].u >> e[i].v >> e[i].w;
			e[i].u--, e[i].v--;
		}
		sort(e, e + m, comp);

		int ans = INF;
		for(int i = 0; i < m; i++) {
			init(n);
			for(int j = i; j < m; j++) {
				unite(e[j].u, e[j].v);
				if(nodeNum[find(0)] == n) {
					ans = min(ans, e[j].w - e[i].w);
					break;
				}
			}
		}

		if(ans == INF) ans = -1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3064
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
a = []
ans = 0
for i in range(n):
    b = int(input()) 
    a.append(b)
for i in range(3):
    if a1[i] in a and a2[i] in a and a3[i] in a:
        ans = 'Yes'
if a1[0] in a and a1[1] in a and a1[2] in a:
    ans = 'Yes'
if a2[0] in a and a2[1] in a and a3[2] in a:
    ans = 'Yes'
if a3[0] in a and a3[1] in a and a3[2] in a:
    ans = 'Yes'
if a1[0] in a and a2[1] in a and a3[2] in a:
    ans = 'Yes'
if a1[2] in a and a2[1] in a and a3[0] in a:
    ans = 'Yes'
if ans == 'Yes':
    print(ans)
else:
    print('No')

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

int main(){
	int x,y;cin>>x>>y;
  	int a,b;
  	if(x>=y){ a=x;b=y;}
  	else{ a=y;b=x;}
  	int c;
  while(true){
  	c=a%b;
  	if(c==0){
      cout<<b<<endl;
      break;
    }else{
    	a=b;
      	b=c;
    }
  }
}


Measured memory_bytes: 3120
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

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

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		double x0, x1, x2, x3, y0, y1, y2, y3;
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

		double p1x, p1y, p2x, p2y;
		p1x = x1 - x0;
		p1y = y1 - y0;
		p2x = x3 - x2;
		p2y = y3 - y2;

		double u1x, u1y, u2x, u2y;
		u1x = p1x / sqrt(p1x*p1x + p1y*p1y);
		u1y = p1y / sqrt(p1x*p1x + p1y*p1y);
		u2x = p2x / sqrt(p2x*p2x + p2y*p2y);
		u2y = p2y / sqrt(p2x*p2x + p2y*p2y);

		double dot = (u1x*u2x + u1y*u2y);

		if (abs(dot) <= 0.000000000000001)
		{
			cout << "1" << endl;
		}
		else if (abs(abs(dot) - 1) <= 0.000000000000001)
		{
			cout << "2" << endl;
		}
		else
		{
			cout << "0" << endl;
		}
	}

	return 0;
}


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

int dp[3002][3002];
char s[3002], t[3002];
struct node {
	int x, y;
} pre[3002][3002];


int main() {
	scanf("%s %s", (s+1), (t+1));
	int n = strlen(s+1);
	int m = strlen(t+1);
	node lin;
	memset(dp, 0, sizeof(dp));
	
	for(int i = 1;i <= n; i++) {
		for(int j = 1;j <= m; j++) {
			if(s[i] == t[j]) {
				dp[i][j] = dp[i-1][j-1]+1;
				lin.x = i-1; lin.y = j-1;
				pre[i][j] = lin;
			}
			else {
				if(dp[i-1][j] > dp[i][j-1]) {
					lin.x = i-1; lin.y = j;
					pre[i][j] = lin;
					dp[i][j] = dp[i-1][j];
				} 
				else {
					lin.x = i; lin.y = j-1;
					pre[i][j] = lin;
					dp[i][j] = dp[i][j-1];
				}
			}
		}
	}
	
	string ans = "";
	
	int i = n, j = m;
	while(i > 0){
		lin.x = i-1;
		lin.y = j-1;
//		cout << pre[i][j].x << " " << pre[i][j].y << endl;
		if(pre[i][j].x == lin.x && pre[i][j].y == lin.y) {
			ans += s[i];
//			cout << " ! " << endl;
		}
		int tx = i, ty = j;
		i = pre[tx][ty].x;
		j = pre[tx][ty].y;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 109196
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
struct aaa{
	ll x,y;
}a[2010];
ll n,ans,f[2010][2010];
bool cmp(aaa a,aaa b){
	return a.x>b.x;
}
int main(){
	ll i,j,w,x;
	scanf("%lld",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&a[i].x);
		a[i].y=i;
	}
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			w=a[i].x*abs(a[i].y-j-1);
			f[i][j+1]=max(f[i][j+1],f[i-1][j]+w);
			x=n-(i-1-j);
			w=a[i].x*abs(a[i].y-x);
			f[i][j]=max(f[i][j],f[i-1][j]+w);
		}
	}
	for(i=0;i<=n;i++)ans=max(ans,f[n][i]);
	printf("%lld",ans);
}

Measured memory_bytes: 26516
(defun calc-81(n)
  (loop :named calc
        :for i :from 1 :below 10
        :do (multiple-value-bind (v m)(floor n i)
              (when (and (= m 0) (< v 10))
                (return-from calc-81 "Yes"))))
  "No")

(format t "~a~%" (calc-81 (read)))

Measured memory_bytes: 24224
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    x_y_arr = []
    for i in range(N):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        x_y_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    f_x_y_arr0 = []
    f_x_y_arr1 = []
    for x, y in x_y_arr:
        f_x_y_arr0.append(x - y)
        f_x_y_arr1.append(x + y)
    f_x_y_arr0.sort(reverse=True)
    f_x_y_arr1.sort(reverse=True)
    ans = max((f_x_y_arr0[0] - f_x_y_arr0[-1]), (f_x_y_arr1[0] - f_x_y_arr1[-1]))
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 157948
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 1e9+7;

const int MAXN = 100005;

ll add(ll a,ll b)
{
	a%=MOD; b%=MOD;
	a+=b;a%=MOD;
	if(a<0) a+=MOD;
	return a;
}
ll mult(ll a, ll b)
{
	a%=MOD; b%=MOD;
	ll ans=(a*b)%MOD;
	if(ans<0) ans+=MOD;
	return ans;
}
ll pw(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll add2(ll a,ll b)
{
	a%=13; b%=13;
	a+=b;a%=13;
	if(a<0) a+=13;
	return a;
}
ll mult2(ll a, ll b)
{
	a%=13; b%=13;
	ll ans=(a*b)%13;
	if(ans<0) ans+=13;
	return ans;
}
ll pw2(ll a, ll b)
{
	ll r=1;
	while(b){
		if(b&1) r=mult2(r,a);
		a=mult2(a,a);
		b>>=1;
	}
	return r;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s; cin>>s; s='0'+s;
	int n=s.length();
	
	ll dp[n][13]{};
	dp[0][0]=1;
	
	forn(i,1,n){
		forn(j,0,13){
			forn(k,0,10){
				if(s[i]!='?' && s[i]-'0'!=k) continue;
				dp[i][j]=add(dp[i][j], dp[i-1][add2(j,-mult2(k, pw2(10,n-1-i)))]);
			}
		}
	}
	
	cout<<dp[n-1][5]<<'\n';
	
	return 0;
}


Measured memory_bytes: 13912
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int N;
string s, t;

int main(int argc, char const *argv[]) {
	cin >> N >> s >> t;
	for (int i = 0; i < N; i++) {
		if (s[i] == t[0]) {
			bool flag = true;
			int k = 0;
			for (int j = i; j < N; j++) {
				if (s[j] != t[k]) {
					flag = false;
					break;
				}
				k++;
			}
			if (flag) {
				cout << N + i << endl;
				return 0;
			}
		}
	}
	cout << 2 * N << endl;
	return 0;
}

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

#define ll long long
#define NIL 0
#define INF 1e18
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vl vector<ll>
#define vvl vector<vector<ll>> 
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pb push_back
#define F first
#define S second
#define pp pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rpk(i,k,n) for(int i=k;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++) 
#define RPK(i,k,n) for(int i=k;i<=n;i++) 
#define ritr(i,gr) for(auto i=gr.begin();i!=gr.end();i++)

const int M = 1e9+7;

int V, E, i, j, k, u, v, x, y, p, q, r;
vi *g;
vb sn;

void add_edge(int a,int b) { g[a].pb(b); g[b].pb(a);}

pp dfs_util( int s) {
    sn[s] = true;
    ll cb = 1, cw = 1;
    ritr(i, g[s]) {
        int to = *i;
        if(!sn[to]) {
            pp cnt = dfs_util(to);
            cb = (cb*(cnt.F%M))%M;
            cw = (cw*((cnt.F+cnt.S)%M))%M;
        }
    } 
    return mp(cw, cb);
}

void solve() {
    ll res = 0 ;
    sn.assign(V+1,false);
    pp cnt = dfs_util(1);
    res = (cnt.F+cnt.S)%M;
    cout<<res<<"\n";
}


int main() {
    cin>>V;
    E=V-1;
    g = new vi[V+1];
    rep(i,E) {
        cin>>x>>y;
        add_edge(x,y);
    }
    solve();
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;

int main() {
   int N;
   cin >> N;
   vector<int> a(N);
   map<int, int> cnt;
   for(int i = 0; i < N; i++) {
      cin >> a[i];
      cnt[a[i]]++;
   }
   int ci = 0, cj = 0;
   vector<int> najmanji;
   for(auto e: cnt) {
      najmanji.push_back(e.first);
      if(najmanji.size() > 2) 
         break;
   }
   for(int i = 0; i < najmanji.size(); i++) {
      for(int j = 0; j < najmanji.size(); j++) {
         if(i == j && cnt[najmanji[i]] < 2) 
            continue;
         auto pomcnt = cnt;
         vector<int> v = {najmanji[i], najmanji[j]};
         pomcnt[najmanji[i]]--;
         pomcnt[najmanji[j]]--;
         while(pomcnt[v[v.size() - 1] ^ v[v.size() - 2]]-- > 0) {
            v.push_back(v[v.size() - 1] ^ v[v.size() - 2]);
         }
         
         if(a.size() == v.size() && (v[v.size() - 1] ^ v[v.size() - 2]) == v[0]) {
            cout << "Yes";
            return 0;
         }
      }
   }
   cout << "No";
   return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
int A,B,tot,d[15][15];
bool mp[205][205];
struct edge{int i,j,x;};
edge tg[15][15],e[23333];
int main(){
	scanf("%d%d",&A,&B);
	for (int i=1;i<=A;i++)
		for (int j=1;j<=B;j++){
			scanf("%d",&d[i][j]);
			tg[i][j].i=-1;
		}
	for (int i=0;i<=100;i++)
		for (int j=0;j<=100;j++)
			for (int x=0;x<=100;x++){
				bool fl=0;
				for (int k=1;k<=A&&!fl;k++)
					for (int l=1;l<=B&&!fl;l++)
						if (i*k+j*l+x<d[k][l])
							fl=1;
				if (fl) continue;
				for (int k=1;k<=A&&!fl;k++)
					for (int l=1;l<=B&&!fl;l++)
						if (i*k+j*l+x==d[k][l])
							tg[k][l]=(edge){i,j,x};
			}
	for (int i=1;i<=100;i++)
		e[++tot]=(edge){i,i+1,-1};
	for (int i=102;i<=201;i++)
		e[++tot]=(edge){i,i+1,-2};
	for (int i=1;i<=A;i++)
		for (int j=1;j<=B;j++){
			if (tg[i][j].i==-1){
				puts("Impossible");
				//printf("%d %d\n",i,j);
				return 0;
			}
			if (!mp[tg[i][j].i][tg[i][j].j])
				e[++tot]=(edge){1+tg[i][j].i,202-tg[i][j].j,tg[i][j].x};
			mp[tg[i][j].i][tg[i][j].j]=1;
		}
	puts("Possible");
	printf("%d %d\n",202,tot);
	for (int i=1;i<=tot;i++){
		printf("%d %d ",e[i].i,e[i].j);
		if (e[i].x==-1) printf("X\n");
		else if (e[i].x==-2) printf("Y\n");
		else printf("%d\n",e[i].x);
	}
	printf("1 202");
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int r;
    cin >> r;
    if (r < 1200)cout << "ABC" << endl;
    else if (r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
struct Cake {
  int x, y, z;
  int value() { return (x) + (y) + (z); }
  Cake() { x = y = z = 0; }
};
bool operator<(Cake a, Cake b) { return a.value() < b.value(); }
Cake operator+(Cake a, Cake b) {
  Cake c;
  c.x = a.x + b.x;
  c.y = a.y + b.y;
  c.z = a.z + b.z;
  return c;
}
Cake operator-(Cake a) {
  a.x = -a.x;
  a.y = -a.y;
  a.z = -a.z;
  return a;
}
istream &operator>>(istream &is, Cake &a) {
  is >> a.x >> a.y >> a.z;
  return is;
}

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

  int N, M;
  cin >> N >> M;
  vector<int> x(N), y(N),z(N); rep(i, 0, N){ cin >> x[i] >> y[i]>>z[i]; }
  int ans=-INF;
  rep(bits,0,8){
    vector<int>v(N);
    rep(i,0,N){
      int a=x[i];
      if(bits&1)a=-a;
      v[i]+=a;
      a=y[i];
      if((bits>>1)&1)a=-a;
      v[i]+=a;
      a=z[i];
      if((bits>>2)&1)a=-a;
      v[i]+=a;
    }
    sort(all(v));
    chmax(ans,accumulate(v.end()-M,v.end(),0ll));
  }
  cout<<ans<<endl;

  return 0;
}


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

vector<int> primes;
bitset<1000000100> bs;
void sieve(){
	bs.set();
	bs[0] = bs[1] = 0;
	for(ll i = 2 ; i <= Sv + 1 ; ++i)if(bs[i]){
		for(ll j = i * i ; j <= Sv + 1 ; j += i)bs[j] = 0;
		primes.push_back(int(i));
	}
}
int DifPf (ll n){
	int ind = 0 , res = 0;
	long pf = primes[ind];
	while(pf * pf <= n){
		if(n % pf == 0)++res;
		while(n % pf == 0) n /= pf;
		pf = primes[++ind];
	}
	if(n != 1) ++res;
	return res;
}
ll gcd (ll a , ll b){
	return (b == 0) ? a : gcd(b,a%b);
}
int main() {
	sieve();
	ll a , b ;
	scanf("%lld %lld",&a,&b);
	printf("%d",DifPf(gcd(a,b)) + 1);
	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int[] color = new int[3];
        color[0] = int.Parse(input[0]);
        color[1] = int.Parse(input[1]);
        color[2] = int.Parse(input[2]);
        int N = int.Parse(input[3]);

        Array.Sort(color);
        int counter = 0;
        for(int i = 0;i <= 3000/color[2]; i++)
        {
            int num=N-color[2]*i;
            for (int j = 0; 0 <= N-color[2]*i-color[1]*j; j++)
            {
                    int sum = (N - color[2] * i - color[1] * j)%color[0];
                    if (sum == 0)
                    {
                        counter++;
                    }
            }
        }
        Console.WriteLine(counter);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
struct node{
	int a,c;
	string b;
}q[10000];
bool cmp(node g,node h){
	if(g.b!=h.b){
		return g.b<h.b;
	}
	else{
		return g.a>h.a;
	}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
	cin>>q[i].b>>q[i].a;
	q[i].c=i;
}
sort(q+1,q+n+1,cmp);
	for(int j=1;j<=n;j++){
		cout<<q[j].c<<endl;
	}

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
 
#define mem(dp,a)       memset(dp,a,sizeof dp)
#define ninja           ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb(x)           push_back(x)
#define mp(x,y)         make_pair(x,y)
#define all(c)          c.begin(), c.end()
#define ff              first
#define ss              second
#define nl              '\n'
#define inf             1e9+7

vector<pii> adj[100003];
bool vis[100003];
vector<int> node(100003);

void dfs(int s, int color){
	vis[s]=1;
	node[s]=color;
	for(auto i:adj[s]){
		if(!vis[i.ff]){
			if(i.ss&1)
				dfs(i.ff,!color);
			else
				dfs(i.ff,color);
		}
	}
}
int main()
{
	ninja

	int n;cin>>n;
	int a,b,w;

	for(int i=0;i<n-1;i++){
		cin>>a>>b>>w;
		adj[a].pb(mp(b,w));
		adj[b].pb(mp(a,w));
	}
	mem(vis,0);
	dfs(1,0);
	for(int i=1;i<=n;i++)
		cout<<node[i]<<nl;
}

Measured memory_bytes: 7680
x1,y1,x2,y2 = map(int, input().split())
x12=x2-x1
y12=y2-y1

if x12>=0 and y12>=0:
    x3=x2-abs(y12)
    y3=y2+abs(x12)
    x4=x3-abs(x12)
    y4=y3-abs(y12)
elif x12>=0 and y12<0:
    x3=x2+abs(y12)
    y3=y2+abs(x12)
    x4=x3-abs(x12)
    y4=y3+abs(y12)
elif x12<0 and y12>=0:
    x3=x2-abs(y12)
    y3=y2-abs(x12)
    x4=x3+abs(x12)
    y4=y3-abs(y12)
else:
    x3=x2+abs(y12)
    y3=y2-abs(x12)
    x4=x3+abs(x12)
    y4=y3+abs(y12)
print('{} {} {} {}'.format(x3,y3,x4,y4))

Measured memory_bytes: 38256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

n = gif
a = gif
puts n % 500 <= a ? 'Yes' : 'No'


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

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;cw--;dh--;dw--;
  const int INF = 1e9+5;
  vector<vector<char>> s(h, vector<char>(w));
  vector<vector<bool>> ed(h, vector<bool>(w,false));
  vector<vector<int>> d(h, vector<int>(w,INF));
  rep(i,h) rep(j,w) cin >> s[i][j];

  priority_queue<Pip,vector<Pip>, greater<Pip>> pq;
  pq.push(make_pair(0, make_pair(ch, cw)));
  d[ch][cw] = 0;
  while(!pq.empty()) {
    int u = pq.top().first;
    P p = pq.top().second;
    pq.pop();
    int i = p.first;
    int j = p.second;

    ed[i][j] = true;

    if (d[i][j] < u) continue;

    for (int a = -2; a <= 2; a++) {
      for (int b = -2; b <= 2; b++) {
        if (a == 0 && b == 0) continue;
            //cout << i+a << " " << j+b << endl;
        if (0 <= i+a && i+a < h && 0 <= j+b && j+b < w) {
          if (ed[i+a][j+b] == false && s[i+a][j+b] == '.') {
            int k;
            if ((a == -1 && b == 0) || (a == 1 && b == 0) || (a == 0 && b == 1) || (a == 0 && b == -1)) {
              //pq.push(make_pair(0, make_pair(i+a, j+b)));
              //cout << a << " " << b << " d:" << 0 << endl;
              k = 0;
            } else {
              //pq.push(make_pair(1, make_pair(i+a, j+b)));
              //cout << a << " " << b << " d:" << 1 << endl;
              k = 1;
            }
            if (d[i+a][j+b] > d[i][j] + k) {
              d[i+a][j+b] = d[i][j] + k;
              pq.push(make_pair(d[i+a][j+b], make_pair(i+a, j+b)));
            }
          }
        }
      }
    }
  }
  if (d[dh][dw] == INF) cout << -1 << endl;
  else cout << d[dh][dw] << endl;
/**
    rep(i,h) {
    rep(j,w) {
      cout << d[i][j] << " ";
    }
    cout << endl;
  }
/**/
   return 0;
}

Measured memory_bytes: 8708
import java.io.*;
import java.util.*;

public class Main {
	static int H=0;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
		int A[]=new int[2000001];
		
		for(int i=0;i<2000001;i++)A[i]=-1;
		
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			//String odr = in.next();
			String str="";
			try {
				str=buffer.readLine();
			}catch(IOException e) {
				e.printStackTrace();
			}
			String odr[]=str.split(" ",0);
			if(odr[0].equals("end"))break;
			else if(odr[0].equals("insert")) {
				int k=Integer.parseInt(odr[1]);
				insKey(A,k);
			}
			else if(odr[0].equals("extract")) {
				//buildMaxHeap(A);
				out.println(A[1]);
				delTop(A);
			}
		}
		out.flush();
	}
	
	static void maxHeapify(int A[],int index) {
		int l=index*2, r=index*2+1, L;
		
		if(l<=H && A[l]>A[index])L=l;
		else L=index;
		if(r<=H && A[r]>A[L])L=r;
		
		if(L!=index) {
			int t=A[index];
			A[index]=A[L];
			A[L]=t;
			maxHeapify(A,L);
		}
	}
	
	static void delTop(int A[]) {
		A[1]=A[H];
		H--;
		maxHeapify(A,1);
	}
	
	static void insKey(int A[],int k) {
		H++;
		A[H]=k;
		int i=H;
		while(i>1 && A[i]>A[i/2]) {
			int t=A[i/2];
			A[i/2]=A[i];
			A[i]=t;
			i=i/2;
		}
	}

}



Measured memory_bytes: 169468
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

//ll ans = 0;
//
//void dfs(const int N, const vector<int>& A, int depth)
//{
//    if (depth > N)
//        return;
//
//    auto iter = find(A.begin(), A.end(), depth);
//    if (iter != A.end())
//        return;
//
//    if (N == depth) {
//        ans += 1;
//        return;
//    }
//
//    dfs(N, A, depth+1);
//    dfs(N, A, depth+2);
//}
//
//int main()
//{
//    int N, M; cin >> N >> M;
//    vector<int> A;
//    rep (i, 0, M) {
//        int a; cin >> a;
//        A.push_back(a);
//    }
//
//    dfs(N, A, 0);
//
//    cout << ans << endl;
//}

int main()
{
    int N, M; cin >> N >> M;

    vector<int> oks(N+1, true);
    for (int i = 0; i < M; ++i) {
        int a; cin >> a;
        oks[a] = false;
    }

    vector<long long int> dp(N+1);
    dp[0] = 1;
    for (int now = 0; now < N; ++now) {
        for (int next = now + 1; next <= min(N, now+2) ; ++next) {
            if (oks[next]) {
                dp[next] += dp[now];
                dp[next] %= MOD;
            }
        }
    }

    cout << dp[N] << endl;
}

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

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    
    int ans = 0;
    for(int i = 0; i < M; i++){
        UnionFind uf(N);
        for(int j = 0; j < M; j++){
            if(i == j)continue;
            uf.unionSet(a[j], b[j]);
        }
        if(uf.size() != 1)ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
Bases=[59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6]

N = ARGF.gets.to_i

DP = Array.new(N+1) do Array.new(Bases.size, -1) end
# for i in 0..restN
#   DP[i][0] = 0
# end

def dfs(restN, cur)
  return 0 if restN == 0
  return restN if cur >= Bases.size

  return DP[restN][cur] if DP[restN][cur] >= 0


  if restN >= Bases[cur]
    res = [dfs(restN - Bases[cur], cur)+1, dfs(restN - Bases[cur], cur+1)+1, dfs(restN, cur+1)].min
  else
    res = dfs(restN, cur+1)
  end

  DP[restN][cur] = res
  res
end

puts dfs(N, 0)


Measured memory_bytes: 18684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string S;
  cin >>S;
  int x=0;
  rep(i,4){
    if(S[i]=='+')x++;
    else if(S[i]=='-')x--;
  }
  cout<<x<<endl;
  return 0;
    
  
}


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

int N, Q;
LL D, A[505050], S[505050];
LL R[505050];

int main(){
    scanf("%d %lld", &N, &D);
    S[1] = D;
    for (int i=1; i<=N; i++){
        scanf("%lld", &A[i]);
        if (S[i] >= A[i]) S[i+1] = S[i] - A[i];
        else if (2*S[i] >= A[i]) S[i+1] = A[i] - S[i];
        else S[i+1] = S[i];
    }
    for (int i=N; i>0; i--){
        if (A[i]/2 <= R[i]) R[i-1] = R[i] + A[i];
        else R[i-1] = R[i];
    }
    scanf("%d", &Q);
    while (Q--){
        int x;
        scanf("%d", &x);
        puts((S[x] <= R[x]) ? "NO" : "YES");
    }
    return 0;
}


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

int main() {
	int a[5], k;
	for (int i = 0; i < 5; ++i) cin >> a[i];
	cin >> k;
	if (a[4] - a[0] <= k) cout << "Yay!";
	else cout << ":(";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;
 
 
 
int main()
{
  fastio();
 
ll int T=1;
//cin>>T;
while(T--)
{
  ll int n,count=0,ans=0;
  string s;
  cin>>s;
  ll int i,flag=0;
  for(i=0;i<s.size();i++)
  {
      if(i%2)
      {
          if(s[i]!='i')flag=1;
      }
      else
      {
          if(s[i]!='h')flag=1;
      }
  }
  if(flag||s.size()%2!=0)
  cout<<"No"<<endl;
  else
  cout<<"Yes"<<endl;
}
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#define INF (1<<21)
using namespace std;

int main(){
  int i,j,k,n,m,s,g1,g2,d[101][101],ans;
  while(1){
    cin >> n >> m >> s >> g1 >> g2;
    if(!n && !m && !s && !g1 && !g2) break;

    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	if(i == j) d[i][j] = 0;
	else d[i][j] = INF;
      }
    }

    for(j=0;j<m;j++){
      int a,b,cost;
      cin >> a >> b >> cost;
      d[a][b] = cost;
    }

    for(k=0;k<=n;k++){
      for(i=0;i<=n;i++){
	for(j=0;j<=n;j++){
	  if(d[i][k] >= INF || d[k][j] >= INF) continue;
	  d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
	}
      }
    }

   int ans = d[s][g1] + d[s][g2];
   ans = min(ans,d[s][g1]+d[g1][g2]);
   ans = min(ans,d[s][g2]+d[g2][g1]);

   for(i=1;i<=n;i++){
     if(i != s && i != g1 && i != g2){
       ans = min(ans,d[s][i]+d[i][g1]+d[i][g2]);
     }
   }

    cout << ans << endl;

  }
  return 0;
}

Measured memory_bytes: 904
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(0, N-M+1):
    pos = A[i].find(B[0])
    if pos >= 0:
        for j in range(1, M):
            if A[i+j][pos:pos+M] != B[j]:
                break
        else:
            print('Yes')
            break
else:
    print('No')


Measured memory_bytes: 3060
/*CODE BY VIJAY MUKHIJA*/
#include<bits/stdc++.h>
#define lli long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define SMOD 998244353
#define what_is(x) cout << #x << " is " << x << endl
#define what_are(x,y) cout<< #x <<" is " << x << " "<< #y <<" is " << y <<endl
using namespace std;
lli Powerm(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m; lli t=Powerm(a,b/2,m); t=(t*t)%m; if(b&1)t=(t*a)%m; return t;}
lli Power(lli a,lli b){ if(b==0) return 1; if(b==1) return a; lli t=Power(a,b/2); t=(t*t); if(b&1)t=(t*a); return t;}
lli Gcd(lli a,lli b) { if(b==0) { return a; } else { return Gcd(b,a%b); } }
lli LeftMostSetBit(lli n){ if (n == 0){return 0; } lli msb = 0; while (n != 0) {n = n / 2; msb++; } return msb; }
lli RightMostSetBit(lli n){ return __builtin_ffsl(n); }
lli llsqrt(lli x){ if(x==0 || x==1) return x; lli start=1, end=x/2, ans; while(start<=end) { lli mid=(start+end)/2; if(mid*mid==x) return mid;
else if(mid <= x/mid) ans=mid,start=mid+1; else end=mid-1; }  return ans; }

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
	lli n;
	cin>>n;
	lli a[n];
	for(lli i=0;i<n;i++)
	{
		cin>>a[i];
	}
	//bottomup
	lli dp[n+1];
	memset(dp,INT_MAX,sizeof(dp));
	dp[1]=0;
	dp[2]=abs(a[1]-a[0]);
	for(lli i=2;i<n;i++)
	{
		dp[i+1]=min(abs(a[i]-a[i-1])+dp[i],abs(a[i]-a[i-2])+dp[i-1]);
	}
	cout<<dp[n]<<endl;

}


Measured memory_bytes: 1792
l = [0, 0, 0, 0, 0]

for _ in range(3):
  for s in input().split():
    l[int(s)] += 1
    
l = sorted(l)
ans = [0, 1, 1, 2, 2]
if ans == l:
  print("YES")
else:
  print("NO")
  

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

using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (int)n; i++)

int main(){
  int n,m;
  cin >> n >> m;
  if (n <= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3592
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e8 ;
int main()
{
    ll t,i,ac=0,tl=0,wa=0,re=0;
    cin>>t;
    vector < string > ara;
    string s;
    for(i=0;i<t;i++){
        cin>>s;
        ara.pb(s);
    }
    for(i=0;i<t;i++){
        if(ara[i]=="AC")
           ac++;
        else if(ara[i]=="TLE")
            tl++;
        else if(ara[i]=="WA")
            wa++;
        else
            re++;

    }
    cout<<"AC x "<<ac<<"\n";
     cout<<"WA x "<<wa<<"\n";
      cout<<"TLE x "<<tl<<"\n";
       cout<<"RE x "<<re<<"\n";
    return 0;
}



Measured memory_bytes: 7416
#include<stdio.h>

#define  NUM  3

int main(void)
{
	int i, j;
	int x[NUM] = { 0 };
	
	for (i = 0; i < NUM; i++)
		scanf("%d", &x[i]);

	for (i = 0; i < NUM - 1; i++) {
		for (j = i + 1; j < NUM; j++) {
			if (x[i] > x[j]) {
				int temp = x[i];
				x[i] = x[j];
				x[j] = temp;
			}
		}
	}

	printf("%d %d %d\n", x[0], x[1], x[2]);

	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main()
{
	long long N;
	scanf("%lld", &N);

	if (N % 2 == 0) {
		printf("%lld %lld %lld\n", N/2, N, N);
		fflush(stdout);
		return 0;
	}
	
	long long h, n, w = 0, rest;
	for (h = N / 4; h <= N * 3 / 4; h++) {
		rest = h * N / (4 * h - N);
		for (n = rest + 1; n <= rest * 2 + 1; n++) {
			if ((h * n * N) % (4 * h * n - h * N - n * N) == 0) {
				w = (h * n * N) / (4 * h * n - h * N - n * N);
				if (w > 0) break;
			}
		}
		if (w > 0) break;
	}
	printf("%lld %lld %lld\n", h, n, w);
	fflush(stdout);
	return 0;
}

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

public class Main {

	public static void main(String[] args){
		
		
		Scanner sc = new Scanner(System.in);
		List<Integer> firstList  = new ArrayList<>();
		
		for(int i = 0;i < 6;i++){
			
			firstList.add(Integer.parseInt(sc.next()));
		}
		
		Main.Dice dice = new Main().new Dice(firstList);
		
		int number = Integer.parseInt(sc.next());
		StringBuilder sb = new StringBuilder();
		
		for(int i = 0; i< number;i++){
			
			int upperNumber = Integer.parseInt(sc.next());
			int frontNumber = Integer.parseInt(sc.next());
			dice.adjustDice(dice,upperNumber,frontNumber);
			sb.append(dice.showRight() + "\n");
		}
		System.out.print(sb);
		
		sc.close();
		

	}
	
	
	class Dice{
		
		private int one;
		private int two;
		private int three;
		private int four;
		private int five;
		private int six;
		
		Dice(List<Integer> arg){
			
			if(arg == null || arg.size() != 6){
				throw new IllegalArgumentException();
			}
			
			this.one  = arg.get(0);
			this.two  = arg.get(1);
			this.three= arg.get(2);
			this.four = arg.get(3);
			this.five = arg.get(4);
			this.six  = arg.get(5);
			
		}
		
		
		Dice roll(String direction){
			int tmp;
			switch(direction){
			
			case "N":
				
				tmp = this.five;
				this.five = this.one;
				this.one  = this.two;
				this.two  = this.six;
				this.six  = tmp;
				break;
				
			case "S":
				tmp = this.five;
				this.five = this.six;
				this.six  = this.two;
				this.two  = this.one;
				this.one  = tmp;
				break;
			case "W":
				tmp = this.one;
				this.one = this.three;
				this.three  = this.six;
				this.six  = this.four;
				this.four  = tmp;
				break;
				
			case "E":
				tmp = this.one;
				this.one = this.four;
				this.four  = this.six;
				this.six  = this.three;
				this.three  = tmp;
				break;
			}
			
			return this;
		}
		
		
		int showTop(){
			return this.one;
		}
		
		int showFront(){
			return this.two;
		}
		
		int showRight(){
			return this.three;
		}
		
		int showLeft(){
			return this.four;
		}
		
		int showBack(){
			return this.five;
		}
		
		int showDown(){
			return this.six;
		}

		public void adjustDice(Main.Dice dice, int upperNumber, int frontNumber) {
			
			if(upperNumber == dice.showRight() || upperNumber == dice.showLeft()){
				dice.roll("E");
			}
			
			while(dice.showFront() != upperNumber){
				
				dice.roll("S");
			}
			
			while(dice.showDown() != frontNumber){
				
				dice.roll("E");
				
			}
			dice.roll("N");
			
		}
		
	}
}



Measured memory_bytes: 26132
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };


int main(void) {

	ll x, y,answer = 0;
	cin >> x >> y;

	while (x <= y) {
		x *= 2;
		answer++;
	}

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  vector<int>X(M);
  for(int &x:X)cin>>x;
  sort(X.begin(),X.end());
  vector<int>sa(M-1);
  for(int i=0;i<M-1;i++)
    sa[i]=X[i+1]-X[i];
  sort(sa.begin(),sa.end(),greater<int>());
  int ans=X[M-1]-X[0];
  for(int i=0;i<min(N-1,M-1);i++)
    ans-=sa[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI acos(-1.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define rt return true
#define rf return false
///................function.....................///
#define siz(s) (int)(s.size())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mod 1000000007
int main()
{
    FIO;
    int n,i,j;
    cin>>n;
    vi v(n);
    read(v,0,n);
    sort(all(v));
    int cnt=0;
    for(i=0; i<n-2; i++)
    {
        for(j=i+1; j<n-1; j++)
        {
            if(v[i]==v[j])continue;
            for(int k=j+1; k<n; k++)
            {
                if(v[j]==v[k])continue;
                if(v[i]+v[j]>v[k])
                {
                    cnt++;
                }
                else break;
            }
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=4e5+10;
const int mod=1e9+7;
int d[maxn],a[maxn],z[maxn];
ll sum[maxn];
int k,q,n,x,m,ans,t1,t2;
int main(){
	cin>>k>>q;
	for(int i=0;i<k;i++) cin>>d[i];
	while(q--){
		cin>>n>>x>>m;
		x%=m;
		sum[0]=0;
		z[0]=0;
		for(int i=0;i<k;i++){
			a[i]=d[i]%m;
			sum[i+1]=sum[i]+a[i];
			z[i+1]=z[i]+(a[i]==0);
		}
		t1=(n-1)/k*z[k]+z[(n-1)%k];
		t2=((n-1)/k*sum[k]+sum[(n-1)%k]+x)/m-x/m;
		ans=n-t1-t2-1;
		cout<<ans<<endl;
	}
} 

Measured memory_bytes: 4480
#include <stdio.h>
#include <stdbool.h>
#define MAX 1000000

bool dbl(int *a, int len) {
  int i;
  for(i = 0; i < len-1; ++i) {
	if(a[i] == a[len-1]) { return true; }
  }
  return false;
}

int main(void)
{
  int s, len = 0, a[MAX];
  scanf("%d", &s);
  a[len] = s; ++len;
  while(true) {
    if(a[len-1]%2 == 0) { a[len] = a[len-1]/2; ++len; }
    else { a[len] = 3*a[len-1] + 1; ++len; }
    if(dbl(a, len)) { break; }
    if(len >= 1000000) { break; }
  }
  //int i;
  //for(i = 0; i < len; ++i) {
  //  printf(" %d", a[i]);
  //}
  //printf("\n");
  printf("%d\n", len);
  return 0;
}

Measured memory_bytes: 128