akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,m;
	cin>>n>>m;
	ll a[n];
	for(ll i=0;i<n;i++)
	    cin>>a[i];
	    
	pair<ll,ll> b[m];
    for(ll i=0;i<m;i++)
    {
        cin>>b[i].second>>b[i].first;
    }
    ll sum = 0;
    sort(a,a+n);
    sort(b,b+m);
    
    ll index = 0,beg,mid,last,ans=-1,temp;
    for(ll i=m-1;i>=0;i--)
    {
        temp = index;
        beg = index;
        last = min(b[i].second+index-1,n-1);
        ans = -1;
        while(beg<=last)
        {
            mid = (beg+last)/2;
            if(a[mid]>b[i].first)
            {
                ans = mid;
                last = mid - 1;
            }
            else
            {
                beg = mid + 1;
            }
        }
       
        if(ans!=-1)
        index = ans; 
        else
        {
            index = min(b[i].second+index,n);
        }
        
        if(temp!=index)
        sum = sum + (b[i].first * (index-temp));
        
        if(index>=n)
            break;
    }
    
    for(ll i=n-1;i>=index;i--)
        sum+=a[i];
        
    cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;


struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i,N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	string S; cin >> S;
	int N = S.size();
	N /= 2;
	for (int i = N - 1; i >= 0; i--) {
		bool F = 1;
		REP(j, i) {
			if (S[j] != S[j + i])F = false;
		}
		if (F) {
			cout << i * 2 << endl;
			return 0;
		}
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define ld long double

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int out = a * x + b * y;
  out = min(out, c * 2 * x + max(0, (y - x)) * b);
  out = min(out, max(0, (x - y)) * a + c * 2 * y);
  cout << out << endl;

  return 0;
}

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

long long N, M;

int main () {
    scanf("%lld%lld", &N, &M);
    if (N == 1 && M == 1) printf("1\n");
    else if (N == 1 || M == 1) printf("%lld\n", N * M - 2 < 0 ? 0 : N * M - 2);
    else printf("%lld\n", (N - 2) * (M - 2));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ll long long
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define ls rt << 1
#define rs rt << 1 | 1
#define mod 1000000007
#define sz(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define vi vector<int>
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 1000005;

int main()
{
	int n = read();
	int A = read();
	int B = read();
	if(A == B - 1) {puts("Borys"); return 0;}
	rep(i, 1, n)
	{
		A ++;
		if(A == B - 1) {puts("Alice"); return 0;}
		B --;
		if(A == B - 1) {puts("Borys"); return 0;}
	}

	return 0;
}


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

#define ll long long
#define inf 1e18
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define sp(x, y) fixed << setprecision(y) << x;
#define em emplace_back
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define nl '\n'

typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

const int maxn = 1e6;
const int mod = 1e9 + 7;

void solve() {
  ll n, k;
  cin >> n >> k;
  vi a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sortall(a);
  ll ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans << nl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll test = 1;
  /* cin >> test; */
  while (test--) {
    solve();
  }
  return 0;
}



Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<cstdio>




int main() {

	std::string cinput;
	std::cin >> cinput;

	int flg = 0;

	if (cinput[0] == 'A') {
		flg += 1;
	}
	int cntx = 0;
	for (int xxx = 2; xxx < cinput.length() - 1; xxx++) {
		if ((cinput[xxx] == 'C') ) {
			cntx++;
		}
	}
	if (cntx == 1) {
		flg += 1;
	}

	cntx = cinput.length();
	for(int xxx = 0 ; xxx < (int)cinput.length() ; xxx++){
		if ((cinput[xxx] >= 'a') && (cinput[xxx] <= 'z')) {
			cntx--;
		}
	}
	if (cntx == 2) {
		flg += 1;
	}

	if (flg == 3) {
		std::cout << "AC" << std::endl;

	}
	else {
		std::cout << "WA" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
import math

N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]

add_damage = A-B
left = 1
right = 10**9
ans = float('inf')

for i in range(int(math.log(10**9, 2)+1)):
    T = (left+right) // 2
    h = H.copy()
    h = list(map(lambda x: max(0, x-T*B), h))
    h = list(map(lambda x: math.ceil(x / add_damage), h))
    need = sum(h)
    
    if need <= T:
        right = T
        ans = min(ans, T)
    else:
        left = T

print(int(ans))

Measured memory_bytes: 15900
N = gets.to_i
list = [1,6,9,6**2,6**3,6**4,6**5,6**6,9**2,9**3,9**4,9**5].sort
ans = 0
memo = {}
# 自分の数字以下のターゲットになりうる物をtableで持ち、最小の数を入れていく
(1..100001).each{|i|
    target1 = list.select{|x| x <  i}
    target2 = list.select{|x| x == i}
    if target2 != []
        memo[i] = 1
    else
        memo[i] = (target1.map{|x| memo[i-x] + 1}).min
    end
}

puts memo[N]


Measured memory_bytes: 8700
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=200000+10,maxn=1000000+10,inf=0x3f3f3f3f;

vi v[N];
int d[N];
void dfs(int u,int f,int &o)
{
    for(int x:v[u])if(x!=f)
    {
        d[x]=d[u]+1;
        dfs(x,u,o);
    }
    if(d[o]<d[u])o=u;
}
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int a,b;scanf("%d%d",&a,&b);
        v[a].pb(b),v[b].pb(a);
    }
    int x1=1,x2=1;
    d[1]=1;dfs(1,0,x1);
    d[x1]=1;dfs(x1,0,x2);
    if(d[x2]%3==2)puts("Second");
    else puts("First");
    return 0;
}
/********************

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


Measured memory_bytes: 24448
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a,b;
    top = 0;
    char s[100];

    while(scanf("%s",s) != EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }else if(s[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        }else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        }else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());

    return 0;
}

Measured memory_bytes: 2680
//Created Time:2019年12月01日 星期日 14时56分42秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define N 100005

using namespace std;

struct edge{
	int to, nxt;
}e[N << 1];

int n, cnt;
int fir[N], deg[N], tmp[N], flag[N];
bool vis[N];

queue < int > que;

int read();
void add(int ,int);

int main(){
	n = read();
	for(int i = 1; i < n; ++i){
		int u = read(), v = read();
		add(u, v); add(v, u);
	}
	memcpy(tmp, deg, sizeof tmp);
	for(int i = 1; i <= n; ++i)
		if(deg[i] == 1) que.push(i);
	while(!que.empty()){
		int u = que.front(); que.pop(); 
		if(vis[u]) continue; vis[u] = true;
		bool flag = false;
		for(int i = fir[u]; i; i = e[i].nxt){
			int v = e[i].to; if(vis[v]) continue; 
			flag = true; vis[v] = true;
			for(int j = fir[v]; j; j = e[j].nxt){
				int p = e[j].to; if(vis[p]) continue;
				--deg[p]; if(deg[p] == 1) que.push(p);
			}
		}
		if(!flag){
			puts("First");
			return 0;
		}
	}
	puts("Second");
	return 0;
}

int read(){
	int x = 0; char ch = getchar();
	for(; !isdigit(ch); ch = getchar());
	for(; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
	return x;
}

void add(int u, int v){
	e[++cnt] = (edge){v, fir[u]}; fir[u] = cnt; ++deg[u];
	return ;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));
    vector<int> res;
    rep(i, n){
        vector<int> div;
        for(int x=1; x*x<=a[i]; x++){
            if(a[i] % x == 0){
                div.push_back(x);
                div.push_back(a[i]/x);
            }
        }
        sort(all(div));
        bool f = true;
        for(int d : div){
            if(binary_search(all(res), d)){
                f = false; break;
            }
        }
        if(f) res.push_back(a[i]);
    }

    int s = 0;
    for(int r: res){
        auto itr = lower_bound(all(a), r);
        auto jtr = upper_bound(all(a), r);
        if(jtr - itr > 1) s++;
    }
    out(res.size()-s);
}

Measured memory_bytes: 5008
#include "bits/stdc++.h"
using namespace std;

int dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };
string S[12];

void DFS(int X, int Y) {
	S[X][Y] = '0';
	for (int i = 0; i < 4; i++) {
		int NX = X + dx[i], NY = Y + dy[i];
		if (0 <= NX && NX < 12 && 0 <= NY && NY < 12) {
			if (S[NX][NY] == '1') DFS(NX, NY);
		}
	}
}

int main() {
	while (cin >> S[0]) {
		int COUNT = 0;
		for (int i = 1; i < 12; i++) cin >> S[i];
		for (int i = 0; i < 12; i++) {
			for (int j = 0; j < 12; j++) {
				if (S[i][j] == '1') {
					COUNT++;
					DFS(i, j);
				}
			}
		}
		cout << COUNT << endl;
	}
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long X, K, D, ans;
    long long amari;
    scanf(" %lld %lld %lld", &X, &K, &D);
    X = abs(X);
    amari = floor(X / D);
    if (amari >= K) ans = X - K * D;
    else if ((K-amari)%2 == 0) ans = abs(X - amari*D);
    else ans = abs(X - (amari+1)*D);
    printf("%lld\n", ans);
}


Measured memory_bytes: 3760
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	double x1, y1, x2, y2, x3, y3;
	double a1, b1, c1, a2, b2, c2;
	double xp, yp, r;
	int loop;
	
	cin >> loop;
	
	while(loop>0){
		while(cin>>x1>>y1>>x2>>y2>>x3>>y3){
			a1 = 2*(x2-x1);
			b1 = 2*(y2-y1);
			c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;
		
			a2 = 2*(x3-x1);
			b2 = 2*(y3-y1);
			c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3;
		
			xp = (b1*c2-b2*c1)/(a1*b2-a2*b1);
			yp = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		
			r = sqrt(pow((x1-xp), 2) + pow((y1-yp), 2));
				
			cout << fixed << setprecision(3) << xp << " " << yp << " " << r << endl;
			
			--loop;
			if(loop==0){
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1288
#include <iostream>

using namespace std;
const int n=100000;
int main()
{
    int H,N,res=0;
    int A[n];
    cin >> H >> N ;
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    for (int i=0; i<N; i++){
        res+=A[i];
    }
    if (res>=H){
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
vector< int > dp;
int dfs(vector< vector< int > > &child, int x) {
	int ret = 0;
	priority_queue< int > q;
	rep(i, child[x].size()) {
		int j = child[x][i];
		q.push(dfs(child, j));
	}
	int k = 1;
	while (!q.empty()) {
		int d = q.top();
		q.pop();
		chmax(ret, d + k);
		k++;
	}
	return ret;
}
signed main() {
	cin >> N;
	vector< int > A(N - 1);
	rep(i, N - 1) {
		cin >> A[i];
		--A[i];
	}
	vector< vector< int > > child(N);
	rep(i, N - 1) child[A[i]].push_back(i + 1);
	dp.resize(N, -1);
	//cout << A;
	cout << dfs(child, 0) << endl;
	return 0;
}

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

using namespace std;

typedef long long  ll;

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

    string s;

    cin >> s;

    cout << s.substr(0, 4) + " " + s.substr(4) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <bitset>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;
const int maxn = 1e5+5;

int n,a[maxn],deg[maxn];
vector<int> g[maxn];
int ok;

void dfs(int u,int fa){
	if(deg[u] == 1) return;
	LL sum = 0LL;
	LL mx = 0LL;
	for(int i = 0;i < g[u].size();i++){
		int v = g[u][i];
		if(v == fa) continue;
		dfs(v,u);
		sum += a[v];
		mx = max(mx,1LL*a[v]);
	}
	if(sum < a[u] || sum > 2*a[u] || mx > a[u]) {
		ok = 0;
		puts("NO");
		exit(0);
	}
	a[u] = 2*a[u] - sum;
}

void solve(){
	int root;
	if(n == 2){
		if(a[1] == a[2]) puts("YES");
		else puts("NO");
		return;
	}
	for(int i = 1;i <= n;i++){
		if(deg[i] != 1){
			root = i;
			break;
		}
	}
	ok = 1;
	dfs(root,-1);
	LL ans = a[root];
	//printf("ans = %I64d ok = %d\n",ans,ok);
	if(ok == 1 && ans == 0) puts("YES");
	else puts("NO");
}

int main(){
	while(scanf("%d",&n) != EOF){
		for(int i = 1;i <= n;i++) g[i].clear();
		for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
		int u,v;
		memset(deg,0,sizeof(deg));
		for(int i = 1;i < n;i++){
			scanf("%d %d",&u,&v);
			g[u].push_back(v);
			g[v].push_back(u);
			deg[u]++;
			deg[v]++;
		}
		solve();
	}
	return 0;
}

/*w*


*/


Measured memory_bytes: 13184
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	mp := make(map[string]int)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		mp[s]++
	}

	var m int
	fmt.Scan(&m)
	for i := 0; i < m; i++ {
		var t string
		fmt.Scan(&t)
		mp[t]--
	}

	ans := 0
	for _, v := range mp {
		if v > ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
from itertools import product
n = int(input())
F = [list(map(int,input().split())) for _ in range(n)]
P = [list(map(int,input().split())) for _ in range(n)]
max_profit = -10**9

for c in product(range(2),repeat=10):
    profit = 0

    if c == (0,0,0,0,0,0,0,0,0,0):
        continue

    for i in range(n): #cに対して、各店との共同営業日を確認していく
        common_business_day = 0
        for j in range(10):
            if c[j] == F[i][j] == 1:
                common_business_day += 1
        profit += P[i][common_business_day]
    
    max_profit = max(profit,max_profit)

print(max_profit)
        

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

#define ll long long

const int max_n = 21;

int count_bits(const int x) {
    int result = 0;
    for(int i = 0; i < max_n; i++)
        result += 0 < (x & (1<<i));
    return result;
}

int main() {
    std::ios::sync_with_stdio(false);
    using namespace std;
    const ll mod = 1'000'000'007;
    ll n;
    cin >> n;
    vector< vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++) {
            int tmp;
            cin >> tmp;
            A[i][j] = tmp;
        }
    vector< vector<ll> > B(n + 1, vector<ll>(1<<n, 0));
    B[0][0] = 1;
    for(int i = 1; i <= n; i++) {
        for(int bm = 0; bm < (1<<n); bm++)
            if(count_bits(bm) == i) {
                for(int j = 0; j < n; j++)
                    if(bm & (1<<j) && A[i - 1][j]) {
                        B[i][bm] = (B[i][bm] + B[i - 1][bm ^ (1<<j)]) % mod;
                    }
            }
    }
#if 0
    for(int i = 0; i <= n; i++) {
        for(int bm = 0; bm < (1<<n); bm++)
            cout << B[i][bm] << " ";
        cout << "\n";
    }
#endif
    cout << B[n][(1<<n) - 1] << "\n";
    return 0;
}


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int h, w; gi(h); gi(w);
	if(h==1 || w==1) print(1);
	else {
		print(1ll*((h+1)/2)*((w+1)/2)+1ll*(h/2)*(w/2));
	}
}


Measured memory_bytes: 2304
//##MohK
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
using ld = long double;
using i= int ;
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    ll s=n;
    while(s!=0){
        sum=sum+(s%10);
        s=s/10;
    }
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
int key;
struct node *left, *right;
};
  

struct node *newNode(int item)
{
struct node *temp =  (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
  

void Preorder(struct node* root)
{
static int hit=0;

if (root == NULL)
  return;
 

  printf(" ");
printf("%d",root->key);
hit=1;
Preorder(root->left); 
 
   
Preorder(root->right);
} 

void inorder(struct node *root)
{
static int h=0;

if (root != NULL)
  {

inorder(root->left);

printf(" ");
printf("%d", root->key);
h=1;
inorder(root->right);
}
}
  

struct node* insert(struct node* node, int key)
{
    
if (node == NULL) return newNode(key);
 
   
if (key < node->key)
  node->left  = insert(node->left, key);
 else if (key > node->key)
   node->right = insert(node->right, key);   
 
   
return node;
}
  

int main()
{
int z,n,i;
char str[7];
   
struct node *root = NULL;
scanf("%d",&n);

for(i=0;i<n;i++){
scanf("%s",str);
if(strcmp(str,"insert")==0)
  scanf("%d",&z);
if(i==0)
  root = insert(root, z);
 else insert(root, z);

if(strcmp(str,"print")==0){
  
    
   
inorder(root);
printf("\n");
Preorder(root);
printf("\n");
}}
return 0;
}



Measured memory_bytes: 18300
#include<bits/stdc++.h>
#define ll long long
#define pb push_back()
#define M 1000000007
#define rep(i , l , r) for(ll i=l; i < r; i++)
#define repr(i , r , l) for(ll i=r; i >= l; i--)

using namespace std;

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    /*#ifndef ONLINE_JUDGE
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    #endif*/

    ll n;
    cin >> n;
    ll h[n+1] = {0} , c[n+1] = {0};
    rep(i , 1 , n+1) cin >> h[i];
    c[1] = 0; c[2] = abs(h[2]-h[1]);
    rep(i , 3 , n+1) {
        c[i] = min(c[i-1] + abs(h[i]-h[i-1]) , c[i-2] + abs(h[i] - h[i-2]));
    }
    cout << c[n] << "\n";
    return 0;

}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main(){
    long int N;

    cin>>N;

    long int A[N],max=-1,num;

    for(long int i=0;i<N;i++){
        cin>>A[i];
        if(max<A[i]){
            max=A[i];
            num=i;
        }
        
    }
    
    bool MAX=false;

    for(long int i=0;i<N;i++){
        if(A[i]==max&&i!=num)MAX=true;
    }
    long int B[N],max2=0;

    
    for(long int j=0;j<N;j++){
        if(A[j]>max2&&A[j]<max)max2=A[j];
    }
    for(long int i=0;i<N;i++){
        if(i==num&&!MAX){
            B[i]=max2;   
        }else{
        B[i]=max;
        }
    }

    for(long int o:B)cout<<o<<endl;
}

Measured memory_bytes: 4736
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;


int main() {
	
	int N=0;
	cin >> N;
	vector<int> INPUT(200);

	for (int i = 0; i < N; i++) {
		cin >> INPUT.at(i);
	}
	
	int ans = 0;
	int FinFlag = 0;

	for(int j=0; j<1000; j++){
		for (int i = 0; i < N; i++) {
			if (INPUT.at(i) % 2 == 0) {
				INPUT.at(i) = INPUT.at(i) / 2;
			}
			else {
				FinFlag = 1;
				break;
			}
		}
		if (FinFlag == 0) {
			ans++;
		}
		else { break; }
	}

	cout << ans;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);i++)

int n,m;
int x[1600], y[1600];
int main(){
    while(cin>>n>>m && n){
        x[0] = y[0] = 0;
        rep(i,n){
            int w; cin>>w;
            x[i+1] = x[i]+w;
        }
        rep(i,m){
            int h; cin>>h;
            y[i+1] = y[i]+h;
        }
        map<int,int> ws;
        rep(i,n+1)rep(j,i) ws[x[i]-x[j]]++;
        int ans = 0;
        rep(i,m+1)rep(j,i) ans += ws[y[i]-y[j]];
        cout << ans << endl;
    }
}

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

int h,w;
string s[20];
bool used[20];

deque<string>v;

bool C(){
	multiset<string>se;
	rep(i,w){
		string t;
		rep(j,h)t+=v[j][i];
		se.insert(t);
	}
	vector<string>a;
	while(!se.empty()){
		string t=*se.begin();se.erase(se.begin());
		string k;
		for(char c:t)k=c+k;
		auto it=se.find(k);
		if(it!=se.end()){
			se.erase(it);
		}
		else{
			a.push_back(t);
		}
	}
	if(w%2==0)return a.empty();
	if(a.size()>1)return 0;
	rep(i,h){
		if(a[0][i]!=a[0][h-i-1])return 0;
	}
	return 1;
}
void dfs(int i){
	if(i==h){
		if(C()){
			puts("YES");exit(0);
		}
		return;
	}
	if(used[i]){
		dfs(i+1);
		return;
	}
	used[i]=true;
	v.push_front(s[i]);
	rep(j,h){
		if(used[j])continue;
		used[j]=true;
		v.push_back(s[j]);
		dfs(i+1);
		used[j]=false;
		v.pop_back();
	}
	v.pop_front();
	used[i]=false;
}
int main(){
	cin>>h>>w;
	rep(i,h)cin>>s[i];
	if(h%2==1){
		rep(i,h){
			v.push_back(s[i]);
			used[i]=true;
			dfs(0);
			used[i]=false;
			v.pop_back();
		}
	}
	else{
		dfs(0);
	}
	puts("NO");
}

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

N = int(input())
L = [input().strip() for _ in range(N)]

target = list(L[0])
s = set()
s.add(L[0])

for i in range(1, N):
    v = L[i]
    if v not in s:
        s.add(v)
        
        vv = list(v)
        if target[-1] != vv[0]:
            print("No")
            exit()
        else:
            target = vv
    else:
        print("No")
        exit()
        
print("Yes")

Measured memory_bytes: 3064
//abc124_d.cpp
//Fri Apr 19 21:23:45 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;

	vector<int> nums;

	if (s[0] == '0'){
		nums.push_back(0);
	}

	int cur = 1;
	for (int i=1;i<n;i++){
		if (s[i]==s[i-1]){
			cur++;
		}else {
			nums.push_back(cur);
			cur = 1;
		}
	}
	nums.push_back(cur);
	if (s[n-1]=='0'){
		nums.push_back(0);
	}

	vector<int> imos;
	imos.push_back(nums[0]);
	for (int i=1;i<nums.size();i++){
		imos.push_back(imos[i-1]+nums[i]);
	}

	int ans = 0;
	for (int i=0;i<imos.size();i=i+2){
		int temp = 0;
		int end = i+2*k;
		if (i+2*k>imos.size()-1){
			end = imos.size()-1;
		}

		if (i!=0){
			temp = imos[end]-imos[i-1];
		}else {
			temp = imos[end];
		}
		ans = max(temp,ans);
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d){
		cout<<"Yes"<<endl;
	}
	else if(abs(a-b)<=d&&abs(b-c)<=d){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import(
	"fmt"
	"os"
	"bufio"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
  sc.Scan()
  i, err := strconv.Atoi(sc.Text())
  if err != nil{
    panic(err)
  }
  return i
}

func main(){
  var m int
  var sum int = 1
  var f bool = false
  
  sc.Split(bufio.ScanWords)

  for i := 0; i < 2; i++{
    m = nextInt()
    if m > 9{
      f = true
      continue
    }
    sum *= m
  }
  if(f){
    fmt.Println(-1)
    return
  }
  fmt.Println(sum)
}

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

int n,arr[101],sum;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i = 1;i <= n;i++){
		cin>>arr[i];
	}
	sort(arr + 1,arr + n + 1);
	for(int i = 1;i <= n;i++){
		if(arr[i] != arr[i - 1]){
			sum++;
		}
	}
	cout<<sum<<endl;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll X;

ll i, j, k;
int main(){
    scanf("%lld", &X);
    i = 0;
    while(X>=500){
        i += 1000;
        X -= 500;
    }
    while(X>=5){
        i += 5;
        X -= 5;
    }
    printf("%lld\n", i);

    return 0;
}

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

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn encode(s: String, k: usize) -> usize {
    let x = match s.as_bytes()[0] as char {
        'S' => 0,
        'H' => 1,
        'C' => 2,
        'D' => 3,
        _ => panic!()
    };
    x * 13 + k - 1
}

fn decode_print(id: usize) {
    let s = ['S', 'H', 'C', 'D'];
    println!("{} {}", s[id / 13], id % 13 + 1);
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let mut used = [false; 52];
    let n = sc.read();
    for _ in 0..n {
        let s = sc.read();
        let k = sc.read();
        let id = encode(s, k);
        used[id] = true;
    }
    for i in 0..52 {
        if !used[i] {
            decode_print(i);
        }
    }
}



Measured memory_bytes: 5028
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

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

	      	  int N;
	      	  cin >> N;

	      	  for(i=1;i<=N;i++){
	      		  int t,x,y;
	      		  cin >> t >> x >> y;
	      		  if(t>=x+y && t%2==(x+y)%2) continue;
	      		  else{
	      			  cout << "No" << endl;
	      			  return 0;
	      		  }
	      	  }

	      	  cout << "Yes" << endl;

	          return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, 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 1; } return 0; }
const int INF = 1000000000;

int digit_sum(int x){
    int ret = 0;
    while (x > 9){
        ret += x%10;
        x /= 10;
    }
    ret += x%10;
    return ret;
}


int main() {
    int N;
    cin >> N;
    int ans = INF;
    for (int i=1; i<N; i++){
        chmin(ans, digit_sum(i) +  digit_sum(N-i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 924844033;

struct Combi
{
	vector<int> fact;
	vector<int> ifact;
	vector<int> inv;
	vector<int> pow2;
	int add(int a, int b)
	{
		a+=b;
		while(a>=MOD) a-=MOD;
		return a;
	}
	int mult(int a, int b)
	{
		return (a*1LL*b)%MOD;
	}
	int modpow(int a, int b)
	{
		int r=1;
		while(b)
		{
			if(b&1) r=mult(r,a);
			a=mult(a,a);
			b>>=1;
		}
		return r;
	}
	int choose(int a, int b)
	{
		if(a<b) return 0;
		if(b==0) return 1;
		if(a==b) return 1;
		return mult(fact[a],mult(ifact[b],ifact[a-b]));
	}
	int inverse(int a)
	{
		return modpow(a,MOD-2);
	}
	void init(int _n)
	{
		fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
		fact.resize(_n+1);
		ifact.resize(_n+1);
		inv.resize(_n+1);
		pow2.resize(_n+1);
		pow2[0]=1;
		ifact[0]=1;
		fact[0]=1;
		for(int i=1;i<=_n;i++)
		{
			pow2[i]=add(pow2[i-1],pow2[i-1]);
			fact[i]=mult(fact[i-1],i);
			//ifact[i]=mult(ifact[i-1],inv[i]);
		}
		ifact[_n] = inverse(fact[_n]);
		for(int i=_n-1;i>=1;i--)
		{
		    ifact[i] = mult(ifact[i + 1], i + 1);
		}
		for(int i=1;i<=_n;i++)
		{
		    inv[i] = mult(fact[i-1],ifact[i]);
		}
	}
};

int a[4111];
int dp[4111][2111];
vi adj[4111];
int ptr=0;
int n,k; 
bool vis[4111];

Combi combi;

void dfs(int u)
{
	vis[u]=1;
	int id=u/2;
	int res=0;
	if(u%2==0) res=1;
	if(id+k<n)
	{
		int v=(id+k)*2+res;
		if(!vis[v])
		{
			a[ptr++] = 1;
			dfs(v);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>k;
	combi.init(5001);
	for(int i=0;i<2*n;i++)
	{
		if(!vis[i])
		{
			a[ptr++]=0;
			dfs(i);
		}
	}
	dp[0][0]=1;
	for(int i=1;i<2*n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>0&&a[i])
			{
				int v=0;
				if(i==1&&j==1) v=1;
				if(i>=2) v=dp[i-2][j-1];
				dp[i][j]=combi.add(dp[i][j],v);
			}
		}
	}
	int cur = 1;
	int ans = 0;
	for(int i = 0; i <= n; i++)
	{
		ans=combi.add(ans, combi.mult(dp[2*n-1][i], combi.mult(cur, combi.fact[n-i])));
		cur=combi.mult(cur,MOD-1);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 33408
#include<iostream>
using namespace std;
int main(){
  double d;
  while(cin >> d){
    string s;
    if(d<=48.0) s="light fly";
    else if(d<=51.0) s="fly";
    else if(d<=54.0) s="bantam";
    else if(d<=57.0) s="feather";
    else if(d<=60.0) s="light";
    else if(d<=64.0) s="light welter";
    else if(d<=69.0) s="welter";
    else if(d<=75.0) s="light middle";
    else if(d<=81.0) s="middle";
    else if(d<=91.0) s="light heavy";
    else s="heavy";
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 3224
def get_info(diff):
    length = int(input())
    strings = {}
    for _ in range(length):
        tmp = input()
        if tmp in strings:
            strings[tmp] += diff
        else:
            strings[tmp] = diff
    return length, strings


def main():
    blue_card, blue_card_str = get_info(1)
    red_card, red_card_str = get_info(-1)
    answer = 0
    available_keys = (blue_card_str.keys() & red_card_str.keys()) | blue_card_str.keys()
    for key in available_keys:
        if key in red_card_str:
            diff = blue_card_str[key] + red_card_str[key]
        else:
            diff = blue_card_str[key]
        answer = max(answer, diff)
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll N,D;
ll X[200000];
ll Y[200000];

int main(){
    cin>>N>>D;
    rep(i,N) cin>>X[i]>>Y[i];

    D*=D;
    rep(i,N) X[i]*=X[i];
    rep(i,N) Y[i]*=Y[i];

    ll ans=0;
    rep(i,N) if(X[i]+Y[i]<=D) ans++;

    cout<<ans<<endl;
}

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

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

    if (x == 2 || y == 2)
    {
        cout << "No" << endl;
    }
    else if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))
    {
        cout << "Yes" << endl;
    }
    else if (((x <= 7 && x % 2 == 1) || (x >= 8 && x % 2 == 0)) && ((y <= 7 && y % 2 == 1) || (y >= 8 && y % 2 == 0)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main{
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final List<Long> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextLong())
                .sorted()
                .collect(Collectors.toList());

        final List<Long> list1 = createList(n, 1);
        final List<Long> list2 = createList(n, -1);

        System.out.println(Math.max(sum(list, list1), sum(list, list2)));
    }

    private static long sum(final List<Long> list1, final List<Long> list2) {
        long sum = 0;
        for (int i = 0; i < list1.size(); i++) {
            sum += list1.get(i) * list2.get(i);
        }
        return sum;
    }

    private static List<Long> createList(final int length, long sign) {
        final List<Long> list = new ArrayList<>(length);
        for (int i = 0; i < length; i++) {
            if (i == 0) {
                list.add(sign);
            } else if (i == length - 1) {
                list.add(sign);
            } else {
                list.add(2 * sign);
            }
            sign *= -1;
        }
        Collections.sort(list);
        return list;
    }
}


Measured memory_bytes: 64340
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		boolean can = false;
		int nextId = 0;
		int count = 0;

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

		while (count != N) {
			nextId = a[nextId] - 1;
			count++;
			if (nextId == 1) {
				can = true;
				break;
			}
		}

		if (can) {
			System.out.println(count);
		} else {
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 50908
n = int(input())
A = list(map(int,input().split()))
l = [[0,0],[0,0],[0,0]]
flag = 0
for i in range(n):
  x = A[i]
  for j in range(3):
    if l[j] == [0,0]:
      l[j] = [x,1]
      break
    if x == l[j][0]:
      l[j][1] += 1
      break
  else:
    break
a = l[0][1]
b = l[1][1]
c = l[2][1]
aa = l[0][0]
bb = l[1][0]
cc = l[2][0]
if n % 3 == 0:
  m = n // 3
  if a == m:
    if b == m and c == m:
      if aa ^ bb ^ cc == 0:
        flag = 1
  if a == 2 * m and b == m:
    if bb == 0:
      flag = 1
  if a == m and b == 2 * m:
    if aa == 0:
      flag = 1
if a == n and aa == 0:
  flag = 1
if flag == 1:
  print('Yes')
else:
  print('No')

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

using namespace std;
typedef long long ll;
int n,p;

int main(){
  cin >> n >> p;
  bool kisuu = false;
  ll ans = 1;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(a % 2 == 1) kisuu = true;
    ans *= 2;
  }

  if(!kisuu && p == 1) { cout <<"0"<<endl; return 0; }
  else if(kisuu) ans /= 2;

  cout << ans <<endl;
}
  


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MN 205
#define INF 1<<25
#define init(a) memset(a,0x0f,sizeof(a))
#define min(a,b) (a<b?a:b)
int N,M,R,de[1005],S[MN][MN],L[MN][MN],i,j,k,x,y,s;
int dp[1005][205];

int main()
{
	for(;scanf("%d%d",&N,&M),N;)
	{
		init(S);init(L);init(dp);
		for(i=0;i<N;i++)L[i][i]=S[i][i]=0;
		for(i=0;i<M;i++)
		{
			char t;
			scanf("%d%d%d %c",&x,&y,&s,&t);
			x--;y--;
			if(t=='L')L[x][y]=L[y][x]=s;
			else S[x][y]=S[y][x]=s;
		}
		for(scanf("%d",&R),i=0;i<R;de[i++]--)scanf("%d",&de[i]);
		for(k=0;k<N;k++)
			for(i=0;i<N;i++)
				for(j=0;j<N;j++)
				{
					S[i][j]=min(S[i][j],S[i][k]+S[k][j]);
					L[i][j]=min(L[i][j],L[i][k]+L[k][j]);
				}
		dp[0][de[0]]=0;
		for(k=0;k<R-1;k++)
			for(i=0;i<N;i++)
				for(j=0;j<N;j++)
				{
					dp[k+1][i] = min(dp[k+1][i],dp[k][j]+L[de[k]][j]+S[j][i]+L[i][de[k+1]]);
					if(i == j) dp[k+1][i] = min(dp[k+1][i], dp[k][j] + L[de[k]][de[k+1]]);
				}
		for(i=0,s=INF;i<N;i++)s=min(s,dp[R-1][i]);
		printf("%d\n",s);
	}
	return 0;
}

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

using namespace std;

int main(){

  string s1,s2;
  bool t = false;

  while(1){
	int cnt = 0;
	cin>>s1;

	if(s1==".")
	  break;

	cin>>s2;

	if(s1==s2){
	  cout<<"IDENTICAL"<<endl;
	  continue;
	}

	else{
	  int i=0;
	  int j=0;
	  t = false;
	  
	  while(1){

		if(s1[i]=='\0' &&  s2[j]=='\0')
		  break;
		
		if(s1[i]!=s2[j]){
		  cout<<"DIFFERENT"<<endl;
		  t = true;
		  break;
		}
		
		if(s1[i]=='\"' && s2[j]=='\"'){
		  i++;
		  j++;
		  
		  while(1){
			if(s1[i]=='\"' && s2[j]=='\"')
			  break;
			
			if(s1[i]!=s2[j]){
			  cnt++;
			  while(s1[i]!='\"')
				i++;
			  while(s2[j]!='\"')
				j++;
			  break;
			}
			i++;
			j++;
		  } 
		}
		  i++;
		  j++;
	  }
	  if(t == true)
		continue;
	}
	if(cnt == 1)
	  cout<<"CLOSE"<<endl;
	else
	  cout<<"DIFFERENT"<<endl;
  }
}



Measured memory_bytes: 3188
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<pii> dir = {mp(1, 0), mp(0, 1), mp(-1, 0), mp(0, -1)};

int main(){
    StarBurstStream

    int h, w;
    cin >> h >> w;

    deque<pair<pii, int>> dq;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    dq.eb(mp(mp(ch, cw), 0));
    vector<string> a(h + 2);
    a[0] = a[h + 1] = string(w + 2, '#');
    vector<vector<int>> dis(h + 2, vector<int>(w + 2, MAX));
    dis[ch][cw] = 0;
    for(int i = 1; i <= h; i++){
        cin >> a[i];
        a[i] = '#' + a[i] + '#';
    }

    while(!dq.empty()){
        pii now = dq.front().F;
        int d = dq.front().S;
        dq.pof;
        if(d != dis[now.F][now.S]) continue;

        for(pii di : dir){
            int nx = now.F + di.F;
            int ny = now.S + di.S;
            if(a[nx][ny] == '#' || dis[nx][ny] <= d) continue;
            dq.emplace_front(mp(mp(nx, ny), d));
            dis[nx][ny] = d;
        }

        for(int i = -2; i <= 2; i++){
            for(int j = -2; j <= 2; j++){
                if(i == 0 && j == 0) continue;
                int nx = now.F + i;
                int ny = now.S + j;
                if(nx <= 0 || nx > h || ny <= 0 || ny > w || a[nx][ny] == '#' || dis[nx][ny] <= d + 1) continue;
                dq.eb(mp(mp(nx, ny), d + 1));
                dis[nx][ny] = d + 1;
            }
        }
    }
//    for(int i = 0; i <= h; i++) printv(dis[i], cerr);

    if(dis[dh][dw] == MAX) cout << "-1\n";
    else cout << dis[dh][dw] << "\n";

    return 0;
}

Measured memory_bytes: 9604