akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

const int maxn = 2e5 + 5;
const int inf = 1e9;
int n;
int v[maxn];
int a1[maxn], a2[maxn], b1[maxn], b2[maxn];
struct segment{
	int l, r;
	int val;
} arr[maxn << 2];
long long ans = 0;
void debug(){
	for(int i=1;i<=2*n;i++) printf("%d %d %d %d\n",i,arr[i].l,arr[i].r,arr[i].val);
	printf("\n"); 
}
int build(int pos, int l, int r){
	if(l == r){
		arr[pos].val = v[l];
		arr[pos].l = arr[pos].r = r;
		return arr[pos].val;
	}
	int mid = (l + r) >> 1;
	arr[pos].l = l, arr[pos].r = r;
	arr[pos].val = std::max(build(2*pos,l,mid), build(2*pos+1,mid+1,r));
	return arr[pos].val;
}

int query(int pos, int l, int r){
	if(l > r) return 0;
	int lseg = arr[pos].l, rseg = arr[pos].r;
	if(lseg > r || rseg < l) return 0;
	if(lseg >= l && rseg <= r) return arr[pos].val;
	else return std::max(query(2*pos,l,r),query(2*pos+1,l,r));
}

int solve1(int val, int l, int r){
	if(l == r) return l;
	int mid = (l + r) >> 1;
	if(query(1,l,mid) > val) return solve1(val,l,mid);
	else return solve1(val,mid+1,r);
}

int solve2(int val, int l, int r){
	if(l == r) return l;
	int mid = (l + r) >> 1;
	if(query(1,mid+1,r) > val) return solve2(val,mid+1,r);
	else return solve2(val,l,mid);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	build(1,1,n);
	//debug();
	for(int i=1;i<=n;i++){
		if(query(1,1,i-1) > v[i]){
			a1[i] = solve2(v[i],1,i-1);
			if(query(1,1,a1[i]-1) > v[i]) a2[i] = solve2(v[i],1,a1[i]-1);
			else a2[i] = 0;
		} 
		else a1[i] = a2[i] = 0;
		if(query(1,i+1,n) > v[i]){
			b1[i] = solve1(v[i],i+1,n);
			if(query(1,b1[i]+1,n) > v[i]) b2[i] = solve1(v[i],b1[i]+1,n);
			else b2[i] = n+1;
		}
		else b1[i] = b2[i] = n+1;
	}
	//for(int i=1;i<=n;i++) printf("%d %d %d %d\n",a1[i],a2[i], b1[i], b2[i]);
	for(int i=1;i<=n;i++){
		if(a1[i] > 0) ans += (long long) v[i] * (a1[i] - a2[i]) * (b1[i] - i);
		if(b1[i] <= n) ans += (long long) v[i] * (b2[i] - b1[i]) * (i - a1[i]);
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  int i = 0;
  while (i < (s.size()-1-i)) {
    if (s.at(i) != s.at(s.size()-1-i)) {ans++;}
    i++;
  }
  cout << ans << endl;
}


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;

  vvP to(n);
  rep(i, m) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    to[l].emplace_back(c, r);
    to[r].emplace_back(c, l);
  }
  rep(i, n - 1) to[i + 1].emplace_back(0, i);

  priority_queue<P, vP, greater<P>> pque;
  vll dist(n, INF);
  dist[0] = 0;
  pque.push({0, 0});
  while (!pque.empty()) {
    P p = pque.top();
    pque.pop();
    ll du, u;
    tie(du, u) = p;
    if (dist[u] < du) continue;
    for (auto e : to[u]) {
      ll c, v;
      tie(c, v) = e;
      if (dist[v] > du + c) {
        dist[v] = du + c;
        pque.push({du + c, v});
      }
    }
  }

  rep(i,n) if (dist[i] == INF) dist[i] = -1;
  cout << dist[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 12536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int n,a,b;

bool judge(int key,vint H){
  rep(i,0,n){
    H[i] -= b*key;
  }
  int count = 0;
  rep(i,0,n){
    if(H[i] > 0){
      count += (H[i]-1)/(a-b) + 1;
    }
  }
  return count <= key;
}
signed main(){
  cin >> n >> a >> b;
  vint H(n);
  rep(i,0,n) cin >> H[i];
  int ng = -1;
  int ok = 11010101010;
  while(abs(ng - ok) > 1){
    int mid = (ok + ng)/2;
    if(judge(mid,H)){
      ok = mid;
    }
    else ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if (a > b && b != 1){
    cout << "Alice";
  }
  else if (a == 1 && b != 1){
    cout << "Alice";
  }
  else if (a < b && a != 1){
    cout << "Bob";
  }
  else if (a != 1 && b == 1){
    cout << "Bob";
  }
  else{
    cout << "Draw";
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

long long dp[100005],arr[100005],n,k;

long long min(long long a,long long b) {return (a<b?a:b);}

long long solve(long long index)
{
  long long mini;
  if(index<0) return (long long)1000000009;
  if(index==0) return 0;
  if(dp[index]!=-1) return dp[index]; 
  else
  {
    dp[index]=solve(index-1)+fabs(arr[index-1]-arr[index]);
    for(int i=2;i<=k;i++)
    {
      mini=solve(index-i)+fabs(arr[index-i]-arr[index]);
      if(dp[index]>mini)
        dp[index]=mini;
    }
    return  dp[index];
  }
}

int main()
{
  long long ans;
  scanf("%lld%lld",&n,&k);
  for(int i=0;i<n;i++)
    scanf("%lld",&arr[i]);
  for(int i=0;i<100005;i++) dp[i]=-1;
  ans=solve(n-1);
  printf("%lld",ans);
  return 0;
}


Measured memory_bytes: 4864
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    string s;
    cin >> s;
    for (char c = 'a'; c <= 'z'; c++) {
        int left_min = 1;
        int min_idx = -1;
        int c_cnt = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == c) {
                c_cnt++;
            }
            if (2 * c_cnt - i > left_min && i >= min_idx + 2) {
                cout << min_idx + 2 << " " << i + 1 << endl;
                return 0;
            }
            if (2 * c_cnt - i < left_min) {
                left_min = min(left_min, 2 * c_cnt - i);
                min_idx = i;
            }
        }
    }
    cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
using ll = long long;

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

int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;

	if (X + Y + Z >= 22) { cout << "bust" << endl; }
	else { cout << "win" << endl; }
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
works = []
n.times { works << gets.split.map(&:to_i) }
availables = []
1.upto(m) do |index|
  availables << index
end
works.sort! { |a, b| (b[1] <=> a[1]).nonzero? || b[0] <=> a[0] }
sum = 0
works.each do |day, salary|
  if index = availables.bsearch_index { |item| item >= day }
    availables.delete_at(index)
    sum += salary
  end
end
puts sum


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

int n, k, d, a, ans;

int main() {
  cin >> n >> k;
  vector<bool> sunke(n, false);
  rep (i, k) {
    cin >> d;
    rep (j, d) {
      cin >> a;
      sunke[a-1] = true;
    }
  }
  ans = 0;
  rep (i, n) {
    if (!sunke[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll H,W,x,y; cin >> W >> H >> x >> y;

    cout << double(W*H)/2 << " ";

    if(W%2==0 && H%2 == 0 && H/2 == y && W/2 == x) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 100001
int arr[MAX], N;

int main()
{
  string S;
  cin >> S;
  for(int i=0;i<3;i++){
    if(S[i]==S[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int x,y; cin >> x >> y;

    rep(i,x+1){
        if(i*2+(x-i)*4==y){
            couty;
            return 0;
        }
    }
    coutn;
}

Measured memory_bytes: 3636
#include<cstdio>

char s[10];
int ans, tans;

template<class I>
inline I max(I a, I b) {
	return a > b ? a : b;
}

int main(void) {
	scanf("%s", s);
	for (register int i = 0; i < 3; ++i)
		if (s[i] == 'R')
			++tans,
			ans = max(ans, tans);
		else
			tans = 0;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1712
n = int(input())
H = list(map(int, input().split()))

most = 0
for i in range(n-2, 0, -1):
    if H[i] > H[i+1]:
        H[i] -= 1

    if H[i] > H[i+1]:
        print('No')
        exit()

print('Yes')

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

using namespace std;

int n, W;
long long w[143], v[143];
long long dp[100043];

int main() {
  cin >> n >> W;
  for (int i = 1; i <= n; ++i) {
    cin >> w[i] >> v[i];
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = W; j >= w[i]; --j) {
      dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
    }
  }

  cout << dp[W] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, A, B;
	cin >> N >> A >> B;
	int a[40], b[40], c[40];
	rep(i, N) {
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[401][401][41];
	rep(i, 401) rep(ii, 401) rep(iii, 41) dp[i][ii][iii] = 10000;
	dp[0][0][0] = 0;

	rep(i, N) {
		rep(j, 391) {
			rep(k, 391) {
				if (dp[j][k][i] != 10000) {
					dp[j][k][i + 1] = min(dp[j][k][i + 1], dp[j][k][i]);
					dp[j + a[i]][k + b[i]][i + 1] = min(dp[j + a[i]][k + b[i]][i + 1], dp[j][k][i] + c[i]);
				}
			}
		}
	}
	
	int kaisuu = 400 / max(A, B);
	int saishou = 10000;
	rep1(i, kaisuu) {
		saishou = min(saishou, dp[A * i][B * i][N]);
	}

	if (saishou != 10000) co(saishou);
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 25984
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <numeric>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

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

	vector<int> num;
	int cnum[6];
	int tmp;

	REP(i,3)
	{
		cin >> tmp;
		num.push_back(tmp);
	}
	
	 sort(num.begin(),num.end());

	 cout << (num[2] * 10) + num[1] + num[0] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll k;
  cin >> k;
  string s;
  cin >> s;
  if(sz(s)<=k){
    print(s);
  }
  else{
    s.erase(k);
    cout << s << "..." << endl;
  }
}

Measured memory_bytes: 3624
S = input()
# judge
jf, jl = 0 < int(S[:2]) <= 12, 0 < int(S[2:]) <= 12

if jf and jl:
    print('AMBIGUOUS')
elif jf and not jl:
    print('MMYY')
elif not jf and jl:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> W(N);
    for (int i = 0; i < N; i++) {
        std::cin >> W[i];
    }

    std::vector<int> S(N+1);
    S[0] = 0;
    for (int i = 1; i <= N; i++) {
        S[i] = S[i-1] + W[i-1];
    }

    int ans = 100000;
    for (int t = 0; t < N; t++) {
        int left = S[t];
        int right = S[N] - S[t];
        ans = std::min(std::abs(left - right), ans);
    }

    std::cout << ans << std::endl;

    
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();
		ArrayList<Integer> prices = new ArrayList<>();
		int total = 0;

		for (int i = 0; i < N; i++) {
			int p = scanner.nextInt();
			prices.add(p);
		}

		Collections.sort(prices);

		for (int j = 0; j < K; j++) {
			int price = prices.get(j);
			total += price;
		}

		System.out.println(total);
	}

}

Measured memory_bytes: 39440
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

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

bool visited[10005];
int p;
vector<int>c,d;
vector<vector<int>>g;

void dfs(int v){
    visited[v]=true;
    d[v]=c[p];
    ++p;
    for(auto x:g[v]){
      if(!visited[x]){
        dfs(x);
      }
    }
}

void solve(){
  int n;
  cin>>n;
  vector<int>cnt(n);
  c.resize(n);d.resize(n);
  g.resize(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  rep(i,n)cin>>c[i];
  sort(c.rbegin(),c.rend());
  dfs(0);//始点は自分で決めてよい
  int sum=0;
  for(int i=1;i<n;++i)sum+=c[i];//一番大きいもの以外の和
  cout<<sum<<"\n";
  rep(i,n){
    if(i)cout<<" ";
    cout<<d[i];
  }
  cout<<"\n";
  return;
}

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


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int []arr=new int[5];
		int sum=0;
		int min=9;
		int flag=0;
		for(int i=0;i<5;i++) {
			arr[i]=scn.nextInt();
			sum+=arr[i];
			if(sum%10!=0) {
				if(sum%10<=min) {
					flag=1;
					min=sum%10;
				}
			}
			sum+=sum%10!=0?10-sum%10:0;
			//System.out.println(sum);
		}
		System.out.println(sum+(flag==1?-10+min:0));
	}

}


Measured memory_bytes: 21716
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##

class union_find:
    def __init__(self, n):
        self.N = n
        self._parent = [i for i in range(self.N)]
        self._mem = [1] * self.N
        self.compo = self.N

    def parent(self, a):
        if self._parent[a] == a:
            return a
        self._parent[a] = self.parent(self._parent[a])
        return self._parent[a]

    def united(self,a, b):
        return self.parent(a) == self.parent(b)
    
    def unite(self,a, b):
        a = self.parent(a)
        b = self.parent(b)
        if(a == b): return False
        if self._mem[a] > self._mem[b]: a, b = b, a
        self._parent[a] = b
        self._mem[b] += self._mem[a]
        self.compo -= 1
        return True
    
    def is_root(self,a):
        return a == self._parent[a]
    def mem_cnt(self,a):
        return self._mem[self.parent(a)]
    def dump(self):
        print(self._parent)
    

def main():
    N, M, K = rip()
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = rip()
    C = [0] * K
    D = [0] * K
    for i in range(K):
        C[i], D[i] = rip()

    uf = union_find(N)
    for i in range(M):
        uf.unite(A[i] - 1, B[i] - 1)

    ans = [0] * N
    for i in range(N):
        ans[i] = uf.mem_cnt(i) - 1
    for i in range(K):
        if uf.united(C[i] - 1, D[i] - 1):
            ans[C[i] - 1] -= 1
            ans[D[i] - 1] -= 1
    for i in range(M):
        ans[A[i] - 1] -= 1
        ans[B[i] - 1] -= 1

    print(" ".join([str(n) for n in ans]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 40612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<vector<int> > vec;
  vector<int> vbuf(2);
  for(int i=0; i<N; i++){
    cin>>vbuf[1]>>vbuf[0];
    vec.push_back(vbuf);
  }
  sort(vec.begin(),vec.end());
  int time=0;
  int flag=0;
  for(int i=0; i<vec.size(); i++){
    time+=vec[i][1];
    if(time>vec[i][0]){
      flag=1;
      break;
    }
  }
  if(flag==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 14124
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	vector<int> demical(ll n, int k, int l = -1) {
		vector<int> rtn;
		if (l < 0) {
			while (n > 0) {
				rtn.push_back(n % k);
				n /= k;
			}
		} else {
			rtn.resize(l);
			REP(i, l) {
				rtn[i] = n % k;
				n /= k;
			}
		}
		return rtn;
	}

	void solve() {
		IOS;
		int n,m;
		cin >> n >> m;
		vector<vector<int>> s(m);
		REP(i, m) {
			int k;
			cin >> k;
			s[i].resize(k);
			REP(j, k) {
				cin >> s[i][j];
				s[i][j]--;
			}
		}
		vector<int> p(m);
		REP(i, m) {
			cin >> p[i];
		}
		int res = 0;
		int t = 1 << n;
		REP(i, t) {
			auto d = demical(i, 2, n);
			int tmp = 0;
			vector<int> cnt(m, 0);
			REP(j, m) {
				REP(k, s[j].size()) {
					if (d[s[j][k]]) {
						cnt[j]++;
					}
				}
			}
			bool flag = true;
			REP(j, m) {
				if (cnt[j] % 2 != p[j]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				res++;
			}
		}
		put(res);
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
int main() {
  string s;
  cin>>s;
  int ans=1e9;
  for (int i=1; i+1<s.size(); i++) {
    int x=(s[i-1]-'0')*100+(s[i]-'0')*10+(s[i+1]-'0');
    ans=min(ans,abs(x-753));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

struct Task { int a, b; };

int main() {
  int n;
  cin >> n;
  vector<Task> tasks;
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    tasks.push_back((Task){a, b});
  }
  sort(tasks.begin(), tasks.end(), [&](auto &l, auto &r){
    return l.b < r.b;
  });
  int now = 0;
  for (auto &t: tasks) {
    if (now+t.a > t.b) { 
      cout << "No" << endl;
      return 0;
    }
    now += t.a;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<math.h>
#include<limits.h>
#define _USE_MATH_DEFINES

using namespace std;

int n;
int w[300000] = {}, ans = INT_MAX, pre = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		char c;
		cin >> c;
		if (i == 0) {
			if (c == 'W') {
				w[0] = 1;
			}
		}
		else {
			w[i] = w[i - 1];
			if (c == 'W') {
				w[i] += 1;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (i == 0) {
			ans = n - w[n - 1];
		}
		else {
			ans = min(ans,  w[i - 1] + ((n - i - 1) - (w[n - 1] - w[i])));
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    int n; //1 < n < 10^2
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);


    for(int i = 0; i < n; i++){ // a[i] <= 10^3
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    double mx = 0;

    //p = 1
    double cnt1 = 0;
    for(int i = 0; i < n; i++){
        cnt1 += abs(a[i]-b[i]);
        chmax(mx,(double)abs(a[i]-b[i]));
    }
    printf("%.8lf\n",cnt1);

    //p = 2
    double cnt2 = 0;
    for(int i = 0; i < n; i++){
        cnt2 += (a[i]-b[i])*(a[i]-b[i]);
    }
    cnt2 = sqrt(cnt2);

    printf("%.8lf\n",cnt2);

    //p = 3
    double cnt3 = 0;
    for(int i = 0; i < n; i++){
        cnt3 += abs(a[i]-b[i])*abs(a[i]-b[i])*abs(a[i]-b[i]);
    }
    cnt3 = cbrt(cnt3);

    printf("%.8lf\n",cnt3);

    //p = ∞
    printf("%.8lf",mx);

}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;
int N;

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

    std::cin >> S;

    N = S.size();

    int c = -1, n = 0;
    for(int i=0,j=0;i<N;i=j){
        while(j < N && S[j] == S[i]){
            j += 1;
        }

        int m = j - i;
        if(c == -1){
            c = S[i] - '0';
            n = m;
        }else if(c == S[i] - '0'){
            n += m;
        }else{
            if(n > m){
                n -= m;
            }else if(n == m){
                c = -1;
                n = 0;
            }else{
                c = S[i] - '0';
                n = m - n;
            }
        }
    }

    int res = N - n;
    std::cout << res << std::endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

int main(){
    while(1){
        string s; cin>>s;
        if(s == "#") return 0;
        int a, b, c, d; cin>>a>>b>>c>>d;
        a--, b--, c--, d--;

        vector<vector<int>> board(10, vector<int>(10));

        int H=0, W=0;
        int h=0, w=0;
        for(int i=0; i<s.size(); i++){
            if(s[i] == 'b'){
                board[h][w] = 1;
                w++;
            }
            else if(s[i] == '/'){
                h++;
                w = 0;
            }
            else{
                int num = (s[i] - '0');
                for(int j=w; j<w+num; j++){
                    board[h][j] = 0;
                }
                w += num;
            }

            chmax(H, h);
            chmax(W, w - 1);
        }

        swap(board[a][b], board[c][d]);

        string ans="";
        for(int i=0; i<=H; i++){
            for(int j=0; j<=W; j++){
                if(board[i][j] == 1){
                    ans += "b";
                }
                else{
                    int num=0;
                    while(j <= W && board[i][j] == 0){
                        num++;
                        j++;
                    }

                    j--;
                    ans += patch::to_string(num);
                }
            }

            if(i != H) ans += "/";
        }

        cout << ans << endl;
    }
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> vec(N);
	for (auto& v : vec)
	{
		cin >> v;
	}

	bool ret = true;
	int temp = vec[0];
	for (int i = 1; i < N; ++i)
	{
		if (temp <= vec[i] - 1)
		{
			temp = vec[i] - 1;
		}
		else if (temp <= vec[i])
		{
			temp = vec[i];
		}
		else
		{
			ret = false;
			break;
		}
	}

	string s = ret ? "Yes" : "No";
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cmath>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define ll long long
using namespace std;
struct data{
    long long a,b;
}Data;
bool cmp(const data& m,const data& n){return m.a<n.a;}

int main(){
    ll n,k;
    cin>>n>>k;
    vector<data> ans(n);
    rep(i,0,n)cin>>ans[i].a>>ans[i].b;
    sort(ans.begin(),ans.end(),cmp);
    rep(i,0,n){
        k-=ans[i].b;
        if(k<=0){
            cout<<ans[i].a<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]

ans = 0
for i in A:
    day = 1
    cnt = 0
    while day <= D:
        ans += 1
        cnt += 1
        day = cnt*i+1
print(ans+X)

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

int main(void) {
  string S;
  cin >> S;
  
  if(S[0]=='S') cout << "Cloudy" << endl;
  else if(S[0]=='C') cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    map<int, int> a;
    for (int i = 0; i < n; i++) {
        int aa;
        cin >> aa;
        a[aa]++;
    }
    int ans = 0;
    for (auto& e : a) {
        if (e.second % 2 == 1) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		string s;
		cin>>s;
		vi d(n,0);
		int ba=0;
		rep(i,0,100){
			int turn=i%n;
			if(s[i]=='M'){
				d[turn]++;
			}else if(s[i]=='S'){
				ba+=d[turn]+1;
				d[turn]=0;
			}else{
				d[turn]+=ba+1;
				ba=0;
			}
		}
		sort(all(d));
		rep(i,0,n){
			cout<<d[i]<<" ";
		}
		o(ba);
	}
}

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

int main(){
	int a,b;
	cin >> a >> b;
	int c,d;
	cin >> c >> d;
	
	if(a==c) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int A,B;
	cin>>A>>B;
	int t=1;
	int cnt=0;
	while(true){
		if(t>=B){
			break;
		}
		t+=A-1;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll solve1(ll x) {
    ll ret=1;
    for (ll i=2;i*i<=x;i++){
        if (x%i==0){
            ret+=2;
            if (x/i==i)ret--;
        }
    }
    return ret;
}
ll solve2(ll x) {
    ll ret=1,tp;
    for (ll i=2;i*i<=x;i++) {
        if (x%i==0){
            ll tmp=x/i;
            tp=x;
            while (tp%i==0){
                tp/=i;
            }
            if (tp>i)tp%=i;
            ret+=(tp==1);
            if (tmp!=i) {
                tp=x;
                while(tp%tmp==0){
                    tp/=tmp;
                }
                if (tp>tmp)tp%=tmp;
                ret+=(tp==1);
            }
        }
    }
    return ret;
}
int main(){
 ll n;
    cin>>n;
    if (n==2) {
        cout << 1;
        return 0;
    }
    cout<<solve1(n-1)+solve2(n);
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
const int limit = 200000;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

int main()
{
    int n,m;cin >> n >> m ;

    vector<int> v;
    vector<int> v2;

    for(int i=0;i<m;i++){
        int a,b;cin >> a >> b;
        if(a==1) v.push_back(b);
        if(b==n) v2.push_back(a);
    }
    sort(v.begin(),v.end());

    for(auto t:v2){
        if(binary_search(v.begin(), v.end(), t)) {
            p("POSSIBLE")
            return 0;
        }
    }
    p("IMPOSSIBLE")
    return 0;
}

Measured memory_bytes: 1276
#!/usr/bin/python

import sys

def main(argv):
    for line in sys.stdin:
        a, b, c = map(lambda x: int(x), line.split(" ", 3))
        p = a % b
        q = c % b

        if p == q:
            print("YES")
        elif p == 0:
            print("NO")
        else:
            candidates = []
            i = 1
            candidate = (i * a) % b
            while not candidate in candidates:
                if candidate == q:
                    break
                candidates.append(candidate)

                i += 1
                candidate = (i * a) % b

            if candidate == q:
                print("YES")
            else:
                print("NO")

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	long long sum = 0;
	for (int i = 0; i < 1 << (s.length() - 1); i++) {
		//cout << "i:" << i << endl;
		int f = 0;
		for (int j = 0; j < s.length(); j++) {
			//cout << "i >> j:" << (i >> j) << endl;
			if ((i>>j)&1 || j == s.length()-1) {
				//cout << "i:" << i << " f:" << f << " j+1:" << j+1 <<endl;
				//cout << s.substr(f, j + 1 - f) << endl;
				sum += stoll(s.substr(f, j + 1 - f));
				f = j + 1;
			}
		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
int bubble_sort(vector<int> &vec, int size);

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

    vector<int> vec(n);
    for (int i = 0; i < n; ++i)
        cin >> vec[i];

    int swap_count = bubble_sort(vec, n);
    cout << vec[0];
    for (int i = 1; i < n; ++i)
        cout << ' ' << vec[i];
    cout << '\n' << swap_count << '\n';
}

int bubble_sort(vector<int> &vec, int size)
{
    int swap_count = 0;

    for (int i = 0; i < size; ++i) {
        bool flag = false;
        for (int j = size - 1; j > i; --j) {
            if (vec[j] < vec[j - 1]) {
                swap(vec[j], vec[j - 1]);
                ++swap_count;
                flag = true;
            }
        }

        if (!flag)
            break;
    }

    return swap_count;
}



Measured memory_bytes: 3100
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	int N, M;
	cin >> N >> M;
	vector<string>A(N), B(M);
	rep(i, N)cin >> A[i];
	rep(i, M)cin >> B[i];
	for (int i = 0; i < N - M + 1; i++) {
		for (int j = 0; j < N - M + 1; j++) {
			bool can = true;
			for (int k = 0; k < M; k++) {
				for (int l = 0; l < M; l++) {
					if (A[i + k][j + l] != B[k][l])can = false;
				}
			}
			if (can) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  ll n,k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  ll gcd = v[0];
  rep(i,n-1)gcd = __gcd(gcd,v[i+1]);
  if(*max_element(ALL(v)) < k){
    printf("IMPOSSIBLE\n");
  }else{
    if(k%gcd == 0){
      printf("POSSIBLE\n");
    }else{
      printf("IMPOSSIBLE\n");
    }
  }

  
  




  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int p=998244353;
  vector<int> l(k);
  vector<int> r(k);
  for(int i=0;i<k;i++)
    cin>>l.at(i)>>r.at(i);
  vector<int64_t> c(n,0);
  vector<int64_t> sc(n+1,0);
  c.at(0)=1;
  sc.at(1)=1;
  for(int i=1;i<n;i++){
    for(int j=0;j<k;j++)
      c.at(i)=(c.at(i)+sc.at(max(i-l.at(j)+1,0))-sc.at(max(i-r.at(j),0))+p)%p;
    sc.at(i+1)=(sc.at(i)+c.at(i))%p;
  }
  cout<<c.at(n-1)<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<string> vecB(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vecB.at(i);
  }
  
  int M;
  cin >> M;
  
  vector<string> vecR(M);
  
  for (int j = 0; j < M; j++) {
    cin >> vecR.at(j);
  }
  
  int point = 0;
  
  for (int k = 0; k < N; k++) {
    int p = 0, q = 0;
    for (int l = 0; l < N; l++) {
      if (vecB.at(k) == vecB.at(l)) {
        p++;
      }
    }
    for (int m = 0; m < M; m++) {
      if (vecB.at(k) == vecR.at(m)) {
        q++;
      }
    }
    if (point < p-q) {
      point = p-q;
    }
  }
  
  if (point >= 0) {
    cout << point << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
INF=1000

N=int(input())
S=[]
for i in range(N):
	temp=input()
	S.append({})
	for j in temp:
		if j not in S[i]:
			S[i][j]=1
		else:
			S[i][j]+=1
#print(S)
ans={}
for i in range(97,97+26):
	ans[chr(i)]=INF

for i in range(97,97+26):
	temp=chr(i)
	for j in S:
		if temp not in j:
			ans[temp]=0
			continue
		else:
			ans[temp]=min(ans[temp],j[temp])
ansLine=""
for i in range(97,97+26):
	temp=chr(i)
	if ans[temp]!=0:
		ansLine+=temp*ans[temp]
print(ansLine)

Measured memory_bytes: 3444
def solve(idx, money, current)
  return money if current.all? { |u| u >= X }
  return -1 if idx >= N

  s1 = solve(idx + 1, money, current.dup)
  M.times do |i|
    current[i] += UNDERSTANDINGS[idx][i]
  end
  s2 = solve(idx + 1, money + PRICES[idx], current.dup)

  return s2 if s1 == -1
  return s1 if s2 == -1

  [s1, s2].min
end

N, M, X = gets.split.map(&:to_i)
a = N.times.map { gets.split.map(&:to_i) }
PRICES = []
UNDERSTANDINGS = []
a.each do |a1|
  PRICES << a1[0]
  UNDERSTANDINGS << a1[1..-1]
end

current = Array.new(M, 0)
puts solve(0, 0, current)


Measured memory_bytes: 14404
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        List<Integer> numList = new ArrayList<>();
        for(int i=0;i<N;i++){
            numList.add(Integer.parseInt(sc.next()));
        }
        long count = numList.stream().distinct().count();
        String str = N == count ? "YES" : "NO";
        System.out.println(str);
}
}

Measured memory_bytes: 68472
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < S.size(); j++) {
            if (S.at(j) == 'Z') {
                S.at(j) = 'A';
            }
            else {
                S.at(j)++;
            }
        }
    }
    cout << S << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string a,b;
    cin >> a;

    for(int i=0;i<a.size();i=i+2){
    if(a.at(i) == 'L'){
        b="No";
    }
    }

    for(int i=1;i<(a.size()-1);i=i+2){
    if(a.at(i) == 'R'){
        b="No";
    }
    }
    if(b != "No"){
        b="Yes";
    }
    cout << b <<endl;
    
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){

  int N; cin >> N;
  vector <int> A(N + 1), B(N);
  for (int i = 0; i < N + 1; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i]; 


  long long ans = 0;
  for (int i = 0; i < N; i++){
    int can = B[i];

    if (can >= A[i]){
      int rest = can - A[i];
      ans += A[i];
      A[i] = 0;

      if (rest >= A[i + 1]){
        ans += A[i + 1];
        A[i + 1] = 0;
      }else{
        ans += rest;
        A[i + 1] -= rest;
      }
    }else{
      ans += can;
      A[i] -= can;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw/say/;

my %cards = map { my $line = <STDIN>; chomp $line;  ($_ => [ split(//, $line) ]) } qw/a b c/;
my $turn = 'a';
while (@{ $cards{$turn} }) {
    $turn = shift(@{ $cards{$turn} });
}
say uc($turn);

Measured memory_bytes: 768
from collections import Counter
import math as m
def combinations(n,r):
    return m.factorial(n) // (m.factorial(n-r) * m.factorial(r))
N = int(input())
A = list(map(int,input().split()))
S = [0]
sum_ = 0
for i in range(N):
    sum_ += A[i]
    S.append(sum_)
c = list(Counter(S).values())
c.sort()
c.reverse()
ans = 0
for e in c:
    if e < 2:
        break
    ans += combinations(e,2)
print(ans)

Measured memory_bytes: 41684
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

const int dr[4] = {1, -1, 0, 0};
const int dc[4] = {0, 0, 1, -1};

int main() {
    while(true){
        ll w, h;
        cin >> w >> h;
        if(w == 0 && h == 0) return 0;
        vector<vector<bool>> wall_ver(w+1, vector<bool>(h, false)), wall_hori(h+1, vector<bool>(w, false));
        rep(i, h){
            wall_ver[0][i] = wall_ver[w][i] = true;
        }
        rep(i, w){
            wall_hori[0][i] = wall_hori[h][i] = true;
        }

        FOR(j, 1, w){
            ll f; cin>>f;
            if(f == 1) wall_ver[j][0] = true;
        }
        FOR(i, 1, h){
            rep(j, w){
                ll f; cin>>f;
                if(f == 1) wall_hori[i][j] = true;
            }
            FOR(j, 1, w){
                ll f; cin>>f;
                if(f == 1) wall_ver[j][i] = true;
            }
        }

        vll dist(h, vl(w, 0));
        queue<pll> q;
        dist[0][0] = 1;
        q.push(pll(0, 0));
        while(!q.empty()){
            pll v = q.front();
            q.pop();
            ll r = v.first, c = v.second;
            ll nr, nc;
            rep(i, 4){
                nr = r + dr[i], nc = c + dc[i];
                if(i == 0){
                    if(wall_hori[nr][c]) continue;
                }else if(i == 1){
                    if(wall_hori[r][c]) continue;
                }else if(i == 2){
                    if(wall_ver[nc][r]) continue;
                }else if(i == 3){
                    if(wall_ver[c][r]) continue;
                }
                if(dist[nr][nc] != 0) continue;

                dist[nr][nc] = dist[r][c] + 1;
                q.push(pll(nr, nc));
            }
        }

        cout << dist[h-1][w-1] << endl;
    }
}


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

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

using namespace std;

int n,s;

int dfs(int i,int j,int sum){
	if (sum>s) return 0;
	if (i==n){
		if (sum==s){
			return 1;
		}
		else {
			return 0;
		}
	}
	int res=0;
	FOR(k,j,10){
		res+=dfs(i+1,k+1,sum+k);
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	do{
		cin>>n>>s;
		if (n){
			cout<<dfs(0,0,0)<<endl;
		}
	}while (n);
	return 0;
}

Measured memory_bytes: 1192