akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define maxn 60
#define maxm 10000
#define INF 1e9
using namespace std;
struct Edge
{
	int v,w,next;
}edge[maxm];
struct node
{
	int u,d;
	bool operator<(const node &rhs)const
	{
		return d>rhs.d;
	}
};
int n,m,head[maxn],tot;
int wi[maxn],h[maxn];
int d1[maxn][maxn],d2[maxn][maxn];
long long path1[maxn][maxn],path2[maxn][maxn];
long long ans[maxn][maxn];
bool done[maxn];
inline void addedge(int u,int v,int w)
{
	edge[tot].v=v;
	edge[tot].w=w;
	edge[tot].next=head[u];
	head[u]=tot++;
}
void Dijkstra1(int s,int *d,long long *path)
{
	priority_queue<node>q;
	for(int i=0;i<n;i++)
		d[i]=INF;
	d[s]=wi[s];
	path[s]=(1LL<<s);
	memset(done,0,sizeof(done));
	node tmp;tmp.u=s;tmp.d=wi[s];q.push(tmp);
	while(!q.empty())
	{
		node now=q.top();
		q.pop();
		int u=now.u;
		if(done[u])
			continue;
		done[u]=1;
		for(int e=head[u];e!=-1;e=edge[e].next)
		{
			int v=edge[e].v;
			int w=edge[e].w;
			if(h[u]<=h[v])
			{
				if(d[v]>d[u]+w+wi[v])
				{
					d[v]=d[u]+w+wi[v];
					path[v]=path[u]|(1LL<<v);
					tmp.u=v;tmp.d=d[v];
					q.push(tmp);
				}
			}
		}
	}
}
void Dijkstra2(int s,int *d,long long *path)
{
	priority_queue<node>q;
	for(int i=0;i<n;i++)
		d[i]=INF;
	d[s]=wi[s];path[s]=(1LL<<s);
	node tmp;tmp.u=s;tmp.d=wi[s];
	q.push(tmp);
	memset(done,0,sizeof(done));
	while(!q.empty())
	{
		node now=q.top();
		q.pop();
		int u=now.u;
		if(done[u])
			continue;
		done[u]=1;
		for(int e=head[u];e!=-1;e=edge[e].next)
		{
			int v=edge[e].v;
			int w=edge[e].w;
			if(h[u]>=h[v])
			{
				if(d[v]>d[u]+wi[v]+w)
				{
					d[v]=d[u]+w+wi[v];
					path[v]=path[u]|(1LL<<v);
					tmp.u=v;tmp.d=d[v];
					q.push(tmp);
				}
			}
		}
	}
}
void Floyd()
{
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)
		if(i!=j)
			ans[i][j]=INF;
		else
			ans[i][j]=0;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++)
	{
		if(i==j)
			continue;
		ans[i][j]=d1[i][j]+d2[j][i];
		for(int k=0;k<n;k++)
		{
			if(((1LL<<k)&path1[i][j])&&((1LL<<k)&path2[j][i]))
				ans[i][j]-=wi[k];
		}
	}
	for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)
	{
		if(i==j||i==k||k==j)
			continue;
		ans[i][j]=min(ans[i][j],ans[i][k]+ans[k][j]-wi[k]);
	}
}
int main()
{
	while(scanf("%d%d",&n,&m),n+m)
	{
		wi[0]=wi[n-1]=0;
		h[0]=0;h[n-1]=1000;
		memset(head,-1,sizeof(head));tot=0;
		for(int i=1;i<n-1;i++)
			scanf("%d%d",&wi[i],&h[i]);
		for(int i=0;i<m;i++)
		{
			int u,v,w;
			scanf("%d%d%d",&u,&v,&w);
			u--;v--;
			addedge(u,v,w);
		}
		for(int i=0;i<n;i++)
			Dijkstra1(i,d1[i],path1[i]);
		for(int i=0;i<n;i++)
			Dijkstra2(i,d2[i],path2[i]);
		Floyd();
		if(ans[0][n-1]>=INF)
			printf("-1\n");
		else
			printf("%lld\n",ans[0][n-1])
;	}
}

Measured memory_bytes: 1212
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N, H, W;
    cin >> N >> H >> W;

    int ans = 0;
    REP(i, N) {
        REP(j , N) {
            if (i + H <= N && j + W <= N) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
using namespace std;


 
//階乗先に計算
long long int kaizyou[200005] = { 1 };
long long int kai(long long int a, long long int b, long long int mod) {
             long long int tmp = 1;
             for (long long int i = a; i <= b; i++) {
                           tmp *= i;
                           tmp %= mod;
 
                           kaizyou[i] = tmp;
             }
             return tmp;
}
 
 
//累乗(繰り返し2乗法)　aのb乗(mod)を求める。
long long int rui(long long int a, long long int b, long long mod) {
             int memo[65] = {};
             long long int A[65] = {};
             long long int tmp = 1;
             for (int i = 0; i < 65; i++) {
                           memo[i] = b % 2;
                           b /= 2;
             }
 
             A[0] = a;
             A[0] %= mod;
 
             for (int i = 1; i < 65; i++) {
                           A[i] = A[i - 1] * A[i - 1];
                           A[i] %= mod;
             }
             for (int i = 0; i < 65; i++) {
                           if (memo[i] == 1) {
                                        tmp *= A[i];
                                        tmp %= mod;
                           }
             }
             tmp %= mod;
             return tmp;
}
 
//コンビネーション計算
long long int comb(long long int n, long long int r, long long int mod) {
             long long int tmp;
 
             tmp = (kaizyou[n] * rui(kaizyou[r], mod - 2, mod)) % mod;
             tmp *= rui(kaizyou[n - r], mod - 2, mod);
             tmp %= mod;
             if (tmp < 0) { tmp = (mod - tmp) % mod; }
             return tmp;
}
 

int main() {
	long long int n,dp[5500],mod=1000000007,two[6000]={1},three[6000]={1},res=0,tmp,l,r,tmp2;
	queue<int>que;
	string str;
	int count=0;
	cin>>n;
	cout<<0<<endl;
	cin>>str;
	if(str=="Vacant")
	{
		return 0;
	}else if(str=="Male"){
		tmp=0;
	}else {
		tmp=1;
	}
	l=0,r=n;
	while(1)
	{
		long long int mid=(r+l)/2;
		cout<<mid<<endl;
		cin>>str;
		if(str=="Vacant")
		{
			return 0;
		}else if(str=="Male"){
			tmp2=0;
		}else {
			tmp2=1;
		}
		if(tmp==tmp2&&mid%2==0||tmp2!=tmp&&mid%2==1)
		{
			l=mid;
		}else
		{
			r=mid;
		}
	}
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
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; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

#define PI 3.14159265358979

int main(){
	ll N;
	cin >> N;
	vvll G(N, vll(0));
	for(int i = 1; i < N; i++){
		int A;
		cin >> A;
		A--;
		G.at(A).push_back(i);
	}
	for(int i = 0; i < N; i++){
		cout << G.at(i).size() << endl;
	}
}

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

int main() {
    string n;
    string ans = "No";
    cin >> n;
    if ((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])) ans = "Yes";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  int a[5] = {}, k;
  REP(i,5)cin >> a[i];
  cin >> k;
  REP(i,4)FOR(j,i + 1,5){
    if(a[j] - a[i] > k){
      cout << ":(" << endl;
      return 0;
    }
  }
  cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define vii vector<ll>
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define pb push_back
#define ii pair<int,int>
#define iii pair<ll,ll>
#define MAX 10000000000000
#define pi 3.1415926535
typedef long long ll;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    vector<vector<char> > v(n,vector<char> (m));
    vector<vii> dp(n, vii(m,0));

    f(i,0,n) {
        f(j,0,m)
            cin>>v[i][j];
    }

    int flag = 0;
    f(i,0,m) {
        if(!flag) {
            if(v[0][i]=='.')
                dp[0][i] = 1;
            else {
                flag++;
            }
        }
    }

    flag = 0;
    f(i,0,n) {
        if(!flag) {
            if(v[i][0]=='.')
                dp[i][0] = 1;
            else {
                flag++;
            }
        }
    }

    f(i,1,n) {
        f(j,1,m) {
            if(v[i][j]=='.') {
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
                dp[i][j] %= mod;
            }
               
                
        }
    }

    cout<<dp[n-1][m-1]<<endl;

    return 0;
}



Measured memory_bytes: 9088
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, C, s, t, c;
set<Pii> T;

int main() {
    fastio();
    cin >> N >> C;
    REP(i, N) {
        cin >> s >> t >> c;
        Pii l = make_pair((s << 1) - 1, c);
        Pii r = make_pair(t << 1, c);
        auto le = T.find(make_pair(s << 1, c));
        auto re = T.find(make_pair((t << 1) - 1, c));
        if(le != T.end()) T.erase(le);
        else T.insert(l);
        if(re != T.end()) T.erase(re);
        else T.insert(r);
    }
    int ans = 0, cnt = 0;
    for(auto e : T) {
        // cerr << e.first << " " << e.second << "\n";
        if(e.first & 1) cnt++;
        else cnt--;
        ans = max(cnt, ans);
    }
    cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 9600
H, W = list(map(int, input().split()))
m = [list(input()) for _ in range(H)]
scores = [[None for _ in range(W)] for _ in range(H)]
def calc(i, j):
#     print(f'{i}, {j}')
    global m, scores, H, W
    if scores[i][j] is not None:
        return scores[i][j]
    if i == H - 1 and j == W - 1 and i != 0 and j != 0:
        score = 0
        scores[i][j] = score
#         print(f'i: {i}, j: {j}, score: {score}')
        return score
    diff = []
    if j < W - 1:
        diff.append((0, 1))
    if i < H - 1:
        diff.append((1, 0))
#     print(f'diff: {diff}')
    score_cand = []
    for di, dj in diff:
        additional = 0
        if (m[i][j] == '.' and m[i+di][j+dj] == '#') or (i == 0 and j == 0 and m[0][0] == '#'):
            additional += 1 
        score = calc(i+di, j+dj) + additional
        score_cand.append(score)
    score = min(score_cand)
    scores[i][j] = score
#     print(f'i: {i}, j: {j}, score: {score}')
    return score
print(calc(0, 0))

Measured memory_bytes: 51804
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=20010;
const int M=40000010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
}
int n,cnt;
int x[N],y[N];
int bgn[N],nxt[M],to[M],E;
int dfn[N],low[N],dfs_time;
int bel[N],st[N],top,in[N];
int scc_cnt;
struct node
{
	int pos,id,type;
	node(){}
	node(int pos,int id,int type):pos(pos),id(id),type(type){}
}a[N];
inline bool operator<(node A,node B){return A.pos<B.pos;}
inline void add_edge(int u,int v)
{
	//printf("%d %d\n",u,v);
	nxt[++E]=bgn[u],bgn[u]=E,to[E]=v;
}
inline void dfs(int u)
{
	dfn[u]=low[u]=++dfs_time;
	in[st[++top]=u]=1;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if(!dfn[v=to[i]])
		{
			dfs(v);
			chkmin(dfn[u],low[v]);
		}
		else if(in[v])chkmin(dfn[u],dfn[v]);
	}
	if(low[u]==dfn[u])
	{
		++scc_cnt;
		int x;
		do
		{
			x=st[top--];
			in[x]=0;
			bel[x]=scc_cnt;
		}while(x!=u);
	}
}
inline bool check(int x)
{
	mem(dfn,0);
	mem(bgn,0);
	mem(bel,0);
	E=0;
	scc_cnt=0;
	dfs_time=0;
	int nowl=1,nowr=1;
	For(i,1,cnt)
	{
		while(nowl<cnt&&a[nowl].pos<=a[i].pos-x)nowl++;
		while(nowr<cnt&&a[nowr+1].pos<a[i].pos+x)nowr++;
		For(j,max(i-20,nowl),i)
		if(i!=j)
		{
			add_edge(a[i].id*2+a[i].type,a[j].id*2+(a[j].type^1));
			add_edge(a[j].id*2+a[j].type,a[i].id*2+(a[i].type^1));
		}
		For(j,i,min(i+20,nowr))
		if(i!=j)
		{
			add_edge(a[i].id*2+a[i].type,a[j].id*2+(a[j].type^1));
			add_edge(a[j].id*2+a[j].type,a[i].id*2+(a[i].type^1));
		}
	}
	For(i,1,n)
	{
		if(!dfn[i*2])dfs(i*2);
		if(!dfn[i*2+1])dfs(i*2+1);
	}
	For(i,1,n)if(bel[i*2]==bel[i*2+1])return 0;
	return 1;
}
int main()
{
	read(n);
	int MAX=0;
	For(i,1,n)
	{
		read(x[i]),read(y[i]);
		a[++cnt]=node(x[i],i,0);
		a[++cnt]=node(y[i],i,1);
		chkmax(MAX,x[i]),chkmax(MAX,y[i]);
	}
	sort(a+1,a+cnt+1);
	int l=1,r=MAX/(n-1),ans=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    string S;
    cin >> N;
    cin >> S;

    ll left = 0;
    ll right = 0;
    REP(i, N){
        if(S[i] == ')'){
            if(right > 0){
                right--;
            }
            else{
                left++;
            }
        }
        if(S[i] == '('){
            right++;
        }
    }

    REP(i, left) cout << '(';
    cout << S;
    REP(i, right) cout << ')';
    cout << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    vector <int> start(26, -1);
    vector <int> goal(26, -1);

    for(int i = 0; i < S.size(); i++) {
        int a = S[i] - 'a';
        int b = T[i] - 'a';
        if(start[a] != -1 || goal[b] != -1) {
            if(start[a] != b || goal[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
        start[a] = b;
        goal[b] = a;
    }
    cout << "Yes" << endl;
}


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

using namespace std;

int main (void) {
    int N, M;
    cin >> N >> M;
    int a, b;
    vector<vector<int>> island(N);
    for ( int i=0; i<M; i++ ) {
        cin >> a >> b;
        a--; b--;
        island.at(a).push_back(b);
        island.at(b).push_back(a);
    }

    bool possible = false;
    for ( auto itr1 : island.at(0) ) {
        for ( auto itr2 : island.at(itr1) ) {
            if ( itr2 == N-1 ) {
                possible = true;
                goto END;
            }
        }
    }

END:
    if ( possible )
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 12016
S = gets.chomp.reverse
PTNS = ['dream', 'erase', 'eraser', 'dreamer'].map{|s| [s.reverse, s.size]}
i = 0
while i < S.size
  j = i
  PTNS.each do |p, s|
    i += s if S[i, s] == p
  end
  break if i == j
end
if i == S.size
  puts 'YES'
else
  puts 'NO'
end

Measured memory_bytes: 2044
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W,A,B=MI()

    
    N=H+W
    
    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return (fact[n] * factinv[r] * factinv[n-r])%mod

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]
    
    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
        
        
    ans=cmb(N-2,H-1,mod)
    
    for i in range(min(A,B)):
        h=H-A+i+1
        w=B-i
        #print(h,w,cmb(h+w-2,h-1,mod),cmb(H+W-(h+w),H-h,mod))
        ans-=cmb(h+w-2,h-1,mod)*cmb(H+W-(h+w),H-h,mod)
        ans%=mod
        
    print(ans%mod)

main()


Measured memory_bytes: 80880
n = int(input())
d = []
for i in range(n):
    a,b = map(int,input().split())
    d.append((a+b,a,b))
    
d.sort(reverse = True)

ta,ao = 0,0
for i in range(n):
    if i % 2 == 0:
        ta += d[i][1]
    else:
        ao += d[i][2]
        
print(ta-ao)

Measured memory_bytes: 61400
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[100];

map<string, int> load() {
  map<string, int> dp;
  int n;
  scanf("%d\n", &n);
  while(n--) {
    scanf("%s", buf);
    dp[string(buf)]++;
  }
  return dp;
}

int main() {
  map<string, int> a = load();
  map<string, int> b = load();
  int ret = 0;
  for(auto x: a) {
    ret = max(ret, x.second - b[x.first]);
  }
  printf("%d\n", ret);
}


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

int main()
{
	ll a,b ;
	cin >> a>>b;
	if (a != 1 && b != 1)cout << (a * b + 1) / 2 << endl;
	else cout << 1 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class ABC147B {
    public static void Main() {
        int ans = 0;
        string S = Console.ReadLine();

        for (int i = 0; i < S.Length / 2; i++) {
            if (S[i] != S[S.Length - i - 1]) ans++;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int>  vi;
typedef set<char> setchar;
typedef set<int> sett;
typedef deque <int> dq;
typedef long long ll;
#define vec(a)  a.begin(),a.end()
#define pb     push_back
#define pf     push_front
#define mem(a,b) memset(a,b,sizeof(a));
#define inI(a)  scanf("%d",&a);
#define inT(a,b)  scanf("%d %d",&a,&b);
#define inL(a)  scanf("%lld",&a);
#define SWAP(a,b) a= a^b, b=a^b, a=a^b
 
//int fx[]={+0,-1,-1,-1,+0,+1,+1,+1};
//int fy[]={-1,-1,+0,+1,+1,+1,+0,-1};
int fx[]= {0,-1,0,+1};
int fy[]= {-1,0,+1,0};
 
 
 
int main()
{
 
    //freopen("input.txt","r",stdin);
    double m,sum=0,cnt=0;
    int n;
    cin>>n>>m;
    double arr[n];
    for(int i=0;i<n;i++)
    {
      cin>>arr[i];
      sum+=arr[i];
    }
      for(int i=0;i<n;i++)
    {
       if(arr[i]>= (sum/(4*m)))
       {
         cnt+=1;
       }
     
    }
      if(cnt >=m)
       {
         cout<<"Yes"<<endl;
       }
       else
       {cout<<"No"<<endl;
           
       }
 
      
 
 
 
    return 0;
 
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ld a,b;cin >>a>>b;
    b*=100;
    ll ans=round(a*b);
    cout <<ans/100<<endl;
    return 0;
}


Measured memory_bytes: 3708
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100

int cmpfunc( const void * n1, const void * n2)
{
    if      (*(int *)n1 < *(int *)n2)  return  1;
    else if (*(int *)n1 > *(int *)n2)  return -1;
    else                               return 0;
}

int main()
{
    int n, m;
    int a[MAX];
    
    scanf("%d%d",&n,&m);
    for (int i=0; i<n; i++) scanf("%d",&a[i]);
    
    qsort(a, n, sizeof(a[0]), cmpfunc);
    //for ( int i=0; i<n; i++) printf("%d ",a[i]);
    //printf("\n");
    
    int total = 0;
    for (int i=0; i<n; i++){
        total += a[i];
    }
    
    //printf("total = %d, total/4M = %lf", total, (double)(total)/(double)(4*m));
    
    if (a[m-1] < (double)(total)/(double)(4*m)){
        printf("No\n");
        return 0;
    } else {
        printf("Yes\n");
        return 0;
    }
}


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

typedef long long ll;
const int mod= 1e9+7;
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}
int main ()
{
   string s;
   cin>>s;
   for (ll i=0;i<s.size();i++)
   {
      s[i]='x';
   }
   cout<<s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
vector<string> arr;
map<pair<int, int>, int> memo;
const int big_num = 1e9 + 7;
int moveMonkey(int i, int j) {
    if(memo.count({i, j})) {
        return memo[{i, j}];
    }
    if(i == 0 && j == 0) {
        return 1;
    }
    if(arr[i][j] == '#') 
        return 0;
    int a = 0, b = 0;
    if(i - 1 >= 0)
        a = moveMonkey(i - 1, j);
    if(j - 1 >= 0)
        b = moveMonkey(i, j - 1);
    memo[{i, j}] = (a + b) % big_num;
    return (a + b) % big_num;
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int w, l;
    cin >> w >> l;
    arr.resize(w);
    for(int i = 0; i < w; i++) cin >> arr[i];
    cout << moveMonkey(w - 1, l - 1);
}



Measured memory_bytes: 67192
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

string S;
int N;
int arr[100005];

void construct()
{
	for(int i = 1; i <= N - 2; i++)
	{
		if(arr[i] == 0)	// sheep
		{
			if(S[i] == 'o')	arr[i + 1] = arr[i - 1];
			else			arr[i + 1] = !arr[i - 1];
		}
		else
		{
			if(S[i] == 'o')	arr[i + 1] = !arr[i - 1];
			else			arr[i + 1] = arr[i - 1];
		}
	}
}

bool satisfied()
{
	for(int i = 0; i < N; i++)
	{
		int next = (i + 1) % N;
		int prev = ((i - 1) + N) % N;

		if(arr[i] == 0)
		{
			if(S[i] == 'o')
			{
				if(arr[next] != arr[prev])	return 0;
			}
			else
			{
				if(arr[next] == arr[prev])	return 0;
			}
		}
		else
		{
			if(S[i] == 'o')
			{
				if(arr[next] == arr[prev])	return 0;
			}
			else
			{
				if(arr[next] != arr[prev])	return 0;
			}
		}
	}
	return 1;
}

int main()
{
	int i, j;

	si(N);

	cin >> S;

	int s, e;

	fl(s,0,2)
	{
		fl(e,0,2)
		{
			arr[0] = s;
			arr[1] = e;
			construct();
			if(satisfied())
			{
				fl(i,0,N)
				{
					if(arr[i] == 0)
						printf("%c", 'S');
					else
						printf("%c", 'W');
				}
				return 0;
			}
		}
	}

	printf("-1\n");


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double

using namespace std;

int main()
{
	fio
	ll N,K;
	cin>>N>>K;
	ll arr[N];
	f(i,0,N) cin>>arr[i];
	sort(arr,arr+N);

	ll sum = 0;
	for(int i=0;i<N-K ;i++)
		sum+=arr[i];
	cout<<sum<<endl;
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W,h,w;
int A[555][555];

const int INF=1001001;

signed main(){
    cin>>H>>W>>h>>w;

    if(W%w==0&&H%h==0){
        puts("No");
        return 0;
    }

    if(W%w){
        rep(i,H){
            rep(j,W){
                if(j%w==0)A[i][j]=INF;
                if((j+1)%w==0)A[i][j]=-(INF+1);
            }
        }
    }
    else{
        rep(j,W){
            rep(i,H){
                if(i%h==0)A[i][j]=INF;
                if((i+1)%h==0)A[i][j]=-(INF+1);
            }
        }
    }

    puts("Yes");
    rep(i,H){
        rep(j,W){
            if(j)cout<<" ";
            cout<<A[i][j];
        }cout<<endl;
    }
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector<int> A(n);
	for (int i = 0; i < n; i++)
		cin >> A[i];
		
	int q;
	cin >> q;
	
	int b, e, t, k;
	vector<int>::iterator it = A.begin();
	while (q--)
	{
		cin >> b >> e >> t;	
//		k = e - b;
//		while (k--)
//		{
//			iter_swap(it + b++, it + t++);
//		}
		
		//调用库函数
		 swap_ranges(it+b, it+e, it+t);
		
	}
		
		
	while (it != A.end())
	{
		if(it != A.begin())
			cout << ' ';
		cout << *it++;
	}
	cout << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int dp[150000];
int n;
int num[150000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>num[i];
	}
	for(int i=2;i<=n;i++)
	{
		if(i>2)
			dp[i]=min(dp[i-1]+abs(num[i]-num[i-1]),dp[i-2]+abs(num[i]-num[i-2]));
		else
			dp[i]=abs(num[i]-num[i-1]);
		//cout<<dp[i]<<"\n";
		//cout<<dp[i]<<"\n";
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  import scala.io.StdIn._


  val Array(a, b, k) = readLine.trim.split(' ').map(_.toInt)
  val state = Array.tabulate(a){_ ⇒ Array.tabulate(b){_ ⇒ 0}}
  for (i ← 0 until a){
    val s = readLine.trim.map(_.asDigit)
    for (j ← s.indices){
      state(i)(j) += s(j)
    }
  }
  for (i ← 0 until b){
    val s = readLine.trim.map(_.asDigit)
    for (j ← s.indices){
      state(j)(i) += s(j)
    }
  }
  println(calMinCostFlow(a, b, state, k))

  def calMinCostFlow(aSize: Int, bSize: Int, costs: Array[Array[Int]], k: Int): Int = {
    val start = 0
    val goal = aSize + bSize + 1
    val nodes = Array.tabulate(goal + 1){_ ⇒ ArrayBuffer[Edge]()}.let{a ⇒
      for (i ← 1 to aSize){
        a(i).append(Edge(start, 0, a(start).length, false))
        a(start).append(Edge(i, 0, 0, true))
      }
      for (i ← (aSize + 1) until goal){
        a(i).append(Edge(goal, 0, a(goal).length, true))
        a(goal).append(Edge(i, 0, 0, false))
      }
      for (from ← 0 until aSize; to ← 0 until bSize){
        val i = from + 1
        val j = to + aSize + 1
        a(i).append(Edge(j, costs(from)(to), a(j).length, true))
        a(j).append(Edge(i, -costs(from)(to), a(i).length - 1, false))
      }
      a.map(_.toArray)
    }
    val minCost = Array.tabulate(nodes.length){_ ⇒ Int.MaxValue}.also(_(0) = 0)
    val potential = Array.tabulate(nodes.length){_ ⇒ 0}
    val queue = mutable.PriorityQueue()(Ordering.by[(Int, Int), Int](_._2))
    val prevEdge = Array.tabulate(nodes.length){_ ⇒ nodes(0)(0)}
    var cost = 0
    var count = 0
    var canAddPair = true
    while (canAddPair){
      for (i ← minCost.indices.tail) minCost(i) = Int.MaxValue
      queue.enqueue((0, 0))
      while(queue.nonEmpty){
        val (current, cost) = queue.dequeue()
        if (minCost(current) == cost){
          for (edge ← nodes(current) if edge.canUse) {
            if (minCost(edge.to) > potential(current) + edge.cost - potential(edge.to) + cost) {
              prevEdge(edge.to) = nodes(edge.to)(edge.pair)
              minCost(edge.to) = potential(current) + edge.cost - potential(edge.to) + cost
              queue.enqueue((edge.to, minCost(edge.to)))
            }
          }
        }
      }
      if (minCost(goal) != Int.MaxValue && minCost(goal) + cost <= k){
        cost += minCost(goal)
        count += 1
        var last = goal
        while(last != start){
          val prev = prevEdge(last)
          prev.canUse = true
          nodes(prev.to)(prev.pair).canUse = false
          last = prev.to
        }
        for (i ← 1 until goal) potential(i) += minCost(i)
      }else canAddPair = false
    }
    count
  }
  case class Edge(to: Int, cost: Int, pair: Int, var canUse: Boolean)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


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

int main(){
  int n,m,a,b;
  cin >> n >> m;
  vector<int>ball(n,1);
  vector<bool>red(n,false);
  red.at(0)=true;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    a--,b--;
    ball.at(a)--;
    ball.at(b)++;
    if(red.at(a))
      red.at(b)=true;
    if(ball.at(a)==0)
      red.at(a)=false;
  }
  int ans=0;
  for(int i=0;i<n;i++)
    if(red.at(i)) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3696
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline LL read(){
	LL x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const LL MAXN = 200010;
const LL INF = 2147483600;

LL L,N;
LL a[MAXN+1],suf[MAXN+1],pre[MAXN+1],ans;
inline void solve(){
	LL ssuf=0,spre=0,sf=N,sp=0;
	for(LL i=1;i<=N;i++){
		ans=max(ans,ssuf+spre+suf[N-i+1]);
		LL PC1=min(sp,sf); PC1=max(PC1,0LL);
		LL PC2=min(sp,sf); PC2=max(PC2,0LL);
		++sp; pre[sp]=pre[sp-1]+a[i]-a[i-1]; --sf; 
		
		LL lim=sp,C=min(lim,sf); 
		if(i>1) ssuf-=2*(suf[N-i]-suf[N-i-PC1]);
		if(C>PC1)ssuf+=suf[N-i-C]*2;  
		
		spre+=pre[sp]*2; C=min(sp,sf);
		if(PC2>C) spre-=(pre[sp-C]+pre[sp-C-1])*2;
		if(PC2==C) spre-=pre[sp-C]*2;
	} 
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	L=read(),N=read();
	for(LL i=1;i<=N;i++) a[i]=read();
	for(LL i=1;i<=N;i++) suf[i]=L-a[N-i+1];
	solve();
	for(LL i=1;i<=N;i++) a[i]=L-a[i]; reverse(a+1,a+N+1);
	for(LL i=1;i<=N;i++) suf[i]=L-a[N-i+1];
	solve();
	printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 4992
#include <iostream>
#include <vector>
using namespace std;
int n,m;
int fi[100005];
vector <int> f[100005];
int dfs(int u)
{
    int &res=fi[u];
    if (res!=-1) return res;
    res=0;
    for (int i:f[u])
    {
        res=max(res,dfs(i)+1);
    }
    return res;
}
int main()
{
    cin>>n>>m;
    for (int i=1;i<=m;++i)
    {
        int u,v;
        cin>>u>>v;
        f[u].push_back(v);
    }
    for (int i=1;i<=n;++i)
        fi[i]=-1;
    int res=0;
    for (int i=1;i<=n;++i)
    {
        res=max(res,dfs(i));
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 11400
import java.util.Scanner;
 
//A Point in a Triangle
public class Main{
 
    public static double ex(double ox, double oy, double x1, double y1, double x2, double y2){
        double vx1 = x1-ox;
        double vy1 = y1-oy;
        double vx2 = x2-ox;
        double vy2 = y2-oy;
        return vx1*vy2-vx2*vy1;
    }
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            double[][] p = new double[3][2];
            for(int i=0;i<3;i++){
                p[i][0] = sc.nextDouble();
                p[i][1] = sc.nextDouble();
            }
            double px = sc.nextDouble();
            double py = sc.nextDouble();
 
            boolean f = true;
            boolean g = true;
            for(int i=0;i<3;i++){
                double ex = ex(p[i][0], p[i][1], p[(i+1)%3][0], p[(i+1)%3][1], px, py);
                if(ex >= 0){
                    f = false;
                }
                if(ex <= 0){
                    g = false;
                }
            }
            System.out.println(f||g?"YES":"NO");
        }
    }
}

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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(a) ((int)a.size())

int k;
string s;
set<string> res;

int main() {
  cin >> s;
  cin >> k;

  for (int i = 0; i < sz(s); i++) {
    string cur = "";
    for (int j = i; j < min(sz(s), i + k); j++) {
      if (sz(res) >= 5) {
        auto it = res.upper_bound(cur);
        if (it == res.end()) break;
      }
      cur.push_back(s[j]);
      res.insert(cur);
    }
    if (sz(res) > 5) {
      auto it = res.end();
      it--;
      res.erase(it);
    }
  }

  int now = 0;
  for (auto it = res.begin(); it != res.end(); it++) {
    now++;
    if (now == k) {
      cout << *it;
      return 0;
    }
  }

  return 0;
}


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

long long n,k;
long long T[100000];

int check(long long P){
  int i=0;
  for (int j=0;j<k;j++){
    long long s=0;
    while(s+T[i]<=P){
      s=s+T[i];
      i++;
      if(i==n) return n;
    }
  }
  return i;
}

int sol(){
    long long  left = 0;
    long long right = 100000*10000;
    while(right - left > 1){
      long long m = (left + right) / 2;
      long long v=check(m);  
      //cout<<v<<" m"<<m<<" L"<<left<<" R"<<right<<endl;
        if(v>=n) right = m;
        else left = m;
    }
    return right;
}

int main(){
  cin>>n>>k;
  for (int i=0;i<n;i++){
    cin>>T[i];
  }
  long long ans=sol();
  cout<<ans<<endl;
  return 0;
}










Measured memory_bytes: 3880
import sys

N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)
X = 0
Y = 0
flag = 0

if N == 1:
    X = 9
    Y = 0
elif N == 2:
    X = 99
    Y = 10
else:
    X = 999
    Y = 100

for j in range(Y, X+1):
    for k in range(M):
        if int(str(j)[s[k]-1]) != c[k]:
            flag += 1
    if flag == 0:
        print(j)
        sys.exit()
    else:
        flag = 0

print(-1)

Measured memory_bytes: 3064
//Given a string S representing the type of the contest held last week
//print the string representing the type of the contest held this week.

#include <stdio.h>

int main ()
{
	char S[5];
	scanf("%s", &S);
	
	if(S[1]=='B')
	{
		S[1]='R';
		printf("%s",S);
	}
	
	else if (S[1]=='R')
	{
		S[1]='B';
		printf("%s",S);	
	}
	
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define M 105
using namespace std;

long long n;
vector<int>ans1;
int a[M];
int p=0;

void build(long long n){
    if (n==1)
        return;
    if (n%2==1) {
        a[++p]=1;
        build((n-1)/2);
    }
    else{
        a[++p]=2;
        build(n-1);
    }
        
}


int main() {
    cin >> n;
    int times=1;
    build(n);
    ans1.push_back(1);
    for (int i=p; i>=1; i--) {
        if (a[i]==1) {
            ans1.push_back(++times);
        }
        else{
            ans1.insert(ans1.begin(), ++times);
        }
    }
    cout << 2*(ans1.size()) << endl;
    for (int j=0; j<ans1.size(); j++) {
        cout << ans1[j] << " ";
    }
    for (int k=0; k<ans1.size(); k++) {
        if (k==ans1.size()-1)
            cout << k+1;
        else
            cout << k+1 << " ";
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::{self, Read};

fn main() {
    let mut s = String::new();
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    stdin.read_to_string(&mut s).unwrap();

    let mut args = s.split_whitespace();
    let a: isize = args.next().unwrap().parse().unwrap();
    let b: isize = args.next().unwrap().parse().unwrap();

    if (a * b) % 2 == 0 {
        print!("Even");
    } else {
        print!("Odd");
    }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm

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

    int3(n, m, k);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int a = (i+j) / k % 2, b = (i-j+m) / k % 2;
            if (a && b) {
                cout << "R";
            } else if (a) {
                cout << "G";
            } else if (b) {
                cout << "B";
            } else {
                cout << "Y";
            }
        }
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	  static boolean solve(int i, int m, int[] A) {
	        if (m == 0) return true;
	        if (i >= A.length) return false;
	        boolean res = solve(i+1, m, A) || solve(i+1, m-A[i], A);
	        return res;
	    }

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) {
			A[i] = scanner.nextInt();
		}
		int q = scanner.nextInt();
		int[] m = new int[q];
		for (int i = 0; i < q; i++) {
			m[i] = scanner.nextInt();
		}
		 for (int i=0; i < q; i++) {
	            if ( solve(0, m[i], A) )
	                System.out.println("yes");
	            else
	                System.out.println("no");
	        }

	}

}


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

using namespace std;
const int N = 200010;
const int B = 19260817;
const int M1 = 1e9+7;
const int M2 = 998244353;
int _w;

void add_mod( int &a, int b, int mod ) {
	a += b;
	a -= a >= mod ? mod : 0;
}

void sub_mod( int &a, int b, int mod ) {
	a -= b;
	a += a < 0 ? mod : 0;
}

struct Hash {
	int h1, h2;
	Hash() {}
	Hash( int _h1, int _h2 ) {
		h1 = _h1, h2 = _h2;
	}
	Hash operator+( const Hash &rhs ) const {
		Hash ans = *this;
		add_mod( ans.h1, rhs.h1, M1 );
		add_mod( ans.h2, rhs.h2, M2 );
		return ans;
	}
	Hash operator-( const Hash &rhs ) const {
		Hash ans = *this;
		sub_mod( ans.h1, rhs.h1, M1 );
		sub_mod( ans.h2, rhs.h2, M2 );
		return ans;
	}
	Hash operator*( const Hash &rhs ) const {
		Hash ans = *this;
		ans.h1 = int(1LL * ans.h1 * rhs.h1 % M1);
		ans.h2 = int(1LL * ans.h2 * rhs.h2 % M2);
		return ans;
	}
	void go( int ch ) {
		h1 = int((1LL * h1 * B + ch) % M1);
		h2 = int((1LL * h2 * B + ch) % M2);
	}
	bool operator<( const Hash &rhs ) const {
		if( h1 == rhs.h1 )
			return h2 < rhs.h2;
		else return h1 < rhs.h1;
	}
};

Hash pw[N];

void init() {
	pw[0] = Hash(1, 1);
	for( int i = 1; i < N; ++i ) {
		pw[i] = pw[i-1];
		pw[i].go(0);
	}
}

int n, k, p[N];

Hash pf[N];

Hash hsh( int l, int r ) {
	return pf[r] - pf[l-1] * pw[r-l+1];
}

namespace SGT {
	Hash hsh[N*4];
	int cnt[N*4];
	
	void init() {
		memset(hsh, 0, sizeof hsh);
		memset(cnt, 0, sizeof cnt);
	}
	void _insert( int o, int L, int R, int p ) {
		if( L == R ) {
			hsh[o] = Hash(p, p);
			cnt[o] = 1;
		} else {
			int M = (L+R)/2, lc = o<<1, rc = lc|1;
			if( p <= M ) _insert(lc, L, M, p);
			else _insert(rc, M+1, R, p);
			cnt[o] = cnt[lc] + cnt[rc];
			hsh[o] = hsh[rc] + hsh[lc] * pw[cnt[rc]];
		}
	}
	void insert( int p ) {
		_insert(1, 1, n, p);
	}
	void _erase( int o, int L, int R, int p ) {
		if( L == R ) {
			hsh[o] = Hash(0, 0);
			cnt[o] = 0;
		} else {
			int M = (L+R)/2, lc = o<<1, rc = lc|1;
			if( p <= M ) _erase(lc, L, M, p);
			else _erase(rc, M+1, R, p);
			cnt[o] = cnt[lc] + cnt[rc];
			hsh[o] = hsh[rc] + hsh[lc] * pw[cnt[rc]];
		}
	}
	void erase( int p ) {
		_erase(1, 1, n, p);
	}
	Hash query() {
		return hsh[1];
	}
}

set<Hash> st;

void solve() {
	pf[0] = Hash(0, 0);
	for( int i = 1; i <= n; ++i ) {
		pf[i] = pf[i-1];
		pf[i].go( p[i] );
	}
	SGT::init();
	for( int i = 1; i <= k; ++i )
		SGT::insert( p[i] );
	for( int L = 1; L+k-1 <= n; ++L ) {
		int R = L+k-1;
		Hash front, back;
		if( L == 1 ) {
			front = Hash(0, 0);
		} else {
			front = hsh(1, L-1);
		}
		if( R == n ) {
			back = Hash(0, 0);
		} else {
			back = hsh(R+1, n);
		}
		int mid_len = R-L+1;
		int back_len = n-R;
		Hash mid = SGT::query();
		st.insert( back + mid * pw[back_len] + front * pw[back_len + mid_len] );
		if( R != n ) {
			SGT::erase( p[L] );
			SGT::insert( p[R+1] );
		}
	}
	cout << st.size() << endl;
}

int main() {
	_w = scanf( "%d%d", &n, &k );
	for( int i = 1; i <= n; ++i ) {
		_w = scanf( "%d", p+i );
		++p[i];
	}
	init(), solve();
	return 0;
}


Measured memory_bytes: 22912
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)3e3 + 7, MOD = (int)1e9 + 7;

int n;

double ans;

double a[N];

double dp[N][N];

int main(){
		
	NFS

	cin >> n;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	for(int i=0;i<=n;i++)dp[0][i]=1;
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<i;j++){
			//if(dp[i-1][j] == 0) dp[i][j+1] += a[i];
			dp[i][j+1] += dp[i-1][j] * a[i];
			//if(dp[i-1][j] == 0) dp[i][j] += (1.0 - a[i]);
			dp[i][j] += dp[i-1][j] * (1.0 - a[i]);
		}
	}
	
	//cout << dp[1][0] << endl;
	
	for(int i=(n/2)+1;i<=n;i++)ans+=dp[n][i];
	
	cout << setprecision(12) << fixed << ans << endl;
	
	ioi
}

Measured memory_bytes: 69120
from collections import deque
H,W=map(int, input().split())
 
A=[]
que=[]
done=[[-1]*W for _ in range(H)]
for h in range(H):
    a=list(input())
    A.append(a)
    for w in range(W):
        if a[w]=="#":
            que.append((h,w))
            done[h][w]=0
 
d=[(1,0),(-1,0),(0,1),(0,-1)]
que=deque(que)
ans=0
while que:
    h,w=que.popleft()
    now=done[h][w]
    for t in d:
        dh,dw=t
        nh=h+dh
        nw=w+dw
        if 0<=nh<H and 0<=nw<W:
            if done[nh][nw]==-1:
                done[nh][nw]=now+1
                que.append((nh,nw))
                ans=max(ans, now+1)
 
 
 
print(ans)

Measured memory_bytes: 178688