akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1000;
int n,q[N],qq[N],ans,tot;
bitset<3000> heshu;
ll qqq[N];
map<ll,int> M;
map<ll,int>::iterator it;
ll dl(ll x){
	ll s=1;
	for(int i=1;i<=tot;i++)if(x%qq[i]==0){
		x/=qq[i]; s*=q[i];
	}else if(x%q[i]==0){
		x/=q[i]; s*=qq[i];
	}
	//cout<<s<<" "<<x<<endl;
	ll t=sqrt(x); if(t*t==x)return s*t; else return s*x*x;
}
signed main(){
	n=read();
	int t=pow(1e10,(double)1/3);
	for(int i=2;i<=t;i++)if(!heshu[i]){
		q[++tot]=i; qq[tot]=i*i; qqq[tot]=(ll)i*i*i;
		for(int j=i+i;j<=t;j+=i)heshu[j]=1;
	}
	for(int i=1;i<=n;i++){
		ll x=read();
		for(int j=1;j<=tot;j++)while(x%qqq[j]==0)x/=qqq[j];
		M[x]++;
	}
	ans=M[1]>0; M.erase(1);
	for(it=M.begin();it!=M.end();it++){
		ll t=dl(it->first); //cout<<it->first<<" "<<it->second<<" "<<t<<endl;
		if(it->second>M[t]){ans+=it->second; M.erase(t); }
		else {ans+=M[t]; M.erase(t);}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6656
#!/usr/bin/python3

import math
#標準出力からの読み込み
input_1 = input()
n = int(input_1.split(" ")[0])
m = int(input_1.split(" ")[1])
q = int(input_1.split(" ")[2])

input_array = []
for i in range(q):
    input_array.append(input())

array = []
for i in range(q):
    array.append(input_array[i].split(" "))

for i in range(q):
    for j in range(4):
        array[i][j] = int(array[i][j])


#判定ロジック
#Aについて総当たりで調べる

#重複組み合わせの全組み合わせを得る関数
#1がN個、0がM-1個と考える
def make_all_combi(m, n, array):
    if n == 0:
        for i in range(m-1):
            array = array + [0]
        return array
    elif m == 1:
        for i in range(n):
            array = array + [1]
        return array
    else:
        array_3 = array + [1]
        array_4 = array + [0]
        tmp_list_a = make_all_combi(m, n-1, array_3)
        tmp_list_b = make_all_combi(m-1, n, array_4)
    return tmp_list_a + tmp_list_b

combi = make_all_combi(m, n, [])

#make_all_combiで得た配列に対して、Aを作成する
def make_a(combi):
    A = []
    for i in range(len(combi)//(m+n-1)):
        list_a = combi[i*(m+n-1):(i+1)*(m+n-1)]
        count = 1
        a_cand = []
        for j in range(len(list_a)):
            if list_a[j] == 0:
                count = count + 1
            else:
                a_cand.append(count)
        A.append(a_cand)
    return A

A = make_a(combi)

score = 0
max_a = []
for i in range(len(A)):
    tmp = 0
    for j in range(q):
        if A[i][array[j][1]-1] - A[i][array[j][0]-1] == array[j][2]:
            tmp = tmp + array[j][3]
    if tmp > score:
        score = tmp
        max_a = A

print(score)


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

typedef long long ll;
ll h[200020];
ll n,k;
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h,h+n);
    reverse(h,h+n);
    ll sum = 0;
    for (int i = k; i < n; i++) {
        sum += h[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
H, W = map(int, input().split())
S = [0]*(H+2)
for i in range(1,H+1):
  S[i] = '.'+input()+'.'
S[0]= '.'*(W+2)
S[H+1]= '.'*(W+2)
for i in range(1,H+1):
  for j in range(1,W+1):
    if S[i][j]=='#':
      check = [S[i-1][j],S[i][j-1],S[i+1][j],S[i][j+1]]
      if '#' not in check:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad


main = do
  [a,b,c,x,y] <- map read . words <$> getLine ::IO [Int]
  print $ solve a b c x y


solve a b c x y =
  minimum p
  where
    ab = c*((min x y)*2)
    p =  [a*x+b*y,
          ab + if(x>y) then (x-y)*a else (y-x)*b,
          c *(max x y)*2
         ]
   

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

using namespace std;

int main() {
	int n, k, tmp;
	cin >> n >> k;

	deque<int> input(k), ans(k);
	cin >> input[0];

	if (k > n) {
		k = n;
	}

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

	ans[0] = 0;
	for (int i = 1; i < k; i++) {
		cin >> input[i];
		int mn = INT_MAX;
		for (int j = i-1; j >=0; j--) {
			mn = min(mn, abs(input[i] - input[j]) + ans[j]);
		}
		ans[i] = mn;
	}

	for (int i = k; i < n; i++) {
		cin >> tmp;
		int mn = INT_MAX;
		for (int j = 0; j < k; j++) {
			mn = min(mn, abs(tmp - input[j]) + ans[j]);
		}
		ans.pop_front();
		ans.push_back(mn);

		input.pop_front();
		input.push_back(tmp);
	}
	cout << ans[k-1] << endl;
	return 0;
}
		

Measured memory_bytes: 256
using System;
class transfer{
  public static void Main(){
    String[] str = Console.ReadLine().Split(' ');
    int a = int.Parse(str[0]);
    int b = int.Parse(str[1]);
    int c = int.Parse(str[2]);
    if(a-b >= c){
      Console.WriteLine(0);
    }
    else{
      Console.WriteLine(c-(a-b));
    }
  }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
std::vector<int> v;
void primeFactors(long long n)  
{  
    while (n % 2 == 0)  
    {  
        v.push_back(2);  
        n = n/2;  
    }  
    for (long long i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            v.push_back(i);  
            n = n/i;  
        }  
    }  
  
    if (n > 2)  
        v.push_back(n); 
} 

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

	primeFactors(n);

	long long ans = 0;
	for (long long i = 0; i < v.size(); ++i)
	{
		long long a = v[i],cnt=0;
		while(v[i]==a)
		{
			// printf("nn\n");
			cnt++;
			i++;
		}
		i--;
		// printf("%lld %lld\n",cnt,a );
		long long k = 1,c=0;
		while(cnt>0)
		{
			// printf("%lld %lld\n",cnt,k );
			cnt -= k;
			if(cnt<0)
				break;
			k++; 
			c++;
		}
		ans += c;
	}

	cout<<ans<<endl;

	
	return 0;
}

Measured memory_bytes: 3680
h, w = map(int, input().split())
s = []
for i in range(h):
  s.append(input())

for x in range(h):
  for y in range(w):
    if s[x][y] == '#':
      counter = 0
      direction = 4
      t = [-1, 1, 0, 0, 0, 0, -1, 1]
      for i in range(4):
        try:
          counter += (s[x+t[i]][y+t[i+4]] != '#')
        except:
          direction -= 1
      if counter == direction:
        print('No')
        exit(0)
print('Yes')



Measured memory_bytes: 3064
/**
 * @Author: yujirotakahashi
 * @Date:   2020-05-17T20:23:50+09:00
 * @Last modified by:   yujirotakahashi
 * @Last modified time: 2020-05-31T21:37:45+09:00
 */

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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
using ll = long long;
using PAIR = pair<int, int>;
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/

/******** User-defined Function *******/
using Graph = vector<vector<int>>;
map<ll,int>prime_factor(ll n){
	map<ll,int>res;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n/=i;
		}
	}
	if(n!=1)res[n]++;
	return res;
}

/**************************************/

/********** Main()  function **********/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n; cin >> n;

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

  map<ll,int> mp;
  mp = prime_factor(n);

  ll ans = 0;
  for(auto x: mp){
      int tmp = x.second;
      int cnt = 0;
      for(int i=1; ; ++i){
          tmp-=i;
          if(tmp>=0) cnt++;
          else break;
      }

      ans += cnt;
  }

  cout << ans << endl;





  return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3656
#include<stdio.h>

int main()
{
  int i,j,k,n=0;
  int N,A[100],minj,tmp;

  scanf("%d",&N);
  for(k=0;k<N;k++)
    {
      scanf("%d",&A[k]);
    }
  for(i=0;i<N;i++)
    {
      minj=i;
      for(j=i;j<N;j++)
	{
	  if(A[j]<A[minj])
	    {
	      minj=j;
	    }
	}
      if(A[i]!=A[minj])
	{
	  tmp=A[i];
	  A[i]=A[minj];
	  A[minj]=tmp;
	  n++;
	}
    }
  for(k=0;k<N;k++)
    {
      if(k>0)printf(" ");
      printf("%d",A[k]);
    }
  printf("\n%d\n",n);

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
char s[100],l,hsh[30],c=1;
int main(){
	scanf("%s",s);
	l = strlen(s);
	for(int i=0;i<l;i++){
		hsh[s[i]-'a']++;
	}
	for(int i=0;i<=25;i++){
		if(hsh[i] > 1){
			c = 0;
		}
	}
	if(c == 0){
		printf("no");
	}
	else{
		printf("yes");
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

queue<int> Q;
int d[300010],n;

int p[300010];
bool Fcan(){
    lol(i,n)p[i]=max(1,i);
    while(!Q.empty())Q.pop();
    Q.push(0);
    while(!Q.empty()){
	int x=Q.front();
	Q.pop();
	//cout<<x<<" ";
	int a=max(0,x-d[x]/10),b=a,t;
	while(p[a]!=a)a=p[a];
	while(p[b]!=b)t=p[b],p[b]=a,b=t;
	
	while(true){
	    if(a>x+d[x]/10)break;
	    if(a==n-1)return true;
	    Q.push(a);
	    p[a]=a+1;
	    a=p[a+1];
	}
    }
    return 0;
}

int main(){
    cin>>n;
    lol(i,n){
	cin>>d[i];
	//d[i]=10;
    }
    bool ok=Fcan();
    lol(i,n/2)swap(d[i],d[n-1-i]);
    ok&=Fcan();
    cout<<(ok?"yes":"no")<<endl;
    return 0;
}



Measured memory_bytes: 5740
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        int j = i;
        int sum = 0;
        while(j){
            sum += j % 10;
            j /= 10;
        }

        if(a<=sum&&sum<=b)
            res += i;
    }

cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<map>
#include<cmath>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<string>
#define LL long long
using namespace std;
LL n,s,b;
bool check(LL n, LL b)
{
    long long res = 0;
    while(n > 0)
    {
        res += n%b;
        n/=b;
    }
    return res == s;
}
int main()
{
    //int n,s,b;
    cin >> n >> s;
    LL temp = (LL)sqrt(n)+1;
    for(LL i = 2; i <= temp; i ++)
    {
        if(check(n,i))
        {
            cout << i << endl;
            return 0;
        }
    }
    if(s == n)
    {
        cout << n+1 << endl;
        return 0;
    }
    if(s > n)
    {
        cout << "-1" << endl;
        return 0;
    }
    LL temp1 = n - s, temp2 = temp1/(temp-1) + 1;
    for(int i = temp2; i >= 1; i --)
    {
        if(!(temp1%i) && s - i <= temp1/i && s >= i && i<= temp1/i)
        {
            cout << temp1/i + 1 << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 256
def s(x):print('',x,end='')
def p(u):
 if u+1:s(u);p(T[u]);p(T[u+N])
def i(u):
 if u+1:i(T[u]);s(u);i(T[u+N])
def o(u):
 if u+1:o(T[u]);o(T[u+N]);s(u)
N=int(input())
T=[0,0]*N
for _ in[0]*N:
 a,b,c=map(int,input().split())
 T[a],T[a+N]=b,c
r=(set(range(N))-set(T)).pop()
print('Preorder');p(r)
print('\nInorder');i(r)
print('\nPostorder');o(r)
print()


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

int main(void){
    double n,m,d;
    cin >> n >> m >> d;
    double ans = 2*(n-d)/n*(m-1)/n;
    if(d== 0)ans/=2;
    cout << fixed << setprecision(10) << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

string s,t;
int l;
bool strEqu(string s1,string s2){
    bool rtn = true;
    REP(i,s1.size()){
        if(s1[i]==s2[i]||s1[i]=='?'){
            
        }else{
            rtn = false;
        }
    }
    return rtn;
}

int main() {
    cin >> s >> t;
    string res = "UNRESTORABLE";
    bool flag = false;
    l = s.size()-t.size()+1;
    if(l<=0){
        put(res);
    }else{
        REP(i,l){
            string ss = s;
            REP(j,t.size()){
                ss[i+j] = t[j];
            }
            REP(j,s.size()){
                if(ss[j]=='?'){
                    ss[j] = 'a';
                }
            }
            if(strEqu(s, ss)){
                if(flag){
                    if(ss<res){
                        res = ss;
                    }
                }else{
                    res = ss;
                    flag = true;
                }
            }
        }
        put(res);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int n_routes, time_limit;
    int cost_best = 1001;
    int cost, time;

    std::cin >> n_routes >> time_limit;
    for (int i=0; i<n_routes; i++) {
        std::cin >> cost >> time;
        if (time <= time_limit && cost < cost_best) {
            cost_best = cost;
        }
    }
    if (cost_best < 1001) {
        std::cout << cost_best << std::endl;
    } else {
        std::cout << "TLE" << std::endl;
    }
    return 0;
}


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

int main() {

	int w, h;
	int x, y, r;

	cin >> w >> h >> x >> y >> r;

	if (x - r < 0 || x + r > w)
		cout << "No" << endl;
	else if (y - r < 0 || y + r > h)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int ans[28],cnt[28];
char s[55];
int main(){
	//~ #ifndef ONLINE_JUDGE
    //~ freopen("file.in", "r", stdin);
	//~ #endif	
	int n;
	scanf("%d",&n);
	memset(ans,127,sizeof ans);
	while(n--){
		scanf("%s",s);
		int sz=strlen(s);
		memset(cnt,0,sizeof cnt);
		for(int i=0;i<sz;i++)
			cnt[s[i]-'a']++;
		for(int i=0;i<26;i++)
			umin(ans[i],cnt[i]);
	}
	for(int i=0;i<26;i++){
		while(ans[i])
			printf("%c",char(97+i)),ans[i]--;
	}puts("");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int NMAX=200015;
int f[NMAX];

int main()
{
    int n,i,x;
    cin>>n;
    for(i=2;i<=n;i++)
    {
        cin>>x;
        f[x]++;
    }
    for(i=1;i<=n;i++)
        cout<<f[i]<<"\n";
    return 0;
}


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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

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

    VI dp(100000);
    dp[0] = 1;
    FOR(i,1,99){
        dp[i] =0;
    }
    FOR(i,100,105){
        dp[i]=1;
    }
    FOR(i,106,100000){
        if(dp[i-100] == 1 || dp[i-101] == 1 || dp[i-102] == 1 || dp[i-103] == 1 || dp[i-104] == 1 || dp[i-105] == 1){
            dp[i] =1;
        }
        else{
            dp[i]=0;
        }
    }

    ANS(dp[x]);

    return 0;
}


Measured memory_bytes: 768
#include<stdio.h>

int main(){
	int flag = 0;
	char s[7];
	scanf("%s", s);
	if(s[2] == s[3]){
		if(s[4] == s[5]){
			flag = 1;
		}
	}
	if(flag == 0){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int keta(int n) {
	int res = 0;
	while (n > 0) {
		res++;
		n /= 10;
	}
	return res;
}

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

Measured memory_bytes: 3640
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdint>
#include <deque>

int main() {
  char buf[1<<17];
  scanf("%s", buf);

  std::string S=buf;

  std::deque<int> q;
  q.push_back(1);
  char last=S[0];
  for (size_t i=1; i<S.length(); ++i) {
    if (S[i] != last) {
      last = S[i];
      q.push_back(1);
    } else {
      ++q.back();
    }
  }

  size_t res=S.length();
  while (q.size() > 1) {
    if (q.front() < q.back()) {
      size_t cur=q.front();
      q.pop_front();
      q.front() += cur;
      res = std::min(res, S.length()-cur);
    } else {
      size_t cur=q.back();
      q.pop_back();
      q.back() += cur;
      res = std::min(res, S.length()-cur);
    }
  }

  printf("%zu\n", res);
}


Measured memory_bytes: 640
import java.util.*;

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

        String s = sc.nextLine();

        int count = 0;

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'o')
                count++;
        }

        System.out.println(700 + count * 100);
    }
}

Measured memory_bytes: 21844
# coding: utf-8
# Your code here!
import bisect

A,B,Q=map(int,input().split())

god=[-10**18]
for _ in range(A):
    god.append(int(input()))
god.append(10**18)

buddha=[-10**18]
for _ in range(B):
    buddha.append(int(input()))
buddha.append(10**18)

#print(god,buddha)
for _ in range(Q):
    q=int(input())
    g_i=bisect.bisect_left(god, q)
    b_i=bisect.bisect_left(buddha, q)
    #print(g_i,b_i)
    
    ans=10**18
    G=[god[g_i-1],god[g_i]]
    B=[buddha[b_i-1],buddha[b_i]]
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)
    

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

int main() {
  int r[105], c[105], n, m, i, j;
  cin >> m >> n;
  string s[105];

  for (i = 0; i < m; i++) {
    cin >> s[i];
  }

  for (i = 0; i < m; i++) {
    r[i] = 0;
  }

  for (j = 0; j < n; j++) {
    c[j] = 0;
  }

  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (s[i][j] == '#') {
        r[i] = 1;
      }
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      if (s[i][j] == '#') {
        r[i] = 1;
        c[j] = 1;
      }
    }
  }

  for (i = 0; i < m; i++) {
    if (r[i] == 0) {
      continue;
    } else {
      for (j = 0; j < n; j++) {
        if (c[j] == 0) {
          continue;
        } else {
          cout << s[i][j];
        }
      }
      cout << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 int N,M;
 cin>>N>>M;
 int x[1000000];
 int y[1000000];
 for(int i=0;i<M;i++){
   cin>>x[i]>>y[i];
   x[i]--;y[i]--;
 }
 vector<int>s(N,1);
 vector<bool>aka(N,false);
 aka[0]=true;
 for(int i=0;i<M;i++){
  s[y[i]]++;s[x[i]]--;
  if(aka[x[i]]){aka[y[i]]=true;}
  if(s[x[i]]==0){aka[x[i]]=false;}
 }
 int cnt=0;
 for(int i=0;i<N;i++){
   if(aka[i]){cnt++;}
 }
 cout<<cnt<<endl;
 return 0;
}

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

int main(){

  int n, a, b, c, x, y[100];

  while(cin>>n>>a>>b>>c>>x, n){
    for(int i=0;i<n;i++) cin>>y[i];

    int id=0;
    bool f=true;
    for(int i=0;i<=10000;i++){
      if(y[id]==x) id++;
      if(id==n){
	cout<<i<<endl;
	f=false;
	break;
      }
      x=(a*x+b)%c;
    }
    if(f) cout<<-1<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3092
int h[101];
int main()
{
    int n;
    __builtin_scanf("%d", &n);
    for(int i=0; i<n; ++i) __builtin_scanf("%d", h+i);
    int res=0;
    while (true) {
        for(int i=0; i<n; ++i) {
            int j=i;
            for(; j<n && h[j]; ++j) --h[j];
            if (i!=j) ++res;
            i=j;
        }
        int done=0;
        for(int i=0; i<n; ++i) done+=h[i]==0;
        if (done==n) break;
    }
    __builtin_printf("%d\n", res);
}


Measured memory_bytes: 128
from sys import stdin
from collections import deque
input = stdin.readline

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for a, b in ab:
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

seen = [-1] * N

seen[0] = 1


def bfs(x):
    q = deque([])
    q.append(x)

    while q:
        now = q.popleft()

        for nex in graph[now]:
            if seen[nex] != -1:
                continue
            seen[nex] = now + 1
            q.append(nex)


bfs(0)

if - 1 in seen:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(seen[i])


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

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

Graph<> graph;
int ans = 0;

int dfs(int v, int p = -1) {
    int ch = 0, cnt = 0;
    for (auto e : graph[v]) {
        if (e.dst == p) continue;
        ++ch;
        cnt += dfs(e.dst, v);
    }

    if (ch == 0) {
        return 0;
    } else if (ch == 1) {
        return cnt;
    } else {
        ans += std::max(ch - cnt - 1, 0);
        return 1;
    }
}

void solve() {
    int n;
    std::cin >> n;

    graph.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        std::cin >> u >> v;
        graph[u].emplace_back(u, v);
        graph[v].emplace_back(v, u);
    }

    int r = -1;
    for (int v = 0; v < n; ++v) {
        if (graph[v].size() >= 3) {
            r = v;
            break;
        }
    }

    if (r == -1) {
        std::cout << 1 << std::endl;
        return;
    }

    dfs(r);
    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 1000005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,Q;
char s[maxn];
ll calc(int k){
	ll cntc = 0,cntm = 0,ans = 0,tmp = 0;
	int j = n;
	for(int i=n;i>=1;i--){
		if(i + k - 1 < j){
			if(s[j] == 'M'){
				cntm--;
			}else if(s[j] == 'C'){
				cntc--;
				tmp -= cntm;
			}
			j--;
		}
		if(s[i] == 'M'){
			cntm++;
			tmp += cntc;
		}else if(s[i] == 'C'){
			cntc++;
		}else if(s[i] == 'D'){
			ans += tmp;
		}
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	scanf("%s",s + 1);
	scanf("%d",&Q);
	while(Q--){
		int k;
		scanf("%d",&k);
		printf("%lld\n",calc(k));
	}
	return 0;
}


Measured memory_bytes: 1280
from collections import Counter
import math
def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
n = int(input())
S =[input() for _ in range(n)]
S =[''.join(sorted(s)) for s in S]
ans = 0
c = Counter(S)
for i in c.values():
    if i >= 2:
        ans += combination(i, 2)
print(ans)


Measured memory_bytes: 78424
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
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);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

map<pair<ll,ll>,ll> M;
 
int main(){
    ll N,A,B,K=0,C[100007],ma=0;
    vector<vector<ll>> V(100007);
    cin >> N;
    rep(i,N-1){
        cin >> A >> B;
        M[mp(A,B)]=i;
        V[A].pb(B);
        V[B].pb(A);
    }
    queue<pair<ll,pair<ll,ll>>> Q;  // corrent color prever
    Q.push(mp(1,mp(INF,INF)));
    while(!Q.empty()){
        ll K=0;
        auto X = Q.front();
        Q.pop();
        rep(i,V[X.fr].size()){
            if(V[X.fr][i] != X.sc.sc){
                K++;
                if(K == X.sc.fr){
                    K++;
                }
                C[M[mp(X.fr,V[X.fr][i])]] = K;
                Q.push(mp(V[X.fr][i],mp(K,X.fr)));
                ma=max(K,ma);
            }
        }
    }
    cout << ma << endl;
    rep(i,N-1){
        cout << C[i] << endl;
    }
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int K, X; cin >> K >> X;

	if(K*500 >= X) cout << "Yes" << endl;
	else cout << "No" << endl;
	


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N=200005;
#define inf 1e18+8
const int mod=1e9+7;
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define set multiset
#define all(x) begin(x), end(x)
#define vpii vector<pair<int,int> > 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int A[N],B[N],C[N],D[N];
string s,t,str="";
int len1,len2;
int dp[3001][3001];
//vector <char> str;
int rec(int s1,int t1)
{
    if (dp[s1][t1]!=-1) return dp[s1][t1];
    if(s1==len1 || t1==len2) return 0;
    if(s[s1]==t[t1])
    {
      //  cout<<s[s1];
        //str+=s[s1];
        return dp[s1][t1]=1+rec(s1+1,t1+1);
    }
    return dp[s1][t1]=max(rec(s1+1,t1),rec(s1,t1+1));
}
signed main()
{
    cin>> s>>t;
    for(int i=0;i<3001;i++)
    {
        for(int j=0;j<3001;j++)
        {
            dp[i][j]=-1;
        }
    }
    len1=s.size();
    len2=t.size();
    int y=rec(0,0);
    //cout<<str;
    int i=0,j=0;
    while(i<len1 && j<len2)
    {
        if(s[i]==t[j])
        {
            str+=s[i];
            i++;j++;
        }
        else if (dp[i+1][j]>dp[i][j+1])
        {
            i++;
        }
        else 
        {
            j++;
        }
    }
    cout<<str;
    


}
 
    

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int f(int x) {
  int res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main2() {
  int N = nextInt();

  int ans = 1001001001;
  for (int a = 1; a < N; a++) {
    int b = N - a;
    chmin(ans, f(a) + f(b));
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define testing 1
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = -1;
#if !testing
#define cerr if(0)cout
#endif

int32_t main() 
{
	IAMSPEED
	ll n,k; cin >> n >> k;
	ll ans = 0;
	ll b = 0, s = 0;
	priority_queue<ll>pqbig;
	priority_queue<ll,vector<ll>,greater<ll>>pqsmall;
	FOR(i,0,n){
		pqbig.push(i);
		pqsmall.push(i);
	}
	ll q=k;
	while(q--) {
		b+=pqbig.top();
		b%=MOD;
		pqbig.pop();
		s+=pqsmall.top();
		s%=MOD;
		pqsmall.pop();
	}
	FOR(i,k,n+1) {
		//~ db2(b,s);
		ans += (MOD+b-s+1)%MOD;
		ans += MOD;
		ans %=MOD;
		b+=pqbig.top();
		pqbig.pop();
		s+=pqsmall.top();
		pqsmall.pop();
	}
	cout<<ans;
}



Measured memory_bytes: 6728
str = gets().unpack("U*")

check = Array.new(26,0)

for i in 0..str.size-2
	str[i] = str[i] - 97
	check[str[i]] = check[str[i]] + 1
end

bool = 0

for j in 0..25
	if check[j] > 1
		bool = bool + 1
	end
end

if bool < 1
	print("yes\n")
else
	print("no\n")
end

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
const ll INFF=0x3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=4e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("in2.txt","r",stdin);
    freopen("out2.txt","w",stdout);
}
int n;
char a[305][305],b[305][305];
//int a[305][305],b[305][305];
bitset<605>c[305][305];
bitset<605>now;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
//        for(int j=1;j<=n;j++)
//            scanf("%d",&b[i][j]);
//    for(int i=1;i<=n;i++)
//        for(int j=1;j<=n;j++)a[i][j]=b[j][i];
    for(int i=-n+1;i<=n-1;i++)
    {
        for(int j=1;j<=n;j++)
            for(int k=1;k<=n;k++)
            {
                int tj=j+i;
                while(tj<=0)tj+=n;
                while(tj>n)tj-=n;
                int tk=k-i;
                while(tk<=0)tk+=n;
                while(tk>n)tk-=n;
                if(a[j][k]==a[tk][tj])
                    c[j][k].set(i+n-1);
            }
    }
    for(int i=0;i<=2*n-2;i++)now.set(i);
//    now.reset
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            now&=c[i][j];
    int an=0;
    for(int i=0;i<=2*n-2;i++)
    {
        if(now.test(i))
        {
            an+=(n-abs(i-(n-1)));
        }
    }
    printf("%d\n",an);


}
/*



4 1 1 3 1 5 5 1 3
*/


Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,z,w,pok[2001];
    scanf("%d%d%d",&n,&z,&w);
    for(int i=0;i<n;i++)scanf("%d",&pok[i]);
    if(n==1)printf("%d\n",abs(pok[n-1]-w));else printf("%d\n",max(abs(pok[n-1]-pok[n-2]),abs(pok[n-1]-w)));
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        String t = next();
        String s = next();

        int[][] dp = new int[t.length()][s.length()];

        for (int i = 0; i < t.length(); i++) {
            for (int j = 0; j < s.length(); j++) {
                dp[i][j] = calcDpValue(i, j, dp, t, s);
            }
        }

        StringBuilder ans = new StringBuilder();
        int i = t.length() - 1;
        int j = s.length() - 1;
        while (i >= 0 && j >= 0) {
            if (i == 0 && j == 0 && t.charAt(0) == s.charAt(0)) {
                ans.insert(0, t.charAt(0));
                break;
            }
            if (i > 0 && j > 0 && t.charAt(i) == s.charAt(j) && 1 + dp[i - 1][j - 1] == dp[i][j]) {
                ans.insert(0, t.charAt(i));
                i--;
                j--;
            } else if (i > 0 && (j == 0 || dp[i - 1][j] > dp[i][j - 1])) {
                if (t.charAt(i) == s.charAt(j) && dp[i][j] == dp[i - 1][j] + 1) ans.insert(0, t.charAt(i));
                i--;
            } else if (j > 0 && (i == 0 || dp[i][j - 1] > dp[i - 1][j])) {
                if (t.charAt(i) == s.charAt(j) && dp[i][j] == dp[i][j - 1] + 1) ans.insert(0, t.charAt(i));
                j--;
            }
            else {
                if (j > 0) j--;
                else i--;
            }
        }

//        for (int[] d: dp) System.out.println(Arrays.toString(d));
        System.out.println(ans);
    }

    private static int calcDpValue(int i, int j, int[][] dp, String t, String s) {
        int dpI1J = i == 0 ? 0 : dp[i - 1][j];
        int dpIJ1 = j == 0 ? 0 : dp[i][j - 1];
        int dpI1J1 = (i == 0 || j == 0) ? 0 : dp[i - 1][j - 1];
        if (t.charAt(i) == s.charAt(j)) return Math.max(1 + dpI1J1, Math.max(dpI1J, dpIJ1));

        return Math.max(dpI1J, dpIJ1);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }
}

Measured memory_bytes: 82972
n, m = map(int, input().split())
a, b = [0] * n, [0] * m
for i in range(n):
    a[i] = list(input())
for i in range(m):
    b[i] = list(input())

if n == 1:
    if a[0] == b[0]:
        print('Yes')
    else:
        print('No')
    exit()

for sx in range(n-m):
    for sy in range(n-m):
        chk = True
        for tx in range(m):
            for ty in range(m):
                #print(sx+tx, sy+ty)
                if a[sx+tx][sy+ty] == b[tx][ty]:
                    pass
                else:
                    chk = False
        if chk:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3064
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())
s = input()
t = s[0]
for i in range(1, 4):
    if t == s[i]:
        print('Bad')
        sys.exit()
    t = s[i]
print('Good')

Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
    cin>>n;

     map<string,int>p;

       for(int i=1;i<=n;i++)
       {
          string s;
            cin>>s;

             if(p.find(s)!=p.end())
               {
                    auto itr = p.find(s);
                    itr->second = itr->second + 1;
               }
             else
              p.insert(pair<string,int>(s,1));
       }

         int size = 0;

        for(auto itr = p.begin();itr!=p.end();itr++)
        {
            if(itr->second > size)
              size=itr->second;
        }
         vector<string>vect;

          for(auto itr = p.begin();itr!=p.end();itr++)
          {
               if(itr->second == size)
                vect.push_back(itr->first);
          }
        sort(vect.begin(),vect.end());
         for(int i=0;i<vect.size();i++)
           cout<<vect[i]<<endl;
}


Measured memory_bytes: 26868
#include<iostream>
    using namespace std;
    int main(){
        unsigned long long int first=2;
        unsigned long long int second=1;
        unsigned long long int n;
        cin>>n;
        if(n==0)
        {
            cout<<first;
        }
        else
        if(n==1)
        {
            cout<<second;
        }
        else
        {
            n--;
            while(n>0)
            {
                unsigned long long int sum=first+second;
                first=second;
                second=sum;
                n--;
            }
            cout<<second;
        }
        
    }

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

//重み付きグラフ
//距離の部分をテンプレートに
template<class T>
class wGraph {
public:
	int N;
	vector<vector<pair<int, T>>>* E;
	wGraph(int n, T i) {
		N = n;
		E = new vector<vector<pair<int, T>>>;
		E->resize(N);
		INF = i;
	}
	wGraph() {
	}
	void constructor(int n, T i) {
		N = n;
		E = new vector<vector<pair<int, T>>>;
		E->resize(N);
		INF = i;
	}
	~wGraph() {
		delete E;
	}
	void addEdge(int a, int b, T c) {
		E->at(a).push_back(pair<int, T>(b, c));
	}
	T INF;
};

//ダイクストラする
//条件:重み>0
//グラフ本体、始点、保存用vector
//到達不可能はg.INF
//O(ElogV)
template<class T>
void  dijkstra(wGraph<T>& g, int s, vector<T>& v) {
	v.resize(g.N);
	for (int i = 0; i < g.N; i++) {
		v[i] = g.INF;
	}
	typedef pair<T, int> t;
	priority_queue<t, vector<t>, greater<t>> q;
	q.push(t(0, s));
	while (!q.empty()) {
		t e = q.top();
		q.pop();
		if (v[e.second] != g.INF && v[e.second] <= e.first)continue;
		v[e.second] = e.first;
		for (auto itr = g.E->at(e.second).begin(); itr != g.E->at(e.second).end(); itr++) {
			q.push(t(e.first + (*itr).second, (*itr).first));
		}
	}
	return;
}

int N, M,S,T;
wGraph<int> G;

int main() {
	cin >> N >> M;
	G.constructor(3 * N, INT_MAX);
	for (int m = 0; m < M; m++) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		G.addEdge(s, t + N,1);
		G.addEdge(s + N, t + 2 * N, 1);
		G.addEdge(s + 2 * N, t, 1);
	}
	cin >> S >> T;
	vector<int> ans;
	dijkstra(G, --S, ans);
	if (ans[--T] == INT_MAX)cout << -1 << endl;
	else cout << ans[T]/3 << endl;
	return 0;
}

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

signed main()
{
	
	int x ,k ,d ; 
	cin >> x >> k >> d ; 
	x = abs(x);
	int r = x%d ; 
	int q = x/d  ;
	if(q >= k )
	{
		cout << x - k*d ; 
	}
	else 
	{
		int rem =  k - q ; 
		if(rem%2 == 0 )
			cout << r  ;
		else 
			cout << abs(r - d) ; 


	}

}    



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


int main() {
	char pre[4];
	char fact[4];
	int counter=0;
	cin >> pre;
	cin >> fact;
	for (int i = 0; i < 3 ; ++i)
	{
		if (pre[i] == fact[i]) {
			++counter;
		}
	}

	cout << counter << endl;
}

Measured memory_bytes: 384
<?php

$a = explode(' ', trim(fgets(STDIN)));

$wa = array_fill(0, $a[0] + 1, 0);
$ac = array_fill(0, $a[0] + 1, 0);
while($line = trim(fgets(STDIN))) {
    $r = explode(' ', $line);
    $number = $r[0];
    $results = $r[1];
    if ($results === "WA") {
        if (isset($ac[$number]) && $ac[$number] === 1) {
            continue;
        }
        $wa[$number] += 1;
    }

    if ($results === "AC") {
        if (isset($ac[$number]) && $ac[$number] === 1) {
            continue;
        }
        $ac[$number] += 1;
    }
}


foreach ($ac as $k => $v) {
    if ($wa[$k] !== 0 && $v === 0) {
        $wa[$k] = 0;
    }
}
$wa = array_sum($wa);
$ac = array_sum($ac);
echo "{$ac} {$wa}";

Measured memory_bytes: 12920
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S, T; cin >> S >> T;
    cout << T << S << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Monad.ST
import qualified Data.Array as A
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as AU
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Int
import qualified Data.IntMap as IM
import Data.List
import qualified Data.Map as M
import Data.Maybe
import Data.Ord
import qualified Data.Set as S
import Data.Time
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main = do
  [n, k] <- readInt
  a <- readInt
  print $ solve n k a

solve n k a = 1 + m (n - k) (k - 1)
  where
    b = takeWhile (/= 1) a
    c = tail $ dropWhile (/= 1) a
    b' = m (length b) (k - 1)
    c' = m (length c) (k - 1)

m a x
  | a `mod` x == 0 = a `div` x
  | otherwise = a `div` x + 1

Measured memory_bytes: 1660
#include<iostream>
using namespace std;
#include<iomanip>
#include<cmath>

int main()
{
    int i, n;
    double m, V;
    int s[1000];

    cout << fixed << setprecision(10) << endl;

    while(1){
        cin >> n;
        if(n == 0) break;

        m = 0, V = 0;

		for(i = 0; i < n; i++){ cin >> s[i];  m = m + s[i];}
        m = m / n;

        for(i = 0; i < n; i++){ V = V + (s[i] - m) * (s[i] - m);}
        cout << sqrt(V / n) << endl;
    }

    return 0;
}

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

#define F first
#define S second
#define all(x) (x).begin(), (x).end()

using namespace std;

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

//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    for(int i = 3; i >= 1; i--) {
        string t;
        for(int j = 0; j < i; j++)
            t += 'R';
        if(s.find(t) != string::npos) {
            cout << i;
            return 0;
        }
    }

    cout << 0;

    return 0;
}


Measured memory_bytes: 3648