akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
masu = [list(input()) for a in range(h)]
masu2 =  [[0 for a in range(w)] for a in range(h)]
for i in range(h):
    for j in range(w):
        a = 0
        if i > 0:
            a += masu[i-1][max(0,j-1):min(w,j+2)].count("#")
        a += masu[i][max(0,j-1):min(w,j+2)].count("#")
        if i < h - 1:
            a += masu[i+1][max(0,j-1):min(w,j+2)].count("#")
        if masu[i][j] =="#":
            masu2[i][j]="#"
        else:
            masu2[i][j]=str(a)
for a in masu2:
    print("".join(a))

Measured memory_bytes: 3188
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
int INF=2e+9+1;
int main(){
	int N;
	int X[200000];
	vint Xsort;
	scan(N);
	rep(i,N){
		scan(X[i]);
		Xsort.push_back(X[i]);
	}
	sort(Xsort.begin(),Xsort.end());
	rep(i,N){
		if(X[i]<=Xsort[N/2-1]) prin(Xsort[N/2]);
		else prin(Xsort[N/2-1]);
	}
	return 0;
}


Measured memory_bytes: 3828
N,K = map(int,input().split())
num = (10**5+1)*[0]
tot = 0

for n in range(N):
  a,b=map(int,input().split())
  num[a]+=b 

for n in range(10**5+1):
  tot+=num[n]
  if K<=tot:
    print(n)
    break

Measured memory_bytes: 5736
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A[3];
	rep(i, 0, 3)
	{
		cin >> A[i];
	}

	if (A[0] + A[1] + A[2] >= 22)
	{
		cout << "bust" << endl;
	}
	else
	{
		cout << "win" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
io = STDIN
N,Q=io.gets.split.map(&:to_i)
tree=Hash.new{|h,k|h[k]=[]}
score=Array.new(N,0)
visited=Array.new(N,false)
(N-1).times do
  a,b = io.gets.split.map(&:to_i)
  tree[a.pred] << b.pred
  tree[b.pred] << a.pred
end
Q.times do
  p,x=io.gets.split.map(&:to_i)
  score[p.pred]+=x
end
que=[0]
while n=que.shift
  visited[n]=true
  tree[n].each do |to|
    next if visited[to]
    score[to]+=score[n]
    que << to
  end
end
puts score.join(" ")


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

const int N = 1e5 + 5;

int f[N];

int n, m;

int main() {
#ifdef HOME
	freopen("agc14b.in", "r", stdin);
	freopen("agc14b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int a, b;

	cin >> n >> m;
	while (m--)
		cin >> a >> b, ++f[a], ++f[b];

	for (int i = 1; i <= n; ++i)
		if (f[i] % 2) {
			cout << "NO\n";
			return 0; }

	cout << "YES\n";

	return 0; }


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f

#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,a;

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>n;
    bool flag=true;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(a%2==0)
        {
            if(a%3==0||a%5==0)
                ;
            else
            {
                flag=false;
                break;
            }
        }
    }
    
    if(flag)
        cout<<"APPROVED";
    else
        cout<<"DENIED";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
int main(){
	int n=gi(),k=gi();
	puts(k<=n+1>>1?"YES":"NO");
	return 0;
}


Measured memory_bytes: 128
n, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_f)

sum = as.inject(:+)

as.reject! { |a| a < (sum.to_f * (1.0/(4.0*m))) }

if as.count >= m
  puts 'Yes'
else
  puts 'No'
end

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

int digit(int n){
    int ans=0;
    while(n>0){
        ans+=n%10;
        n/=10;
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    ll ans=MOD;
    for (int i=1;i<N;i++){
        ll sum=digit(i)+digit(N-i);
        ans=min(ans,sum);
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15); 
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] -= i + 1; 
    }
    sort(a.begin(), a.end());
    int mid = n / 2; 
    long long ans = 0; 
    for (int i = 0; i < n; ++i) {
        ans += abs(a[i] - a[mid]); 
    }
    cout << ans << endl; 
    return 0; 
}

Measured memory_bytes: 1024
//ÎÞÎýÇßÔ°ÊµÑéÐ¡Ñ§ ¹¨ÐÀâù
#include <bits/stdc++.h>
using namespace std;

int k[101];
int a[101];
int c[101];
int n, m, ans;

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
	{
		cin >> k[i];
		for (int j = 1; j <= k[i]; ++j)
		{
			cin >> a[j];
			if (a[j] == 1) c[1]++;
			if (a[j] == 2) c[2]++;
			if (a[j] == 3) c[3]++;
			if (a[j] == 4) c[4]++;
			if (a[j] == 5) c[5]++;
			if (a[j] == 6) c[6]++;
			if (a[j] == 7) c[7]++;
			if (a[j] == 8) c[8]++;
			if (a[j] == 9) c[9]++;
			if (a[j] == 10) c[10]++;
			if (a[j] == 11) c[11]++;
			if (a[j] == 12) c[12]++;
			if (a[j] == 13) c[13]++;
			if (a[j] == 14) c[14]++;
			if (a[j] == 15) c[15]++;
			if (a[j] == 16) c[16]++;
			if (a[j] == 17) c[17]++;
			if (a[j] == 18) c[18]++;
			if (a[j] == 19) c[19]++;
			if (a[j] == 20) c[20]++;
			if (a[j] == 21) c[21]++;
			if (a[j] == 22) c[22]++;
			if (a[j] == 23) c[23]++;
			if (a[j] == 24) c[24]++;
			if (a[j] == 25) c[25]++;
			if (a[j] == 26) c[26]++;
			if (a[j] == 27) c[27]++;
			if (a[j] == 28) c[28]++;
			if (a[j] == 29) c[29]++;
			if (a[j] == 30) c[30]++;
		}
	}
	for (int i = 1; i <= m; ++i)
		if (c[i] == n) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        s: chars,
    }
   let mut res:i64   = 0;
    for i in 0..n-2 {
        if s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' {
            res+=1;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
    int a, b, c, d;
    int p;
    int x = 0;
    int y = 0;
    
    scanf("%d %d %d %d", &a, &b, &c, &d);
    scanf("%d", &p);
    
    x = a * p;
    
    y = b;
    if (c <= p){
        y += (p - c) * d;
    }
    
    if (x < y){
        printf("%d\n", x);
    }
    else {
        printf("%d\n", y);
    }
    
    return (0);
    
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
  char c;
  cin>>c;
  if(c=='A')cout<<'T'<<endl;
  else if(c=='T')cout<<'A'<<endl;
  else if(c=='G')cout<<'C'<<endl;
  else cout<<'G'<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,m;
    cin >> n>> m;
    ll nn,mm;
    nn = n;
    mm = m;
    if(llabs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }
    ll answer = 1;
    if(n==m)answer*=2;
    REP(i,nn){
        //cout << n << endl;
        answer = answer*n%MOD;
        n--;
    }
    REP(i,mm){
        //cout << m << endl;
        answer = answer*m%MOD;
        m--;
    }

    cout << answer << endl;

    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	ll N;
	cin >> N;
	vector<int> L(N);
	rep(i, N) cin >> L[i];
	sort(L.begin(), L.end());

	vector<ll> dp; // dp[i]: L[i+2] までの棒を使用する．

	// dp[i+1] = (i+1番目を必ず使用) + dp[i];
	if(L[0]+L[1]>L[2]) dp.push_back(1);
	else dp.push_back(0);

	for(int i=1; i<N-2; i++) {
		int cnt = 0;

	/* 打ち切りや2分探索で高速化できる． */
  	for(int j = i-1+2; j>0; j--) {
			if(L[j]+L[j-1]<=L[i+1]) break; //
			for(int k = j-1; k>=0; k--) {
				if(L[j]+L[k]>L[i+2]) cnt++;
				else break;
				// cout << "cnt " << cnt << ' ' << L[i+2] << ' '<< L[j] << ' '<< L[k] << endl;
			}
		}

		dp.push_back(dp[i-1] + cnt);
		// cout << "dp[i]: " << dp[i] << endl;
	}

	cout << dp[N-3] << endl;

	return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;
  int vec_a[n][m];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>vec_a[i][j];
    }
  }
  int vec_b[m][1];
  for(int i=0;i<m;i++){
    cin>>vec_b[i][0];
  }
  int vec_c[n][1];
  for(int i=0;i<n;i++){
    int tmp=0;
    for(int j=0;j<m;j++){
      tmp+=vec_a[i][j]*vec_b[j][0];
    }
    vec_c[i][0]=tmp;
  }
  for(int i=0;i<n;i++){
    cout<<vec_c[i][0]<<endl;
  }
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int main() {
	int n, m;
	scanf( "%d %d", &n, &m );
	printf( "%d\n", n * m );
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <tuple>
using namespace std;

vector<int>G[1 << 18]; int group[1 << 18];

void init() {
	for (int i = 0; i < (1 << 18); i++) { G[i].push_back(i); group[i] = i; }
}

long long unite(int u, int v) {
	u = group[u]; v = group[v];
	if (G[u].size() < G[v].size()) swap(u, v);

	long long val = 1LL * (long long)(G[u].size()) * (long long)(G[v].size());

	for (int i = 0; i < G[v].size(); i++) {
		group[G[v][i]] = u;
		G[u].push_back(G[v][i]);
	}
	return val;
}

long long N, M, A[1 << 18], B[1 << 18], ans[1 << 18];

int main() {
	cin >> N >> M; init();
	for (int i = 1; i <= M; i++) cin >> A[i] >> B[i];
	ans[M] = N * (N - 1) / 2;

	for (int i = M; i >= 2; i--) {
		if (group[A[i]] != group[B[i]]) {
			long long t = unite(A[i], B[i]);
			ans[i - 1] = ans[i] - t;
		}
		else ans[i - 1] = ans[i];
	}
	for (int i = 1; i <= M; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 25464
using System;

class Program
{
    static void Main(string[] args)
    {
        //入力
        string S = Console.ReadLine();

        Console.WriteLine( ManyFormulas(S, 0) );

    }

    static ulong ManyFormulas(string s, int begin)
    {
        ulong ret = 0;
        for(int i = begin; i < s.Length; i++)
        {
            ret += (ulong.Parse(s.Substring(begin, i - begin + 1)) << Math.Max(0, s.Length - i - 2));
            ret += ManyFormulas(s, i + 1);
        }
        return ret;
    }
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int a[n];
    int odd = 0, even = 0;


    rep(i, n) {
        cin >> a[i];
        if(a[i]%2 == 0){
            ++even;
        }
        else{
            ++odd;
        }
    }

    JUDGE(!(odd%2));


    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

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

//********************************template END****************************************//

typedef pair<string, string> strP;

void solve(void){

	int N;
	string S;
	cin >> N >> S;

	ll ans = 0;

	map <strP, ll> yui, inori;

	rep((1<<N), bit)
	{
		string red = "", blue = "";
		rep(N, i)
		{
			if (bit >> i & 1)
			{
				red += S[i];
			}
			else
			{
				blue += S[i];
			}
		}
		if (red == "")
		{
			continue;
		}
		reverse(all(red));
		yui[strP(red, blue)]++;
	}
	rep((1<<N), bit)
	{
		string red = "", blue = "";
		rep(N, i)
		{
			if (bit >> i & 1)
			{
				red += S[N+i];
			}
			else
			{
				blue += S[N+i];
			}
		}
		if (red == "")
		{
			continue;
		}
		reverse(all(blue));
		inori[strP(red, blue)]++;
	}

	for (auto p : yui)
	{
		strP q = strP(p.fst.fst, p.fst.snd);
		/*
		if (p.snd && inori[q])
		{
			cout << p.fst.fst << ' ' << p.fst.snd << endl;
		}*/

		ans += p.snd * inori[q];
	}

	int f = 1;

	rep(N, i)
	{
		f &= S[i] == S[2*N-1-i];
	}

	ans += f;

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

using namespace std;

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

const int MAX_N=1e2;

int N;
int L[MAX_N*2];

int main(){
	cin>>N;
	REP(i,2*N){
		cin>>L[i];
	}
	sort(L,L+2*N);
	int ans=0;
	REP(i,N){
		ans+=L[i*2];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int c, n, m;
    cin >> c >> n >> m;
    vector<ll> dp(c+1, -INF<ll>);
    dp[0] = 0;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &v[i].first, &v[i].second);
    }
    sort(v.begin(),v.end());
    for (int j = 0; j < n; ++j) {
        for (int i = c; i >= v[j].first; --i) {
            dp[i] = max(dp[i], dp[i-v[j].first]+v[j].second);
        }
    }
    for (int i = 0; i < c; ++i) {
        dp[i+1] = max(dp[i+1], dp[i]);
    }
    for (int i = 1; i <= m; ++i) {
        cout << dp[c/i]*i << "\n";
    }
    return 0;
}


Measured memory_bytes: 3360
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;


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

	ll N;
	cin >> N;

	vector<P> e;

	if (N % 2 == 0)
	{
		for (ll i = 1; i <= N; ++i)
		{
			for (ll j = i + 1; j <= N; ++j)
			{
				if (i + j == N + 1)
				{
					continue;
				}

				e.emplace_back(i, j);
			}
		}
	}
	else
	{
		for (ll i = 1; i <= N; ++i)
		{
			for (ll j = i + 1; j <= N; ++j)
			{
				if (i + j == N)
				{
					continue;
				}

				e.emplace_back(i, j);
			}
		}
	}

	cout << e.size() << "\n";

	for (const auto& ee : e)
	{
		cout << ee.first << " " << ee.second << "\n";
	}

	//system("pause");
}

Measured memory_bytes: 512
def main():
    n, *xy = map(int, open(0).read().split())
    f = [(i - j, i + j) for i, j in zip(xy[::2], xy[1::2])]

    a = max(x[0] for x in f)
    b = min(x[0] for x in f)

    c = max(x[1] for x in f)
    d = min(x[1] for x in f)

    ans = max(a - b, c - d)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

bool cmp(int a, int b)
{
    return a < b;
}

int main()
{
    int N, i, t, s = 0;
    vector<int> l;

    cin >> N;

    for (i = 0; i < N; i++)
    {
        cin >> t;
        l.push_back(t);
    }

    sort(l.begin(), l.end(), cmp);

    for (t = 0; t < i - 1; t++)
        s += l[t];

    if (s > l[t])
        cout << "Yes";
    else
        cout << "No";

    return 0;
}

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

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

  int n, x;
  cin >> n >> x;

  int mn = ~(1 << 31);
  for (int i = 0; i < n; ++i) {
    int y; cin >> y;
    x -= y;
    mn = min(mn, y);
  }

  int res = n;
  cout << res + (x / mn) << "\n";
}


Measured memory_bytes: 3652
from collections import deque

h, w = map(int, input().split())
grid = ["#" * (w + 2)]
grid += ["#" + input() + "#" for _ in range(h)]
grid += ["#" * (w + 2)]
move = ((1, 0), (-1, 0), (0, 1), (0, -1))

ans = 0
for i, j in enumerate(grid):
    for k, l in enumerate(j):
        if l == ".":
            done = [[-1 for _ in range(w + 2)] for _ in range(h + 2)]
            done[i][k] = 0
            todo = deque([(i, k)])
            while todo:
                n, m = todo.popleft()
                d = done[n][m]
                for dn, dm in move:
                    if grid[n + dn][m + dm] == "#":
                        pass
                    elif done[n + dn][m + dm] >= 0:
                        pass
                    elif grid[n + dn][m + dm] == ".":
                        todo.append((n + dn, m + dm))
                        done[n + dn][m + dm] = d + 1
            for x in done:
                for y in x:
                    ans = max(ans, y)
print(ans)

Measured memory_bytes: 3316
n, a, b, c, d = map(int, input().split())

a, b = 0, abs(b-a)
if b > (n-1) * d:
    print('NO')
    exit()
if (n-1) * c <= b <= (n-1) * d:
    print('YES')
    exit()

if c == d:
    if b % c == 0 and b // c <= n-1:
        print('YES')
    else:
        print('NO')
    exit()

if (b//d) % 2 == (n-1)%2:
    diff1 = b - (b//d) * d
    if (diff1 - 1) // (d-c) + 1 <= (n-1 - (b//d)) // 2:
        print('YES')
        exit()
else:
    diff1 = b - (b//d - 1) * d
    if (diff1 - 1) // (d-c) + 1 <= (n-1 - (b//d - 1)) // 2:
        print('YES')
        exit()

if (((b-1)//c)+1) % 2 == (n-1)%2:
    diff2 = (((b-1)//c)+1) * c - b
    if (diff2-1) // (d-c) + 1 <= (n-1 - (((b-1)//c)+1)) // 2:
        print('YES')
        exit()
else:
    diff2 = (((b-1)//c)+2) * c - b
    if (diff2-1) // (d-c) + 1 <= (n-1 - (((b-1)//c)+2)) // 2:
        print('YES')
        exit()

print('NO')


Measured memory_bytes: 38384
import sys
input = sys.stdin.readline
def main():
  n,k=map(int,input().split())
  mod=pow(10,9)+7
  ans=0
  def ncr_mod(n,r,mod):
    a,b=1,1
    for i in range(r):
      a*=n-i
      a%=mod
      b*=i+1
      b%=mod
    return (a*pow(b,mod-2,mod))%mod
  for i in range(1,k+1):
    a=ncr_mod(n-k+1,i,mod)
    b=ncr_mod(k-1,i-1,mod)
    print((a*b)%mod)
if __name__=='__main__':
  main()


Measured memory_bytes: 3316
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
  std::ios_base::sync_with_stdio(false);
  map<string,bool> mp;
  int n;
  cin >> n;
  while(n--){
    string BUFF,c;
    cin >> BUFF >> c;
    if(BUFF=="insert") mp[c] = true;
    else cout << (mp[c]?"yes":"no") << endl;
  }
}

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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , x ;
const int N = 200 ;
int d[ N ] ;

int main() {

   cin >> n >> x ;
   vector < int > a( n + 1 ) ;
   forn( int , i , 1 , n + 1 ){
     cin >> a[ i ] ;
   }


   forn( int , i , 0 , n + 2 ){
      d[ i + 1 ] = d[ i ] + a[ i ] ;
   }

   int cnt = 0 ;

   forn( int , i , 1 , n + 2 )
     if( d[ i ] <= x ) cnt++ ;

   cout << cnt ;

   return 0 ;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int d[16][16];


int main() {

	int max = 0;

	int N;

	cin >> N;

	rep(i, N)rep(j, N)d[i][j] = -1;

	int A, x;

	rep(i, N) {
		cin >> A;
		rep(j, A) {
			cin >> x; 
			cin >> d[i][x-1];
		}
	}

	

	rep(i, 1 << N) {

		bool rF = true;
		int cnt = 0;
		vector<int> rd(N);
		rep(j, N) {
			
			if (i >> j & 1) { rd[j] = 1; cnt++; }

		}

		rep(j, N) {

			if (rd[j]) {
				rep(p, N) {
					if (d[j][p] == -1) { continue; }

					if (d[j][p] != rd[p]) { rF = false;  }

				}
			}

			
		}

		if (rF) { if (max < cnt) { max = cnt; }}

	}

	cout << max << endl;

	return 0;

}

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

typedef long long int64;

int main() {
  int k, x;
  scanf("%d", &k);
  scanf("%d", &x);

  int start = x - k + 1;
  int end = x + k;

  for(int i = start; i < end; i++){
    if(i==end-1) printf("%d\n",i);
    else printf("%d ",i);
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912 2の29乗
const long double PI = acos(-1);
const ll DEP = 1e18;
const int I = 1001001001001001ll;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    string s; cin >> s;
    string t1 = s.substr(0,2), t2 = s.substr(2,2);
    //cout << t1 << " " << t2 << endl;
    int t3 = stoi(t1);
    int t4 = stoi(t2);
    if(t4 <= 12 && t4 >= 1 && 1 <= t3 && t3 <= 12){
        cout << "AMBIGUOUS" << endl;
    } else if(t3 <= 12 && t3 >= 1){
        cout << "MMYY" << endl;
    } else if(t4 <= 12 && t4 >= 1){
        cout << "YYMM" << endl;
    } else {
        //cout << t3 << t4 << endl;
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
aA = [int(_) for _ in input().split()]
iM = min(aA)
i0,i1,i2 = sorted([a - iM for a in aA])

if i1 % 2 :
    print((i1+1)//2 + i2-i1 + 1)
else:
    print( i2-i1 //2)


Measured memory_bytes: 2940
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}


int main(){
  ll w,a,b; cin >> w >> a >> b;
  
  if(a <= b and b <= a+w) cout << 0 << endl;
  else cout << min(abs(b-a-w),abs(a-b-w)) << endl;
                   
}

Measured memory_bytes: 3616
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N = list(map(int, input().split()))
        H = list(map(int, input().split()))
    else:
        pass

    max = 0
    count = 0
    for h in H:
        if max <= h:
            count += 1
            max = h
    print(count)

if __name__ =='__main__':
    main()

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve(){
	string s;
	cin>>s;
	bool n=0,so=0,e=0,w=0;
	for(auto i:s)
		if(i=='N')
			n=true;
		else if(i=='S')
			so=true;
		else if(i=='E')
			e=true;
		else 
			w=true;
	puts(!(n^so) && !(e^w)?"Yes":"No");

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
use std::io;
use std::collections::HashSet;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn read_pair() -> (i32, i32) {
    let s = read_line();
    let mut it = s.split_whitespace().map(|s| s.parse().unwrap());
    let h = it.next().unwrap();
    let w = it.next().unwrap();
    (h, w)
}

struct UnionFind {
    parent: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).collect(),
        }
    }

    fn find(&mut self, i: usize) -> usize {
        if self.parent[i] == i {
            return i;
        }

        let p = self.parent[i];
        let p = self.find(p);
        self.parent[i] = p;
        p
    }

    fn unite(&mut self, i: usize, j: usize) {
        let pi = self.find(i);
        let pj = self.find(j);
        self.parent[pi] = pj;
    }
}

fn main() {
    let (n, m) = read_pair();
    let vs: Vec<(i32, i32)> = (0..m).map(|_| read_pair()).collect();

    let mut ans = 0;

    for i in 0..vs.len() {
        let mut uf = UnionFind::new(n as usize);
        for j in 0..vs.len() {
            if i != j {
                uf.unite((vs[j].0 - 1) as usize, (vs[j].1 - 1) as usize);
            }
        }

        let mut ss = HashSet::new();
        for j in 0..n {
            ss.insert(uf.find(j as usize));
        }

        if ss.len() != 1 {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import heapq
X, Y, A, B, C = map(int, input().split())
P = sorted([int(i) for i in input().split()], reverse=True)
Q = sorted([int(i) for i in input().split()], reverse=True)
R = sorted([int(i) for i in input().split()], reverse=True)


hq = P[:X]+Q[:Y]
ans = sum(hq)
heapq.heapify(hq)  # リストhqのheap化

i = 0
while hq and i < len(R):
    t = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    if R[i] > t:
        ans = ans - t + R[i]
        i += 1
    else:
        break
print(ans)


Measured memory_bytes: 23456
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
bool is_palindrome(const std::string str) {
	for (auto i = 0; i < str.size() - i; ++i) {
		if (str[i] != str[str.size() - i - 1])
			return false;
	}
	return true;
}
constexpr long long int MOD = 1000000007;
long long int power(const long long int base, const int exp) {
	switch (exp) {
	case 0: return 1LL;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
	}
}
long long int small(const std::string zaki, const std::string o, const int n) {
	std::string str(zaki.size() + o.size() + (n << 1), ' ');
	std::vector<int> pair(str.size(), -1);
	for (auto i = 0; i < zaki.size(); ++i) {
		str[n + i] = zaki[i];
	}
	for (auto i = 0; i < o.size(); ++i) {
		str[(n << 1) + zaki.size() + i] = o[i];
	}
	for (auto i = 0; i < n; ++i) {
		pair[i] = i + n + zaki.size();
		pair[i + n + zaki.size()] = i;
	}
	for (auto i = 0; i < str.size(); ++i) {
		const auto left = str[i];
		const auto right = str[str.size() - i - 1];
		if (left != ' ' && right != ' ' && left != right)
			return 0;
		if (right != ' ') str[i] = right;
		if (left != ' ') str[str.size() - i - 1] = left;
		if (pair[i] != -1) {
			if (str[i] != ' ' && str[pair[i]] != ' ' && str[i] != str[pair[i]])
				return 0;
			if (str[i] != ' ') str[pair[i]] = str[i];
			if (str[pair[i]] != ' ') str[i] = str[pair[i]];
		}
	}

	long long int result = 1;
	for (auto i = 0; i < ((str.size() + 1) >> 1); ++i) {
		if (str[i] == ' ') {
			result = (result * 26) % MOD;
			str[pair[i]] = 'a';
		}
	}
	return result;

}

long long int large(const std::string zaki, const std::string o, const int n) {
	if (zaki.size() >= o.size()) {
		if (!is_palindrome(zaki.substr(o.size())))
			return 0;
		auto zaki_sub = zaki.substr(0, o.size());
		for (auto i = 0; i < o.size(); ++i) {
			if (o[i] != zaki_sub[i])
				return 0;
		}
		return power(26, (n - o.size() + 1) >> 1);
	}
	else {
		if (!is_palindrome(o.substr(zaki.size())))
			return 0;
		auto o_sub = o.substr(0, zaki.size());
		for (auto i = 0; i < zaki.size(); ++i) {
			if (zaki[i] != o_sub[i])
				return 0;
		}
		return power(26, (n - o.size() + 1) >> 1);
	}
}
int main() {
	std::string zaki, o; int n; std::cin >> zaki >> o >> n;
	if (n >= o.size()) {
		std::cout << large(zaki, o, n) << '\n';
	}
	else {
		std::cout << small(zaki, o, n) << '\n';
	}
}


Measured memory_bytes: 3676
#include<stdio.h>
int n,k;
int a[200010];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    for(int i=k+1;i<=n;i++){
        if(a[i]>a[i-k]) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 2400
import java.util.*;
 
public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String[] s = new String[N];
        Map<String, Integer> map = new HashMap<>();
        for(int i = 0; i < N; i++){
            s[i] = sc.next();
            if(map.containsKey(s[i]))
                map.put(s[i], map.get(s[i]) + 1);
            else
                map.put(s[i], 1);
        }
        int M = sc.nextInt();
        String[] t = new String[M];
        for(int i = 0; i < M; i++){
            t[i] = sc.next();
            if(map.containsKey(t[i])){
                map.put(t[i], map.get(t[i]) - 1);
            }
        }
        sc.close();

        int max = 0;
        for(String key: map.keySet()){
            max = Math.max(max, map.get(key));
        }

        System.out.println(max);        
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
using ll=long long;
using vi=vector<ll>;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
int main() {
  ll n,a,b,c;
  cin>>n>>a>>b>>c;
  vector<string> s(n);
  rep(i,n) cin>>s[i];
  bool f=true;
  string t="";
  rep(i,n){
    if(s[i]=="AB"){
      if(a+b==0){
        f=false;
        break;
      }
      else{
        if(a<b||(a==b&&i<n-1&&s[i+1]!="BC")){
          t+="A";
          a++; b--;
        }
        else{
          t+="B";
          a--; b++;
        }
      }
    }
    else if(s[i]=="AC"){
      if(a+c==0){
        f=false;
        break;
      }
      else{
        if(a<c||(a==c&&i<n-1&&s[i+1]!="BC")){
          t+="A";
          a++; c--;
        }
        else{
          t+="C";
          a--; c++;
        }
      }
    }
    else{
      if(b+c==0){
        f=false;
        break;
      }
      else{
        if(b<c||(b==c&&i<n-1&&s[i+1]!="AC")){
          t+="B";
          b++; c--;
        }
        else{
          t+="C";
          b--; c++;
        }
      }
    }
  }
  YesNo(f);
  if(f){
    rep(i,n) out(t[i]);
  }
}

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

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

    int n;
    cin >> n;
    long long A[n][n];
    bool F[n][n];
    REP(i, n){
        REP(j, n){
            cin >> A[i][j];
            F[i][j] = true;
        }
    }

    REP(i, n){
        REP(j, n){
            REP(k, n){
                if(A[j][i] + A[i][k] < A[j][k]){
                    cout << -1 << endl;
                    return 0;
                }else if(A[j][i] + A[i][k] == A[j][k] and i != j and i != k){
                    F[j][k] = false;
                }
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(F[i][j]) ans += A[i][j];
        }
        cout << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

const int N=100010;
int n;
char ch[N];

int main()
{
    int i;
    scanf("%d\n",&n);
    for(i=1;i<=n;++i)scanf("%c",&ch[i]);ch[0]='#';
    int ans=0;
    for(i=1;i<=n;++i)
    {
        if(ch[i]!=ch[i-1])ans++;
    }
    printf("%d",ans);

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
vector<pii> g[525];
int v0,a,b,c;

ll dist[525*50];
ll dist2[50][525*50];

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int x,y,t;
    scanf("%d%d%d",&x,&y,&t);
    --x;--y;
    g[x].push_back(pii(y,t));
    g[y].push_back(pii(x,t));
  }
  scanf("%d%d%d%d",&v0,&a,&b,&c);
  priority_queue<pll> Q;
  REP(i,n*50)dist[i] = 1e18;
  dist[0*50 + v0] = 0;
  Q.push(pll(-0, 0*50+v0));
  while(!Q.empty()){
    pll P = Q.top(); Q.pop();
    int pos = P.second;
    if(-P.first != dist[pos])continue;
    int p = pos/50;
    int v = pos%50;
    int nv = (a*v+b)%c;
    for(pii P : g[p]){
      int to = P.first;
      int tt = P.second;
      ll ndist = dist[pos] + (ll)tt*v;
      if(ndist < dist[to*50 + nv]){
        dist[to*50+nv] = ndist;
        Q.push(pll(-ndist, to*50 + nv));
      }
    }
  }

  REP(v1,50){
    REP(i,n*50)dist2[v1][i] = 1e18;
    dist2[v1][(n-1)*50+v1] = 0;
    Q.push(pll(-0, (n-1)*50+v1));
    while(!Q.empty()){
      pll P = Q.top(); Q.pop();
      int pos = P.second;
      if(-P.first != dist2[v1][pos])continue;
      int p = pos/50;
      int v = pos%50;
      int nv = (a*v+b)%c;
      for(pii P : g[p]){
        int to = P.first;
        int tt = P.second;
        ll ndist = dist2[v1][pos] + (ll)tt*v;
        if(ndist < dist2[v1][to*50 + nv]){
          dist2[v1][to*50+nv] = ndist;
          Q.push(pll(-ndist, to*50 + nv));
        }
      }
    }
  }

  ll ans = 1e18;
  REP(i,c)REP(j,c){
    CHMIN(ans, dist[(n-1)*50+i] + dist2[i][0+j]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 13600
#include<cstdio>
#define N 3003
#define ll long long
inline int calc(int x,int y,int m)
{
	int z=1;
	for(;y;x=(ll)x*x%m,y>>=1)if(y&1)z=(ll)x*z%m;
	return z;
}
int a[N],b[N],f[N][N],g[N],i,j,m,n,s,t;
int main()
{
	scanf("%d%d",&n,&m),*a=a[1]=*b=b[1]=1;
	for(i=2;i<=n;i++)a[i]=(ll)a[i-1]*i%m,b[i]=(ll)(m-m/i)*b[m%i]%m;
	for(i=1;i<=n;i++)b[i]=(ll)b[i-1]*b[i]%m;
	for(i=0;i<=n;i++)for(j=f[i][0]=1;j<=i;j++)f[i][j]=(f[i-1][j-1]+f[i-1][j]*(j+1ll))%m;
	for(i=n,s=1;i>=0;i--,s=(s<<1)%m)for(j=0,t=1;j<=i;j++,t=(ll)s*t%m)g[i]=(g[i]+(ll)f[i][j]*t)%m;
	for(i=s=0;i<=n;i++)i&1?s=(s+(ll)(m-a[n])*b[i]%m*b[n-i]%m*g[i]%m*calc(2,calc(2,n-i,m-1),m))%m:s=(s+(ll)a[n]*b[i]%m*b[n-i]%m*g[i]%m*calc(2,calc(2,n-i,m-1),m))%m;
	return 0*printf("%d\n",s);
}

Measured memory_bytes: 34176
import math
def resolve():
    n = int(input())
    ans = len(str(n))
    MAX = int(math.sqrt(n))

    for a in range(1, MAX + 1):
        if n % a != 0:
            continue
        b = int(n / a)
        tmp = max(len(str(a)), len(str(b)))
        ans = min(ans, tmp)

    print(ans)
    return

resolve()


Measured memory_bytes: 9012
N = int(input())

now = [0, 0]
for i in range(N):
  t, x, y = map(int, input().split())
  time = abs(x - now[0]) + abs(y - now[1])
  if t >= time and (t - time)%2==0:
    continue
  print('No')
  quit()

print('Yes')

Measured memory_bytes: 3060
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(M)]
ab = sorted(ab, key=lambda x:x[1])

cut_set = set()

for t in ab:
    todo = 1
    for s in cut_set:
        if t[0] <= s <= t[1]:
            todo = 0
            break
    if todo:
        cut_set.add(t[1] - 1)
print(len(cut_set))


Measured memory_bytes: 19012
#include<bits/stdc++.h>
#define N 100001
using namespace std;
long long c;
int x[N],w[N],ans[N];
int main()
{
	int n,L,t;
    scanf("%d%d%d",&n,&L,&t);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x[i],&w[i]);
    }
    for(int i=1;i<=n;i++)
    {
        if(w[i]==2)w[i]=-1;
        int r=x[i]+w[i]*t;
        if(r>0) 
        {
        	(c+=r/L)%=n;
		}
        else if(r<0)
        {
        	(c+=(r+1)/L-1)%=n;
		}
        ans[i]=(r%L+L)%L;
    }
    sort(ans+1,ans+n+1);
    c=(c+n)%n;
    for(int i=c+1;i<=n;i++)
    {
        printf("%d\n",ans[i]);
    }
    for(int i=1;i<=c;i++)
    {
       printf("%d\n",ans[i]); 
    }
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, u, w, z, N, M;
	scanf("%d %d", &N, &M);
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * M * 2);
	for (i = 1; i <= N; i++) adj[i] = NULL;
	for (i = 0; i < M; i++) {
		scanf("%d %d %d", &u, &w, &z);
		d[i*2].v = w;
		d[i*2+1].v = u;
		d[i*2].next = adj[u];
		d[i*2+1].next = adj[w];
		adj[u] = &(d[i*2]);
		adj[w] = &(d[i*2+1]);
	}
	
	int k, flag[100001] = {}, q[100001], head, tail;
	list *p;
	for (i = 1, k = 0; i <= N; i++) {
		if (flag[i] != 0) continue;
		flag[i] = ++k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = adj[q[head]]; p != NULL; p = p->next) {
				if (flag[p->v] == 0) {
					flag[p->v] = k;
					q[tail++] = p->v;
				}
			}
		}
	}
	
	printf("%d\n", k);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6336
n, m = map(int, input().split())
ps = []
for _ in range(m):
    p, s = input().split()
    ps.append((int(p), s))
was = [0]*(n+1)
total_ac = 0
total_wa = 0
for p, s in ps:
    if was[p]<0:
        continue
    if s=='AC':
        total_wa += was[p]
        total_ac += 1
        was[p] = -1
    else:
        was[p] += 1
print(total_ac, total_wa)


Measured memory_bytes: 19720
def solve(string):
    x, y, z, k, *abc = map(int, string.split())
    a = abc[:x]
    b = abc[x:x + y]
    c = abc[x + y:]
    ab = sorted([_a + _b for _b in b for _a in a])[-k:]
    *abc, = map(str, sorted([_ab + _c for _c in c for _ab in ab], reverse=True)[:k])
    return "\n".join(abc)


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))


Measured memory_bytes: 185840