akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
#define MAX_LOG 30
vector<int>G[MAX];
int depth[MAX];
int parent[MAX_LOG][MAX];
int root;
void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<G[v].size();i++)
    if(G[v][i]!=p)dfs(G[v][i],v,d+1);
}
void init(int V){
  dfs(root,-1,0);
  for(int k=0;k+1<MAX_LOG;k++)
    for(int v=0;v<V;v++)
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
}
int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(int k=0;k<MAX_LOG;k++)
    if((depth[v]-depth[u])>>k&1)
      v=parent[k][v];
  if(u==v)return u;
  for(int k=MAX_LOG-1;k>=0;k--)
    if(parent[k][u]!=parent[k][v]){
    u=parent[k][u];
    v=parent[k][v];
  }
  return parent[0][u];
}
int main(){
  root=0;int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int p=0;cin>>p;
    while(p--){
      int t;cin>>t;
      G[i].push_back(t);
    }
  }
  init(n);  int p;  cin>>p;
  while(p--){
    int q,w;
    cin>>q>>w;
    cout<<lca(q,w)<<endl;
  }
}

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

int main() {
    long long X,K,D; cin >> X >> K >> D;
    long long ans;
    X = abs(X);
    long long straight = min(K, X/D);
    K -= straight;
    X -= straight*D;

    if (K%2 == 0) cout << X << endl;
    else cout << D - X << endl;
}


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

int main() {
  string s;
  cin >> s;
  if (s == "SUN") cout << 7 << endl;
  if (s == "MON") cout << 6<< endl;
  if (s == "TUE") cout << 5 << endl;
  if (s == "WED") cout << 4 << endl;
  if (s == "THU") cout << 3 << endl;
  if (s == "FRI") cout << 2 << endl;
  if (s == "SAT") cout << 1 << endl;
}

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

int main() {
 int N , A , B ;
 cin >> N >> A ;
 B = N / 500 ;
 if (N - 500 * B <= A){
   cout << "Yes" << endl;
 }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    string s,t;
    int n,a,b,c,d,e,x,y;
    cin >> a >> b >> c >> d >> x;
    int p = a*60+b;
    int q = c*60+d;
    cout << max(0LL, q-p-x) << endl;

}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define forsub(s, S) for (int _ = S, s = _; ; (-- s) &= _)
#define ri rd<int>
using namespace std;
const int maxN = 17;
const int maxS = (1 << 15) + 7;
const int mod = 1e9 + 7;

inline int pls(int x, int y) { return (x + y) % mod; }
inline int mns(int x, int y) { return pls(x, mod - y); }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline void Add(int &x, int y) { x = pls(x, y); }
inline void Mul(int &x, int y) { x = mul(x, y); }
inline void Minus(int &x, int y) { x = mns(x, y); }
inline int pwr(int x, int tms) {
	int res = 1;
	for (; tms > 0; tms >>= 1, Mul(x, x))
		if (tms & 1) Mul(res, x);
	return res;
}
inline int inv(int x) { return pwr(x, mod - 2); }

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline int lb(int x) { return x & -x; }
inline bool ok(int s) { return (s & 1) == (s >> 1 & 1); }

int n, m, mask;
int pw2[maxN * maxN];
int f[maxS];
int to[maxN];
int cnt[maxS];

int main() {
	
	n = ri(), m = ri(), mask = (1 << n) - 1;
	rep (i, 1, m) {	
		int x = ri() - 1, y = ri() - 1;
		to[x] |= 1 << y;
	}
	pw2[0] = 1; rep (i, 1, n * n) pw2[i] = mul(pw2[i-1], 2);
	rep (i, 1, mask) cnt[i] = cnt[i >> 1] + (i & 1);

	f[0] = 1;
	rep (S, 1, mask) forsub(s, S) if (f[s] && ok(s)) {
		int t = S ^ s; if (t == 0 || !ok(t)) {
			if (s == 0) break;
			continue;
		}
		int ways = 1;
		For (i, 0, n) {
			if (s >> i & 1) {
				int c = cnt[to[i] & t];
				Mul(ways, mns(pw2[c], 1));
			}
			if (t >> i & 1) {
				int c = cnt[to[i] & s];
				Mul(ways, pw2[c]);
			}
		}
		Add(f[S], mul(f[s], ways));
		if (s == 0) break;
	}

	int res = mns(pw2[m], f[mask]);
	printf("%d\n", res);

	return 0;
}

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

using namespace std;

typedef long long ll;

int dp[3005][3005];

int main(int argc, char *argv[])
{
	string s, t;

	cin >> s >> t;

	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < t.size(); j++) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			} else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}

	int i = s.size();
	int j = t.size();
	string ans = "";
	while (i >= 1 && j >= 1) {
		if (dp[i][j] == dp[i][j - 1]) {
			j--;
		} else if (dp[i][j] == dp[i - 1][j]) {
			i--;
		} else {
			ans += s[i - 1];
			i--;
			j--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35456
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int ant[] = new int[5];
    for (int i = 0; i < 5; i++){
      ant[i] = sc.nextInt();
    }
    int k = sc.nextInt();
    String ans[] = {":(", "Yay!"};
    int a = 1;
    for (int i = 0; i < 5; i++){
      for (int j = 0; j < 4; j++){
        if (i != j){
          if (Math.abs(ant[i]-ant[j]) > k) a *= 0;
        }
      }
    }
    System.out.println(ans[a]);
  }
}

Measured memory_bytes: 35692
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto sum = 0;
	vector<int> A(N);
	for (auto& a : A)
	{
		cin >> a;
		sum += a;
	}

	auto ans = 0;
	for (auto i = 0; i < N; ++i)
	{
		if (4 * M * A[i] >= sum)
		{
			++ans;
		}
	}

	if (ans >= M)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

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

	string ans;
	if(S=="Sunny"){
		ans="Cloudy";
	}else if(S=="Cloudy"){
		ans="Rainy";
	}else{
		ans="Sunny";
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define dbug printf("I am here\n");
    #define Fast ios_base::sync_with_stdio(false); cin.tie(0);
    #define vs            v.size()
    #define ss             s.size()
    #define be            v.begin(),v.end()
    #define pii             pair<int,int>
    #define ll               long long
    #define pb             push_back
    #define mpp            make_pair
    using namespace std;

    int main() {

    ll int a,b,c,d,n,k;
    int tst;
    cin>>a;
    vector<ll int>ar(a+1,0);
    for(int i = 1; i<=a; i++){
        for(int j = 0; j <= a; j += i){//eikhane 0 theke shuru korar koron jare second loop e gia i er por i+oi shonkga hoi.
            ar[j]++;
        }
    }
    ll int sum = 0;

    for(int i =1;i<=a; i++){
        sum += (ar[i]*i);
    }
    cout<<sum<<endl;

        return 0;
    }


Measured memory_bytes: 81392
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	lli num=1;
	lli cnt=1;
	if(n<10){
		cout<<n<<endl;
		return 0;
	}
	while(num<=n){
		if(num==n){
			cout<<9*(cnt-1)<<endl;
			return 0;
		}
		if(n==(num-1)){
			cout<<9*(cnt-1)<<endl;
			return 0;
		}
		num*=10;
		cnt++;
	}
	cnt--;
	num/=10;

	if(n%num == num-1){
		cout<<n/num+9*(cnt-1)<<endl;
		return 0;
	}

	cout<<n/num-1+9*(cnt-1)<<endl;



	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse =  True)
ans = A[0]
flag = 0
index = 1
for i in range(N-2):
    if flag == 0:
        ans += A[index]
        flag = 1
    else:
        ans += A[index]
        index += 1
        flag = 0
print(ans)

    

        




Measured memory_bytes: 33044
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

typedef string::const_iterator State;

int number(State &begin){
  int ret=0;
  while(isdigit(*begin)){
    ret*=10;
    ret+=(*begin-'0');
    begin++;
  }
  //cout<<"ret: "<<ret<<endl;
  return ret;
}

int solve(State &begin){
  //cout<<*begin<<endl;
  if(*(++begin)!='[')return number(begin)/2+1;
  vector<int> data;
  while(*begin=='['){
    data.push_back(solve(begin));
    begin++;
  }
  sort(all(data));
  int ret=0;
  for(int i=0;i<data.size()/2+1;i++)ret+=data[i];
  return ret;
}

int main(){
  int n;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    State begin=s.begin();
    cout<<solve(begin)<<endl;;
  }
  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<limits.h>
#include<math.h>

using namespace std;
#define MOD 1000000007


static long long int fact[200000] = { 0 };

long long int factrial(long long int num) {
	if (num == 0)return 1;
	if (num == 1)return 1;
	if (fact[num] != 0)return fact[num];

	long long int ans = 1;

	ans = num * factrial(num - 1) % MOD;
	fact[num] = ans;
	return ans;



}




long long int superpow(long long int num, long long int count) {
	if (count == 0)return 1;
	if (count == 1)return num;

	long long int wk = superpow(num, count / 2);

	if (count % 2 == 0)return (wk * wk) % MOD;

	return (((wk * wk) % MOD) * num) % MOD;

}

long long int inv(long long int num) {

	return superpow(num, MOD - 2) % MOD;

}

//nCrのやつ
long long int comb(long long int n, long long int r) {
	if (n == r)return 1;
	if (r == 0)return 1;
	long long int ans = 1;

	ans = factrial(n);

	long long int wk = 1;

	wk = factrial(r);
	
	ans = (ans * inv(wk)) % MOD;

	wk = 1;
	
	wk = factrial(n - r);

	ans = (ans * inv(wk)) % MOD;

	return ans;
}



long long int min(long long int a, long long int b) {
	if (a > b)return b;
	return a;



}

int main()
{

	long long int n, a, b, c;

	cin >> n >> a >> b >> c;
	long long int ans = 0;
	long long int wk;

	fact[0] = 1;
	for (long long int i = 1; i < 200000; i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}


	

	//aが0じゃなければ。
	if (a != 0) {
		for (long long int i = 0; i < n; i++) {
			wk = 1;
			wk = wk * superpow(a, n) % MOD;
			wk = wk * superpow(b, i) % MOD;
			wk = wk * inv(superpow(a + b, n + i)) % MOD;

			wk = wk * comb(n + i - 1, min(n-1, i)) % MOD;
			wk = wk * (n + i) % MOD;
			ans = (ans + wk) % MOD;
		}
	}

	//bが０でない場合
	if (b != 0) {

		for (long long int i = 0; i < n; i++) {
			wk = 1;
			wk = wk * superpow(b, n) % MOD;
			wk = wk * superpow(a, i) % MOD;
			wk = wk * inv(superpow(a + b, n + i)) % MOD;

			wk = wk * comb(n + i-1, min(n-1, i)) % MOD;
			wk = wk * (n + i) % MOD;
			ans = (ans + wk) % MOD;
		}
	}

	ans = ans * 100 % MOD;
	ans = ans * inv(a + b) % MOD;
	
	
	

	cout << ans << endl;

	





	return 0;



}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pi 3.1415926535897932384
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18 ;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
cout.precision(12);
cout.setf(ios::fixed,ios::floatfield);
double a,b,c,x,d,y,z,r,k,s;
cin>>a>>b>>x;
y=(a*a*b-x)/(a*a);
z=x/(a*a);
s=y;
y=(2.0)*y;
d=a/y;
r=b/(2.0);
if(s>r)
    {
        d=(2.0*x)/(a*b*b);
        c=atan(d);
c=(180.0 *c)/pi;
c=90.00000000000000-c;
cout<<c<<endl;
return 0;
    }
//cout<<d;
c=atan(d);
c=(180.0 *c)/pi;
c=90.00000000000-c;
//c=(pi/(2.0))-c;
cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int x,y,r;
  while(cin>>x>>y,x){
    r=max(x,y);
    int a[x+2]={0},b[y+2]={0},k,c[2000000],s=0;
    r(i,2000000)c[i]=-1;
    r(i,x){cin>>k;a[i+1]+=k;a[i+2]=a[i+1];}
    r(i,y){cin>>k;b[i+1]+=k;b[i+2]=b[i+1];}
    r(i,y+1)r(j,x+1)c[b[i]-a[j]+1000000]++;
    r(i,2000000)if(c[i]>0)for(int j=1;j<=c[i];j++)s+=j;
    cout<<s<<endl;
  }
}

Measured memory_bytes: 10812
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
#define long ll
#define double ld
using namespace std;

string s;

bool f(char c) {
	return count(all(s), c);
}

int main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	cin >> s;
	if ((f('N') ^ f('S')) || (f('W') ^ f('E'))) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
const double PAI = acos(-1);

vector<int> E[100050];
vector<bool> dist(100050);
vector<int> par(100050);
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        a--;b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    queue<int> q;
    q.push(0);
    dist[0] = true;
    while(!q.empty()){
        auto u = q.front(); q.pop();
        for(auto v : E[u])if(!dist[v]){
            par[v] = u;
            dist[v] = true;
            q.push(v);
        }
    }
    cout << "Yes" << endl;
    for(int i=1;i<n;++i){
        cout << par[i]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 10220
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] kane = new int[N];

        for(int i=0;i<N;i++){
            kane[i] = scan.nextInt();
        }

        Arrays.sort(kane);
        int y=0;
        y+=kane[N-1]/2;

        for(int i=0;i<N-1;i++){
            y+=kane[i];
        }

        System.out.println(y);

    }
}

Measured memory_bytes: 23124
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

f n = take 10 . tail $ iterate g n
  where
    g m = read $ take 4 $ drop 2 $ s'
      where
        s = show (m ^ 2)
        s' = replicate (8 - length s) '0' ++ s
    

main = do
    n <- getInt
    forM_ [1..n] $ \i -> do
        putStrLn $ "Case " ++ show i ++ ":"
        getInt >>= mapM_ print . f

Measured memory_bytes: 4128
A,B,K=map(int,input().split())

a=A
b=B
list=[]
while a<A+K and a<=b:
    list.append(a)
    a+=1

while b>B-K and b>=a:
    list.append(b)
    b-=1

list.sort()
ANS=set(list)
ANS=sorted(ANS)

for ans in ANS:
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N,M;
    cin >> N >> M;
    string A[N],B[M];
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<M;i++) cin >> B[i];

    for(int i=0;i<N-M+1;i++){
        for(int k=0;k<N-M+1;k++){
            bool match=true;
            for(int j=0;j<M;j++){
                if(A[i+j].substr(k,M) != B[j]) match=false;
            }
            if(match){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
static const int INFTY = (1 << 21);

class Edge{
public:
	int from, to, cost;
	int backedge;
	Edge(int from = 0, int to = 0, int cost = 0) :
		from(from), to(to), cost(cost){
	}

};

class Node{
public:
	vector<Edge> edges;
	int prenum;
	int parent;
	int lowest;
	Node(){
		prenum = -1;
		parent = -1;
	}
};

class Graph{
public:
	vector<Node> nodes;
	int prenum;

	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
		prenum = 0;
	}

	Node& operator [] (int i){
		return nodes[i];
	}

};

Graph G(0);

void dfs(Edge &e){

	Node& n = G[e.to];

	if (n.prenum != -1) {
		int parent = G[e.from].parent;
		if (e.to == parent){
			e.backedge = -1; // edge to its parent
		}
		else{
			e.backedge = 1; // backedge
		}
		return;
	}

	// set parameter
	G.prenum++;
	e.backedge = 0; // edge-of-DFStree
	n.prenum = G.prenum;
	n.parent = e.from;
	n.lowest = n.prenum;

	for (Edge &eg : n.edges){
		dfs(eg);
	}

	for (Edge &eg : n.edges){
		// edge-of-DFStree
		if (eg.backedge == 0){
			n.lowest = min(n.lowest, G[eg.to].lowest);
		}
		// backedge
		if (eg.backedge == 1){
			n.lowest = min(n.lowest, G[eg.to].prenum);
		}
	}

}


int main() {

	int V, E;
	cin >> V >> E;

	G = Graph(V);

	rep(i, E){
		int from, to;
		cin >> from >> to;
		G[from].edges.push_back(Edge(from, to, 0));
		G[to].edges.push_back(Edge(to, from, 0));
	}

	Edge e0(-1, 0, 0);
	dfs(e0);

	rep(i, V){
		// printf("%d %d %d %d\n", i, G[i].parent, G[i].prenum, G[i].lowest);
	}

	set<int> ret;

	// root
	rep(i, V){
		if (G[i].parent == -1){
			int count = 0;
			rep(j, V){
				if (G[j].parent == i) count++;
			}
			if (count > 1) ret.insert(i);
		}
	}

	// not root
	rep(i, V){
		if(G[i].parent != -1){
			Node& n = G[i];
			Node& p = G[n.parent];
			if (p.prenum <= n.lowest && p.parent != -1){
				ret.insert(n.parent);
			}
		}
	}

	for (int i : ret){
		cout << i << endl;
	}
}

Measured memory_bytes: 5964
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <random>
#include <cassert>
#include <limits>

using namespace std;

#define mp make_pair
#define pb push_back
#define repi(i, p, q) for (long long i = p; i < q; i++)
#define repd(i, p, q) for (long long i = p; i >= q; i--)
#define INF 2000000000
#define MOD 1000000007

typedef map<int, int> M;
typedef map<long, long> ML;
typedef map<long long, long long> MLL;
typedef pair<int, int> P;
typedef pair<long, long> PL;
typedef pair<long long, long long> PLL;
typedef int I;
typedef double D;
typedef long double LD;
typedef long L;
typedef long long LL;

LL a[100003];
vector<LL> dis, temp;
set<LL> num;

int main()
{
    LL n, m;
    cin >> n >> m;
    repi(i, 0, m)
    {
        cin >> a[i];
    }
    sort(a, a + m);
    repi(i, 1, m)
    {
        dis.push_back(abs(a[i] - a[i - 1]));
    }
    if (n >= m)
    {
        cout << 0;
    }
    else
    {
        LL ans = 0;
        sort(dis.begin(), dis.end());
        repi(i, 0, dis.size() - n + 1)
        {
            ans = ans + dis[i];
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 2168
N, K, Q = map(int,input().split())

A = [int(input()) for _ in range(Q)]
W = [0] * N

for i in A:
    W[i-1] += 1

for i in range(N):
    t = K - Q
    if W[i] + t > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 8636
class Node
  attr_accessor :next, :cost
  def initialize(i)
    @next=i
    @cost=0
  end
end

def cal_cost(x)
  temp = x
  cost = 0
  while temp != $nodes[temp].next
    cost += $nodes[temp].cost
    temp = $nodes[temp].next
  end
  return [temp,cost]
end

n,q = gets.split.map(&:to_i)
$nodes = []
n.times{|i| $nodes << Node.new(i)}

q.times{
  com, x, y, z = gets.split.map(&:to_i)
  tempx, costx = cal_cost(x)
  tempy, costy = cal_cost(y)
  if com == 0
    if tempx != tempy
      if tempx < tempy
        $nodes[tempy].next = tempx
        $nodes[tempy].cost = costx - costy + z
      else
        $nodes[tempx].next = tempy
        $nodes[tempx].cost = costy - costx - z
      end
    end
#    $nodes.each_with_index{|node,i| puts "id:#{i} next:#{node.next} cost:#{node.cost}"}
#    puts
  elsif com == 1
#    $nodes.each_with_index{|node,i| puts "id:#{i} next:#{node.next} cost:#{node.cost}"}
#    puts
    puts tempx != tempy ? "?" : costy-costx
  end
}


Measured memory_bytes: 12688
import java.util.Scanner;

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

    int ans = 0;
    int n = stdIn.nextInt();
    int a = stdIn.nextInt();
    int b = stdIn.nextInt();

    for (int i = 1; i <= n; i++) {
      int sum = 0;
      String s = String.valueOf(i);
      String[] str = s.split("");
      for (int j = 0; j < s.length(); j++) {
        sum += Integer.parseInt(str[j]);
      }
      if (sum >= a && sum <= b) {
        ans += i;
      }
    }

    System.out.println(ans);
  }
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> X(M);
    rep(i, M){
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    vector<int> D;
    for (int i = 1; i < M; i++){
        int d = X[i] - X[i-1];
        D.push_back(d);
    }
    sort(D.begin(), D.end());
    ll ans = 0;
    for (int i = 0; i < M-1-N+1; i++){
        ans += D[i];
    }

    cout << ans << endl;
    

    return 0;
}

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

void solve(){
    string s,t;
    cin>>s>>t;
    int change = 0;
    for(int i = 0; i<s.size();i++){
        if(s[i]!=t[i])++change;
    }
    cout<<change<<endl;



}

int main(){
  solve();
  return 0;


}



Measured memory_bytes: 3860
n = int(input())
st = [list(input().split()) for _ in range(n)]
x = input()

sums = 0
for s, t in st:
  t = int(t)
  sums += t

ans = 0
for s, t in st:
  t = int(t)
  ans += t
  if s == x:
    break

print(sums - ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;

int N,K,Q;
vector<int> vec(1e5+1,0);

void input() {
    cin >> N >> K >> Q;
    rep(i, Q) {
        int a;cin >> a;
        vec[a] += 1;
    };
}

void solve () {
    input();
    for(int i=1;i<=N;i++){
        vec[i] = K - (Q - vec[i]);
        if(vec[i] <= 0){
            cout << "No" << endl;
            continue;
        }
        cout << "Yes" << endl;

    }
}

int main () {
    solve();
    return 0;

}

Measured memory_bytes: 1024
#include<iostream>
    #include<cstdio>
    using namespace std;
     
    int gcd(int a,int b)
    {
    	if(b==0) return a;
    	return gcd(b,a%b);
    } 
     
    int lcm(int a,int b)
    {
    	return a/gcd(a,b)*b;
    }
     
    int main()
    {
    	int a,b;
    	while(cin>>a>>b) {
    		cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
    	}
    	return 0;
    }


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

// dp[i][j] = i番目までコインを投げたとき表がj枚の確率
double dp[3005][3005] = {0};
double P[3005];

int main() 
{
    int n;
    cin >> n;
    rep(i,n) cin >> P[i];

    dp[0][0] = 1;

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

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


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

int w,h,used[1<<10][20][20],bt[20][20];;
char c[20][20];
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int sx,sy,n;
int bfs(){
  memset(used,0,sizeof(used));
  queue<P> q;
  q.push(P(0,p(sx,sy)));
  while(!q.empty()){
    int s=q.front().first,x=q.front().second.first,y=q.front().second.second;
    q.pop();
    if(s==n-1)return used[s][y][x];
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx<0||w<=nx||ny<0||h<=ny||c[ny][nx]=='x')continue;
      int ns=s|bt[ny][nx];
      if(!used[ns][ny][nx])
	q.push(P(ns,p(nx,ny))),used[ns][ny][nx]=used[s][y][x]+1;
    }
  }
  return -1;
}

int ans(){
  memset(used,0,sizeof(used));
  memset(bt,0,sizeof(bt));
  n=1;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      cin>>c[i][j];
      if(c[i][j]=='o')sx=j,sy=i;
      if(c[i][j]=='*')bt[i][j]=n,n*=2;
    }
  return bfs();
}

int main(){
  while(cin>>w>>h,w)cout<<ans()<<endl;
  return 0;
}

Measured memory_bytes: 4800
S = input()
Sr = S[::-1]

while len(Sr) > 0:
  L = len(Sr)
  if Sr[:5] == "maerd":
      Sr = Sr[5:]
  elif L >= 7 and Sr[:7] == "remaerd":
    Sr = Sr[7:]
  elif Sr[:5] == "esare":
    Sr = Sr[5:]
  elif L >= 6 and Sr[:6] == "resare":
    Sr = Sr[6:]
  else:
    print("NO")
    exit()
print("YES")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool n=false;
  bool s=false;
  bool w=false;
  bool e=false;
  for(int i=0;i<S.size();i++){
    if(S.at(i) == 'S'){
      s = true;
    }
    if(S.at(i) == 'N'){
      n = true;
    }
    if(S.at(i) == 'E'){
      e = true;
    }
    if(S.at(i) == 'W'){
      w = true;
    }
  }
  bool ans=false;
  if( n && s){
    if ( e && w|| e!=true&&w!=true){
      ans = true;
    }
  }
    if( n!= true && s!=true){
    if ( e && w|| e!=true&&w!=true){
      ans = true;
    }
  }
  cout << (ans ? "Yes":"No");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
#define PI 3.14159265358979
//#define rep(i,init,n) for(ll i=init;i<=n;++i)
using P = pair<string , int>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;


int main(){
    ll k;
    string s;
    string ans_s="";
    cin >> k >> s;
    if(s.size() <= k) cout << s << endl;
    else{
        rep(i,k) ans_s += s.at(i);
        ans_s += "...";
        cout << ans_s << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
const int MX_N = 100005;
int n,m;
vector<vector<int>> tree(MX_N,vector<int>());

/*
DP構造体 足し算は頂点の情報を集めていくときに行う演算　addrootは最後に情報を根に足し込むときに使う関数
*/
struct DP{
    ll dp;
    DP(ll dp=1):dp(dp){}
    DP operator + (const DP& r) const {
        return DP((dp*r.dp)%m);
    }
    DP addroot() const{
        return DP((dp+1)%m);
    }
};

vector<DP> dp[MX_N];//それぞれの頂点について隣接する頂点から集めてきた情報
DP ans[MX_N];//答え

//dfs1では子から情報を集めてくる。
DP dfs1(int v,int p=-1){
    DP dpsum;
    dp[v] = vector<DP>(tree[v].size());
    rep(i,tree[v].size()){
        int c = tree[v][i];
        if(c == p) continue;
        dp[v][i] = dfs1(c,v);
        dpsum = dpsum + dp[v][i];
    }
    return dpsum.addroot();//根に足し込むときにaddroot
}

void dfs2(int v,int p=-1,DP dpP = DP()){
    int deg = tree[v].size();
    rep(i,deg) if(tree[v][i] == p) dp[v][i] = dpP;//dpPは１回目のdfs1では唯一情報を手に入れられなかった親からの情報を埋めるための引数

    vector<DP> dpL(deg+1);//左側からの累積DP 0番目を持っておくと楽
    rep(i,deg) dpL[i+1] = dpL[i] + dp[v][i];

    vector<DP> dpR(deg+1);//右側からの累積DP　0番目を持っておくと楽
    for(int i=deg-1;i>=0;--i) dpR[i] = dpR[i+1] + dp[v][i];

    ans[v] = dpL[deg];

    rep(i,deg){
        int c = tree[v][i];
        if(c == p) continue;
        DP dpV = dpL[i] + dpR[i+1];
        dfs2(c,v,dpV.addroot());//根に足し込むときにaddroot
    }
}

int main(){
    cin >> n >> m;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs1(0);
    dfs2(0);
    rep(i,n) cout << ans[i].dp << endl;
    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int num = i;
		int cmp = 0;
		while(num > 0){
			cmp += num%10;
			num /= 10;
		}
		if(a <= cmp && cmp <= b) ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


n,c = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(c)]
C = [[int(x)-1 for x in input().split()] for _ in range(n)]
C0,C1,C2 = [0]*c,[0]*c,[0]*c
for i in range(n):
    for j in range(n):
        if (i+j)%3 == 0:
            C0[C[i][j]] += 1
        elif (i+j)%3 == 1:
            C1[C[i][j]] += 1
        else:
            C2[C[i][j]] += 1
ans = inf
for (i,j,k) in permutations(range(c),3):
    cur = 0
    for l in range(c):
        cur += D[l][i]*C0[l]+D[l][j]*C1[l]+D[l][k]*C2[l]
    ans = min(ans,cur)
print(ans)


Measured memory_bytes: 44892
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

ll hoge(ll x, ll y, ll z) {
    return max({abs(x - y), abs(y - z), abs(z - x)});
}

void solve() {
    ll h, w, ans = INF; cin >> h >> w;
    if(h % 3 == 0) {
        ans = 0;
    }
    if(w % 3 == 0) {
        ans = 0;
    }
    if(h % 3 != 0) {
        ans = min(ans, w);
    }
    if(w % 3 != 0) {
        ans = min(ans, h);
    }
    for(ll i = 1; i < h; i++) {
        ll res = hoge(i * w, (h - i) * (ll)(w / 2), (h - i) * (w - w / 2));
        ans = min(ans, res);
    }
    for(ll i = 1; i < w; i++) {
        ll res = hoge(i * h, (w - i) * (ll)(h / 2), (w - i) * (h - h / 2));
        ans = min(ans, res);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){

  int n;
  cin>>n;
  vector<int> A[2];
  A[0].resize(n);
  A[1].resize(n);
  for(int i=0;i<2;i++) cin>>A[i];
  
  int ans = -INF;
  for(int i=0;i<n;i++){
    int sum = 0;
    for(int j=0;j<n;j++) {
      if(i == j) sum += A[0][j] + A[1][j];
      else sum += A[i<j][j];
    }
    Max(ans,sum);
  }

  cout<<ans<<endl;



  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    string s;
    cin >> s;
    int w;
    cin >> w;
    int n = s.size();
    int i=0;
    while(1){
        if(i*w >= n) break;
        cout << s[i*w];
        i++;
    }
    return 0;
}

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

int main()
{
  int x,y;
  while(1){
    cin>>x>>y;
    if(x==0 && y==0)break;
    if(x>=y)cout<<y<<" "<<x<<endl;
    else cout<<x<<" "<<y<<endl;
  }
  return 0;
}

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

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nMeTo;

  StDist(int nDist) : m_nDist(nDist), m_nMeTo(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    if (rvoDist[nx].m_nMeTo)  continue; 

    rvoDist[nx].m_nMeTo = 1;
    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
      if (cnrvvnAdjcy[nx][ny])
      {
        int nDist = rvoDist[nx].m_nDist + 1;
        if (rvoDist[ny].m_nDist == nIMPOS)
          rvoDist[ny].m_nDist = nDist;

        rqnBFSrch.push(ny);
      }
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

Measured memory_bytes: 3148
#include <stdio.h>
#include <algorithm>
using namespace std;
char a[10];
int main()
{
	while(~scanf("%s",a))
	{
		sort(a,a+4);
		if(a[0]==a[1]&&a[2]==a[3]&&a[0]!=a[2])
		printf("Yes\n");
		else printf("No\n");
	}
	return 0;
} 

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
using namespace std;

void swap(int &a, int &b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int a[3];
	for (int i = 0; i < 3; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < 2; i++) {
		for (int j = i + 1; j < 3; j++) {
			if (a[i] < a[j]) swap(a[i], a[j]);
		}
	}
	printf("%d", abs(a[1] - a[0]) + abs(a[2] - a[1]));
	return 0;
}


Measured memory_bytes: 256
from itertools import permutations

N = int(input())
P = list(map(str,input().split()))
Q = list(map(str,input().split()))
P = "".join(P)
Q = "".join(Q)
l = []
ll = []
for i in range(1,N + 1):
    l.append(i)

comb = list(permutations(l,N))

for i in range(len(comb)):
    a = list(map(str,comb[i]))
    ll.append("".join(a))

P_ind = ll.index(P)
Q_ind = ll.index(Q)
print(abs(P_ind - Q_ind))

Measured memory_bytes: 10996
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int top = -1;
		int max = -1;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			int v = in.nextInt();
			if (v > max || v == max && top > a) {
				top = a;
				max = v;
			}
		}
		System.out.print(top);
		System.out.print(' ');
		System.out.println(max);
		in.close();
	}
}

Measured memory_bytes: 17376
N = int(input())
ans = 0

def f(target):
    for i in '753':
        targetJoin = str(target) + str(i)
        
        if int(targetJoin) > N:
            continue

        if  '7' in targetJoin and '5' in targetJoin and '3' in targetJoin :
            
            flag = True
            if '0' in targetJoin:
                flag = False
            if '1' in targetJoin:
                flag = False
            if '2' in targetJoin:
                flag = False
            if '4' in targetJoin:
                flag = False
            if '6' in targetJoin:
                flag = False
            if '8' in targetJoin:
                flag = False
            if '9' in targetJoin:
                flag = False
            
            if flag :
                global ans
                ans+=1
                
        f(targetJoin)
        
f(3)
f(5)
f(7)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll n,arr[100015],v;
     mem(arr,0);
     cin>>n;
     for(int i=0;i<n;i++)
     {
         cin>>v;
         arr[v]++;
     }
     ll mx=0,kk;
     for(int i=0;i<100000;i++)
     {
         kk=arr[i]+arr[i+1]+arr[i+2];
         mx=max(mx,kk);
     }
     cout<<mx<<endl;
}




Measured memory_bytes: 1024
from collections import deque
q = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        cnt += 1
    else :
        if query[1] == '1':
            if cnt % 2 == 0:
                q.appendleft(query[2])
            else :
                q.append(query[2])
        else :
            if cnt % 2 == 1:
                q.appendleft(query[2])
            else :
                q.append(query[2])
if cnt % 2 == 1: q.reverse()
print(''.join(q))

Measured memory_bytes: 73944
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string s,t;
  int a=0,i=0;
  cin>>s;cin>>t;
  
  for(i=0;i<s.size();i++){
    if(s[i]==t[i])a++;
  }
  cout<<a;
  return 0;
}

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

int main()
{
    ll n,wt;cin>>n>>wt;
    vector<ll> w(n),v(n),t(wt+1,0);
    for(ll i=0;i<n;i++)cin>>w[i]>>v[i];
    vector<vector<ll>> val(n+1,t);
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=wt;j++){
            val[i][j]=val[i-1][j];
            if(w[i-1]<=j){
                val[i][j]=max(val[i][j],val[i-1][j-w[i-1]]+v[i-1]);
            }
        }
    }
    cout<<val[n][wt]<<"\n";
    return 0;
}


Measured memory_bytes: 80256
#include <iostream>

#define MAX 100000
int A[MAX];

int partition(int A[],int p,int r) {
    int x = A[r];
    int i = p - 1, tmp;
    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            tmp = A[i]; A[i]=A[j]; A[j] = tmp;
        }
    }
    tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp;
    
    return i+1;
}

int main(void){
    // Your code here!
    int n, p;
    
    std::cin >> n;
    
    for (int i = 0; i < n; i++) {
        std::cin >> A[i];
    }
    
    p = partition(A, 0, n-1);
    
    for (int i = 0; i < n; i++) {
        if (i) std::cout << " ";
        if (i == p) std::cout << "[";
        std::cout << A[i];
        if (i == p) std::cout << "]";
    }
    
    std::cout << std::endl;
    
    return 0;
}



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

using namespace std;
#define int long long
#define N 366666
#define inf 99999999
vector<pair<int,int> > v[N]; 
int k;
int dis[N];
void spfa(){
	queue<int> q;
	q.push(1);
	for(int i=0;i<=k;i++) dis[i]=inf;
	dis[1]=1;
	while(!q.empty()){
		int t=q.front();
		q.pop();
		//if(vis[t]) continue;
		for(int i=0;i<v[t].size();i++){
			if(dis[v[t][i].first]>dis[t]+v[t][i].second){
				dis[v[t][i].first]=dis[t]+v[t][i].second;
				q.push(v[t][i].first);
			}
		}
	}
	
}
signed  main(){
	
	cin>>k;
	for(int i=1;i<k;i++){
		v[i].push_back(make_pair((i+1)%k,1));
		v[i].push_back(make_pair((10*i)%k,0));
	} 
	spfa();
	cout<<dis[0];
	return 0;
}

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

using namespace std;

int main(){
    double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xa1, &ya1, &xa2, &ya2, &xb1, &yb1, &xb2, &yb2) != EOF){
        if(xa2 < xb1 || xb2 < xa1 || ya2 < yb1 || ya1 > yb2) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;
typedef int64_t SI;
typedef uint64_t UI;

void read(SI& N, vector<SI>& V) {
  cin >> N;
  V.resize(N);
  for(size_t i=0; i<N; i++) {
    SI x;
    cin >> x;
    V[i] = x;
  }
}

int solve(const vector<SI>& V) {
  return 0;
}

void test() {
  {
    vector<UI> A = {4,6};
    vector<UI> B = {1,5};
    vector<UI> C = {3,8};
    UI K = 8;
    vector<SI> V = {0,1,2};
    assert(solve(V)==0);
  }
  cerr << "OK" << endl;
}

int main() {
  UI X,Y,Z,K;
  cin >> X >> Y >> Z >> K;
  vector<UI> A(X),B(Y),C(Z);
  for(SI i=0; i<X; i++) { cin >> A[i]; }
  for(SI i=0; i<Y; i++) { cin >> B[i]; }
  for(SI i=0; i<Z; i++) { cin >> C[i]; }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  sort(C.begin(), C.end());
  reverse(C.begin(), C.end());

  vector<UI> ABC;
  for(size_t i=0; i<X; i++) {
    for(size_t j=0; j<Y; j++) {
      if( (i+1)*(j+1) > K ) break;
      for(size_t k=0; k<Z; k++) {
        if( (i+1)*(j+1)*(k+1) > K ) break;
        ABC.push_back(A[i]+B[j]+C[k]);
      }
    }
  }

  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());

  for(size_t i=0; i<K; i++) {
    cout << ABC[i] << std::endl;
  }

  return 0;
}



Measured memory_bytes: 1404
#a
n = int(input())
s = input()
t = input()

same = 0
for i in range(n):
    
    judge = 1
    for j in range(i+1):
        if not t[j]==s[n-1-i+j]:
            judge = 0
            break
    
    if judge==1:
        same = i+1

print(2*n - same)

Measured memory_bytes: 3060