akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().strip().split())
    T = input().strip()

    i = 0
    score = 0
    while i != K:
        before = ""
        #print(T[i::K])
        for c in T[i::K]:
            #print(c, before)
            if c != before:
                if c == 'r':
                    score += P
                elif c == 's':
                    score += R
                else:
                    score += S
                before = c
            else:
                before = ""
                #print("?")
        i += 1
    print(score)
if __name__ == '__main__':
    main()


Measured memory_bytes: 41708
#include <stdio.h>
 
int main()
{
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
 
	int da = abs(x - a), db = abs(x - b);
	if (da < db) {
		puts("A");
	} else {
		puts("B");
	}
	return 0;
}

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

int main(){
  int N ;
  cin >> N ; 
  
  for(int a = 1 ; a < 230 ; a++){
    int64_t a5 = 1; 
    for(int i = 0 ; i < 5 ; i++) a5 *= a ; 
    
    for(int b = -230 ; b < 230 ; b++){
      int64_t b5 = 1 ; 
      for(int i = 0 ; i < 5 ; i++) b5 *= b ; 
      
      if(a5 - b5 == N) {
        cout << a << " "<< b << endl  ;
        return 0 ; 
      }
    }
  }
    
    
}

Measured memory_bytes: 3636
/* https://atcoder.jp/contests/dp/tasks/dp_d */


#include <bits/stdc++.h>
using namespace std;
/*
             
                       .:.
                       :|:
                      .:|:.
                      ::|::
       :.             ::|::             .:
       :|:.          .::|::.          .:|:
       ::|:.         :::|:::         .:|:;
       `::|:.        :::|:::        .:|::'
        ::|::.       :::|:::       .::|:;
        `::|::.      :::|:::      .::|::'
         :::|::.     :::|:::     .::|::;
         `:::|::.    :::|:::    .::|::;'
`::.      `:::|::.   :::|:::   .::|::;'      .:;'
 `:::..     ¹::|::.  :::|:::  .::|::¹    ..::;'
   `:::::.    ':|::. :::|::: .::|:'   ,::::;'
     `:::::.    ':|:::::|:::::|:'   :::::;'
       `:::::.:::::|::::|::::|::::.,:::;'
          ':::::::::|:::|:::|:::::::;:'
             ':::::::|::|::|:::::::''
                  `::::::::::;'
                 .:;'' ::: ``::.
                      :':':
                        ;
*/

#define ll long long 
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   

    ll n,c; cin >> n >> c;
    ll val[n]; ll wt[n];
    for(ll i=0;i<n;i++) {cin >> wt[i]; cin >> val[i];}
    
    ll dp[n+1][c+1];
    memset(dp,0,sizeof(dp));

    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=c;j++)
        {
            if(wt[i-1]<=j)
            {
                dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            }
            else if(wt[i-1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }

    cout << dp[n][c] << endl;

}

Measured memory_bytes: 79232
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N,M,X=MI()
C=[]
A=[]
for i in range(N):
  L=LI()
  C.append(L[0])
  A.append(L[1:])
ans=-1
for i in range(1<<N):
  tmp=[0]*M
  cost=0
  for j in range(N):
    if 1&(i>>j):
      cost+=C[j]
      for m in range(M):
        tmp[m]+=A[j][m]
  if min(tmp)>=X:
    if ans==-1:
      ans=cost
    else:
      ans=min(ans,cost)
print(ans)

Measured memory_bytes: 9180
s = gets.chomp

if s == "SUN"
  puts 7
elsif s == "MON"
  puts 6
elsif s == "TUE"
  puts 5
elsif s == "WED"
  puts 4
elsif s == "THU"
  puts 3
elsif s == "FRI"
  puts 2
elsif s == "SAT"
  puts 1
end


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=510*510;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int fa[N],f[N];
bool o[N];
int ans[N];
inline int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
int main()
{
	int n=gi(),i,p,k;
	for (i=1;i<=n*n;i++) fa[i]=i;
	for (i=1;i<=n;i++) {
		p=i,k=f[i]=gi();
		if (o[k]) return puts("No"),0;
		o[k]=true;
		while (p--) {
			k=find(k);
			if (!k) return puts("No"),0;
			ans[k]=i;
			fa[k]=k-1;
		}
		swap(ans[k],ans[f[i]]);
	}
	for (i=1,p=0;i<=n*n;i++)
		if (!o[i]&&ans[i]) {
			while (p<i&&ans[++p]);
			if (p!=i) {
				ans[p]=ans[i];
				ans[i]=0;
			}
		}
	for (i=1;i<=n*n;i++) fa[i]=ans[i]?i+1:i;
	for (i=1;i<=n;i++) {
		p=n-i,k=f[i]+1;
		while (p--) {
			k=find(k);
			if (!k) return puts("No"),0;
			ans[k]=i;
			fa[k]=k+1;
		}
	}
	puts("Yes");
	for (i=1;i<=n*n;i++) printf("%d ",ans[i]);
	return 0;
}


Measured memory_bytes: 4480
#include<stdio.h>

int main(){
	
	int n,i,j,t[7]={};
	float s;
	
	scanf("%d",&n);
	
	for(i=1;i<=n;i++){
		scanf("%f",&s);
		
		if(s<165.0){
			t[1]++;
		}
		else if(s>=165.0 && s<170.0){
			t[2]++;
		}
		else if(s>=170.0 && s<175.0){
			t[3]++;
		}
		else if(s>=175.0 && s<180.0){
			t[4]++;
		}
		else if(s>=180.0 && s<185.0){
			t[5]++;
		}
		else if(s>=185.0){
			t[6]++;
		}
	}
	
	for(i=1;i<=6;i++){
		printf("%d:",i);
		for(j=1;j<=t[i];j++){
			printf("*");
		}
		printf("\n");
	}
	
return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long a, b;
	cin >> a >> b;
	if ((a + b) % 2 != 0) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << (a + b) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import javax.net.ssl.SSLContext;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

public class Main {

    private static long gcd(long a, long b)
    {
        while (b > 0)
        {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b)
    {
        return a * (b / gcd(a, b));
    }

    private static long lcm(long[] input)
    {
        long result = input[0];
        for(int i = 1; i < input.length; i++) result = lcm(result, input[i]);
        return result;
    }


    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] input = reader.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        BigDecimal b = new BigDecimal(Integer.parseInt(input[1]));
        BigDecimal c = new BigDecimal(Integer.parseInt(input[2]));

        for (int x = 1; x <= 100000; x++) {
            BigDecimal ax = new BigDecimal(a*x);
            BigDecimal remain = ax.divideAndRemainder(b)[1];
            if (remain.compareTo(c) == 0) {
                System.out.print("YES");
                return;
            }
        }

        System.out.println("NO");



//        PrintWriter writer = new PrintWriter(System.out);
//
//        writer.close();


    }
}


Measured memory_bytes: 88684
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int A,B,K;
	while(cin>>A>>B>>K)
	{
		for(int i=0;i<K;i++)
		{
			if(A%2) A--;
			A=A/2;
			B+=A;
			int t=B;
			B=A;
			A=t;
		}
		if(K&1)
		{
			cout<<B<<' '<<A<<endl;;
		}
		else
		{
			cout<<A<<' '<<B<<endl;;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x;
    vector<long long int>v;
    map<long long int,long long int>m;
    cin>>n;
    for(long long int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
        m[x]++;
    }
    long long int ans=0;
    map<long long int,long long int>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        if(it->second>it->first)
        {
            ans+=(it->second)-(it->first);
        }
        else if(it->second<it->first)
        {
            ans+=it->second;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    string S,T;
    cin >> S >> T;
    ll cnt = 0;
    repi(i,3,0){
        if(S.at(i) == T.at(i)){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

fn solve(N: i64) {
    println!("{}", if N % 2 == 0 {N} else {2 * N});
}

fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8572
#include<cstdio>

#include<cstring>

int main(){

	char str[ 1001];

	while( 1){

		scanf("%s", str);

		if ( str[0] == '0' ) break;

		int sum = 0;

		for ( int i = 0; i < strlen( str); i++ ){

			sum += (str[i] - '0');

		}

		printf ("%d\n", sum);

	}

	return 0;

}

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

int main(){
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    rep(i,n){
        int x;
        cin >> x;
        if(x >= k){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n;

ll g(ll x,ll p){
	auto s=to_string(x);
	ll n=s.size(),t=0;
	vl dp1(p),dp2(p);
	for(int i=0;i<n;i++){
		vl DP1(p),DP2(p);
		ll c=s[i]-'0';
		for(int j=(i?0:1);j<c;j++){
			DP1[(t+j)%p]+=i+1;
			DP2[(t+j)%p]++;
		}
		if(i){
			for(int j=1;j<10;j++){
				DP1[j%p]++;
				DP2[j%p]++;
			}
		}
		for(int j=0;j<p;j++){
			for(int k=0;k<10;k++){
				DP1[(10*j+k)%p]+=dp1[j]+dp2[j];
				DP2[(10*j+k)%p]+=dp2[j];
			}
		}
		t=(t+c)*10%p;
		dp1=DP1,dp2=DP2;
	}
	dp1[x%p]+=n;
	return dp1[0];
}

ll f(ll x){
	if(!x) return 0;
	return (x/3+x/5)*4+g(x,1)-g(x,3)-g(x,5)+g(x,15);
}

string h(ll x){
	if(x%3!=0&&x%5!=0) return to_string(x);
	string s="";
	if(x%3==0) s+="Fizz";
	if(x%5==0) s+="Buzz";
	return s;
}

int main(){
	cin>>n;
	ll l=0,r=1e17;
	while(r-l>1){
		ll m=(l+r)/2;
		if(f(m)>=n) r=m;
		else l=m;
	}
	n-=f(l);
	string res;
	for(int i=0;i<20;i++){
		auto t=h(r+i);
		if(i==0) t=t.substr(n-1,100);
		res+=t;
	}
	cout<<res.substr(0,20)<<endl;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define vec_rep(itr,v) for(auto itr = v.begin(); itr != v.end(); ++itr)

int main(void){
    int H,W,K;
    cin >> H >> W >> K;
    bool board_white[H][W];
    string input;
    rep(i,H){
        cin >> input;
        rep(j,W)board_white[i][j] = (input[j] == '1');
    }
    int ans = INT_MAX; 
    rep(i,1<<H-1){
        int split_count_H = bitset<32>(i).count();
        int split_count = split_count_H;
        int white_count[split_count+1] = {};
        bool row_count0 = true;
        rep(j,W){
            int block_num = 0;
            bool count_over = false;
            rep(k,H){
                if(board_white[k][j]){
                    if(white_count[block_num] == K){
                        count_over = true;
                        break;
                    }
                    white_count[block_num]++;
                }
                if(k != H-1 && 1 << (H-k-2) & i)block_num++;
            }
            if(count_over){
                if(row_count0){split_count = INT_MAX;break;}
                row_count0 = true;
                rep(k,split_count_H+1)white_count[k] = 0;
                split_count++;j--;
            }
            else row_count0 = false;
        }
        ans = min(ans, split_count);
    }   
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;
  int cur;
  cin >> cur;
  int m;
  cin >> m;
  int it = 0;

  // int vans = 0;
  // {
  //   int c = cur;
  //   int no = n;
  //   while (no--) {
  //     vans += c;
  //     // debug(cur);
  //     c = c * c % m;
  //   }
  // }

  int x = cur;
  int ans = 0;
  int no = n;
  int last = -1;
  vi vis(m + 1, -1);
  vi t(m + 1, -1);
  while (cur != 0 && vis[cur] == -1 && n--) {
    vis[cur] = ans;
    t[cur] = it;
    ans += cur;
    last = cur;
    cur = cur * cur % m;
    ++it;
  }
  if (cur == 0 || n == -1) {
    cout << ans << endl;
    return;
  }
  // debug(cur);
  // debug(last);
  // debug(ans);
  int sz = it - t[cur];
  int ini = it - sz;
  no -= ini;
  int v1 = 0;
  // debug(ini);
  while (ini--) {
    v1 += x;
    x = x * x % m;
  }
  // debug(v1);
  ans -= v1;
  ans = ans * (no / sz);
  no %= sz;
  // debug(no);
  while (no--) {
    ans += cur;
    cur = cur * cur % m;
  }
  ans += v1;
  // debug(ans);
  // debug(vans);
  // assert(vans == ans);
  cout << ans << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 4752
#include<stdio.h>
int main(void){
	int n[100][100],r,c,i,j,t[100],v[100],b=0;
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&n[i][j]);
			t[i]+=n[i][j];
			v[j]+=n[i][j];
			b+=n[i][j];
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			printf("%d ",n[i][j]);
		}
		printf("%d\n",t[i]);
	}
	for(i=0;i<=c;i++){
		if(i!=c){
			printf("%d ",v[i]);
		}else{
			printf("%d\n",b);
		}
	}
	return 0;
}

Measured memory_bytes: 2768
s = input()
variety = set(s)
if len(variety) == 2:
    x = []
    for i in variety:
        x.append(i)
    count_1 = s.count(x[0])
    count_2 = s.count(x[1])
    if count_1 == count_2:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

using namespace std;

typedef long long int lli;

int main() {
    lli n, ans = 0;

    cin >> n;
    vector<lli> yaku;
    for (lli i=1; i*i<=n; i++) {
        if (n%i == 0) {
            yaku.push_back(i);
            if (i*i != n) {
                yaku.push_back(n/i);
            }
        }
    }
    
    for (lli i=0; i<yaku.size(); i++) {
        lli a = yaku[i]-1;
        if (a != 0 && n/a == n%a) {
            ans += a;
        }
        /*
        cout << yaku[i] << " " << (n/yaku[i]) - 1 << endl;
        if (yaku[i] > n/yaku[i]) {
            ans += (n / yaku[i]) - 1;
        }
        */
        /*
        else {
            cout << yaku[i] << endl;
        }
        */
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
li = list(map(int,input().split()))
a=int(input())
magic = 0
for i in range(0,8):
    if li[0] >= li[1]:
        li[1] = li[1] * 2
        magic = magic + 1

for i in range(0,8):
    if li[1] >= li[2]:
        li[2] = li[2] * 2
        magic = magic + 1
if a >= magic:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9228
def resolve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    import math
    def isok(n):
        ndiv = 0
        for a in A:
            if a <= n:
                continue
            ndiv += math.ceil(a/n)-1
        return True if ndiv <= K else False 
    left = 0
    right = 10**9+1
    while (right - left) > 1:
        mid = left + (right - left) // 2
        if isok(mid):
            right = mid
        else:
            left = mid
    print(math.ceil(right))


if '__main__' == __name__:
    resolve()


Measured memory_bytes: 31088
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct TopologicalSort{
  int n;
  vector<set<int> > G;
  vector<int> indeg,V,p;
  TopologicalSort(){}
  TopologicalSort(int sz):n(sz),G(n),indeg(n),V(n){}

  void add_edge(int s,int t){
    G[s].insert(t);
  }
  
  void bfs(int s){
    queue<int> q;
    q.push(s);
    V[s]=1;
    while(!q.empty()){
      int u=q.front();q.pop();
      p.push_back(u);
      for(int v:G[u]){
	indeg[v]--;
	if(indeg[v]==0&&!V[v]){
	  V[v]=1;
	  q.push(v);
	}
      }
    }
  }
  
  void tsort(){
    fill(V.begin(),V.end(),0);
    fill(indeg.begin(),indeg.end(),0);
    for(int u=0;u<n;u++)
      for(int v:G[u])
	indeg[v]++;
    for(int u=0;u<n;u++)
      if(indeg[u]==0&&!V[u]) bfs(u);
    for(int i=0;i<n;i++)
      cout<<p[i]<<endl;
  }
};
//END CUT HERE

signed main(){
  int n,e;
  cin>>n>>e;
  TopologicalSort ts(n);
  for(int i=0;i<e;i++){
    int s,t;
    cin>>s>>t;
    ts.add_edge(s,t);
  }
  ts.tsort();
  return 0;
}

/*
verified on 2017/10/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=jp
*/

Measured memory_bytes: 5764
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
vector<vector<int>> vt;
vector<pair<int,int>> vt1;
int gap[1010];
int sz[1010];
int dp[1010][5010];
int func(int here, int gp)
{
	if (gp < 0)return -1234567890;
	if (here == vt1.size())return 0;
	int &ret = dp[here][gp];
	if (ret != -1)return ret;
	ret = -1234567890;
	ret = max(ret, func(here + 1, gp - vt1[here].first) + vt1[here].first);
	ret = max(ret, func(here + 1, gp - vt1[here].second) + vt1[here].second);
	return ret;
}
void dfs(int here)
{
	if(vt[here].size()==0)
		sz[here] = gap[here];
	else {
		for (int i = 0; i < vt[here].size(); i++)
		{
			int next = vt[here][i];
			dfs(next);
			sz[here] += sz[next];
		}
		vt1.clear();
		for (int i = 0; i < vt[here].size(); i++)
		{
			int next = vt[here][i];
			vt1.push_back({ gap[next],sz[next] - gap[next] });
		}
		int t = func(0, gap[here]);
		for (int i = 0; i < vt[here].size(); i++)
			for (int y = 0; y <= gap[here]; y++)
				dp[i][y] = -1;
		if (t < -5000)
		{
			puts("IMPOSSIBLE");
			exit(0);
		}
		sz[here] += (gap[here]-t);
	}
}

int main()
{
	memset(dp, -1, sizeof(dp));
	int n;
	scanf("%d", &n);
	vt.resize(n + 1);
	for (int i = 2; i <= n; i++)
	{
		int q;
		scanf("%d", &q);
		vt[q].push_back(i);
	}
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &gap[i]);
	}
	dfs(1);
	puts("POSSIBLE");
}

Measured memory_bytes: 20096
fun main(args: Array<String>) {
    // Your code here!
    val n = readLine()!!.toInt()
    var list = (1..n).map {readLine()!!.toCharArray().sorted()}
    
    println(list.groupBy { it }.map { it.value.size.toLong() }.map { (it - 1) * it / 2 }.fold(0L, Long::plus))
}

Measured memory_bytes: 77212
n = int(input())
cl = list(map(int, input().split()))
cl.sort(reverse=True)
MOD = 10**9+7

ans = 0
num = pow(2,n-1,MOD)
inc = pow(2,n-2,MOD)
for i in range(n):
    ans += num*cl[i]
    ans%=MOD
    num += inc
    num%=MOD

ans *= pow(2,n,MOD)
ans%=MOD
print(ans)

Measured memory_bytes: 31668
<?php
$line = fgets(STDIN);
$line = fgets(STDIN);
rtrim($line, "\r\n");
$int_list = explode(" ", $line);
$sum = 0;
foreach ($int_list as $int) {
  $sum += $int;
}
if ($sum % 2 == 0) { print 'YES'; }
else                      { print 'NO'; }

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

void compute(vector<vector<int> > & cost,vector<vector<int> > & best,
			 vector<int> & A,int s,int e){
	int minc = 0;
	int mink = -1;
	for(int k=s+1;k<=e;++k){
		if (cost[s][k-1] < 0){
			compute(cost,best,A,s,k-1);
		}
		if (cost[k][e] < 0) {
			compute(cost,best,A,k,e);
		}
		int c = cost[s][k-1] + A[s]*A[k]*A[e+1] + cost[k][e];
		if (mink < 0 || c < minc) {
			minc = c;
			mink = k;
		}
	}
	cost[s][e] = minc;
	best[s][e] = mink;
}

int main(){
	vector<vector<int> > cost,best;
	vector<int> A;
	int n;
	cin >> n;
	A.resize(n+1);
	for(int i=0;i<n;++i) {
		int r,c;
		cin >> r >> c;
		if (i==0){
			A[0] = r;
		}
		if (A[i] != r){ cout << "error";return (0);}
		A[i+1] = c;
	}
	cost.resize(n);
	best.resize(n);
	for(int i=0;i<n;++i){
		cost[i].resize(n);
		best[i].resize(n);
		for(unsigned j=0;j<cost[i].size();++j){
			cost[i][j] = -1;
			best[i][j] = -1;
		}
		cost[i][i]=0;
		best[i][i]=i;
	}
	compute(cost,best,A,0,n-1);
	cout << cost[0][n-1] << std::endl;
	return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;

    vector<char> s(N);

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

    sort(s.rbegin(), s.rend());
    s.erase(unique(s.begin(), s.end()), s.end());

    if (s.size() == 4){
        cout << "Four" << endl;
    }
    else {
        cout << "Three" << endl;
    }
}

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

using namespace std;

int main (){
  int N;
  cin >> N;
  
  int T,A;
  cin >> T >> A;
  
  int h[N];
  for(int i =0; i< N;i++){
    cin >> h[i];
  }
  
  double min_1;
  double min_2 = fabs(A - (T-0.006*h[0]));
  int min = 1;
  for(int i= 1; i<N;i++){
    min_1 = fabs(A - (T-0.006*h[i]));
    if(min_2 > min_1){
      min = i+1;
      min_2 = min_1;
    }
  }
      
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))

count = 0
total= 0

for i in a2:
  total += i
  count += i

total += a1[0]
count += a1[0]
  
for k in range(1,n):
  total = total + a1[k] - a2[k-1]
  count = max(count,total)

print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

int main()
{

	int a = 1, b = 0, c = 0, d = 0, e = 0, maxy = 0, max = 0, ans = 1, count = 0, min = 0;

	int yoko = 0, tate = 0;
	std::string output, output2, output3, input = {};
	bool okada = false;
	int array[10000], array2[10000];


	cin >> b >> max;
	for (int i = 0; i < b; i++) {
		cin >> array[i] >> array2[i];
		if (array2[i] <= max) {
			okada = true;
			if (i == 0) {
				min = i;
			}
			else if (array[min] >= array[i]) {
				min = i;

			}
		}
	}
	if (okada) {
		cout << array[min] << endl;
	}
	else {
		cout << "TLE" << endl;
	}
}







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

int n,m;
int a[maxn];

set<int> s;

bool ok[maxn];

int l[maxn];
int L[maxn],R[maxn];

int main()  {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i)
        scanf("%d",a+i);

    for (int i=1;i<=n;++i)  {
        s.insert(a[i]);
        if (i<m)   continue;
        L[i]=*s.begin();
        R[i]=*s.rbegin();
        s.erase(a[i-m+1]);
        // cout<<i<<":"<<L[i]<<" "<<R[i]<<endl;
    }
    int ans=ok[m]=1;
    for (int i=m+1;i<=n;++i)    
        if (!(a[i-m]<L[i]&&a[i]>R[i-1]))
            ++ans,ok[i]=1;
    for (int i=1,j=1;i<=n;i=j+1)  {
        for (j=i;j<=n&&a[j]<=a[j+1];)    ++j;
        for (int k=i;k<=j;++k)
            l[k]=i;
    }
    bool flag=0;
    for (int i=1;i<=n;++i)
        if (ok[i]&&i-l[i]+1>=m)
            --ans,flag=1;
    ans+=flag;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 11264
MOD = 1_000_000_007
n, m = gets.split.map(&:to_i)

dp = Array.new(m + 2)
m.times do
  a = gets.to_i
  dp[a] = 0
end

dp[n + 1] = 0
dp[n] = 1

(n - 1).downto(0) do |i|
  next if dp[i]
  dp[i] = (dp[i + 1] + dp[i + 2]) % MOD
end

puts dp[0]

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

using namespace std;

int b[100100];

int main(){
	int n,h;
	scanf("%d%d",&n,&h);
	int maxa=-10;
	for(int i=0;i<n;i++){
		int temp;
		scanf("%d%d",&temp,&b[i]);
		if(temp>maxa)maxa=temp;
	}
	sort(b,b+n);
	int ans=0;
	int now=n-1;
	while(h>0){
		//printf("h = %d\n",h);
		if(now==-1){
			ans+=h/maxa;
			h-=(h/maxa)*maxa;
			if(h<=0)break;
			h-=maxa;
			ans++;
			continue;
		}
		if(b[now]>=maxa){
			h-=b[now];
			now--;
			ans++;
		}else{
			//h-=maxa;
			//ans++;
			ans+=h/maxa;
			h-=(h/maxa)*maxa;
			if(h<=0)break;
			h-=maxa;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long int;

int N,A,B;
vector<ll> h;

bool clear(ll T){
  ll num=0;
  for (int i=0;i<N;i++){
    if (h[i]>T*B){
      num+=ceil((double)(h[i]-B*T)/(A-B));
    }
  }
  if (num<=T) return true;
  else return false;
}

ll bs(ll max){
  ll ans;
  ll right=max+10,left=-1;
  ll mid;
  while(abs(right-left)>1){
    mid=(right+left)/2;
    if (clear(mid)){
      right=mid;
    }
    else {
      left=mid;
    }
  }
  return right;
}

int main(void){
  cin>>N>>A>>B;
  for (int i=0;i<N;i++){
    int t;
    cin>>t;
    h.push_back(t);
  }
  sort(h.begin(),h.end(),greater<int>());
  ll Nmax=ceil((double)h[0]/B);
  cout<<bs(Nmax)<<endl;;
  /*
  for (int i=800000000-10;i<800000000+10;i++){
    cout<<i<<" ";
    if (clear(i)) cout<<"OK";
    else cout<<"NG";
    cout<<endl;
  }
  */
  /*
  for (int i=0;i<=Nmax;i++){
    cout<<i;
    if (clear(i)) cout<<"OK";
    else cout<<"NG";
    cout<<endl;
  }
  */
  return 0;
}


Measured memory_bytes: 1400
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()
S = S[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
flag = 0
tmp = ""
while 1:
	if tmp == S:
		print("NO")
		break
	tmp = S
	for w in word:
			# print(S)
			# print(w)
			if len(S) <= 4:
				print("NO")
				flag = 1
			elif S[:5] == w[::-1]:
				if len(S) == 5:
					print("YES")
					flag = 1
					break
				else:
					S = S[5:]
			elif S[:6] == w[::-1]:
				if len(S) == 6:
					print("YES")
					flag = 1
					break
				else:
					S = S[6:]
			elif S[:7] == w[::-1]:
				if len(S) == 7:
					print("YES")
					flag = 1
					break
				else:
					S = S[7:]
	if flag == 1:
		break

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

int main(){
	int n;
	int ary[44] = { 1, 1 };

	cin >> n;

	for (int i = 2; i <= n; i++){
		ary[i] = ary[i - 1] + ary[i - 2];
	}
	
	cout << ary[n] << endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <map>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

vector<int> g[550];
bool used[550];
int ans=0;

void dfs(int s,int cnt){
	if(cnt>2)return;
	if(!used[s])ans++;
	used[s]=1;
	for(int t:g[s]){
		dfs(t,cnt+1);
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
	    int n,m; cin >> n;
	    if(n==0)break;
	    cin >> m;
	    ans=0;
	    for(int i=0;i<=n;i++){
	        g[i].clear();
	        used[i]=0;
	    }
    	for(int i=0;i<m;i++){
    		int x,y; cin >> x >> y;
    		g[x].push_back(y);
    		g[y].push_back(x);
    	}
    	dfs(1,0);
	    cout << ans-1 << endl;
	}
}



Measured memory_bytes: 3312
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

check = int(2e9)
bar = []
for i in A:
    if check == i:
        bar.append(i)
        check = int(2e9)
    else:
        check = i
    if len(bar) == 2:
        break

if len(bar) == 2:
    ans = bar[0]*bar[1]
else:
    ans = 0
print(ans)

Measured memory_bytes: 14252
n = int(input())
d = []

for i in range(n) :
    input_line = list(map(int, input().split(" ")))
    d.append(input_line)

count = 0
answer = "no"
for i in range(n) :
    if d[i][0] == d[i][1] :
        count += 1
        if count > 2 :
            answer = "yes"
    else :
        count = 0
    
if answer == "yes" :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 62468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long a, b , c;
    cin >> a >> b >> c;
    if(c-a-b<=0) cout << "No";
    else if (4*a*b<(c-a-b)*(c-a-b)) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

ll f(ll x) {
    ll res = 0;
    if (x % 2 == 0) {
        res += x;
    }
    if ((x + 1) / 2 % 2 == 0) {
        res++;
    }
    return res;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout << (f(A - 1) ^ f(B)) << endl;
    return 0;
}


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

int main(void) {
    using std::cin;
    using std::cout;
    using std::fill;
    using std::vector;

    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C);
    for (int i = 0; i < C; ++i) {
        D.at(i).resize(C);
        for (int j = 0; j < C; ++j) {
            cin >> D.at(i).at(j);
        }
    }
    vector<int> c_mod_0(C);
    vector<int> c_mod_1(C);
    vector<int> c_mod_2(C);
    fill(c_mod_0.begin(), c_mod_0.end(), 0);
    fill(c_mod_1.begin(), c_mod_1.end(), 0);
    fill(c_mod_2.begin(), c_mod_2.end(), 0);
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            int c;
            cin >> c;
            if ((i + j) % 3 == 0) c_mod_0.at(c - 1) += 1;
            if ((i + j) % 3 == 1) c_mod_1.at(c - 1) += 1;
            if ((i + j) % 3 == 2) c_mod_2.at(c - 1) += 1;
        }
    }

    // c_mod_0 -> color i
    // c_mod_1 -> color j
    // c_mod_2 -> color k
    int min_wrongness = 1'000'000'000;  //'
    for (int i = 0; i < C; ++i) {
        for (int j = 0; j < C; ++j) {
            if (j == i) continue;
            for (int k = 0; k < C; ++k) {
                if (k == i || k == j) continue;
                int d_sum = 0;
                for (int c = 0; c < C; ++c) {
                    d_sum += c_mod_0.at(c) * D.at(c).at(i);
                    d_sum += c_mod_1.at(c) * D.at(c).at(j);
                    d_sum += c_mod_2.at(c) * D.at(c).at(k);
                }
                min_wrongness = std::min(min_wrongness, d_sum);
            }
        }
    }

    cout << min_wrongness << '\n';
    return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  int x,y,z;
  x = a+b;
  y = a-b;
  z = a*b;
  if(x >= y && x >=z){
    cout << x << endl;
  }
  else if(y>=x && y>=z){
    cout << y << endl;
  }
  else {
    cout << z << endl;
  }
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] argas){
        Scanner sc = new Scanner(System.in);
        int a,b,c,d,min_t,min_b,min;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        d=sc.nextInt();
        if(a>b) min_t = b;
        else min_t =a;

        if(c>d) min_b = d;
        else min_b =c;

        min = min_t+min_b;
        System.out.println(min);
    }
}

Measured memory_bytes: 21204
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

map<Int, Int> prime_factor(Int n) {
    map<Int, Int> ret;
    for (Int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        ret[n] = 1;
    }

    return ret;
}

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

    Int n, p;
    cin >> n >> p;

    map<Int, Int> pf = prime_factor(p);
    Int ans = 1;
    for (auto [pri, cnt] : pf) {
        Int ro = cnt / n;
        for (Int i = 0; i < ro; i++) {
            ans *= pri;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(int argc, char* argv[]) {
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> tree_size;
    UnionFind(int N) : par(N),tree_size(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++){
            par[i] = i;
            tree_size[i] = 1;  //集合ごとのサイズは1と初期化しておきます
        }
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        tree_size[ry]+=tree_size[rx];
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int tree_size_info(int x){//xの属する集合のサイズを返す
        return tree_size[root(x)];
    }
};
/*
実装例
int main(){
    UnionFind tree(V);
    //UnionFind 構造体のインスタンス化　まず最初にこれを書いてください　Vは頂点数を入れてください(頂点数初期化)
    tree.unite(x,y);//xとyの頂点をつなげる
    tree.same(x,y);//xとyが同じグループに存在するかどうか
    tree.root(x);//xの根を返す
    tree.tree_size_info(x);//xの属するグループのサイズを返す
}
*/
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,m;
    cin>>n>>m;
    UnionFind tree(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        tree.unite(a,b);
    }
    ll Max=0;
    rep(i,n){
        chmax(Max,(ll)tree.tree_size_info(i));
    }
    cout<<Max<<endl;
}


Measured memory_bytes: 11108
#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(){
  int n, m;
  cin >> n >> m;
  vector<vector<int> > jobs(m);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    if(a > m) continue;
    jobs[m - a].push_back(b);
  }
  priority_queue<int> q;

  ll ans = 0;
  for(int i = m - 1; i >= 0; --i){
    for(int b : jobs[i]){
      q.push(b);
    }
    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
    
  }

  cout << ans << endl;
}


Measured memory_bytes: 5632
#include <cstdio>
#include <cmath>
#include <climits>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <fstream>
#include <functional>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <iomanip>


#define memtst(x) (sizeof(x) / 1024. / 1024.)
#define mem0(x) memset((x), 0, (sizeof x))
#define meminf(x) memset((x), INF, (sizeof x))
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define pq std::priority_queue
#define iter iterator
#define mp(x, y) std::make_pair((x), (y))
#define fst first
#define sec second
#define lc(x) ((x) * 2)
#define rc(x) ((x) * 2 + 1) 
#define md(x, y) (((x) + (y)) / 2)


typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair <int, int> pii;


const double PI = acos(-1);
const double EPS = 1e-6;
const ll MOD = 1000000007;
const ll INF = 0x3F3F3F3F;


template <typename T>
inline T Abs(T x)
{
	return x < 0 ? x * -1 : x;
}


template <typename T>
inline T Max(T x, T y, T z)
{
	return std::max(std::max(x, y), z);
}
template <typename T>
inline T Min(T x, T y, T z)
{
	return std::min(std::min(x, y), z);
}


template <typename T>
inline void Ckmax(T &x, T y)
{
	x = std::max(x, y);
}


template <typename T>
inline void Ckmin(T &x, T y)
{
	x = std::min(x, y);
}


template <typename T>
inline T Sqr(T x)
{
	return x * x;
}


template <typename T>
inline T Pow(T x, T y)
{
	T r = 1;
	while (y > 0)
	{
		if (y % 2 > 0)
			(r *= x) %= MOD;
		(x *= x) %= MOD;
		y /= 2;
	}
	return r % MOD;
}


template <typename T>
T Pow(T x, T y, T z)
{
	T r = 1;
	while (y > 0)
	{
		if (y % 2 > 0)
			(r *= x) %= z;
		(x *= x) %= z;
		y /= 2;
	}
	return r % z;
}


template <typename T>
inline T gcd(T x, T y)
{
	return y > 0 ? gcd(y, x % y) : x;
}


template <typename T>
inline T lcm(T x, T y)
{
	return x / gcd(x, y) * y;
}


inline void cinspu(void)
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
}


inline ll read(void)
{
	char x;
	while (x = getchar(), x != '-' && !isdigit(x))
		;
	char flg = x == '-';
	ll num = (flg ? getchar() : x) - '0';
	while (isdigit(x = getchar()))
		(num *= 10) += x - '0';
	return flg ? -num : num;
}


const int N = 100000 + 10;


pii b[N];
std::set <int> a[N];
std::map <pii, int> c;


std::string fk(int x)
{
	std::string r = std::to_string(x);
	if (r.size() < 6)
		r.insert(r.begin(), 6 - r.size(), '0');
	return r;
}


int main()
{
	cinspu();
	int n, m;
	std::cin >> n >> m;
	for (int i = 1; i <= m; ++i)
	{
		std::cin >> b[i].fst >> b[i].sec;
		a[b[i].fst].insert(b[i].sec);
	}
	for (int i = 1; i <= n; ++i)
	{
		int k = 1;
		for (std::set <int, int> ::iterator j = a[i].begin(); j != a[i].end(); ++j, ++k)
			c[mp(i, *j)] = k;
	}
	for (int i = 1; i <= m; ++i)
		std::cout << fk(b[i].fst) << fk(c[b[i]]) << std::endl;
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    int M;
    cin >> M;
    set<int> pool;
    REP0(i, M)
    {
        int a, b;
        cin >> a >> b;
        if (a != 1 and b != N)
            continue;

        // (a,b) は互いに相異なるため,
        // 1-> または ->N に絞ると,
        // 中間点が2回出現すればそれが答え
        if (a == 1)
        {
            if (pool.find(b) != pool.end())
            {
                cout << "POSSIBLE" << endl;
                return;
            }
            pool.insert(b);
        }
        if (b == N)
        {
            if (pool.find(a) != pool.end())
            {
                cout << "POSSIBLE" << endl;
                return;
            }
            pool.insert(a);
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <complex>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EPS (1e-8)

typedef complex<double> p;
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

double cross(p a, p b) {
	return ( a.real() * b.imag() - a.imag() * b.real() );
}


int main() {
	while (true) {
		double x[4], y[4];
		if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
			&x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) == EOF) break;
		p point[4];
		REP(i, 4) point[i] = p(x[i], y[i]);
		
		int cnt[2] = {};
		REP(i, 4) {
			p v[2];
			v[0] = point[(i + 1) % 4] - point[i];
			v[1] = point[(i + 2) % 4] - point[i];
			
			if (cross(v[0], v[1]) < -EPS) cnt[0]++;
			else cnt[1]++;
		}
		
		if (cnt[0] == 4 || cnt[1] == 4) puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int x,y;
    cin >> x >> y;
    
    if (y-2*x >= 0 && (y-2*x)%2 == 0 && y <= 4*x){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3628
import java.io.*;
import java.util.ArrayList;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		
		String str=br.readLine();
		int n=Integer.parseInt(str);
		
		ArrayList<String>list=new ArrayList<>();
		
		for(int i=0;i<n;i++){
			list.add(br.readLine());
		}
		for(int j=0;j<4;j++){
			for(int k=0;k<13;k++){
				if(j==0){
					if (list.contains("S " +(k+1)) == false) {
						sb.append("S ").append(k+1).append("\n");
					}
				}
				else if(j==1){
					if (list.contains("H " +(k+1)) == false) {
						sb.append("H ").append(k+1).append("\n");
					}
				}
				else if(j==2){
					if (list.contains("C " +(k+1)) == false) {
						sb.append("C ").append(k+1).append("\n");
					}
				}
				else if(j==3){
					if (list.contains("D " +(k+1)) == false) {
						sb.append("D ").append(k+1).append("\n");
					}
				}
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 24224
#include <iostream>
using namespace std;
int N,S;
int set = 0;
int main(){
  while(set <= 20){
    //while(cin >> N && N >= 3 && N <= 100) {
    cin >> N;
    if (N == 0) break;
    int largest = 0;
    int smallest = 1000;
    int sum = 0;
    for (int i = 0; i <N;++i) {
      cin >> S;
      if(largest < S) largest = S;
      if(smallest >S) smallest = S;
      sum += S;
    }
    cout << (sum - largest - smallest)/(N-2) << endl; 
  ++set;
  }
  return 0;
}

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

int main() {
  int l,r,d,k=0;
  cin >> l >> r >> d;
  for (int i = l; i < (int)(r+1); i++){
    if(i%d==0) k++;
  }
  cout << k << endl;  
}


Measured memory_bytes: 3628
N = int(input())
S = list(map(int, input().split()))
flg = True
for num in S:
    if num%2 == 0:
        if num%3 !=0 and num%5 != 0:
            flg = False
            break
if flg:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060