akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll M=1e9+7;
const ll mxx=1e5+7;


int main()
{

    int n;
    cin>>n;
    int a[n],b[n];
    for(auto &x:a)cin>>x;
    for(auto &x:b)cin>>x;

    reverse(b,b+n);
    
    int l=-1,r=-1;
    for(int i=0;i<n;i++)
    {
       if(a[i]==b[i])
       {
       	if(l==-1)l=i,r=i;
       	else r=i;
       }
    }
    vector<int> v;
    if(l!=-1)
    {
        int num=a[l];
        for(int i=0;i<l;i++)
        {
        	 if(a[i]!=num && b[i]!=num)v.push_back(i);
        }
         for(int i=r+1;i<n;i++)
        {
        	 if(a[i]!=num && b[i]!=num)v.push_back(i);
        }
        if(v.size()<r-l+1){cout<<"No";return 0;}
        int cur=l;
        while(cur<=r)
        {
            swap(b[cur],b[v.back()]);
            v.pop_back();
            cur++;
        }
    }
    cout<<"Yes"<<endl;
    for(auto &x:b)cout<<x<<" ";
}


   


Measured memory_bytes: 5872
N = int(input())
cnt_dict = dict()

for _ in range(N):
    s = ''.join(sorted(list(input())))
    if s in cnt_dict:
        cnt_dict[s] += 1
    else:
        cnt_dict[s] = 1

ans = 0
for cnt in cnt_dict.values():
    ans += cnt * (cnt - 1) // 2

print(ans)
    

Measured memory_bytes: 60504
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

const int N = 1e5 + 10;
vector<int> edg[N];

bool vis[N];

void dfs(int u, int f) {
  vis[u] = true;
  for(int i = 0; i < int(edg[u].size()); i++) {
    if(!vis[edg[u][i]]) {
      dfs(edg[u][i], u);
    }
  }
}

void Main() {
  int n, m; cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int x, y, z; cin >> x >> y >> z;
    edg[x].push_back(y);
    edg[y].push_back(x);
  }
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(!vis[i]) {
      dfs(i, -1);
      ans++;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 8448
//I̲n̲ ̲t̲h̲e̲ ̲N̲a̲m̲e̲ ̲o̲f̲ ̲G̲o̲d̲
#define pb push_back
#define F first
#define S second
#define sz size()
#define ll long long

#include <bits/stdc++.h>

using namespace std;

string s;
int a[12], c[12], ans = 100000;
int b[] = {7,5,4};
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> s;
	for (int i = 0; i < s.sz; i++)
    {
        a[i] = s[i]-'0';
    }
    for (int i = 0; i < s.sz-2; i++)
    {
        c[i] = a[i]*100 + a[i+1]*10 + a[i+2];
    }
    for (int i = 0; i < s.sz-2; i++)
    {
        c[i] = abs((c[i]-753));
        ans = min(ans,c[i]);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 100000
using namespace std;

typedef long long ll;

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

  int n;
  cin >> n;
  string s[MAX_N];
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }

  const int M = 0, A = 1, R = 2, C = 3, H = 4;
  ll count[5];
  fill(count, count + 5, 0);
  for(int i = 0; i < n; i++){
    if(s[i][0] == 'M') ++count[M];
    else if(s[i][0] == 'A') ++count[A];
    else if(s[i][0] == 'R') ++count[R];
    else if(s[i][0] == 'C') ++count[C];
    else if(s[i][0] == 'H') ++count[H];
  }

  ll sum = 0;
  for(int i = 0; i < 5; i++){
    for(int j = i + 1; j < 5; j++){
      for(int k = j + 1; k < 5; k++){
        sum += count[i] * count[j] * count[k];
      }
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 2808
#include <iostream>
#include <vector>

using namespace std;

using i64 = long long;

int main(){
    i64 n;
    cin >> n;
    bool f = false;
    for(int i = 1; i < 10; ++i){
        if(n % i == 0 && n / i < 10) f = true; 
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [[]for _ in range(n)]
for _ in range(m):
    a, b = list(map(lambda x: int(x)-1, input().split()))
    edges[a].append(b)
    edges[b].append(a)

ans = 0
for v in range(n):
    for v2 in edges[v]:
        if h[v] <= h[v2]:
            break
    else:
        ans += 1
print(ans)


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

int main(){
    char a[150];
    pair<pair<string, int>, int> p[150];
    int n;
    cin >> n;
    REP(i, n){
        int t;
        cin >> a >> t;
        p[i] = make_pair(make_pair(a, -t), i);
    }
    sort(p, p+n);
    REP(i, n){
        cout << p[i].second + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)

int main() {
	in(int, n);
	out(n * 800 - (n / 15) * 200);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
string s;
int a[26];
signed main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		a[(int)(s[i] - 'a')]++;
	}
	int n = s.size();
	int ans = n * (n - 1) / 2 + 1;
	for (int i = 0; i < 26; i++) {
		ans -= a[i] * (a[i] - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = null;
        try {
            sc = new Scanner(System.in);
            while (sc.hasNextInt()) {
                int d = sc.nextInt();
                int areaCulcCount = 600 / d - 1;
                long sum = 0L;

                for (int i = 1; i <= areaCulcCount; i++) {
                    int x = i * d;
                    int y = x * x;
                    sum += y * d;
                }
                System.out.println(sum);
            }
        } finally {
            sc.close();
        }
    }
}

Measured memory_bytes: 26076
// finish date: 2018/05/05
#include <bits/stdc++.h>


using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int a, b;
    cin >> a >> b;
    int ans = (a <= b) ? a : a - 1;
    cout<<ans<<endl;


    return 0;
}

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll n;
	cin>>n;
	cout<<(n-1)*n/2<<"\n";
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no2();
	}

	static void no2() {
		try (Scanner sc = new Scanner(System.in)) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int k = sc.nextInt();

			int t = 0;
			if (a >= b && a >= c) {
				t = b + c + (int) Math.pow(2, k) * a;
			}
			if (b > c && b > a) {
				t = a + c + (int) Math.pow(2, k) * b;
			}
			if (c > a && c > b) {
				t = b + a + (int) Math.pow(2, k) * c;
			}
			System.out.println(t);
		}
	}
}


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

int main(){
    ll n, t;
    vector<ll> v;
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++){
        scanf("%lld", &t);
        v.push_back(t);
    }
    v.erase(unique(v.begin(), v.end()), v.end());
    for(auto i = v.begin(); i != v.end(); i++){
        if(i != v.begin()){
            printf(" ");
        }
        printf("%lld", *i);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3912
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
signed main()
{
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    int cc = 0;
    if (k != 0)
    {
        cc = log2(double(k));
    }
    int ans = 0;
    rep(i, cc + 1)
    {
        int count0 = 0;
        int count1 = 0;
        rep(j, n)
        {
            if ((a[j] >> (cc - i)) & 1)
            {
                count1++;
            }
            else
            {
                count0++;
            }
        }
        if (count0 > count1 && (ans + pow(2, (cc - i))) <= k)
        {
            ans += pow(2, (cc - i));
        }
    }
    int res = 0;
    rep(i, n)
    {
        res += a[i] ^ ans;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
X,K,D = map(int, input().split())

def calc(M):
	return ( -1 * D * M ) + ( D * ( K - M ) )


MAX_X = 1e15
L = 0
R = K
curMin = MAX_X + 1
sumTmp = 0
while True:
	M = ((L+R)//2)

	sumTmp = calc( M )
	# print(M, L,R, sumTmp, X+sumTmp)

	if abs(curMin - abs(X+sumTmp)) < 1:
		# print("curMin:", curMin, abs(X+sumTmp))
		break

	# if M == 0:
	# 	break

	if 0 < X + sumTmp:
		# increase left range
		# (decrease current)
		L = M + 1
		# print("left inc",L,R)
	elif X == sumTmp:
		L = R = M
		curMin = 0
		break
	else:
		# sumTmp < X
		# decrease right range
		# (increase current)
		# print("right dec",L,R)
		R = M - 1

	if L < 0 or R < 0:
		L = R = 0
		break
	elif L > K or R > K:
		L = R = K
		break
	elif R < L:
		# FIXME: これ微妙では。。。?
		# 短調増加でなくなってしまっているため、これがありえる？
		L,R = R,L

	curMin = min(abs(curMin), abs(X+sumTmp))


# print("X:",X,"K:",K, "L:",L, "D:", D)
# print(calc(L) )
print(abs( X + calc(L)))

Measured memory_bytes: 62084
# https://atcoder.jp/contests/arc091/tasks/arc091_b

n, k = map(int, input().split())
ans = 0
for i in range(1, n + 1):
    surplus = n // i
    quotient = n % i
    ans += surplus * max(0, i - k) + max(0, quotient - k + 1)
print(ans if k != 0 else ans - n)


Measured memory_bytes: 66672
#include<stdio.h>
char data[1010];
void proc(){
  int sum=0;
  char*p=data;
  while(*p!=0){
    sum+=*p-'0';
    ++p;
  }
  printf("%d\n",sum);
}
int main(){
  while(true){
    gets(data);
    if(data[0]=='0')break;
    proc();
  }
  return 0;
}

Measured memory_bytes: 928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int canTriangle(int, int, int);

int main() {
    int n;
    cin >> n;
    string s;
    vector<int> l;
    for (int i = 0; i < n; i++) {
        char failed = 0;
        cin >> s;
        int buf = atoi(s.c_str());
        l.push_back(buf);
    }
    sort(l.begin(), l.end());



    int result = 0;
    for (int i = 0; i < l.size(); ++i) {
        for (int j = 0; j < i; ++j) {
            for (int k = 0; k < j; ++k) {
                result += canTriangle(l[k], l[j], l[i]);
            }
        }
    }

    cout << result << endl;

    return 0;
}

int canTriangle(int a, int b, int c) {
    if (a == b
        || b == c
        || c == a) {
        return 0;
    }
    return a + b > c;
}


Measured memory_bytes: 3628
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            if (N % 10 == 3)
            {
                Console.WriteLine("bon");
            }
            else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8)
            {
                Console.WriteLine("pon");
            }
            else
            {
                Console.WriteLine("hon");
            }
        }
    }
}

Measured memory_bytes: 27544
import sys
sys.setrecursionlimit(10000)

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        par[rx] = ry

def same(x, y):
    return root(x) == root(y)

n, m = map(int, input().split())
E = []
for i in range(m):
    s, t, w = map(int, input().split())
    E.append([w, s, t])

E.sort()

par = [i for i in range(n)]

ans = 0

for e in E:
    if not same(e[1], e[2]):
        unite(e[1], e[2])
        ans += e[0]

print(ans)


Measured memory_bytes: 24760
/*  ex3_2
    ruuu0048 */
#include <stdio.h>

int main(void){

    int book_number,keta; //本の数とその数の一桁の変数を宣言

    scanf("%d",&book_number); //変数に本の数を入力する

    keta = book_number % 10; //本の一桁を計算し代入

    
    //条件分岐して助数詞を出力
    if(keta == 3){ //一桁目が3なら
        printf("bon\n");
    }
    else if(keta == 0 || keta == 1 || keta == 6 || keta == 8) //一桁目が0,1,6,8なら
    {
        printf("pon\n");
    }
    else //それ以外なら
    {
        printf("hon\n");
    }
    

    return 0; 
}

Measured memory_bytes: 1640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    long long ans = A * X + B * Y;
    
    int piza_Max = max(X, Y);
    
    for(int i = 1; i <= piza_Max; i++){
        
        long long piza_Now_Money;
        long long now_X = X - i;
        long long now_Y = Y - i;
        long long now_C = i * 2;
        
        if(now_X >= 0 && now_Y >= 0) piza_Now_Money = A * now_X + B * now_Y + C * now_C;
        if(now_X < 0) piza_Now_Money = B * now_Y + C * now_C;
        if(now_Y < 0) piza_Now_Money = A * now_X + C * now_C;

        ans = min(ans, piza_Now_Money);
    }

    cout << ans << endl;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


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

    set<char> ans;
    rep(i,N)
    {
        char tmp;
        cin >> tmp;
        ans.insert(tmp);
    }

    if( ans.size() == 3 ) cout << "Three" << endl;
    else cout << "Four" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N, M;
ll x[100010], y[100010];

ll cnt[100010];
bool red[100010];
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N>>M;
    REP(i,0,M){
        cin>>x[i]>>y[i];
    }

    red[0] = true;
    REP(i,0,N) cnt[i]=1;

    REP(i,0,M){
        cnt[x[i]-1]--;
        cnt[y[i]-1]++;

        if(red[x[i]-1]) red[y[i]-1] = true;
        if(cnt[x[i]-1] == 0) red[x[i]-1] = false;
    }

    int ans = 0;
    REP(i,0,N){
        if(red[i]) ans++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
using namespace std;

int main()
{
	int N;
	cin >> N;
	unordered_map<string, int> mp;
	string s[100];
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		mp[s[i]] = 0;
	}
	int M;
	cin >> M;
	string t[100];
	for (int i = 0; i < M; i++) {
		cin >> t[i];
		mp[t[i]] = 0;
	}
	for (int i = 0; i < N; i++) {
		mp[s[i]]++;
	}
	for (int i = 0; i < M; i++) {
		mp[t[i]]--;
	}
	int n{ 0 };
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr->second > n) {
			n = itr->second;
		}
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<bool> A(100001,false);
  int ans=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(A[a])ans++;
    A[a]=true;
  }
  cout<<N-(ans+1)/2*2<<endl;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=1000000007>struct fp {
   unsigned v;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp():v(0){}
   fp(ll x):v(x>=0?x%mod:mod+(x%mod)){}
   fp operator-()const{return fp(-v);}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){if((v+=x.v)>=mod)v-=mod; return *this;}
   fp& operator-=(const fp& x){if((v+=mod-x.v)>=mod)v-=mod; return *this;}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
}; using Fp=fp<>;

Fp dp[5010][2][2],sub[5010][2];

int main(){
   int n,a,b; cin>>n>>a>>b; n+=2;
   if(a>b)swap(a,b);
   sub[0][0]=1;
   rep(i,0,n){
      for(int add=1;i+add<=n;add++)sub[i+add][1]+=sub[i][0];
      for(int add=a;i+add<=n;add++)sub[i+add][0]+=sub[i][1];
   }
   dp[0][0][0]=1;
   rep(i,0,n)rep(k,0,2){
      for(int add=1;i+add<=n and add<a;add++)dp[i+add][0][k]+=dp[i][1][k];
      for(int add=1;i+add<=n;add++){
         int cur=add; if(i==0)cur--; if(i+add==n)cur--;
         dp[i+add][1][cur>=b?1:k]+=dp[i][0][k]*sub[add][1];
      }
   }
   cout<<dp[n][1][1].v<<endl;
   return 0;
}

Measured memory_bytes: 3716
#!/usr/bin/env python3


def put(a, k, v):
    if k in a:
        if a[k] != v:
            return False
    else:
        a[k] = v
    return True


def check(n, t, i):
    a = {}
    m = 0
    for j in range(n):
        honest = i >> j & 1
        m += honest
        if not put(a, j+1, honest):
            return 0
        if honest:
            for (k, h) in t[j+1].items():
                if not put(a, k, h if honest else 1 - h):
                    return 0
    return m


def solve(n, t):
    print(max([check(n, t, i) for i in range(1 << n)]))


def main():
    t = {}
    n = int(input())
    for i in range(n):
        a = int(input())
        t[i+1] = {}
        for j in (range(a)):
            x, y = map(int, input().split())
            t[i+1][x] = y
    solve(n, t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3480
s = list(str(input()))
s.reverse()
S = []

c = ''
for i in range(len(s)):
    c += s[i]
    if S:
        if c != S[-1]:
            S.append(c)
            c = ''
    else:
        S.append(c)
        c = ''
#print(S)
print(len(S))


Measured memory_bytes: 9636
h, w = map(int, input().split())
G = []
ans = 0
for i in range(10):
    G.append(list(map(int, input().split())))
for i in range(10):
    G[i][i] = 0
for k in range(10):
    for i in range(10):
        for j in range(10):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])
for i in range(h):
    wall = list(map(int, input().split()))
    for j in range(w):
        if wall[j] == -1:
            continue
        ans += G[wall[j]][1]
print(ans)




Measured memory_bytes: 40556
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

H,W = MI()
sh,sw = MI()  # スタート
gh,gw = MI()  # ゴール
S = [['#']*(W+1)] + [['#'] + LS2() for i in range(H)]
directions1 = [(-1,0),(1,0),(0,-1),(0,1)]
directions2 = [(i,j) for i in range(-2,3) for j in range(-2,3)]

from collections import deque

# 01BFS

q = deque([(sh,sw)])
ans = [[-1]*(W+1) for _ in range(H+1)]
ans[sh][sw] = 0
while q:
    nh,nw = q.pop()
    for dh,dw in directions1:
        if 1 <= nh+dh <= H and 1 <= nw+dw <= W and S[nh+dh][nw+dw] == '.':
            if ans[nh+dh][nw+dw] == -1 or ans[nh+dh][nw+dw] > ans[nh][nw]:
                ans[nh+dh][nw+dw] = ans[nh][nw]
                q.append((nh+dh,nw+dw))
    for dh,dw in directions2:
        if 1 <= nh+dh <= H and 1 <= nw+dw <= W and S[nh+dh][nw+dw] == '.':
            if ans[nh+dh][nw+dw] == -1:
                ans[nh+dh][nw+dw] = ans[nh][nw] + 1
                q.appendleft((nh+dh,nw+dw))

print(ans[gh][gw])


Measured memory_bytes: 123532
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    n = I()
    x = LI()
    f = [(i,x[i]) for i in range(n)]
    f.sort(key = lambda x:x[1])
    g = [(f[i][0],i) for i in range(n)]
    g.sort(key = lambda x:x[0])
    for i in range(n):
        if g[i][1] < n//2:
            print(f[n//2][1])
        else:
            print(f[n//2-1][1])
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    G()


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

vector<vector<int> > S;
vector<int> A;
vector<bool> used;

void dfs(int pos, int n) {
    if (pos == n) {
        S.push_back(A);
        return;
    }

    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            A[pos] = i+1;
            used[i] = true;
            dfs(pos+1, n);
            used[i] = false;
        }
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    A.resize(N);
    used.assign(N, false);
    dfs(0, N);
    int p, q;
    rep(i, S.size()) {
        if (S[i] == P) p = i;
        if (S[i] == Q) q = i;
    }
    cout << abs(p - q) << endl;
    return 0;
}

Measured memory_bytes: 3256
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        ret = dict()
        for i in range(self.n):
            r = self.find(i)
            if r in ret:
                ret[r].append(i)
            else:
                ret[r] = [i]
        return ret

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():

    N = in_n()
    x = [0] * N
    y = [0] * N

    for i in range(N):
        x[i], y[i] = in_nn()

    sort_ind_x = sorted(range(N), key=lambda i: x[i])
    sort_ind_y = sorted(range(N), key=lambda i: y[i])

    cost = []
    for i in range(N - 1):
        j1, j2 = sort_ind_x[i], sort_ind_x[i + 1]
        c = abs(x[j1] - x[j2])
        cost.append((c, j1, j2))

        j1, j2 = sort_ind_y[i], sort_ind_y[i + 1]
        c = abs(y[j1] - y[j2])
        cost.append((c, j1, j2))

    cost.sort()
    uni = UnionFind(N)
    ans = 0

    for c, v1, v2 in cost:
        if not uni.same(v1, v2):
            ans += c
            uni.union(v1, v2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 114760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=105;
//i_am_noob
int n,m,a[maxn],x,y=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m;
	rep(n) cin >> a[i];
	sort(a,a+n);
	x=a[n-m];
	rep(n) y+=a[i];
	print1(x*4*m>=y?"Yes":"No"); 
	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N = int(readline())
G = [None]*(N+1)
for i in range(N):
    u, k, *vs = map(int, readline().split())
    G[u] = vs


begin = [-1]*(N+1)
end = [-1]*(N+1)
lb = iter(range(1, 2*N+1)).__next__
def dfs(v):
    begin[v] = lb()
    for w in G[v]:
        if begin[w] != -1:
            continue
        dfs(w)
    end[v] = lb()


for v in range(1, N+1):
    if begin[v] != -1:
        continue
    dfs(v)
write("\n".join("{} {} {}".format(*args) for args in zip(range(1, N+1), begin[1:], end[1:])))
write("\n")



Measured memory_bytes: 5636
#include <stdio.h>
int main(void){
  int n,x,i,j,k,c=0;
  while(scanf(" %d%d",&n,&x)){
    if(n==0&&x==0)break;
    c=0;
    for(i=1;i<=n-2;i++)for(j=i+1;j<=n-1;j++)for(k=j+1;k<=n;k++)if(i+j+k==x)c++;
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==1)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    ll flag = 1;
    ll minh;
    for(ll i=n-1;i>=1;i--)
    {
        if(a[i]>=a[i-1])
            continue;
        else if(a[i-1] - 1 == a[i])
        {
            a[i-1] = a[i-1]-1;
            continue;
        }
        else
        {
            flag = 0;
            break;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


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

int N, M;
vector<vector<int>> graph(200001);
bitset<200001> bit;

void rec(int corrent = 1, int count = 0){
    
    if(count > 2) return;
    if(corrent == N && count == 2){
        printf("POSSIBLE\n");
        exit(0);
    }
    for(int i = 0; i < graph[corrent].size(); ++i){
        int next = graph[corrent][i];
        if(!bit[next]){
            bit[next] = true;
            rec(next, count + 1);
            bit[next] = false;
        }
    }
    return;
}

int main(void){
	
	scanf("%d %d", &N, &M);
	for(int i = 0; i < M; ++i){
	    int a, b; scanf("%d %d", &a, &b);
	    graph[a].push_back(b), graph[b].push_back(a);
	}
	
	bit[1] = true;
	rec();
	printf("IMPOSSIBLE\n");
	
    return 0;
}


Measured memory_bytes: 12016
r,g,b,n=map(int,input().split())

lst=[r,g,b]
lst.sort()
r=lst[2]
g=lst[1]
b=lst[0]

rlim=n//r
glim=n//g
blim=n//b

"""
blist = [i*b for i in range(blim+1)]

glist = [i*g for i in range(glim+1)]

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return False
"""

cnt=0

for i in range(rlim+1):
    glim=(n-i*r)//g
    for j in range(glim+1):
        if (n-i*r-j*g)%b==0:
            cnt+=1
print(cnt)

Measured memory_bytes: 40300
#include <iostream>
using namespace std;
int main (void) {
    int A, B, C;

    cin >> A >> B >> C;

    if (A == 5 && B == 5 && C == 7) cout << "YES" << endl;
    else if (A == 5 && B == 7 && C == 5) cout << "YES" << endl;
    else if (A == 7 && B == 5 && C == 5) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int m;
  cin>>m;
  REP(i,m){
    string str;
    cin>>str;
    set<string> s;
    REP(i,str.size()-1){
      REP(j,2)REP(k,2){
        string fwd=str.substr(0,i+1);
        string bwd=str.substr(i+1);
        if(j)
          reverse(begin(fwd),end(fwd));
        if(k)
          reverse(begin(bwd),end(bwd));
        s.insert(fwd+bwd);
        s.insert(bwd+fwd);
      }
    }
    cout << s.size() << endl;
  }
  return 0;
}

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

int main() {
	int n, m; cin >> n >> m;
	int waCnt = 0, acCnt = 0;
	vector<bool>check(100005, false);
	map<int, map<string, int>>mp;
	for (int i = 0, tmp; i < m; i++) {
		cin >> tmp; string s; cin >> s;
		if (s == "AC") {
			if (!check[tmp]) {
				waCnt += mp[tmp]["WA"];
				check[tmp] = true;
				mp[tmp][s]++;
			}
		}
		else {
			mp[tmp][s]++;
		}
	}
	for (auto&& x : mp) {
		if (x.second["AC"])acCnt++;
	}
	cout << acCnt << ' ' << waCnt << endl;
	
	return 0;
}

Measured memory_bytes: 31488
#include<stdio.h>
int main() {
	int a, b, x;
	scanf("%d", &a);
	scanf("%d", &b);
	x = a + b;
	if ((x % 2) == 1) {
		printf("%d", x / 2 + 1);
	}
	else {
		printf("%d", x / 2);
	}
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int dp[1005][(1 << 13)];

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

    int n, m;
    cin >> n >> m;
    vector<P> v(m);
    for(int i = 0; i < m; ++i) {
        int b;
        cin >> v[i].F >> b;
        while(b--) {
            int c;
            cin >> c;
            v[i].S += (1 << (c - 1));

        }
    }

    for(int i = 0; i < m; ++i) {
        for(int j = 1; j < (1 << n); ++j) {
            dp[i][j] = INF;

        }
    }

    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < (1 << n); ++j) {
            if(i == 0) {
                if(j == 0) {
                    dp[i][j | v[i].S] = v[i].F;

                }
            } else {
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                dp[i][j | v[i].S] = min(dp[i - 1][j | v[i].S], dp[i][j | v[i].S]);
                if(dp[i - 1][j] != INF) {
                    dp[i][j | v[i].S] = min(dp[i][j | v[i].S], dp[i - 1][j] + v[i].F);

                }
            }
        }
    }


    if(dp[m - 1][(1 << n) - 1] == INF) {
        cout << -1 << endl;

    } else {
        cout << dp[m - 1][(1 << n) - 1] << endl;

    }

    return 0;
}



Measured memory_bytes: 30976
#include<iostream>
#include<vector>

int main(void){
    std::vector<int> t(2), a(2);
    std::cin >> t[0] >> t[1] >> a[0] >> a[1];
    while(true){
	if(a[0] - t[1] <= 0){
	    std::cout << "Yes" << std::endl;
	    break;
	}
	a[0] = a[0] - t[1];
	if(t[0] - a[1] <= 0){
	    std::cout << "No" << std::endl;
	    break;
	}
	t[0] = t[0] - a[1];
    }
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = (int)s.size();

    int r[2] = {};
    for (int i = 0; i < n; i++) {
        int c = s[i] - '0';
        for (int j = 0; j < 2; j++) {
            if (c == (i + j) % 2) r[j]++;
        }
    }

    cout << min(r[0], r[1]) << endl;

    return 0;
}

Measured memory_bytes: 512
n,k=map(int,input().split())
A=list(map(int,input().split()))

ans=float("inf")
for i in range(1,2**n):
    num=format(i,"b").zfill(n)
    point=0
    if num.count("1")!=k:continue
    highest=A[0]
    for j in range(1,n):
        if highest>=A[j] and  num[j]=="1":
            point +=highest-A[j]+1
            highest +=1
        highest=max(highest,A[j])
    ans=min(ans,point)

print(ans)

Measured memory_bytes: 41072
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define MAX 1010
 
int H,W;
char a[MAX][MAX],b[2][2];
const char c[3] = {'J','O','I'};
 
bool inField(int y,int x){
    return 0 <= y && y < H && 0 <= x && x < W;
}
 
int Cnt(int y,int x,char ch){
    int res = 0;
 
    if(a[y][x] == b[0][0] && 
       (inField(y,x+1) && a[y][x+1] == b[0][1]) && 
       (inField(y+1,x) && a[y+1][x] == b[1][0]) &&
       (inField(y+1,x+1) && a[y+1][x+1] == b[1][1])) res++;
  
    if(b[0][0] == ch && 
       (inField(y,x+1) && a[y][x+1] == b[0][1]) && 
       (inField(y+1,x) && a[y+1][x] == b[1][0]) &&
       (inField(y+1,x+1) && a[y+1][x+1] == b[1][1])) res--;
  
    if(a[y][x] == b[0][1] && 
       (inField(y,x-1) && a[y][x-1] == b[0][0]) && 
       (inField(y+1,x-1) && a[y+1][x-1] == b[1][0]) &&
       (inField(y+1,x) && a[y+1][x] == b[1][1])) res++;
  
    if(b[0][1] == ch && 
       (inField(y,x-1) && a[y][x-1] == b[0][0]) && 
       (inField(y+1,x-1) && a[y+1][x-1] == b[1][0]) &&
       (inField(y+1,x) && a[y+1][x] == b[1][1])) res--;
 
    if(a[y][x] == b[1][0] && 
       (inField(y-1,x) && a[y-1][x] == b[0][0]) && 
       (inField(y-1,x+1) && a[y-1][x+1] == b[0][1]) &&
       (inField(y,x+1) && a[y][x+1] == b[1][1])){
	res++;
    }
    if(b[1][0] == ch && 
       (inField(y-1,x) && a[y-1][x] == b[0][0]) && 
       (inField(y-1,x+1) && a[y-1][x+1] == b[0][1]) &&
       (inField(y,x+1) && a[y][x+1] == b[1][1])) res--;
  
    if(a[y][x] == b[1][1] && 
       (inField(y-1,x) && a[y-1][x] == b[0][1]) && 
       (inField(y,x-1) && a[y][x-1] == b[1][0]) &&
       (inField(y-1,x-1) && a[y-1][x-1] == b[0][0])) res++;
  
    if(b[1][1] == ch && 
       (inField(y-1,x) && a[y-1][x] == b[0][1]) && 
       (inField(y,x-1) && a[y][x-1] == b[1][0]) &&
       (inField(y-1,x-1) && a[y-1][x-1] == b[0][0])) res--;
  
    return res;
}
 
int main(){
    cin >> H >> W;
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    cin >> a[i][j];
	}
    }
    for(int i = 0 ; i < 2 ; i++){
	for(int j = 0 ; j < 2 ; j++){
	    cin >> b[i][j];
	}
    }
    int ans = 0;
    for(int i = 0 ; i < H-1 ; i++){
	for(int j = 0 ; j < W-1 ; j++){
	    for(int k = 0 ; k < 2 ; k++){
		for(int l = 0 ; l < 2 ; l++){
		    if(a[i+k][j+l] != b[k][l]){
			goto next;
		    }
		}
	    }
	    ans++;
	next:;
	}
    }
    int d = ans;
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    char tmp = a[i][j];
	    for(int k = 0 ; k < 3 ; k++){
		if(tmp == c[k]) continue;
		a[i][j] = c[k];
		ans = max(ans,d+Cnt(i,j,tmp));
	    }
	    a[i][j] = tmp;
	}
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 4088
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

const int Inf = 1000000000;
const int Maxm = 200005;
const int Maxl = 26;

int nxt[Maxm][Maxl];
char S[Maxm];
int slen;
int dp[Maxm];
int wth[Maxm];

int main()
{
	scanf("%s", S); slen = strlen(S);
	for (int i = 0; i < Maxl; i++)
		nxt[slen][i] = slen + 1;
	for (int i = slen - 1; i >= 0; i--)
		for (int j = 0; j < Maxl; j++)
			if (S[i] == 'a' + j) nxt[i][j] = i + 1;
			else nxt[i][j] = nxt[i + 1][j];
	for (int i = slen; i >= 0; i--) {
		dp[i] = Inf;
		for (int j = 0; j < Maxl; j++)
			if (1 + dp[nxt[i][j]] < dp[i]) {
				dp[i] = 1 + dp[nxt[i][j]];
				wth[i] = j;
			}
	}
	int cur = 0;
	while (cur <= slen) {
		printf("%c", wth[cur] + 'a');
		cur = nxt[cur][wth[cur]];
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 22272
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut cnts = vec![0; n];
    for _ in 0..m {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        cnts[a] += 1;
        cnts[b] += 1;
    }
    for i in 0..n {
        println!("{}", cnts[i]);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    string s;
    cin >> s;
    bool flag = false;
    int ans = 0, cnt = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'A')
        {
            flag = true;
        }
        if (flag)
        {
            cnt++;
        }
        if (s[i] == 'Z')
        {
            ans = cnt;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include"iostream"
#include"set"
using namespace std;
int main()
{
set<char>m;
string s;cin>>s;
for(int i=0;i<s.length();++i)
{
if(m.find(s[i])!=m.end())
{
cout<<"no\n";return 0;
}
else m.insert(s[i]);
}
cout<<"yes\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		//半径を入力
		Scanner sc = new Scanner(System.in);
		double r = sc.nextDouble();
		
		//結果を計算
		double area = r * r * Math.PI;
		double length = 2.0 * r * Math.PI;
		
		//結果を出力
		System.out.printf("%f %f",area,length);
	}
}


Measured memory_bytes: 28228
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
#define ls node + node
#define rs node + node + 1
//#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;

const int maxn = 4e5+5;
vector<int> G[maxn];
int dp[maxn], ans[maxn], mod;

void dfs(int now,int fa) {
	dp[now] = 1;
	for (int k:G[now]) {
		if (k != fa) {
			dfs(k, now);
			dp[now] = (dp[now] * (dp[k] + 1)) % mod;
		}
	}
}

struct SegMent_Tree {
	int seg[maxn * 4], tag[maxn * 4], val[maxn];
	void init(int node,int l,int r) {
		if (l == r) {
			seg[node] = 1;
			tag[node] = 1;
		}
		else {
			int m = (l + r) >> 1;
			init(ls, l, m);
			init(rs, m + 1, r);
			seg[node] = tag[node] = 1;
		}
	}
	void upd(int node,int l,int r,int ql,int qr,int val) {
		if (ql <= l && r <= qr) {
			tag[node] *= val;
			tag[node] %= mod;
		}
		else {
			int m = (l + r) >> 1;
			if (ql <= m) upd(ls, l, m, ql, qr, val);
			if (qr > m) upd(rs, m+1, r, ql, qr, val);
		}
	}
	void push(int node) {
		tag[ls] = (tag[node] * tag[ls]) % mod;
		tag[rs] = (tag[node] * tag[rs]) % mod;
	}
	void get_val(int node,int l,int r) {
		if (l == r) {
			val[l] = seg[node] * tag[node];
		}
		else {
			push(node);
			int m = (l + r) >> 1;
			get_val(ls, l, m);
			get_val(rs, m+1, r);
		}
	} 
} Seg;

void dfs2(int now,int fa,int val) {
	vector<int> Val;
	ans[now] = val;
	Seg.init(1, 0, SZ(G[now]));
	for (int i = 0; i < SZ(G[now]); i++) {
		if (G[now][i] == fa) continue;
		ans[now] = (ans[now] * (dp[G[now][i]] + 1)) % mod;
		if (i - 1 >= 0) {
			Seg.upd(1, 0, SZ(G[now]), 0, i - 1, dp[G[now][i]] + 1);
		}
		Seg.upd(1, 0, SZ(G[now]), i + 1, SZ(G[now]), dp[G[now][i]] + 1);
	}
	Seg.get_val(1, 0, SZ(G[now]));
	
	for (int i = 0; i < SZ(G[now]); i++) Val.pb(Seg.val[i]);
	for (int i = 0; i < SZ(G[now]); i++) {
		int k = G[now][i];
		if (k != fa) {		
//			cout << G[now][i] << " " << Seg.val[i] << " " << "\n";
 			dfs2(k, now, (val * Val[i] + 1) % mod);
		}
	} 
}

main() {
	IOS
	int n;
	cin >> n >> mod;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(1, 0);
//	cout << dp[1] << "W\n";
	dfs2(1, 0, 1);
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << "\n";
	}
}


Measured memory_bytes: 31496