akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int a = sc.nextInt();
		Pair[] monster = new Pair[n];

		ArrayList<Integer> hitPos = new ArrayList<>();
		ArrayList<Long> hitSum = new ArrayList<>();
		
		hitSum.add(0L);

		for (int i=0;i<n;i++) {
			Pair p = new Pair();
			p.left =sc.nextInt();
			p.right =(sc.nextInt()-1)/a+1;
			monster[i]=p;
		}
		Arrays.sort(monster, Comparator.comparing((Pair p)->p.left));

		for (int i=0;i<n;i++) {
			int tmp = Collections.binarySearch(hitPos, monster[i].left-d);
			long damage = 0;
			if (tmp>=0) {
				damage = hitSum.get(hitSum.size()-1)-hitSum.get(tmp);
			} else {
				damage = hitSum.get(hitSum.size()-1)-hitSum.get(-tmp-1);
			}
			if (monster[i].right-damage>0) {
				hitPos.add(monster[i].left+d);
				hitSum.add(hitSum.get(hitSum.size()-1)+monster[i].right-damage);
			}
		}
		System.out.println(hitSum.get(hitSum.size()-1));
	}
	
}

class Pair {
	int left;
	long right;
}

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

const int maxn = 1e5 + 58;
int sz[maxn];
vector <int> adj[maxn];

bool dfs(int v, int p = -1) {
	bool f = 1;
	int t = 0;
	sz[v] = 1;
	for (auto u: adj[v]) {
		if (u != p) {
			f = dfs(u, v) & f;
			sz[v] += sz[u];
			if (sz[u] % 2) t++;
		}
	}
	return f && (t <= 1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--;
		u--;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	if (dfs(0) && n % 2 == 0) cout << "Second";
	else cout << "First";
}


Measured memory_bytes: 9640
#include<bits/stdc++.h>
using namespace std;
 
int main(){
 int N;
 cin>>N;
 set<int> st;
 int A[N];
 for(int i = 0;i < N;i++){
     cin>>A[i];
     st.insert(A[i]);
}
if(N ==st.size())cout<<"YES";
else cout<<"NO";
}

Measured memory_bytes: 10368
// https://atcoder.jp/contests/abc169/tasks/abc169_d

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

//------------------------------------------------------------------------------
map<ll, int> prime_factor(ll n) {
  map<ll, int> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

//------------------------------------------------------------------------------
const ll N_MAX = 1e12;

ll N;

int unique_div(int n) {
  int k = 1;
  while (n >= k) {
    n -= k++;
  }
  return k - 1;
}

int main() {
  cin >> N;

  auto mp = prime_factor(N);

  int ans = 0;
  for (auto p : mp) {
    int d = unique_div(p.second);
    // cout << "[" << p.first << "," << p.second << "," << d << "]" << endl;
    ans += d;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    vector<int> a(9);
    const vector<vector<int>> bingo_tab({{0,1,2},{3,4,5},{6,7,8},
    {0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}});
    rep(i,9) cin >> a[i];
    cin >> n;
    vector<bool> bingo(9,false);
    rep(i,n) {
        int b;
        cin >> b;
        rep(i, 9) if(a[i] == b) {
            bingo[i] = true;
        }
    }
    for (auto i: bingo_tab) {
        if(bingo[i[0]]==true && bingo[i[1]] == true && bingo[i[2]] == true) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int x = -1;

    int X;
    scanf("%d", &X);

    for (int i = X, j = 2; x == -1; j++) {
        if (i == j) {
            x = i;
            j = 1;
        } else if (i % j == 0) {
            x = -1;
            i++;
            j = 1;
        }
    }

    printf("%d\n", x);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll N, A[100100], B[100100], ans=0;
    scanf("%lld", &N);
    rep(i, N) scanf("%lld %lld", A+i, B+i);
    for(ll i=N-1; i>=0; i--) {
        A[i] += ans;
        if( A[i]%B[i]!=0 ) ans += B[i] - A[i]%B[i];
    }
    printf("%lld\n", ans);
    return 0;
}


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

int n,k;
int h[100001];
bool visited[100001];
int inf = 1e9+1;
vector<int> DP(100001,inf);

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

	//mincost to reach stone 1
	DP[1] = 0;

	for(int i=1 ; i <=n ; i++)
	{
		for(int j=1; j <= 2 ; j++)
		{
			if(i+j<=n)
				DP[i+j] = min(DP[i+j], DP[i]+abs(h[i]-h[i+j]));
		}
	}

	cout << DP[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
 int n,p[101],ans[101]={},k=0;
 cin >> n;
 for(int i=0;i<n;i++)
  cin >> p[i];
	
 for(int i=0;i<n;i++)
  if(p[i]<400)
   ans[0]++;
  else if(p[i]<800)
   ans[1]++;
  else if(p[i]<1200)
   ans[2]++;
  else if(p[i]<1600)
   ans[3]++;
  else if(p[i]<2000)
   ans[4]++;
  else if(p[i]<2400)
   ans[5]++;
  else if(p[i]<2800)
   ans[6]++;
  else if(p[i]<3200)
   ans[7]++;
  else
	ans[8]++;
 for(int i=0;i<8;i++)
   if(ans[i]>0)
	 k++;
 if(k==0)
   cout << "1 " << n << endl;
 else
   cout << k << " " << k+ans[8] << endl;
}

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

using namespace std;

typedef long long ll;

const int N = 4000, INF = (1LL << 31) - 1;

int a[N], t[N * 4];

void build(int v, int tl, int tr) {
    if (tl == tr)
        t[v] = a[tl];
    else {
        int tm = (tl + tr) / 2;
        build (v*2, tl, tm);
        build (v*2+1, tm+1, tr);
        t[v] = min(t[v*2], t[v*2+1]);
    }
}

int get_min(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return INF;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return  min(get_min(v*2, tl, tm, l, min(r,tm)), get_min(v*2+1, tm+1, tr, max(l,tm+1), r));
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    ll x, ans = 0;
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i + n] = a[i];
        ans += a[i];
    }
    build(1, 0, n * 2 - 1);
    for (int i = 0; i < n; ++i) {
        ll s = x * i;
        for (int j = n; j < n * 2; ++j) {
            s += get_min(1, 0, n * 2 - 1, j - i, j);
        }
        ans = min(ans, s);
    }
    cout << ans;
    return 0;
}

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

using namespace std;

int main(){
	
	int n;
	
	cin >> n;
	
	vector<int>num(n);
	
	long long int mod = 1000000007;
	
	long long int sum = 0;
	for (int i = 0;i <n;i++ ){
		cin >> num[i];
		sum += num[i];
		sum %= mod;
	}
	
	long long int ans = 0;
	for (int i = 0; i < n;i++){
		sum -= num[i];
		
		if (sum < 0) sum += mod;
		ans += num[i]*sum;
		ans %= mod;
	}
	
	cout << ans;
	
	
	return 0;
}
		


Measured memory_bytes: 4048
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int D, N;

int main() {
  cin >> D >> N;
  
  if (D == 2) {
    if (N != 100) cout << N*10000 << endl;
    else cout << 101*10000 << endl;
  } else if (D == 1) {
    if (N != 100) cout << N*100 << endl;
    else cout << 101*100 << endl;
  } else if (D == 0) {
    if (N != 100) cout << N << endl;
    else cout << 101 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,a,b;cin>>n>>a>>b;
	int ans = 0;
	for(int i = 1;i <= n;i++){
		int t = i;
		int keta = 0;
		while(t!=0){
			keta += t%10;
			t /= 10;
		}
		if(a <= keta && keta <= b){
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
   int A,B,C,K;
   cin >> A >> B >> C >> K;
   if (A>K) {
       cout << K <<endl;
   }
   else {
       if (A+B>=K) {
       cout << A << endl; 
   }
       else {
           cout << A-(K-A-B) << endl;
   }
   }
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();

		int[] C = new int[N];
		int[][] A = new int[N][M];
		long C_sum = 0;
		long[] A_sum = new long[M];
		for(int i=0; i<N; i++) {
			C[i] = sc.nextInt();
			C_sum += C[i];

			for(int j=0; j<M; j++) {
				A[i][j] = sc.nextInt();
				A_sum[j] += A[i][j];
			}
		}

		//すべて選ぶ
		for(int i=0; i<M; i++) {
			if(A_sum[i] < X) {
				System.out.println(-1);
				return;
			}
		}

		long ans = C_sum;
		for(int i=0; i<(1<<N); i++) {
			long sum = C_sum;
			long[] Ai_sum = new long[M];
			System.arraycopy(A_sum, 0, Ai_sum, 0, A_sum.length);
			for(int j=0; j<N; j++) {
				//選択しない
				if((1 & (i >> j)) == 0) {
					sum -= C[j];
					for(int k=0; k<M; k++) {
						Ai_sum[k] -= A[j][k];
					}
				}
			}

			boolean ok = true;
			for(int j=0; j<M; j++) {
				if(Ai_sum[j] < X) {
					ok = false;
					break;
				}
			}

//			System.out.println("ans: " + ans);
			if(ok) {
				ans = Math.min(ans, sum);
//				System.out.println("ans_change: " + ans);
			}
		}

		System.out.println(ans);

	}

}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    map<pair<ll,ll>,ll> mp;
    vector<ll> xv;
    vector<ll> yv;
    for(i = 0;i < n;++i){
        ll x,y;
        cin >> x >> y;
        mp[make_pair(x,y)] = 0;
        xv.push_back(x);
        yv.push_back(y);
    }
    sort(all(xv));
    sort(all(yv));
    vector<vector<ll>> tizu(n+1,vector<ll>(n+1,0));
    for(auto point:mp){
        ll x = point.first.first;
        ll y = point.first.second;
        ll xind = lower_bound(all(xv), x) - xv.begin()+1;
        ll yind = lower_bound(all(yv), y) - yv.begin()+1;
        ++tizu.at(xind).at(yind);
    }
    for(i = 0;i <= n;++i){
        rep(j,n){
            tizu.at(i).at(j+1) += tizu.at(i).at(j);
        }
    }
    for(i = 0;i < n;++i){
        rep(j,n+1){
            tizu.at(i+1).at(j) += tizu.at(i).at(j);
        }
    }
    ll ans = 5e18;
    for(i = 1;i <= n-1;++i){
        for(j = i+1;j <=n;++j){
            ll iy,jy;
            for(iy = 1;iy <= n-1;++iy){
                for(jy = iy+1;jy <=n;++jy){
                    ll num = tizu.at(j).at(jy) - tizu.at(j).at(iy-1) - tizu.at(i-1).at(jy) + tizu.at(i-1).at(iy-1);
                    if(num < k) continue;
                    ll tmp = (xv.at(j-1)-xv.at(i-1))*(yv.at(jy-1) - yv.at(iy-1));
                    ans = min(ans, tmp);
                }   
            }
        }   
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [str(input()) for i in range(n)]
dic = {}
m = 1
for a in s:
    if not a in dic:
        dic[a] = 1
    else:
        dic[a] += 1
        cnt = dic[a]
        m = max(m, cnt)
se = set()
for a in s:
    if dic[a] == m:
        se.add(a)
l = ['a'] * len(se)
for i in range(len(se)):
    l[i] = se.pop()
l.sort()
for i in range(len(l)):
    print(l[i])

Measured memory_bytes: 45836
/*
 * main.cpp
 *
 *  Created on: 2020/04/07
 *      Author: SkAaO
 */

#include <iostream>
#include <string>

using namespace std;

int main(){
	string S;
	cin >> S;

	/*
	char swap;
	int length = (int)S.size();
	for(int i = 0; i < length; i++){
		for(int j = i + 1; j < length; j++){
			if(S.at(i) > S.at(j)){
				swap = S.at(i);
				S.at(i) = S.at(j);
				S.at(j) = swap;
			}
		}
	}

	char min = 0;
	char pre, cre;
	for(int i = 1; i < length; i++){
		pre = S.at(i-1);
		cre = S.at(i);
		char dist = cre - pre;
		if(dist >= 2){
			min = pre + 1;
			cout << min << endl;
			break;
		}else{
			if(i == length - 1){
				cout << "None" << endl;
				break;
			}
		}
	}
	*/

	bool exist[26] = {false};
	int length = (int)S.size();
	for(int i = 0; i < length; i++){
		exist[(S.at(i) - 'a')] = true;
	}
	for(int i = 0; i < 26; i++){
		if(exist[i] == false){
			char word = i + 'a';
			printf("%c", word);
			break;
		}else{
			if(i == 25){
				cout << "None" << endl;
				break;
			}
			continue;
		}
	}

	return 0;
}




Measured memory_bytes: 512
def judge(s):
    if len(s) == 0: return True
    si = 0
    for t in T:
        if t == s[si]:
            si += 1
            if si == len(s): return True
    return False

S,T = input(),input()
N = len(S)
print('Yes' if judge(S[::2]) or judge(S[1::2]) else 'No')

Measured memory_bytes: 5568
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val count = Array(4) {0}
    repeat(3) {
        count[sc.nextInt() - 1]++
        count[sc.nextInt() - 1]++
    }
    var isNo = false
    var oddCount = 0
    for (x in count) {
        if (x == 0) {
            isNo = true
            break
        }
        if (x % 2 == 1) {
            oddCount++
        }
    }
    if (isNo || oddCount != 0 && oddCount != 2) {
        println("NO")
    } else {
        println("YES")
    }
}

Measured memory_bytes: 31264
#include<stdio.h>
using namespace std;
int power(int a, int b) {
	int ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a;
	}

	return ans;
}
int main(void)
{
	int X;
	scanf("%d", &X);
	int max=1;
	for (int i = 2; i < 11; i++) {
		for (int j = 1; j < 1000; j++) {
			if (power(j, i) > X) {
				break;
			}
			if (max <= power(j, i)) {
				max = power(j, i);
			}
		}
	}
	printf("%d", max);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  if(N >= 105 && N < 135) ans = 1;
  if(N >= 135 && N < 165) ans = 2;
  if(N >= 165 && N < 189) ans = 3;
  if(N >= 189 && N < 195) ans = 4;
  if(N >= 195) ans = 5;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[]) {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double ans = 0;
  ll ans_sugar = 0;
  ll ans_water = 0;
  for (int a = 0; a <= 30; a++) {
    if (a * A * 100 > F) continue;
    for (int b = 0; b <= 30; b++) {
      if (b * B * 100 > F || (b * B + a * A) * 100 > F) continue;
      for (int c = 0; c < 3001; c++) {
        if (c * C > F) continue;
        for (int d = 0; d < 3001; d++) {
          if (a + b + c + d == 0) continue;
          if (d * D > F) continue;
          if (ans < (double)100 * (C * c + D * d) /
                        (A * a * 100 + B * b * 100 + C * c + D * d) &&
              (double)100 * (C * c + D * d) /
                      (A * a * 100 + B * b * 100 + C * c + D * d) <=
                  (double)100 * E / (100 + E) &&
              (A * a + B * b) * 100 + C * c + D * d <= F) {
            ans = (double)100 * (C * c + D * d) /
                  (A * a * 100 + B * b * 100 + C * c + D * d);
            ans_sugar = C * c + D * d;
            ans_water = (A * a + B * b) * 100;
            //cout << "e;"
              //   << (double)100 * (C * c + D * d) /
                //        (A * a * 100 + B * b * 100 + C * c + D * d)<<"limit_density"<<(double)E*100/(100+E)<<endl;
          }
        }
      }
    }
  }
  if(ans_water==0){printf("%d %d",min(F,min(A*100,B*100)),0);
  return 0;}
  printf("%lld %lld\n", ans_water + ans_sugar, ans_sugar);

  return 0;
}

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

//考察寄りの問題。ちょっと難しかった。
//2(mod4)がある場合とない場合で場合分けする。
//2(mod4)がある場合はそれらを全部ひとまとめにする。


int main(){
    int n;
    cin >> n;
    int a[110000];
    int fourCount = 0, twoCount = 0, oddCount = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] % 4 == 0){
            fourCount++;
        }else if(a[i] % 4 == 2){
            twoCount++;
        }else{
            oddCount++;
        }
    }
    string ans = "Yes";
    if(twoCount == 0  &&  fourCount >= n/2){
        cout << ans << endl;
        return 0;
    }
    vector<int> vec;
    for(int i=0; i<twoCount; i++){
        vec.push_back(2);
    }
    for(int i=0; i<n-twoCount; i++){
        if(fourCount > 0){
            vec.push_back(4);
            fourCount--;
        }else{
            vec.push_back(1);
            oddCount--;
        }
        i++;
        if(i==n-twoCount) break;
        if(oddCount > 0){
            vec.push_back(1);
            oddCount--;
        }else{
            vec.push_back(4);
            fourCount--;
        }
    }

    // for(auto itr = vec.begin(); itr != vec.end()-1; itr++) {
    //     if(*itr * *(itr+1) % 4 != 0){
    //         ans = "No";
    //     }
    // }
    for(int i=0; i<vec.size()-1; i++) {
        if(vec[i] * vec[i+1] % 4 != 0){
            ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define loop(i,n) for(int i=1;i<=n;i++)
bool a[92][92];

int dfs(int i,int j){
  if(a[i][j]){
    int s=0;
    a[i][j]=0;
    int d[5]={0,-1,0,1,0};
    loop(e,4){
      int dx=d[e-1];
      int dy=d[e];
      s=max(s,dfs(i+dx,j+dy));
    }
    a[i][j]=1;
    return s+1;
  }else{
    return 0;
  }
}

int main(){
  int m,n;
  while(cin>>m>>n,m){
    loop(i,m)loop(j,n)a[i-1][j-1]=0;
    loop(i,m)loop(j,n)cin>>a[i][j];
    int r=0;
    loop(i,m)loop(j,n)r=max(r,dfs(i,j));
    cout<<r<<endl;
  }
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020, mod = 1'000'000'007;
int f[maxn][maxn], s[maxn], t[maxn];
int solve(int x, int y){
	if(min(x, y) == -1) return 1;
	if(~f[x][y]) return f[x][y];
	int ans = 0;
	if(s[x] == t[y]){
		ans += solve(x - 1, y - 1);
	}
	ans += solve(x - 1, y); if(ans >= mod) ans -= mod;
	ans += solve(x, y - 1); if(ans >= mod) ans -= mod;
	ans += mod - solve(x - 1, y - 1); if(ans >= mod) ans -= mod;
	return f[x][y] = ans;
}
int main(){
	memset(f, -1, sizeof(f));
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> s[i];
	for(int i = 0; i < m; i++) cin >> t[i];
	cout << solve(n - 1, m - 1) << endl;
	return 0;
}


Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
const int MAX = 2020;
bool a[MAX][MAX]={};
using BS = bitset<MAX>;
BS st[MAX],dpL[MAX],dpR[MAX];
signed main(){
  int n;
  cin>>n;
  for(int i=1;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<i;j++){
      a[i][j]=s[j]-'0';      
      a[j][i]=!a[i][j];
    }
  }
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(a[i][j]) st[i].set(j);
      
  for(int i=0;i<n;i++){
    dpL[i].set(i);
    dpR[i].set(i);
  }

  for(int w=2;w<=n;w++){
    for(int i=0;i+w<=n;i++){
      int l=i,r=i+w-1;
      {
        BS x=dpR[l+1]&dpL[r]&st[l];      
        if((((x>>(r+1))<<(r+1))^((x>>(l+1))<<(l+1))).any()) dpL[r].set(l);
      }
      { 
        BS x=dpR[l]&dpL[r-1]&st[r];
        if((((x>>r)<<r)^((x>>l)<<l)).any()) dpR[l].set(r);        
      }
    }
  }
  
  cout<<(dpR[0]&dpL[n-1]).count()<<endl;  
  return 0;
}


Measured memory_bytes: 5760
N,M = map(int,input().split())
S = [input().split() for i in range(M)]
cntAC = [0] * N
cntWA = [0] * N

for p,s in S:
    if cntAC[int(p)-1] == 0:
        if s == "AC":
            cntAC[int(p)-1] = 1
        elif s == "WA":
            cntWA[int(p)-1] += 1

sumWA = sum([cntWA[p] for p in range(N) if cntAC[p]==1])

print(sum(cntAC),sumWA)


Measured memory_bytes: 34664
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
mod = 0
for i in range(N):
    tmp = A[i]
    if mod >= tmp:
        ans += tmp
        mod = B[i]
    else:
        ans += mod
        tmp = tmp - mod
        if B[i] >= tmp:
            ans += tmp
            mod = B[i]-tmp
        else:
            ans += B[i]
            mod = 0
if mod > 0:
    ans += min(mod, A[N])
print(ans)

Measured memory_bytes: 18476
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y, ll p)
{
	ll res = 1;

	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}


ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
	if (r == 0)
		return 1;

	vector<ll> fac(n + 1, 0);
	fac[0] = 1;
	for (ll i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % p;

	return (fac[n] * modInverse(fac[r], p) % p *
		modInverse(fac[n - r], p) % p) % p;
}

bool check(ll a)
{
	ll count = 0;
	while (a % 2 == 0)
	{
		a /= 2;
		count += 1;
	}
	if (count > 1)
		return false;
	bool flag = true;
	for (ll i = 3; i <= sqrt(a); i += 2)
	{
		if (a % i == 0)
		{
			flag = false;
			break;
		}
	}
	return flag;
}
ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a;
	cin>>a;
	cout<<(a+(a*a)+(a*a*a));
	return 0;
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt();
			System.out.println(((c >= a) && (c <= b)) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 998244353;
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;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<string> s(n);
    vector<pair<ll,ll>> xup, xdown;
    ll minuscnt = 0;
    rep(i,n) {
        cin>>s[i]; 
        ll cnt = 0;
        while(s[i][cnt]==')'&&cnt<s[i].size()) {
            cnt++;
        }
        ll cnt2 = 0;
        for(auto a:s[i]) {
            cnt2 += (a=='(' ? 1 : -1);
        }
        if (cnt2 >=0) {
            xup.emplace_back(cnt, cnt2);
        }
        else {
            minuscnt -= cnt2;
            ll cnt = 0;
            while(s[i][s[i].size()-1-cnt]=='('&&cnt<s[i].size()) {
                cnt++;
            }
            xdown.emplace_back(cnt, -cnt2);
        }
    }

    sort(begin(xup), end(xup));
    sort(begin(xdown), end(xdown));
    ll now = 0;

    for(auto up:xup) {
        if (up.first > now) {
            cout << "No" << endl;
            return 0;
        }
        now += up.second;
    }
    ll tmp = now;
    now=0;
    for(auto up:xdown) {
        if (up.first > now) {
            cout << "No" << endl;
            return 0;
        }
        now += up.second;
    }
    if (tmp == now) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 50260
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    a,b,c,d = INTM()
    print(max(a*b,c*d))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<utility>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define MAX1(a,b) (((a)>(b))?(a):(b))
typedef long long ll;
void rot(string& s){
char tmp=s[s.length()-1];
for(int i=s.length()-1;i>=1;i--)
    s[i]=s[i-1];
s[0]=tmp;
}
int main(){
string s,t;
cin>>s>>t;
for(int i=1;i<=s.length();i++){
    rot(s);
    if(s==t){
        cout<<"Yes"<<endl;
        return 0;}
}
cout<<"No"<<endl;
}


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

using namespace std;
template <class T> string toStr(T par) {
	ostringstream oss;
	oss<<par;
	return oss.str();
}
string s;
int n, k, q, dislikes[11];
int main()
{
    cin >> n >> k;
    for(int i = 0; i < k ; i++)
    {
        cin >> q;
        dislikes[q] = 1;
    }

    while(true)
    {
        int prev_n = n, cnt = 0;
        bool ok = false;
        s = toStr(n);
        for(int i = s.size() - 1; i >= 0; i--)
        {
            if(dislikes[s[i] - '0'])
                ok = true;
        }
        if(ok) n++;
        else break;
    }
    cout << n << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

const double PI=acos(-1.0);

int main()
{
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    double th = double(h*60+m)/720 * 2*PI;
    double tm = double(m)/60 * 2*PI;
    double xh = a*cos(th), yh = a*sin(th);
    double xm = b*cos(tm), ym = b*sin(tm);
    double dx = xh - xm, dy = yh - ym;
    double ans = sqrt(dx*dx + dy*dy);
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 4060
/*
本宝的程序外人别想看！！

name: [夏宝宝]
run time：[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
using namespace std;

int read(){
    int x=0,f=1;
	char ch=getchar();
    
    while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;ch=getchar();
	}
	
    while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';ch=getchar();
	}
	
    return x*f;
}

int main()
{
	long long int a=read(), b=read(), sum=0;;
    
    sum+=a/b;
  
    if(a%b!=0)
    {
        sum++;
    }
    
    cout<<sum<<endl;
  
	return 0;
}


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

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

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


    int n=0;
      cin>>n;
  
      unsigned long long ans=0;
    

    for(int i =1 ; i <=n; i++)
    {
        for(int j=1; j <=n ; j++)
        {
            for(int k=1; k <=n ; k++)
            {
                int t = gcd(i,j);

                ans+=gcd(t,k);
            }
        }
    }
  
  cout<<ans<<endl;
      

    
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define LL long long

int n;
LL A[100005];

int main(){
  scanf("%d",&n);
    bool zero = false;
    for ( int i = 0; i < n; i++ ){
      scanf("%lld",&A[i]);
        if ( A[i] == 0 ) zero = true;
    }
    if ( zero ) {
    printf("0\n");
        return 0;
    }
  
    LL p = 1, mx = 1e18;
  for ( int i = 0; i < n; i++ ){
      LL tmp = (mx/p);
        if ( tmp < A[i] ) {
          printf("-1\n");
            return 0;
        }
     p *= A[i];
    }
    printf("%lld\n",p);
  
  return 0;
}







Measured memory_bytes: 4452
S = input()
T = input()

s_len = len(S)
t_len = len(T)
ans_array = [[0] * (s_len + 1) for _ in range(t_len + 1)]

for t in range(1, t_len + 1):
    for s in range(1, s_len + 1):
        ans_array[t][s] = max(ans_array[t - 1][s], ans_array[t][s - 1])
        if T[t - 1] == S[s - 1]:
            ans_array[t][s] = ans_array[t - 1][s - 1] + 1

# ans_r = []

# s = s_len
# t = t_len

# while s > 0 and t > 0:
#     if ans_array[t][s] == ans_array[t - 1][s]:
#         t -= 1
#     elif ans_array[t][s] == ans_array[t][s - 1]:
#         s -= 1
#     else:
#         t -= 1
#         s -= 1
#         ans_r.append(S[s])

# print("".join(reversed(ans_r)))

ans_len = ans_array[-1][-1]
ans = [""] * ans_len
s_last = s_len
t_last = t_len
for i in range(ans_len - 1, -1, -1):
    s_next = 0
    t_next = 0
    for s in range(s_last, 0, -1):
        if ans_array[t_last][s] != ans_array[t_last][s - 1]:
            s_next = s
            break
    s_last = s_next
    for t in range(t_last, 0, -1):
        if ans_array[t][s_last] != ans_array[t - 1][s_last]:
            t_next = t
            break
    ans[i] = S[s_next - 1]
    s_last = s_next - 1
    t_last = t_next - 1

print("".join(ans))


Measured memory_bytes: 113372
#include <stdio.h>
 
int dp[32];
int main() {
    int i;
    dp[1] = dp[2] = 1;
    for(i=3; i<32; i++) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    while(scanf("%d", &i) && i != 0) {
        printf("%d\n", (dp[i+1]-1)/3650+1);
    }
}



Measured memory_bytes: 2028
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;



int main(){
  char c;
  cin >> c;
  cout << char(c + 1) << endl;

}

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

int main(){
  long n;
  cin>>n;
  long arr[3000]; long sum=0;
  for(int i=0;i<n;i++){ cin>>arr[i]; sum+=arr[i];}
  long dp[3005][3005];
  for(int i=0;i<=3004;i++){
    for(int j=0;j<=3004;j++){
      dp[i][j]=0;
    }
  }
  for(int i=1;i<=n;i++) dp[i][i]=arr[i-1];
  for(int i=1;i<n;i++){
    for(int j=1;j<=n-i;j++){
      long a=arr[j-1]+min(dp[j+2][i+j],dp[j+1][i+j-1]);
      long b=arr[i+j-1]+min(dp[j][i+j-2],dp[j+1][i+j-1]);
        dp[j][i+j]=max(a,b);
      
    }
  }
  
   long ans=dp[1][n]-(sum-dp[1][n]);
  cout<<ans;
}
  
  
  
  

Measured memory_bytes: 70784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader br =
    		new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    
    
    StringTokenizer st =
    		new StringTokenizer(str, " ");

    String tate = st.nextToken();
    String yoko = st.nextToken();  

    int tateNum = Integer.parseInt(tate);
    int yokoNum = Integer.parseInt(yoko);
    
    int men = tateNum * yokoNum;
    int enshu = (tateNum + yokoNum)*2;
    
    System.out.println(men + " " + enshu);

  }
}

Measured memory_bytes: 24120
#include<bits/stdc++.h>
using namespace std;
int n,a[200010],head[400010],tot;
int vis[200010],in[200010],out[200010];
vector<int>v,A;
struct edge{
	int nxt,to;
}e[200010*2];
inline void add(int x,int y){
	e[++tot].to=y;
	e[tot].nxt=head[x];
	head[x]=tot;
}
typedef long long ll;
ll k;
void dfs(int x){
	v.push_back(x);
	for(int i=head[x];i;i=e[i].nxt){
		int j=e[i].to;
		if(vis[j])return;
		vis[j]=1;dfs(j);
	}
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i){
		add(i,a[i]);
		in[a[i]]++;
		out[i]++;
	}
	vis[1]=1;dfs(1);
	/*for(int i=0;i<v.size();++i){
		if(out[v[i]]<1||in[v[i]]<1)continue;
		A.push_back(v[i]);
	}
	int L=(int)A.size();
	k%=L;
	cout<<A[k]<<endl;
	for(int i=0;i<L;++i)cout<<A[i]<<" ";
	cout<<endl;*/
	int nt=a[v.back()],ss=0;
	for(int i=0;i<v.size();++i){
		if(v[i]==nt)break;
		ss++;
	}
	if(k<=ss){
		cout<<v[k]<<endl;
		return 0;
	}
	k-=ss;
	for(int i=0;i<ss;++i)v[i]=0;
	for(int i=0;i<v.size();++i){
		if(v[i]==0)continue;
		A.push_back(v[i]);
	}
	int L=A.size();
	k%=L;
	cout<<A[k]<<endl;
	return 0;
}

Measured memory_bytes: 18664
d = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(d)]
T = [int(input())-1 for i in range(d)]

day = 0
score = 0
last_li = [-1]*26

def incrase(day,probrem_id,last_li,score):
    score+=S[day][problem_id]
    last_li[problem_id]=day+1
    return score,last_li
    
def decrease(day,last_li,score):
    for i in range(26):
        score-=C[i]*(day+1-(0 if last_li[i]==-1 else last_li[i]))
    return score

for i in range(d):
    problem_id = T[i]
    score,last_li = incrase(i,problem_id,last_li,score)
    score = decrease(i,last_li,score)
    print(score)


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

int main()
{
	double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f)
	{
		printf("%.3f %.3f\n", (c*e-b*f)/(a*e-b*d)+0.0001, (c*d-a*f)/(b*d-a*e)+0.0001);
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int total = sc.nextInt();
			if (total == 0)break;
			for (int i = 0; i < 9; i++)
			{
				total -= sc.nextInt();
			}
			System.out.println(total);
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<stack>
#include<climits>
#include<vector>
#include<string>
#include<map>
using namespace std;
int main(){
    int a[101];
    a[0]=0;
    for(int i=1; i<=100; i++){
        a[i]=i;
        a[i]+=a[i-1];
    }
    int n;
    while(~scanf("%d", &n))
        printf("%d\n", a[n]);
    return 0;
}


Measured memory_bytes: 256
import itertools
N = int(input())
l = len(str(N))
ans = 0
if l < 3:
	pass
else:
	S = []
	for k in range(3,l+1):
		S += list(itertools.product(['3', '5', '7'], repeat=k))
	# print(S)
	for i in range(len(S)):
		num = ''
		for t in range(len(S[i])):
			num = num + S[i][t]
		# print(num)
		if '3' in num:
			if '5' in num:
				if '7' in num:
					if int(num) <= N:
						# print(num)
						ans += 1
print(ans)


Measured memory_bytes: 7028
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a.at(x-1)++;
    }
    sort(a.begin(), a.end(), greater<int>());
    int ans=0;
    for(int i=0;i<n;i++){
        if(i>=k){
            ans+=a.at(i);
        }
    }
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1024
class UnionFind():
    # 親と高さを入れる配列をつくる
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
    
    # 一番上の親を見つける。ついでに、一番上の親に親を張り替える
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    
    def sama_check(self, x, y):
        return self.find(x) == self.find(y)


n, k, l = map(int, input().split())

un_load = UnionFind(n)
un_train = UnionFind(n)

for i in range(k):
    p, q = map(lambda x: int(x) - 1, input().split())
    
    if not un_load.sama_check(p, q):
        un_load.union(p, q)

for i in range(l):
    r, s = map(lambda x: int(x) - 1, input().split())
    
    if not un_train.sama_check(r, s):
        un_train.union(r, s)

load_train = {}
for i in range(n):
    comb = (un_load.find(i), un_train.find(i))
    
    if comb in load_train:
        load_train[comb] += 1
    else:
        load_train[comb] = 1

for i in range(n):
    print(load_train[(un_load.par[i], un_train.par[i])])

Measured memory_bytes: 55708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j) for(int i=0;i<j;i++)
#define print(a) cout<<a<<endl
typedef long long ll;
typedef string str;
typedef unsigned long long ul;
#define vint vector<int>

int main() {
	int a;
	str s;
	cin >> a >> s;
	
	if(a<3200){
		print("red");
	} else{
		print(s);	
	}
	
	return 0;
}

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

int main() {
	string w;	
	register int i;
	int c, s;
	while (cin >> w) {
		if (w == "-") break;
		cin >> c;
		for (i = 0; c-- ;) {
			cin >> s;
			i += s;
		}
		i %= w.length();
		cout << w.substr(i) << w.substr(0, i) << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import math
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    if a[i]<0:
        a[i]=-a[i]
        cnt+=1
q=min(a)
if cnt%2==0:
    print(sum(a))
else:
    print(sum(a)-2*q)

Measured memory_bytes: 15020
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
//const ll MAX = 510000LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll n;cin>>n;
  vl a(n+1);
  rep(i,n+1)cin>>a[i];
  vl two(52);
  two[0]=1;
  rep(i,49)two[i+1]=2*two[i];
  //rep(i,50)cout<<two[i]<<" ";
  //cout<<endl;
  rep(i,min(50LL,n+1)){
    if(a[i]>two[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  ll sum=0;
  rep(i,n+1)sum+=a[i];
  vl b(n+1);
  b[0]=sum;
  rep(i,n){
    b[i+1]=b[i]-a[i];
  }
  //rep(i,n+1)cout<<a[i]<<" ";
  //cout<<endl;
  // rep(i,n+1)cout<<b[i]<<" ";
  // cout<<endl;
  vl v(n+1);
  v[0]=1;
  rep(i,n){
    v[i+1]=min((v[i]-a[i])*2,b[i+1]);
  }
  ll ans=0;
  // rep(i,n+1)cout<<v[i]<<" ";
  // cout<<endl;
  //rep(i,min(50LL,n+1))b[i]=min(b[i],two[i]);
  rep(i,n+1){
    if(v[i]<a[i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  rep(i,n+1)ans+=v[i];
  cout<<ans<<endl;
  //rep(i,n+1)cout<<b[i]<<" ";
  //cout<<endl;
}

Measured memory_bytes: 5640
package main
 
import (
	"fmt"
	"time"
)
 
const (
	yyyymmdd = "2006/01/02"
)
func main() {
	var s string
	_, _ = fmt.Scan(&s)
	target, _ := time.Parse(yyyymmdd, s)
	ss := "2019/04/30"
	deadline, _ := time.Parse(yyyymmdd, ss)
	if target.Unix() <= deadline.Unix() {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using Pii = pair<int, int>;
using Vi = vector<int>;
using St = string;
using Ch = char;

const double pi = 3.1415926535;

long long Div (long long n, long long x) {
	if (n < 0) {
		return 0;
	}
	return n / x + 1;
}

void Main()
{
	ll a, b, x;
	cin >> a >> b >> x;
	cout << Div(b, x) - Div(a-1, x) << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

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

using namespace std;

int main()
{
	int n; cin>>n;
	vector<pair<int,int>> v(n);
	for(int i = 0; i<n; i++)
	{
		cin>>v[i].first;
		v[i].second = i+1;
	}

	sort(v.begin(), v.end());

	for(int i = 0; i<n; i++)
	{
		cout<<v[i].second<<" ";
	}
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;
#define ull unsigned long long int
#define all(a) a.begin(),a.end()s
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define hell 1000000007
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define MAX 10000001
int main()
{
  ll a;
  cin>>a;
  long double b;
  cin>>b;
  long double ans = (long double)a*b;
 // cout<<ans<<endl;
  ll final = ll(ans);
  cout<<final;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=401;
ll dp[N][N],n;
vector<ll> a(N),pref(N);

ll go(int l, int r){
    if(l==r) return 0;
    if(dp[l][r]!=-1)
        return dp[l][r];
    ll ans=MAX,srange=pref[r]-(l>0?pref[l-1]:0);
    for(int i=l;i<r;i++)
        ans=min(ans,srange+go(l,i)+go(i+1,r));
    return dp[l][r]=ans;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<n;i++)
        cin>>a[i];
    pref[0]=a[0];
    for(int i=1;i<n;i++)
        pref[i]=pref[i-1]+a[i];
    cout<<go(0,n-1);

    

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

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

#define ll long long int
#define fl(i,a,n) for(int i = a; i < (n); i++)
#define fls(i,a,s) for(int i = a; s[i] != '\0'; i++)

int main() {
    int n,m;
    scanf("%d %d", &n, &m);
    int ctr = 0;
    fl(i,0,n){
        fl(j,i+1,n){
            ctr++;
        }
    }
    fl(i,0,m){
        fl(j,i+1,m){
            ctr++;
        }
    }
    printf("%d\n", ctr);
    
    return 0;
}


Measured memory_bytes: 3208
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
ans = 0
for x in range(k, n + 2):
    p = x * (x - 1) // 2
    q = x * (x - 1) // 2 + (n - x + 1) * x
    ans += q - p + 1
print(ans % MOD)


Measured memory_bytes: 9080
// WeirdBugsButOkay

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

void solve()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll k;
    cin >> k;
    ll ans = 0;
    ans = min(a, k);
    k -= a;
    k -= b;
    if(k > 0)
        ans -= min(k, c);
    cout << ans << endl;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++)
    {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

int main(void){
	int a,b,c;
	
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	
	if(a==b && a!=c){
		printf("Yes");
	}
	else if(b==c && b!=a){
		printf("Yes");
	}
	else if(c==a && c!=b){
		printf("Yes");
	}
	else{
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
constexpr uint32_t h_base = 360 / 12;
constexpr uint32_t m_base = 360 / 60;

int main()
{
	uint32_t a,b,h,m;
	std::cin >> a >>b >>h>>m;
	float deg_h = h*h_base + (static_cast<float>(h_base)/60)*m;
	float deg_m = m * m_base;
	float theata = std::abs(deg_m - deg_h);
	if (theata > 180.f) theata = 360 - theata;
	const auto rad = theata * ((2.f * M_PI)/360.f);
	const auto result = a*a + b* b -2.f*a*b*cos(rad);
	std::cout << std::setprecision(10) << sqrt(result) << std::endl;
    return 0;

}



Measured memory_bytes: 3584