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

int main() {
  
  string s;
  cin >> s;
  int t = s.size() - 1;
   
  
  if(s.at(t) == 's'){
    cout << s << "es" << endl;
  }
  else{
    cout << s << "s" << endl;
  }

}



Measured memory_bytes: 3596
import java.util.*;

public class Main {
    int[] parent;
    int[] size;
    
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[] p = new int[n];
        parent = new int[n];
        size = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = scan.nextInt();
            parent[i] = i;
            size[i] = 1;
        }
        for(int i = 0; i < m; i++){
            int x = scan.nextInt() - 1;
            int y = scan.nextInt() - 1;
            unite(x, y);
        }
        int out = 0;
        for(int i = 0; i < n; i++){
            if(same(i, p[i] - 1)) out++;
        }
        System.out.println(out);
    }
    
    int root(int x){
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }
    
    boolean same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(size[x] < size[y]){
            parent[x] = y;
            size[y] += size[x];
        }else{
            parent[y] = x;
            size[x] += size[y];
        }
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

int main() {

	int n,x; cin>>n;
	vector<pair<int,int>>a;
	for(int i=0;i<n;i++) {
		cin>>x; a.push_back(make_pair(x,i+1));
	}
	sort(a.begin(),a.end());  
	for(int i=0;i<n;i++) {
		cout<<a[i].second<<" ";
	}
	return 0;
}

Measured memory_bytes: 1780
#include <cstdio>
using namespace std;

char field[8][12];

void bomb(int x, int y){
    field[x][y] = '0';
    for(int i = -3; i <= 3; i++){
        if(x + i >= 0 && x + i < 8 && field[x + i][y] == '1'){
            bomb(x + i, y);
        }
        if(y + i >= 0 && y + i < 8 && field[x][y + i] == '1'){
            bomb(x, y + i);
        }
    }
}

int main(){
    int N, X, Y;
    scanf("%d", &N);
    for(int n = 1; n <= N; n++){
        for(int i = 0; i < 8; i++){
            scanf(" %s", field[i]);
        }
        scanf("%d%d", &Y, &X);
        --X; --Y;
        bomb(X, Y);
        printf("Data %d:\n", n);
        for(int i = 0; i < 8; i++){
            printf("%s\n", field[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 1036
N, M = map(int, input().split())
lists = [list(map(int, input().split()))[1:] for _ in range(M)]
p_list = list(map(int, input().split()))

def is_on(n, idx):
    bin_string = str(bin(n)[2:]).zfill(N)
    return bin_string[idx - 1]

num = 0
for n in range(2 ** N):
    all_flag = True
    for p, lis in zip(p_list, lists):
        flag = (sum([is_on(n, l) == '1' for l in lis]) % 2) == p
        all_flag = all_flag & flag
    num += all_flag
print(num)

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

int n, m, bp, nbp, lonely;
vector<vector<int> > g;
vector<int> color;
bool dfs(int u, int curr = 0) {
	color[u] = curr;
	bool ret = true;
	for(int v: g[u]) {
		if(color[v] == -1) ret &= dfs(v, curr ^ 1);
		else if(color[v] != curr ^ 1) ret = false;
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	g.resize(n);
	color.assign(n, -1);
	for(int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		g[u-1].push_back(v-1);
		g[v-1].push_back(u-1);
	}
	for(int i = 0; i < n; i++) if(color[i] == -1) {
		if(g[i].empty()) {
			lonely++;
			continue;
		}
		bool res = dfs(i);
		bp += res;
		nbp += !res;
	}
	cout << 1ll*n*n - 1ll*(n-lonely)*(n-lonely) + 1ll*(bp+nbp)*(bp+nbp) + 1ll*bp*bp;
}


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

bool Solve(string s) {
  if (s[0] != 'A')
    return false;
  s[0] = 'a';
  int count = 0;
  for (int i = 2; i < s.size() - 1; ++i) {
    if (s[i] == 'C') {
      ++count;
      s[i] = 'c';
    }
  }
  if (count != 1)
    return false;
  for (char c : s) {
    if (isupper(c))
      return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  cout << (Solve(s) ? "AC\n" : "WA\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <stack>
#include <algorithm>
#include <random>
#include <bitset>
#include <map>
#include <ctime>
#include <cstdlib>

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<pair<int, int>> arr(n);
    for (int i = 0; i < n; ++i) {
        int c;
        cin >> c;
        
        arr[i] = {c, i};
    }
    
    
    sort(arr.begin(), arr.end());
    
    vector<int> ans(n);
    
    int c1 = arr[arr.size() / 2 - 1].first;
    int c2 = arr[arr.size() / 2].first;
    
    for (int i = 0; i < n; ++i) {
        if (i < arr.size() / 2) {
            ans[arr[i].second] = c2;
        } else {
            ans[arr[i].second] = c1;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << endl;
    }
    
    return 0;
}


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

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector <int> > vvi;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);


typedef pair<int,bool> P;

int w,h;

bool check(int y, int x){
    if(y < 0 || y >= h)return false;
    if(x < 0 || x >= w)return false;
    return true;
}

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

void dfs(int y, int x, vvb &V){
    V[y][x] = false;
    REP(i,8){
        if(check(y + dy[i],x + dx[i]) && V[y + dy[i]][x + dx[i]]){
            dfs(y + dy[i], x + dx[i], V);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> w >> h;
    vi ansV;
    while(w != 0 && h != 0){
        int ans = 0;
        vvb V(h,vb(w,false));
        REP(i,h){
            REP(j,w){
                int a;
                cin >> a;
                if(a == 1)V[i][j] = true;
            }
        }
        REP(i,h){
            REP(j,w){
                if(V[i][j]){
                    dfs(i,j,V);
                    ans++;
                }
            }
        }
        ansV.push_back(ans);
        cin >> w >> h;
    }
    for(int a: ansV){
        cout << a << endl;
    }
    return 0;
}



Measured memory_bytes: 3140
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; scanf("%d", &___T); for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int main()
{
    double n;
    cin >> n;
    printf("%.10f",pow(n/3.0,3));
    
}

Measured memory_bytes: 256
require 'pp'

a, b, n = gets.split.map(&:to_i)

=begin
0.upto(n) do |i|
    t = a * i / b - a * (i / b)
    puts "i=#{i}, t=#{t}"
end
=end

if n < b
    puts (a * n / b) - a * (n / b)
else
    puts (a * (b-1) / b) - a * ((b-1) / b)
end


Measured memory_bytes: 14496
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if (
    ($a == 1 AND $b == 2)
    OR ($a == 2 AND $b == 1)
    ) {
    $ans = 3;
} elseif (
    ($a == 1 AND $b == 3)
    OR ($a == 3 AND $b == 1)
    ) {
    $ans = 2;
} elseif (
    ($a == 2 AND $b == 3)
    OR ($a == 3 AND $b == 2)
    ) {
    $ans = 1;
}
echo $ans.PHP_EOL;
?>

Measured memory_bytes: 3700
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <set>
#include <climits>
#include <map>
#include <iostream>
#include <string>
#include <queue>
#include <math.h>
#include <cstring>
#define test 0
using namespace std;
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define int long long
#define vll vector<long long>
#define so(v) sort(v.begin(), v.end())
#define REP(i, a, n) for (int i = a; i < n; i++)
const int N=10005;
int arr[N],dp[N];
// const ll md=1000000007;
// ll dp[N],vis[N];
// bool prime[N];
// void sieve()
// {
//     REP(i,0,N)
//     prime[i]=true;
//     prime[0]=false;
//     prime[1]=false;
//     for(int i=2;i*i<=N;i++)
//     {
//         if(prime[i])
//         {
//             for(int j=i*i;j<=N;j+=i)
//             prime[j]=false;
//         }
//     }
// }
int solve(int n,int k)
{
    return n*k;
}
int32_t main()
{
    //sieve();
    int t = 1, n;
    if (test == 1)
        cin >> t;
    while (t--)
    {
        int n,s=0,k;
        cin>>n>>k;
        int ans=solve(n,k);
        cout<<ans;
    }
}

Measured memory_bytes: 3636
N=int(input())
T,X,Y=0,0,0
ans=True
for i in range(N):
  t,x,y=map(int,input().split())
  dt,dx,dy=t-T,abs(X-x),abs(Y-y)
  if dt<dx+dy:
    ans=False
    # print(1)
  if dt%2!=(dx+dy)%2:
    ans=False
    # print(2)
  T,X,Y=t,x,y
print('Yes' if ans else 'No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
string solve(ll x)
{
    string res;
    if (x == 0LL) return "0";
    ll a,b;
    int t = 0;
    for (; x; t++) {
	t = t & 1;
	a = x / 10;
	b = x - a * 10;
	if (b < 0 && t == 0) {
	    a--;
	    b += 10;
	} else if (b > 0 && t == 1) {
	    a++;
	    b -= 10;
	}
	b = (b < 0 ? -b : b);
	res = " " + res;
	res[0] = b + '0';
	x = a;
    }
    return res;
}
 
int main()
{
    ll x;
    while (cin >> x, x) {
	cout << solve(x) << endl;
    }
    return 0;
}

Measured memory_bytes: 3052
#include<stdio.h>
#define N 100005

typedef struct pp{
  char name[100];
  int t;
}P;
P s[N];
void enqueue(P);
P dequeue(void);
int compare(int, int);
int top, tail;

int main(){

  int i,j,k,T,TT=0;
  P GX;
  

  scanf("%d%d",&k,&T);
  for(i=1;i<=k;i++){
    scanf("%s%d",s[i].name,&s[i].t);
  }
  top=1;
  tail=k+1;
  while(top!=tail){
    GX = dequeue();
    j = compare(GX.t,T);
    GX.t-=j;
    TT+=j;
    if(GX.t > 0) {enqueue(GX);}
    else {
      printf("%s %d\n",GX.name,TT);
    }
  }
  
  return 0;
}

void enqueue(P x){
  s[tail] = x;
  if(tail+1 == N)
    tail =0;
  else tail++;
}

P dequeue(){
  P x;
  x = s[top];
  if(top + 1 == N)
    top = 0;
  else
    top++;
  return x;
}

int compare(int a,int b){
  if(a>b) return b;
  else return a;
}
  

Measured memory_bytes: 10756
import numpy as np
N = int(input())
m = [[0 for j in range(10)] for i in range(10)]
for i in range(1, N+1):
  m[i%10][int(str(i)[0])] += 1

m = np.array(m)
mt = m.T
mm = m * mt
print(np.sum(mm))


Measured memory_bytes: 12440
#include <iostream>

using namespace std;

int main() {
  int K, a{}, ans{-1};
  cin >> K;
  for (int i = 1; i <= K; ++i) {
    a = (a * 10 + 7) % K;
    if (!a) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
 
void solve() {
    int N;
    cin >> N;
    ll A[N];
    rep(i, N) cin >> A[i];
 
    ll result = 0;
    
    for(int i = 0; i < 60; ++i) {
        ll zero = 0;
        ll one = 0;
        for(int j = 0; j < N ; ++j) {
            if ((A[j] >> i) & 1LL) ++one;
            else ++zero;
        }
        // cout << "i" << i << endl;
        // cout << "one:" << one << endl;
        // cout << "zero" << zero << endl;
        result += (((one * zero) % MOD) * ((1LL << i) % MOD)) % MOD;
        // cout << "result" << result << endl;
    }
    result = result % MOD;
 
    cout << result << endl;
    return;
}
 
int main() {
    solve();
    return 0;
 
}

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

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

const int maxn = 2005, maxp = 1e7 + 5;

int n, m, x[maxn], p[maxn];
int Vis[maxp];

struct edge
{
	int to, next, cap;
} e[maxn * maxn * 2];
int h[maxn], cur[maxn], tot = 1, dis[maxn], s, t;
bool vis[maxn];

inline void add(int u, int v, int w)
{
	e[++tot] = (edge) {v, h[u], w}; h[u] = tot;
	e[++tot] = (edge) {u, h[v], 0}; h[v] = tot;
}

void pre()
{
	static int p[maxp], cnt;
	Vis[1] = 1;
	for (int i = 2; i <= 1e7; ++i) {
		if (!Vis[i]) p[++cnt] = i, Vis[i] = i;
		for (int j = 1; j <= cnt && i * p[j] <= 1e7; ++j) {
			Vis[i * p[j]] = p[j];
			if (p[j] >= Vis[i]) break;
		}
	}
	Vis[2] = 1;
	for (int i = 2; i <= 1e7; ++i)
		if (Vis[i] == i) Vis[i] = 0;
}

bool bfs()
{
	static int u, l, r, q[maxn];
	l = 0; q[r = 1] = s; vis[s] = 1;
	while (l < r) {
		u = q[++l];
		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
			if (!vis[v] && e[i].cap) {
				vis[v] = 1; dis[v] = dis[u] + 1;
				q[++r] = v;
			}
	}
	return vis[t];
}

int dfs(int u, int a)
{
	if (u == t || !a) return a;
	int f = 0, flow = 0;
	for (int &i = cur[u], v; v = e[i].to, i; i = e[i].next)
		if (dis[v] == dis[u] + 1 && (f = dfs(v, min(e[i].cap, a)))) {
			e[i].cap -= f; e[i ^ 1].cap += f;
			flow += f; a -= f;
			if (!a) break;
		}
	return flow;
}

int dinic()
{
	int res = 0;
	while (bfs()) {
		memset(vis + 1, 0, sizeof(bool) * t);
		memcpy(cur + 1, h + 1, sizeof(int) * t);
		res += dfs(s, 1e9);
	}
	return res;
}

int main()
{	
	n = gi();
	for (int i = 1; i <= n; ++i) x[i] = gi();
	sort(x + 1, x + n + 1);

	pre();

	for (int i = 1, j; i <= n; i = j + 1) {
		j = i;
		while (x[j + 1] == x[j] + 1) ++j;
		p[++m] = x[i]; p[++m] = x[j] + 1;
	}

	s = m + 1; t = s + 1;
	int odd = 0;
	for (int i = 1; i <= m; ++i)
		if (p[i] & 1) add(s, i, 1), ++odd;
		else add(i, t, 1);
	for (int i = 1; i <= m; ++i)
		if (p[i] & 1)
			for (int j = 1; j <= m; ++j)
				if ((~p[j] & 1) && !Vis[abs(p[i] - p[j])])
					add(i, j, 1);

	int ans = dinic();
	printf("%d\n", ans + ((odd - ans) / 2 + (m - odd - ans) / 2) * 2 + ((odd - ans) & 1) * 3);
	
	return 0;
}


Measured memory_bytes: 43392
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.15f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s = RD!string;
	long cnt;
	foreach (c; s)
	{
		if (c == 'p')
			++cnt;
	}

	auto ans = s.length / 2 - cnt;
	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 2556
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;
#define SORTVL(v) sort(v.begin(), v.end());
#define SORTVL_GR(v) sort(v.begin(), v.end(), greater<LL>());

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }
// 末尾数字で切り上げ
LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; }
//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	char C;
	cin >> C;
	char ans = C + 1;
	O(ans);

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

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

ll N;

int main() {
  cin >> N;
  map<ll, ll> pf;
  repe(i, 2, N) {
    auto mp = prime_factor(i);
    for (auto e : mp) {
      pf[e.first] += e.second;
    }
  }

  ll over2 = 0, over4 = 0, over14 = 0, over24 = 0, over74 = 0;
  for (auto e : pf) {
    if (e.second >= 74) ++over74;
    if (e.second >= 24) ++over24;
    if (e.second >= 14) ++over14;
    if (e.second >= 4) ++over4;
    if (e.second >= 2) ++over2;
  }

  ll ans = over4 * (over4 - 1) / 2 * (over2 - 2);
  ans += over24 * (over2 - 1);
  ans += over74;
  ans += over14 * (over4 - 1);
  cout << ans << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll N, M;
	cin >> N >> M;

	vector<double> node_probs(N, 0.0);
	vector<vector<double>> edge_expects(N, vector<double>(N, 0.0));

	vector<vector<ll>> edges(N);
	vector<vector<ll>> rev_edges(N);
	ll s, t;
	for (ll i = 0; i < M; ++i) {
		cin >> s >> t;
		--s, --t;
		edges[s].emplace_back(t);
		rev_edges[t].emplace_back(s);
	}

	node_probs[0] = 1.0;
	for (ll i = 0; i < N; ++i) {
		for (ll j = 0; j < edges[i].size(); ++j) {
			node_probs[edges[i][j]] += node_probs[i] / double(edges[i].size());
		}
	}

	for (ll i = N - 1; i >= 0; --i) {
		double node_expect = 0.0;
		for (ll j = 0; j < edges[i].size(); ++j) {
			edge_expects[i][edges[i][j]] /= double(edges[i].size());
			node_expect += edge_expects[i][edges[i][j]];
		}
		for (ll j = 0; j < rev_edges[i].size(); ++j) {
			edge_expects[rev_edges[i][j]][i] = 1.0 + node_expect;
		}
	}

	double max_val = 0.0;
	for (ll i = 0; i < N; ++i) {
		double node_expect = 0.0;
		for (ll j = 0; j < edges[i].size(); ++j) {
			node_expect += edge_expects[i][edges[i][j]];
		}
		for (ll j = 0; j < edges[i].size(); ++j) {
			if (edges[i].size() > 1LL) {
				double diff = node_expect;
				diff -= (node_expect - edge_expects[i][edges[i][j]]) *
					double(edges[i].size()) /
					(double(edges[i].size()) - 1.0);
				max_val = max(max_val, node_probs[i] * diff);
			}
		}
	}

	double res = 0.0;
	for (ll i = 0; i < edges[0].size(); ++i) {
		res += edge_expects[0][edges[0][i]];
	}
	res -= max_val;

	cout << fixed << setprecision(10) << res << endl;

	return 0;
}


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

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let n = read::<i32>();
  let t = read::<i32>();
  let mut ans = 1001;

  for _ in 0..n {
    let c = read::<i32>();
    let t_i = read::<i32>();
    if (t >= t_i) {
      ans = min(ans, c);
    }
  }
  if ans == 1001 {
    println!("TLE");
  } else {
    println!("{}", ans);
  }

}



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

const int N = 5005;

int mod = 1e9 + 7;

vector<int> all;
vector<int> G[N];
int dp[N][N];
int fact[N];
int nxt[N];
bool vis[N];
int sz;

int solve(int pos, int rem) {
    if(rem < 0) return 0;
    if(pos == all.size()) return rem == 0;
    if(dp[pos][rem] != -1) return dp[pos][rem];
    int ans = solve(pos+1, rem);
    ans += 1ll*all[pos]*solve(pos+1, rem-1)%mod;
    ans %= mod;
    return dp[pos][rem] = ans;
}

void dfs2(int u) {
    sz++;
    vis[u] = 1;
    for(int v : G[u]) if(vis[v] == 0) dfs2(v);
}

int bm(int b, int p) {
    if(p == 0) return 1;
    int t = bm(b, p/2);
    t = 1ll*t*t%mod;
    if(p%2 == 1) return 1ll*t*b%mod;
    return t;
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    fact[0] = 1;
    for(int i = 1; i < N; i++) {
        fact[i] = 1ll*i*fact[i-1]%mod;
    }

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> nxt[i];
        if(nxt[i] != -1) {
            G[nxt[i]].push_back(i);
            G[i].push_back(nxt[i]);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(nxt[i] == -1) {
            sz = 0;
            dfs2(i);
            all.push_back(sz);
        }
    }
    int comp = 0;
    for(int i = 1; i <= n; i++) {
        if(vis[i]) continue;
        sz = 0;
        dfs2(i);
        comp++;
    }
    memset(dp, -1, sizeof dp);
    int r = all.size();
    int ans = 1ll*comp*bm(n-1, r)%mod;
    for(int k = 2; k <= r; k++) {
        int cur = 1ll*fact[k-1]*solve(0, k)%mod;
        cur = 1ll*cur*bm(n-1, r-k)%mod;
        ans += cur;
        ans %= mod;
    }
    for(int i = 0; i < r; i++) {
        int sz = all[i];
        int cur = 1ll*(sz-1)*bm(n-1, r-1)%mod;
        ans += cur;
        ans %= mod;
    }
    ans = 1ll*n*bm(n-1, r)%mod - ans;
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 102004
#include<stdio.h>
int main(void)
{
    int x,n,t;
    scanf("%d %d %d",&n,&x,&t);
    if(n % x == 0)
    {
        printf("%d\n",n * t / x);
    }
    else
    {
        printf("%d\n",(n / x + 1) * t);
    }
    
    return 0;
}

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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define maxn 101
#define maxh 1001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
const int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
typedef std::pair<int, int> P;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

signed main() {
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P;
    cin >> T;
    int ans = 0;
    rep(i, T.size()) {
        if (i - K < 0) {
            if (T[i] == 'r') {
                ans += P;
            } else if (T[i] == 's') {
                ans += R;
            } else {
                ans += S;
            }
        } else {
            if (T[i - K] == T[i]) {
                T[i] = 'q';
                continue;
            } else {
                if (T[i] == 'r') {
                    ans += P;
                } else if (T[i] == 's') {
                    ans += R;
                } else {
                    ans += S;
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define mp make_pair
long long a[1005],b[1005],c[1005];
bool cmp(long long x,long long y){
	return x>y;
}
int main(){
	int x,y,z,k;
	cin>>x>>y>>z>>k;
	for(int i=0;i<x;i++) cin>>a[i];
	for(int i=0;i<y;i++) cin>>b[i];
	for(int i=0;i<z;i++) cin>>c[i];
	sort(a,a+x,cmp);
	sort(b,b+y,cmp);
	sort(c,c+z,cmp);
	set<pair<long long,pair<int,pair<int,int> > > > q;
	long long sum=a[0]+b[0]+c[0];
	q.insert(mp(-sum,mp(0,mp(0,0))));
//	cout<<sum<<endl;
//	int p1=0,p2=0,p3=0;
//	k--;
	while(k--){
		pair<long long,pair<int,pair<int,int> > > tmp=*q.begin();
		cout<<-tmp.first<<endl;
		q.erase(q.begin());
		int p1=tmp.second.first,p2=tmp.second.second.first,p3=tmp.second.second.second;
		long long s1=0,s2=0,s3=0;
		if(p1+1<x) {
			s1=a[p1+1]+b[p2]+c[p3];
			q.insert(mp(-s1,mp(p1+1,mp(p2,p3))));
		}
		if(p2+1<y) {
			s2=a[p1]+b[p2+1]+c[p3];
			q.insert(mp(-s2,mp(p1,mp(p2+1,p3))));
		}
		if(p3+1<z) {
			s3=a[p1]+b[p2]+c[p3+1];
			q.insert(mp(-s3,mp(p1,mp(p2,p3+1))));
		}
		sum=max(s1,max(s2,s3));
	//	cout<<sum<<endl;
	//	cout<<s1<<" "<<s2<<" "<<s3<<" "<<p1<<" "<<p2<<" "<<p3<<endl;
	}
//	cout<<sum;
}

Measured memory_bytes: 512
import java.util.*;


import java.io.*;
/**
 * MLASERP
 */
public class Main {

    
    static MyScanner in  = new MyScanner();
   static int mod  = 1000000007;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      static StringTokenizer st;
      static int []dr  = {1,-1,0,0};
      static int [] dc = {0,0,-1,1};
public static void main(String[] args) {
   int N = in.nextInt();
    int X = in.nextInt();
     int T = in.nextInt();
     int time = (int)Math.ceil((N*1.0)/X);
     out.println(time*T);
    out.flush();
   

}
static int rcToxy(int r, int c,int W){
    return r*W+c;
}
static class Node{
    int r, c,prev,change;
    Node(int r, int c){
        this.r =r ;
        this.c = c;
    }
}
public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
}

Measured memory_bytes: 32972
#include <iostream>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;


int main(void) {
    int A,B,C,D,E,F;cin>>A>>B>>C>>D>>E>>F;
    vector<int> v4(4);
    v4.push_back(A);
    v4.push_back(B);
    v4.push_back(C);
    v4.push_back(D);
    sort(all(v4));
    reverse(all(v4));
    int result = v4[0]+v4[1]+v4[2]+max(E,F);
    cout << result << endl;   
    return 0;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000
#define PI 3.14159265359

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    if (A + B > C * 2) {
        if (X > Y) {
            cout << min(X * 2 * C, Y * 2 * C + (X - Y) * A) << endl;
        } else {
            cout << min(Y * 2 * C, X * 2 * C + (Y - X) * B) << endl;
        }
    } else {
        cout << A * X + B * Y << endl;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};

fn read<T: FromStr>() -> T {
    let s = stdin()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let (n, d, x): (i32, i32, i32) = (read(), read(), read());

    let mut cnt = 0;

    for _ in 0..n {
        cnt += (d - 1) / read::<i32>() + 1;
    }

    println!("{}", cnt + x);
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  sort(v.begin(),v.end());
  double ans = v[0]+v[1];
  ans *= 0.5;
  for(int i = 2;i<n;++i){
    ans = ans+v[i];
    ans *= 0.5;
  }
  printf("%.10f\n",ans);
  
  return 0;
}


Measured memory_bytes: 3816
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll a, b, c, k;

	cin >> a >> b >> c >> k;

	ll x = a - b;

	if (abs(x) > 1000000000000000000) {
		cout << "Unfair" << endl;
	}
	else if (k % 2 == 0) {
		cout << x << endl;
	}
	else {
		cout << -x << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define F first
#define S second
#define ld long double
#define rep(i,a,n) for (ll i= (a) ; i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
#define M_PI 3.14159265358979323846
const ll MOD = 1e9 + 7;

void solve() {
	ll n, W; cin >> n >> W;
	vi dp(W + 1);
	vi value(n), weight(n);

	rep(i, 0, n) {
		ll weight, value;
		cin >> weight >> value;

		for (ll w = W - weight; w >= 0; w--) {
			dp[w + weight] = max(dp[w + weight], dp[w] + value);
		}
	}

	cout << *max_element(all(dp)) << endl;
}


int main() {

	int t = 1;

	//cin >> t;
	ll k = 1;
	while (t--) {
		//cout << "Case #" << k++ << ": ";
		solve();
	}
	return 0;
}


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

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

int main() {
    string s;
    cin >> s;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    string w;
    int cnt = 0;
    while(cin >> w, w != "END_OF_TEXT") {
        transform(w.begin(), w.end(), w.begin(), ::tolower);
        if (s == w) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>                                                                              
#include <string>                                                                                
using namespace std;                                                                             
                                                                                                 
int main (void) {                                                                                
  string T, W;                                                                                   
  int i, ans = 0;                                                                                
  cin >> T;                                                                                      
  while (true) {                                                                                 
    cin >> W;                                                                                    
    if (W=="END_OF_TEXT") {                                                                      
      break;                                                                                     
    }                                                                                            
    for (i=0; i<W.length(); i++) {                                                               
      W[i] = tolower(W[i]);                                                                      
    }                                                                                            
    if (W==T) {                                                                                  
      ans++;                                                                                     
    }                                                                                            
  }                                                                                              
  cout << ans << endl;                                                                           
}                                                                                                
                                              

Measured memory_bytes: 3140
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


X,Y,Z,K = MI()
A,B,C = LI(),LI(),LI()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ANS = []
for i in range(X):
    if i >= K:
        break
    a = A[i]
    for j in range(Y):
        if i*j >= K:
            break
        b = B[j]
        for k in range(Z):
            if i*j*k >= K:
                break
            c = C[k]
            ANS.append(a+b+c)

ANS.sort(reverse=True)
print(*ANS[:K],sep='\n')


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

struct UnionFind
{
  vector<int> par;   // par[i]が親を表す
  vector<int> _size; // _size[i]でそのノードの属しているサイズを返す

  // コンストラクタ
  UnionFind(int n)
  {
    _size = vector<int>(n);
    par = vector<int>(n);
    for (int i = 0; i < n; i++)
    {
      par[i] = i;
      _size[i] = 1;
    }
  }

  // データxの根を求める
  int root(int x)
  {
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]); // 木構造の縮約を行っている
  }

  // xとyの親が違うとき、マージする。そのときyの根がxの根の子になる
  void merge(int x, int y)
  {
    int rootx = root(x);
    int rooty = root(y);
    if (rootx == rooty)
      return;
    par[rooty] = rootx;
    int s = _size[rooty] + _size[rootx];
    _size[rooty] = s;
    _size[rootx] = s;
  }

  // xの属している集団のサイズ
  int size(int x)
  {
    return _size[x];
  }

  // 同じグループに属しているか
  bool isSame(int x, int y)
  {
    return root(x) == root(y);
  }
};

int main()
{
  int h, w;
  bool map[2000][2000] = {};
  cin >> h >> w;
  UnionFind ufx(h * w); // i*w + j
  UnionFind ufy(h * w);
  REP(i, h)
  {
    string s;
    cin >> s;
    REP(j, s.length())
    {
      if (s[j] == '.')
      {
        map[i][j] = true;
        if (i != 0)
        {
          if (map[i - 1][j])
          {
            ufy.merge(i * w + j, (i - 1) * w + j);
          }
        }
        if (j != 0)
        {
          if (map[i][j - 1])
          {
            ufx.merge(i * w + j, i * w + j - 1);
          }
        }
      }
    }
  }

  int result = 0;
  REP(i, h)
  {
    REP(j, w)
    {
      result = max(result, ufx.size(ufx.root(i * w + j)) + ufy.size(ufy.root(i * w + j)) - 1);
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 10000000000000000
#define INF 200000000
#define MOD 1000000007
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}
struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

vector<ll> dijkstra(vector<vector<edge>> g, int start, int n) {
    priority_queue<P, vector<P>, greater<P>> que;
    vector<ll> dist(n, INF_LL);
    dist[start] = 0;
    que.push(P(0, start));
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        rep(i, g[v].size()) {
            edge e = g[v][i];
            if(dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    return dist;
}

signed main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    vector<vector<edge>> G1(n), G2(n);
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        G1[u - 1].push_back(edge(v - 1, a));
        G1[v - 1].push_back(edge(u - 1, a));
        G2[u - 1].push_back(edge(v - 1, b));
        G2[v - 1].push_back(edge(u - 1, b));
    }
    vl d1(n), d2(n), res(n);
    d1 = dijkstra(G1, s - 1, n);
    d2 = dijkstra(G2, t - 1, n);
    ll tmp = 0;
    rep(i, n) {
        chmax(tmp, 1000000000000000 - d1[n - i - 1] - d2[n - i - 1]);
        res[n - i - 1] = tmp;
    }
    rep(i, n) { cout << res[i] << endl; }
}


Measured memory_bytes: 26588
#include<bits/stdc++.h>
using namespace std;
inline void read(int &x)
{
       char c=getchar();int w=1;x=0;
	   while(!isdigit(c))
	    	(c=='-')&&(w=-w),c=getchar();
	    while(isdigit(c))
	    x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	    x*=w;
}
	   string a[1000];
int main()
{
	char c;
	int n,m,i,j;
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	read(n);read(m);
	   for(i=1;i<=n;i++)
	    {
	    		c=getchar();
	    	while(c!='\n'){
	    	 a[i]+=c;
	    		c=getchar();
			}
		}
	     sort(a,a+n+1);
	     for(i=1;i<=n;i++)
	      cout<<a[i];
	     cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll A, B, C;
	cin >> A >> B >> C;
	if ((C - A)*(C - B) > 0) { cout << "No"; }
	else { cout << "Yes"; }

	system("PAUSE");
}


Measured memory_bytes: 504
#include <bits/stdc++.h> 
using namespace std ; 
#define ll long long int 
#define pb push_back
#define ff first 
#define dobara(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define ss second 
#define S(x) scanf("%d",&x) 
#define SL(x) scanf("%lld",&x)
#define M 1000000007
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()

int n , m , ans[1002][1002] , vis[1002][1002] ;
string arr[1002] ; 

bool valid(int x , int y){
	if(x < 0 || x >= n || y < 0 || y >= m){
		return 0 ; 
	}
	return 1 ; 
}

int main(){
	cin>>n>>m ; 
	for(int i=0;i<n;i++){
		cin>>arr[i] ; 
	}

	priority_queue<pair<int,pair<int,int> > , vector< pair<int,pair<int,int> > > , greater< pair<int,pair<int,int> > > > pq ; 

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(arr[i][j] == '#'){
				ans[i][j] = 0  ;
				pq.push({0,{i,j}}) ; 
				vis[i][j] = 1;  
			}
		}
	}

	while(!pq.empty()){
		int add = pq.top().first ; 
		int x = pq.top().ss.ff ; 
		int y = pq.top().ss.ss ; 
		pq.pop() ; 

		if(valid(x + 1 , y) && !vis[x + 1][y]){
			vis[x + 1][y] = 1 ; 
			ans[x + 1][y] = add + 1 ; 
			pq.push({ans[x+1][y] , {x+1,y}}) ; 
		}

		if(valid(x - 1 , y) && !vis[x - 1][y]){
			vis[x - 1][y] = 1 ; 
			ans[x - 1][y] = add + 1 ; 
			pq.push({ans[x-1][y] , {x-1,y}}) ; 
		}

		if(valid(x , y+1) && !vis[x][y+1]){
			vis[x ][y+1] = 1 ; 
			ans[x ][y+1] = add + 1 ; 
			pq.push({ans[x][y+1] , {x,y+1}}) ; 
		}

		if(valid(x , y-1) && !vis[x][y-1]){
			vis[x ][y-1] = 1 ; 
			ans[x ][y-1] = add + 1 ; 
			pq.push({ans[x][y-1] , {x,y-1}}) ; 
		}
	}

	int val = 0 ; 

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			val = max(val , ans[i][j]) ; 
		}
	}

	cout<<val<<"\n" ;   
}

Measured memory_bytes: 21356