akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 5e5 + 10;
typedef long long ll;
ll n, a, b, c, d;

int main() {
    cin >> n >> a >> b >> c >> d;
    n--;
    rep(x, 0, n)
        if (b >= a - 1ll * x * d + (n - x) * c && b <= a - 1ll * x * c + (n - x) * d)
            return puts("YES"), 0;
    puts("NO");
    return 0;
}


Measured memory_bytes: 3580
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>

using  ll = long long;
using ull = unsigned long long;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
constexpr ll kINF = 1152921504606846976;//2^60
constexpr double kEPS = 1e-6;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define rep(i,n) REP(i,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep(i,n) RREP(i,n)
#define mp make_pair
#define fi first
#define sc second

using P = pair<int, int>;

template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false;}
string s,t; 
int dp[3010][3010];

P from[3010][3010];
int main(void) {
  cin >> s >> t;

  int n = s.length();
  int m = t.length();

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
      if (dp[i - 1][j] >= dp[i][j - 1]) {
        dp[i][j] = dp[i - 1][j];
        from[i][j] = P(i - 1, j);
      } else {
        dp[i][j] = dp[i][j - 1];
        from[i][j] = P(i, j - 1);
      }
      if (s[i - 1] == t[j - 1]) {
        if(chmax(dp[i][j], dp[i - 1][j - 1] + 1)) {
          from[i][j] = P(i - 1, j - 1);
        }
      }
    }
  }

  int i = n, j = m;

  string ans;

  while( i > 0 && j > 0) {
    P f = from[i][j];
    if ( i - f.first > 0 && j - f.second > 0) {
      ans.push_back(s[f.first]);
    } 
    i = f.first;j = f.second;
  }

  reverse(ans.begin(), ans.end());

  cout << ans << endl;

}

Measured memory_bytes: 106368
#include<iostream>
using namespace std;
int main(){
  string sa,sb,sc; cin >> sa >> sb >> sc;
  char turn='a'; // 誰のターンか.
  int a_card=0,b_card=0,c_card=0; // 各人の何枚目が先頭にあるか.
  while(true){
    if(turn=='a'){
      if(a_card==sa.size()){
        cout << 'A' << endl;
        return 0;
      }
      turn=sa[a_card];
      a_card++;
    }
    if(turn=='b'){
      if(b_card==sb.size()){
        cout << 'B' << endl;
        return 0;
      }
      turn=sb[b_card];
      b_card++;
    }
    if(turn=='c'){
      if(c_card==sc.size()){
        cout << 'C' << endl;
        return 0;
      }
      turn=sc[c_card];
      c_card++;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n;
	cin >> n;
	vector<vector<char>> s(n, vector<char>(10));
	REP(i, n) {
		REP(j, 10)
			cin >> s[i][j];
		sort(s[i].begin(), s[i].end());
	}
	sort(s.begin(), s.end());
	ll c = 1,  ans = 0;
	REP(i, n - 1) {
		if (s[i] == s[i + 1])
			c++;
		else if (c != 1) {
			ans += (c * (c - 1)) / 2;
			c = 1;
		}
	}
	if (c != 1) {
		ans += (c * (c - 1)) / 2;
		c = 1;
	}
	cout << ans;
}

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

def main():
    *N, = map(int, open(0).read().split())
    A = N[1:]
    N = N[0]

    cnt = 0
    for i in A:
        if i % 2 == 0:
            for j in range(0, max(A)):
                i = i//2
                cnt = cnt + 1
                if (i < 2) or not (i % 2 == 0):
                    break
    print(cnt)


main()

Measured memory_bytes: 42972
// ※※※ 解答不能 ※※※
// kort0n氏
// https://atcoder.jp/contests/agc039/submissions/7859826
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1){
        init(n);
    }
    void init(int n = 1){
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }
    int root(int x){
        if(par[x] == x){
            return x;
        }else{
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }
    ll size(int x){
        return Size[root(x)];
    }
};

int N;
string S[205];
ll dist[205][205];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> S[i];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) dist[i][j] = 1e9;
        dist[i][i] = 0;
    }
    UnionFind uni(2 * N);
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            if(S[i][j] == '0') continue;
            dist[i][j] = 1;
            dist[j][i] = 1;
            uni.merge(i, j + N);
            uni.merge(i + N, j);
        }
    }
    for(int i = 0; i < N; i++){
        if(uni.issame(i, i + N)){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                chmin(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            chmax(ans, dist[i][j] + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

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

using namespace std;

int main(void)
{
	int N;
	long M;
	while(cin >> N >> M, N > 0){
		long D[MAX_P + 1];
		long result = 0;
		//配列Dを初期化
		rep(i, MAX_P + 1){
			D[i] = 0;
		}
		//配列Dを構成
		rep(i, N){
			int d, p;
			cin >> d >> p;
			D[p] += d;
		}
		rep(i, MAX_P + 1){
			if (M >= D[MAX_P - i]){
				M -= D[MAX_P - i];
			}else if(M > 0){
				result += (D[MAX_P - i]-M) * (MAX_P - i);
				M = 0;
			}else{
				result += D[MAX_P - i] * (MAX_P - i);
			}
		}
		cout << result << endl;
	}
	return 0;
}


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

vector<pair<int,int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;
	vector<string> grid(h);
	for (int i = 0; i < h; ++i){
		cin >> grid[i];
	}
	//do bfs from (x1, y1)
	auto valid = [&](const pair<int, int>& p){
		return p.first >= 0 && p.first < h && p.second >= 0 && p.second < w;
	};
	vector<vector<int>> dist(h, vector<int>(w, 1e9));
	function<void(pair<int, int>)> bfs = [&](pair<int, int> s){
		int startX = s.first, startY = s.second;
		dist[s.first][s.second] = 0;
    	queue<pair<int, int>> Q;
		Q.emplace(s);
    	while (!Q.empty()) {
        	int x = Q.front().first;
        	int y = Q.front().second;
	        Q.pop();
    	    for (int i = 0; i < 4; i++) {
        	    for (int j = 1; j <= k; j++) {
            	    int xx = x + dir[i].first * j;
                	int yy = y + dir[i].second * j;
                	if (!valid({xx, yy})) continue;
	                if (grid[xx][yy] == '@' || dist[xx][yy] <= dist[x][y]) {
    	                break;
       	 	        }
    	        	if (dist[xx][yy] == dist[x][y] + 1) {
     	  	          	continue;
                	}
                	dist[xx][yy] = dist[x][y] + 1;
                	Q.push({xx, yy});
            	}
        	}
    	}
	};
	bfs({x1, y1});
	if (dist[x2][y2] >= 1e9) dist[x2][y2] = -1;
	cout << dist[x2][y2] << '\n';
}


Measured memory_bytes: 12152
n = int(input())
hs = list(map(int, input().split()))

res = 0
cnt = 0
for i in range(n - 1):
    if hs[i] >= hs[i + 1]:
        cnt += 1
    else:
        res = max(res, cnt)
        cnt = 0

res = max(res, cnt)
print(int(res))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Does coordinate compression.
// Arguments:
// - raw_xs: Values to compress.
// Returns:
// - xs: Compressed values.
// - to_raw: A mapping from a compressed value to a raw value.
// Verified: CF573Div1D
tuple<vector<int>, vector<int>> Compress(const vector<int>& raw_xs) {
  set<int> raw_x_set(raw_xs.begin(), raw_xs.end());
  vector<int> to_raw(raw_x_set.begin(), raw_x_set.end());
  map<int, int> to_index;
  for (int i = 0; i < to_raw.size(); i++) {
    to_index[to_raw[i]] = i;
  }
  vector<int> xs;
  for (int raw_x : raw_xs) {
    xs.push_back(to_index[raw_x]);
  }
  return make_tuple(xs, to_raw);
}

// Verified: AOJ-DSL1A
class UFSet {
 private:
  vector<int> ranks;
  vector<int> prevs;

 public:
  UFSet(int n) : ranks(n), prevs(n) {
    for (int i = 0; i < n; i++) prevs[i] = i;
  }

  // Returns a root of a tree which x belongs to.
  int Find(int x) {
    if (x != prevs[x]) prevs[x] = Find(prevs[x]);
    return prevs[x];
  }

  // Merges a set which x blongs to and a set which y belongs to.
  void Union(int x, int y) {
    int x_root = Find(x);
    int y_root = Find(y);
    if (ranks[x_root] > ranks[y_root]) {
      prevs[y_root] = prevs[x_root];
    } else if (ranks[x_root] < ranks[y_root]) {
      prevs[x_root] = prevs[y_root];
    } else if (prevs[x_root] != prevs[y_root]) {
      prevs[y_root] = prevs[x_root];
      ranks[x_root]++;
    }
  }
};

struct WEdge {
  int v1, v2;
  int64 weight;
  WEdge(int v1, int v2, int64 weight) : v1(v1), v2(v2), weight(weight) {}
};

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

  int n;
  cin >> n;
  vector<int> raw_xs(n), raw_ys(n);
  for (int i = 0; i < n; i++) {
    cin >> raw_xs[i];
    cin >> raw_ys[i];
  }

  vector<int> xs, xs_to_raw, ys, ys_to_raw;
  tie(xs, xs_to_raw) = Compress(raw_xs);
  tie(ys, ys_to_raw) = Compress(raw_ys);
  vector<vector<int>> x_to_ps(xs_to_raw.size()), y_to_ps(ys_to_raw.size());
  for (int i = 0; i < n; i++) {
    x_to_ps[xs[i]].push_back(i);
    y_to_ps[ys[i]].push_back(i);
  }

  UFSet uf_set(n);
  for (const auto& ps : x_to_ps) {
    for (int i = 1; i < ps.size(); i++) {
      uf_set.Union(ps[0], ps[i]);
    }
  }
  for (const auto& ps : y_to_ps) {
    for (int i = 1; i < ps.size(); i++) {
      uf_set.Union(ps[0], ps[i]);
    }
  }

  vector<WEdge> edges;
  for (int i = 0; i + 1< x_to_ps.size(); i++) {
    edges.push_back(WEdge(x_to_ps[i][0], x_to_ps[i + 1][0], xs_to_raw[i + 1] - xs_to_raw[i]));
  }
  for (int i = 0; i + 1< y_to_ps.size(); i++) {
    edges.push_back(WEdge(y_to_ps[i][0], y_to_ps[i + 1][0], ys_to_raw[i + 1] - ys_to_raw[i]));
  }
  sort(edges.begin(), edges.end(), [](const auto& e1, const auto& e2) {
    return e1.weight < e2.weight;
  });

  int64 ans = 0;
  for (const auto& e : edges) {
    if (uf_set.Find(e.v1) == uf_set.Find(e.v2)) continue;
    ans += e.weight;
    uf_set.Union(e.v1, e.v2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 20196
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = sc.nextLong();
        
        for (long i = m/n; i > 0 ; i--) {
            if (m%i == 0) {
                System.out.println(i);
                break;
            }
        }

        sc.close();
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;

const int INF = 1e9;
const int MAX_V = 1010;
struct edge{ int to,cap,rev;edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}};

vector<vector<edge> > G(MAX_V); //??°???????????£??\???????????¨???
bool used[MAX_V]; //DFS??§??¢???????????????????????????????????°

void init(int n){
	for(int i = 0;i < n;i++)G[i].clear();
}

void add_edge(int from, int to, int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size() - 1));
}

int dfs(int v, int t, int f){
	if(v == t) return f;
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if( !used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -=d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t){
	int flow = 0;
	for(;;){
		fill(used,used + MAX_V,false);
		int f = dfs(s,t,INF);
		if(f == 0)return flow;
		flow += f;
	}
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int m,n;
	while(cin >> m >> n,m){
		int s = m + n,t = s + 1;
		init(t);
		vector<int> b(m),r(n);
		REP(i,m){
			cin >> b[i];
			add_edge(s,i,1);//????????§????§??????????????????¶
		}
		REP(i,n){
			cin >> r[i];
			add_edge(i + m,t,1);//????????§???????????????????????¶
		}
		REP(i,m){
			REP(j,n){
				if(__gcd(b[i],r[j]) != 1){
					add_edge(i,j + m,1);
				}
			}
		}
		cout << max_flow(s,t) << endl;
	}
  return 0;
}

Measured memory_bytes: 9820
#include<bits//stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF = (1 << 27);
#define rep(i,n) for(int i = 0; i < n;i++)
const int MAX = 510000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMint() {
    fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    int h, w, a, b; cin >> h >> w >> a >> b;
    COMint();
    ll ans = 0;
    for (int i = b+1; i <= w; i++) {
        ll sum = COM(h - a + i - 2, i - 1) * COM(a - 1 + w - i, w - i);
        sum %= MOD;ans += sum;ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12160
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
#include<iostream>

#define maxn 200005
#define INF 0x3f3f3f3f

using namespace std;

inline long long getint()
{
    long long num=0,flag=1;char c;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
    return num*flag;
}

string S,T;

int main()
{
	cin>>S>>T;
	cout<<T<<S<<endl;
}

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

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

int main () {
    string s;
    int a=0,i,t,x,W,H,maxnum=0,N,num[12]={0};
    cin >> N;
    REP(i,N) {cin >> num[i];a+=num[i];}
    REP(i,N) maxnum=max(num[i],maxnum);
    a-=maxnum/2;
    cout << a << endl;
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int i, j, k;
    int a, b;
    vector<int> graph[n];
    for (i = 0; i < m; i++){
        cin >> a >> b;
        graph[a - 1].push_back(b - 1);
        graph[b - 1].push_back(a - 1);
    }
    
    int visted[n];
    int room[n];
    for (i = 0; i < n; i++){
        visted[i] = 0;
        room[i] = -1;
    }
    
    queue <int> q;
    visted[0] = 1;
    room[0] = -1;
    q.push(0);
    while (!q.empty()){
        int x = q.front();
        q.pop();
        for (i = 0; i < graph[x].size(); i++){
            int y = graph[x][i];
            if (visted[y] == 0){
                visted[y] = 1;
                room[y] = x;
                q.push(y);
            }
        }
    }
    for (i =0 ; i < n; i++){
        if (visted[i] == 0){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes\n";
    for (i = 1; i < n; i++){
        cout << room[i] + 1 << "\n";
    }
}


Measured memory_bytes: 10944
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    string s;
    cin>>s;
    int n=s.size();
    int K=4;
    vector<vector<int>>dp(n+1,vector<int>(K+1,-1));
    dp[0][0]=0;
    for (int i = 0; i < n; i++)
    {
        for(int j=0;j<=K;j++){
            if(dp[i][j]==-1){
                continue;
            }
        
        for(int k=1;k<=K && k+i<=n;k++){
            if (j!=k || s.substr(i-j,j)!=s.substr(i,k)){
                dp[i+k][k]=max(dp[i+k][k],dp[i][j]+1);
            }
        }
    }
    }
    int ans=0;
    for (int i = 0; i <=K; i++)
    {
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;
    

    return 0;
}

Measured memory_bytes: 14468
n, k = list(map(int, input().split(" ")))

ans = 0
ans1 = 0
j = 1
flag = False
for i in range(n, 0, -1):

    if(i >= k):
        ans1 += 1
        continue

    if(flag == False):
        flag = True
        while(i*2**j < k): j += 1

        tmp = j
        ans += 1
    else:
        while(i*2**j >= k): j -= 1
        j += 1

        if(tmp != j):
            ans *= 2
            ans += 1
            tmp = j
        else: ans += 1

print((ans+ans1*2**j) / (n*2**j))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;
 
  cout << endl;
}
 
int main(){
  int n;
  cin >> n;
  call(n);
}


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

const int N = 200000+5;
const int M = 100000;

int n;
int r[N];
int c[N];
int par[N];
int sizes[N];

void create(int x){
	par[x] = x;
	sizes[x] = 1;
	if(x <= M) r[x] = 1;
	else c[x] = 1;
}

int get(int x){
	return par[x] == x? x : par[x] = get(par[x]);
}

void join(int a, int b){
	a = get(a);
	b = get(b);
	if(a == b) return;
	if(sizes[a] > sizes[b]) swap(a, b);
	par[a] = b;
	sizes[b] += sizes[a];
	r[b] += r[a];
	c[b] += c[a];
}

int main(){
	scanf("%d", &n);
	for(int i=1; i<=M+M; i++) create(i);
	for(int i=1; i<=n; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		join(x, y + M);
	}
	long long ans = -n;
	for(int i=1; i<=M+M; i++){
		if(par[i] == i){
			ans += 1LL * r[i] * c[i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;string s;cin>>a>>s;int r,b;
  r=count(s.cbegin(),s.cend(),'R');
  b=count(s.cbegin(),s.cend(),'B');
  if(r>b)cout<<"Yes";
  else cout<<"No";
}

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

#define f(a, b) for(auto i = a;i < b;i++)
typedef long long int ll;

void solve()
{
	return ;
}

ll is_palindrome(string str, ll n)
{
	// cout << a << " " << b;
	for(ll i = 0;i < n/2;i++)
	{
		// cout << str[a + i] << " " << str[b - i] << "\n";
		if(str[i] != str[n - i - 1])
			return 0;
	}
	return 1;
}
int main()
{

	string str ,arr, brr;
	cin >> str;
	// solve();

	ll n = str.size();
	ll a = 0, b = (n - 1)/2 - 1, c = (n + 3)/2 - 1, d = n - 1;

	for(ll i = 0;i <= b;i++)
		arr.push_back(str[i]);

	for(ll i = c;i <= d;i++)
		brr.push_back(str[i]);
	
	if(is_palindrome(str, str.size()) && is_palindrome(arr, arr.size()) && is_palindrome(brr, brr.size()))
		cout << "Yes\n";
	else
		cout << "No\n";


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <bits/stdc++.h>
#include <string>


using namespace std;

int main()
{
    int a,b,c,way=0,x;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    	for(int i=0; i<=a; i++){
            for(int j=0;j<=b;j++){
                for(int k=0;k<=c;k++){
                    if(i*500+j*100+k*50==x){
                        way++;
                    }
                }
            }
			}
			printf("%d\n",way);
			return 0;
}

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



int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    cout << max(0,c - (a - b)) << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3620
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
char ans[N][N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n = 100;
	int a, b;
	cin >> a >> b;
	MEM(ans, '#');
	for (int i = 1; i <= n / 2; i++)
	{
		for (int j = 1; j <= 100; j++) ans[i][j] = '.';
	}
	a--, b--;
	for (int i = 1; i <= n / 2; i += 2)
	{
		for (int j = 1; j <= 100 && b > 0; j += 2, b--)
		{
			ans[i][j] = '#';
		}
	}
	for (int i = n; i >= n / 2; i -= 2)
	{
		for (int j = 1; j <= 100 && a > 0; j += 2, a--)
		{
			ans[i][j] = '.';
		}
	}
	puts("100 100");
	for (int i = 1; i <= n; i++)
	{
		ans[i][n + 1] = 0;
		puts(ans[i] + 1);
	}
	return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

string O, E;

void solve()
{
    cin >> O >> E;
    string ans = "";
    int o = 0, e = 0;
    REP(i, O.length()+E.length())
    {
        if(i % 2 == 0) ans += O[o++];
        else ans += E[e++];
    }

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n  =  Integer.parseInt(sc.next());
		int a[] =  new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		
		Arrays.sort(a);
		
		
		
		int tmp = a[0];
		String ans = "YES";
		for(int i = 1 ; i < n ; i++) {
			if(tmp == a[i]) {
				ans = "NO";
				break;
			}
			tmp = a[i];
		}
		
		
		
		System.out.println(ans);
	}




}



Measured memory_bytes: 51924
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,a,b,c,d,INF=((1LL<<31)-1);
vector<ll> node,lazy,v;
void ini(ll n){
    m=1;
    while(m<n)m*=2;
    node.resize(2*m-1,INF);
    lazy.resize(2*m-1,0);
    v.resize(2*m-1,0);
    return ;
}
void eval(ll k,ll l,ll r){
    if(v[k]!=0){
        node[k]=lazy[k];
        if(r-l>1){
            lazy[2*k+1]=lazy[k];
            lazy[2*k+2]=lazy[k];
            v[2*k+1]=1;
            v[2*k+2]=1;
        }
        lazy[k]=0;
        v[k]=0;
    }
    return ;
}
void add(ll a,ll b,ll x,ll k,ll l,ll r){
    eval(k,l,r);
    if(b<=l||r<=a)return ;
    if(a<=l&&r<=b){
        lazy[k]=x;
        v[k]=1;
        eval(k,l,r);
    }
    else{
        add(a,b,x,2*k+1,l,(l+r)/2);
        add(a,b,x,2*k+2,(l+r)/2,r);
        node[k]=min(node[2*k+1],node[2*k+2]);
    }
    return ;
}
ll getsum(ll a,ll b,ll k,ll l,ll r){
    if(b<=l||r<=a)return INF;
    eval(k,l,r);
    if(a<=l&&r<=b)return node[k];
    ll vl=getsum(a,b,2*k+1,l,(r+l)/2);
    ll vr=getsum(a,b,2*k+2,(l+r)/2,r);
    return min(vr,vl);
}
int main(void){
    cin>>n>>k;
    ini(n);
    for(int i=0;i<k;i++){
        cin>>a;
        if(a==0){
            cin>>a>>b>>c;
            add(a,b+1,c,0,0,m);
        }
        else{
            cin>>a>>b;
            cout<<getsum(a,b+1,0,0,m)<<endl;
        }
        //for(auto x:node)cout<<x<<" ";
        //cout<<endl;
    }
}



Measured memory_bytes: 8844
using System;
class aoj
{
    static void Main()
    {
        int all = 0;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            char[] b = a.ToCharArray();
            Array.Reverse(b);
            string c = new string(b);
            if (a == c)
                all++;
        }
        Console.WriteLine(all);
    }
}

Measured memory_bytes: 9032
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cassert>
using namespace std;
 
char s[5000];
int len;
 
int length(int const k, int const l, int const r){
    int cur = 0, res = 0, p = l;
    while(s[p] && p < r){
        if(isalpha(s[p])){
            while(isalpha(s[p])){
                if(cur == k) throw s[p];
                res++;
                p++;
                cur++;
            }
        } else if(isdigit(s[p])){
            int mul = 0;
            while(isdigit(s[p])){
                mul = mul * 10 + s[p] - '0';
                p++;
            }
            int d = 0, i = p++;
            while(1){
                if(s[i] == '(') d++;
                else if(s[i] == ')') d--;
                if(d == 0) break;
                i++;
            }
            int memo = -1;
            for(int j = 0; j < mul; j++){
                if(memo != -1 && cur + memo < k){
                    res += memo;
                    cur += memo;
                } else {
                    int x = length(k - cur, p, i);
                    res += x;
                    cur += x;
                    memo = x;
                }
            }
            p = i + 1;
        }
    }
    return res;
}
 
int main(){
    static char t[5000];
    int k;
    while(scanf("%s%d",t,&k), t[0] != '0'){
        int tlen = strlen(t);
        len = 0;
        for(int i = 0; i < tlen; i++){
            if(i > 0 && isdigit(t[i - 1]) && isalpha(t[i])){
                s[len++] = '(';
                s[len++] = t[i];
                s[len++] = ')';
            } else {
                s[len++] = t[i];
            }
        }
        s[len] = 0;
        try{
            length(k, 0, len);
            putchar('0');putchar('\n');
        } catch (char e) {
            putchar(e);putchar('\n');
        }
    }
}

Measured memory_bytes: 1092
import math
e,o = map(int,input().split())
if e < 2:
    e_cases = 0
else:
    e_cases = math.factorial(e)/math.factorial(e-2)/2
if o < 2:
    o_cases = 0
else:
    o_cases = math.factorial(o)/math.factorial(o-2)/2
print(int(e_cases+o_cases))

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  if(s == "RRR") cout << 3 << endl;
  else if(s == "SRR" || s == "RRS") cout << 2 << endl;
  else if(s == "SSS") cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

double f(double x, double y) {
	if (y < x) y += M_PI * 2;
	return y - x;
}

int main() {
	int n; cin >> n;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i];
	bool pos = true;
	for (int i = 0; i < n; i++)
		if (i == 0 || i == n - 1) {
			bool ok = false;
			for (int j = 0; j < n; j++) {
				if (j == i) continue;
				ll dx = x[j] - x[i], dy = y[j] - y[i];
				bool a = false, b = false;
				for (int k = 0; k < n; k++) {
					if (k == i || k == j) continue;
					if ((x[k] - x[i]) * dy - (y[k] - y[i]) * dx > 0)
						a = true;
					else
						b = true;
				}
				if (!a || !b) ok = true;
			}
			if (!ok) pos = false;
		}
		else {
			vector<d_i> p;
			for (int j = 0; j < n; j++) {
				if (j == i) continue;
				p.push_back(d_i(atan2(y[j] - y[i], x[j] - x[i]), j < i));
			}
			int m = p.size();
			sort(p.begin(), p.end());
			bool ok = false;
			for (int j = 0; j < m; j++)
				if (p[j].second != p[(j + 1) % m].second || p[j].second != p[(j + m - 1) % m].second) {
					vector<bool> a(2), b(2);
					for (int k = 0; k < m; k++) {
						if (k == j) continue;
						if (f(p[j].first, p[k].first) < M_PI) a[p[k].second] = true;
						else b[p[k].second] = true;
					}
					if (!(a[0] && b[0]) && !(a[1] && b[1]) && !(a[0] && a[1]) && !(b[0] && b[1]))
						ok = true;
				}
			if (!ok) pos = false;
		}
		cout << (pos ? "Possible" : "Impossible") << endl;
}

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

using namespace std;

void test()
{
   int a;
   cin>>a;
   
   cout<<a+a*a+a*a*a<<endl;
   
}

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

    test();

    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
const int N = 3e5 + 1;
int n, m, k;
long long int A[N], B[N], cs[N], sum; 
int main(){
    ll H , W , N ;
    cin >> H >> W >> N ;
    if(N % max(H , W ) == 0) cout << N / max(H , W ) << endl;
    else cout <<  ( N / max(H , W ) ) + 1 << endl;
    return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  string S;
  int x,y;
  cin>>S>>x>>y;
  vector<vector<int>> v(2);
  int t = 0,s = 0;
  for(int i = 0; i < (int)S.size();i++){
    if(S[i]=='F') t++;
    if(S[i]=='T') {
      v[s].push_back(t);t=0;
      s=1-s;
    }
    if(i==(int)S.size()-1&&t!=0)v[s].push_back(t); 
  }
  x-=v[0][0];
  v[0].erase(v[0].begin());
  map<int,bool> X,Y;
  X[0]=true;
  Y[0]=true;
  for(auto x:v[0]){
    map<int,bool> nx;
    for(auto y:X){
      nx[y.first+x]=true;
      nx[y.first-x]=true;
    }
    X=nx;
  }
  for(auto x:v[1]){
    map<int,bool> ny;
    for(auto y:Y){
      ny[y.first+x]=true;
      ny[y.first-x]=true;
    }
    Y=ny;
  }
  if(X[x]&&Y[y]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  
  if(A==B){
    cout << C << endl;
  }
  else if(B==C) {
    cout << A << endl;
  }
  else if(C==A) {
    cout << B << endl;
  }
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	ans := "Yes"
	for i, r := range s {
		if i%2 == 0 && string(r) == "L" {
			ans = "No"
		}
		if i%2 == 1 && string(r) == "R" {
			ans = "No"
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
    int x=0,f=1;char ch =getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int N,K,p,ans,t;
main(){
    N=read();K=read();
    p=N/K;
    if(K&1){printf("%lld\n",p*p*p);return 0;}
    for(int i=0;i<=N;i++){
        if(i%K==K/2)++t;
    }
    printf("%lld\n",p*p*p+t*t*t);return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  vector<ll> v;
  for(ll i=2; i*i<=n; i++) {
    ll c=0;
    while(n%i==0) {
      n/=i;
      c++;
    }
    if(c) v.pb(c);
  }
  if(n>1) v.pb(1);
  ll ans=0;
  rep(i,v.size()) {
    ll k=1;
    while(v[i]) {
      ans++;
      v[i]-=k;
      k++;
      if(v[i]<k) break;
    }
  }
  pr(ans);
}

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


Measured memory_bytes: 3656
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
a.sort(reverse=True)
ans=0
ans1=0
ans2=0
if n%2==0:
    for i in range(n//2):
        if i==n//2-1:
            ans+=a[i]
        else:
            ans+=2*a[i]
    for i in range(n-1,n//2-1,-1):
        if i==n//2:
            ans-=a[i]
        else:
            ans-=2*a[i]
else:
    for i in range((n+1)//2):
        if (i==(n-3)//2)|(i==(n-1)//2):
            ans1+=a[i]
        else:
            ans1+=2*a[i]
    for i in range((n+1)//2,n):
        ans1-=2*a[i]
    for i in range((n-1)//2):
        ans2+= 2 * a[i]
    for i in range((n-1)//2,n):
        if (i == (n-1)//2) | (i ==(n+1)//2):
            ans2-=a[i]
        else:
            ans2-=2 * a[i]
    ans=max(ans1,ans2)

print(ans)

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

a = [0]*(n+1)
b = [0]*(m+1)

for i in range(n):
    a[i+1] = a[i] + A[i]
for i in range(m):
    b[i+1] = b[i] + B[i]

ans = 0
best = m
for i in range(n+1):
    if k < a[i]:
        break
    for j in range(best,-1,-1):
        if b[j] <= k-a[i]:
            break
    ans = max(ans,i+j)
    best = j
print(ans)

Measured memory_bytes: 47288
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  map<string, int> mp;
  REP(i, n) {
    string tmp;
    cin >> tmp;
    mp[tmp]++;
  }
  cout << mp.size() << endl;
}


Measured memory_bytes: 19204
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
const int N=2005;
const int maxn=0x3f3f3f3f;
vector<int>v[N];
int vis[N];
int cnt,cnt2;
int n,k;
struct bian{
	int x,y;
}vv[N];
void dfs(int p,int deep){
	if(deep>k/2){
		cnt++;
	}
	int len=v[p].size();
	vis[p]=1;
	for(int i=0;i<len;i++){
		if(vis[v[p][i]])continue;
		dfs(v[p][i],deep+1);
	}
	vis[p]=0;
}
int main(){

	int x,y;
	cin>>n>>k;
	for(int i=0;i<N;i++){
		v[i].clear();
		vis[i]=0;
	}
	for(int i=1;i<=n-1;i++){
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
		vv[i].x=x;vv[i].y=y;
	}
	int ans=maxn;
	if(k%2){
		for(int i=1;i<=n-1;i++){
			cnt=0;
			vis[vv[i].x]=1;
			dfs(vv[i].y,0);
			vis[vv[i].x]=0;
			vis[vv[i].y]=1;
			dfs(vv[i].x,0);
			vis[vv[i].y]=0;
			ans=min(ans,cnt);
		}
	}
	else {
		for(int i=1;i<=n;i++){
			cnt=0;cnt2=0;
			 dfs(i,0);
			ans=min(cnt,ans);
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, 0, n) {
        int tmp;
        cin >> tmp;
        ans+= tmp-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
from math import floor
A, B = map(int, input().split())

def check(x):
    if floor(x*0.08) == A and floor(x*0.1) == B:
        return True
    return False

x = 1
while(x < 1251):
    if check(x):
        break
    x += 1

if x == 1251:
    print(-1)
else:
    print(x)

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	ab := readInt()
	bc := readInt()
	_ = readInt()
	fmt.Println((ab * bc) / 2)
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
import copy
N, M = map(int, input().split())
connectdic = {}
for i in range(1,N+1):
    connectdic[i] = set()

for _ in range(M):
    a, b = map(int, input().split())
    connectdic[a].add(b)
    connectdic[b].add(a)

count = 0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if j not in connectdic[i]:
            continue
        tempdic = copy.deepcopy(connectdic)
        tempdic[i].remove(j)
        tempdic[j].remove(i)
        startset = set([1])
        check = set([1])
        while len(startset) > 0:
            nextset = set()
            for k in startset:
                for l in tempdic[k]:
                    if l not in check:
                        check.add(l)
                        nextset.add(l)
            startset = nextset
        if len(check) != N:
            count += 1
print(count)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main(){
    // Your code here!
    string a, b;
    cin >> a >> b;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    if (a>=b) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
        
    }
}

Measured memory_bytes: 3576
#include <algorithm>
#include <climits>
#include <iostream>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	int K;
	cin >> K;
	int h[N];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	int d[N];
	d[0] = 0;
	for (int i = 1; i < N; i++) {
		int cost[K];
		for (auto& c : cost) {
			c = INT_MAX;
		}
		for (int j = 1; j <= K; j++) {
			if (i>=j) {
				cost[j-1] = d[i-j] + abs(h[i]-h[i-j]);
			}
		}
		int *p = min_element(&cost[0], &cost[K]);
		d[i] = *p;
	}
	cout << d[N-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
n = gets.chomp.to_i
s = []
n.times { |i| s[i] = gets.chomp }

m = gets.chomp.to_i
t = []
m.times { |i| t[i] = gets.chomp }

k = 0
n.times do |i|
  k = [s.count(s[i]) - t.count(s[i]), k].max
end
puts [0, k].max

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

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<int>X;
	vector<int>Y;
	for (int i = 0; i < N; ++i) {
		if (0 == i%2) {
			X.push_back(A[i]);
		}
		else {
			Y.push_back(A[i]);
		}
	}
	vector<int>Ans(N);
	for (int i = 0;i<Y.size();++i) {
		Ans[i] = Y[Y.size()-1-i];
	}
	for (int i = 0;i<X.size();++i) {
		Ans[Y.size()+i] = X[i]; 
	}
	if (1 == N%2) {
		reverse(Ans.begin(),Ans.end());
	}
	for (int i = 0; i < N; ++i) {
		if(0 !=i){
			cout << " ";
		}
		cout << Ans[i];
	}
	return 0;
}

Measured memory_bytes: 5548
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,k,s,ss;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k>>s;
	for(int i=1;i<=k;i++)cout<<s<<' ';
	if(s==1000000000) ss=s-1;
	else ss=s+1;
	for(int i=k+1;i<=n;i++)cout<<ss<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1280
import sys

inf = 1<<30

def solve():
    n = int(sys.stdin.readline().rstrip())

    for i in range(n):
        x, y = sys.stdin.readline().split()

        x = mcxi_to_digit(x)
        y = mcxi_to_digit(y)

        ans = digit_to_mcxi(x + y)

        print(ans)

def mcxi_to_digit(x):
    res = 0
    ps = -1

    mcxi = {'m':1000, 'c':100, 'x':10, 'i':1}

    for i, num in enumerate(x):
        if ps == i:
            continue
        if num.isdigit():
            res += mcxi[x[i + 1]] * int(num)
            ps = i + 1
        else:
            res += mcxi[num]

    return res

def digit_to_mcxi(x):
    res = []
    mcxi = ['i', 'x', 'c', 'm']

    for k in range(len(mcxi)):
        if x % 10 >= 1:
            res.append(mcxi[k])

            if x % 10 > 1:
                res.append(str(x % 10))

        x //= 10
        
    res.reverse()

    return ''.join(res)

if __name__ == '__main__':
    solve()

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

int main() {
	int n;
	long long int a[100010];

	cin >> n;

	long long int MAX = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		MAX = max(MAX, a[i]);
	}

	long long int MAX2 = 0;
	int x = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] * (MAX - a[i]) > MAX2) {
			MAX2 = a[i] * (MAX - a[i]);
			x = a[i];
		}
	}
	cout << MAX << " " << x << endl;
}

Measured memory_bytes: 1024