akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <sys/time.h>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef pair<int, int> P;
typedef complex<double> comp;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int m, n;

int cave[2000][2000];
P memo[2000010];
bool is_prime[1000010+1];

void sieve(int k) {
    memset(is_prime, true, sizeof(is_prime));
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= k; i++) {
	if (is_prime[i]) {
	    for (int j = i + i; j <= k; j += i)
		is_prime[j] = false;
	}
    }
}

void init() {
    sieve(2000005);
    int px = 1000, py = 1000;
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, -1, 0, 1};
    int dir = 0;
    int c = 0, t = 1;
    for (int i = 1; i <= 2000000;) {
	int k = i;
	for (int j = i; j < min(k+t, 2000001); j++, i++) {
	    cave[py][px] = j;
	    memo[j] = P(py, px);
	    px += dx[dir];
	    py += dy[dir];
	}
	dir = (dir + 1) % 4;
	if (c == 1) {
	    t++;
	    c = 0;
	} else {
	    c++;
	}
    }
}

P dp[1000010];
const P zero = P(0, 0);
int dx2[3] = {-1, 0, 1};
int dy2[3] = {1, 1, 1};
P solve(int m, int n, int y, int x) {
    if (n > m) return zero;
    if (dp[n].first < 0) {
	P maxi = P(0, 0);
	for (int i = 0; i < 3; i++) {
	    int Y = y + dy2[i], X = x + dx2[i];
	    P ret = solve(m, cave[Y][X], Y, X);
	    if (maxi < ret) {
		maxi = ret;
	    }
	}
	if (is_prime[n]) {
	    dp[n] = P(maxi.first+1, (maxi.second==0?n:maxi.second));
	} else {
	    dp[n] = maxi;
	}
    }
    return dp[n];
}

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

    init();

    while (true) {
	cin >> m >> n;
	if (m == 0 && n == 0) break;
	for (int i = 0; i < 1000010; i++) dp[i] = P(-1, -1);
	P res = solve(m, n, memo[n].first, memo[n].second);
	cout << res.first << " " << res.second << endl;
    }
}

Measured memory_bytes: 38620
n=int(input())
t=list(map(int,input().split()))
v=list(map(int,input().split()))
x=[0]
for i in range(n):x+=[v[i]]*t[i]*2
x+=[0]
l=[min(x[i],x[i+1])for i in range(len(x)-1)]
for i in range(1,len(l)):l[i]=min(l[i],l[i-1]+0.5)
for i in range(len(l)-2,-1,-1):l[i]=min(l[i],l[i+1]+0.5)
print(sum(0.25*(l[i]+l[i-1])for i in range(1,len(l))))

Measured memory_bytes: 3760
Q = int(input())
for q in range(Q):
    A, B = map(int, input().split())
    A, B = min(A, B), max(A, B)
    
    # コーナーケース
    if A == B:
        print(2 * (A - 1))
        continue

    # にぶたん: K組作れるか
    ok, ng = 0, A + B - 1
    while abs(ok - ng) > 1:
        K = (ok + ng) // 2
        m = (K + 2) // 2

        if m * (K + 2 - m) < A * B:
            ok = K
        else:
            ng = K

    print(ok)


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

int n,m;
string a[2000],b[2000];
int cnt=0;

int main(){
    cin>>n>>m;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        cin>>b[i];
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(a[i][j]!=b[i][j]){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 11256
import java.util.*;

public class Main {
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int idx = 0;
		int prev = sc.nextInt();
		for (int i = 1; i < n; i++) {
			int x = sc.nextInt();
			if (x + prev >= l) {
				idx = i;
				break;
			}
			prev = x;
		}
		if (idx == 0) {
			System.out.println("Impossible");
		} else {
			StringBuilder sb = new StringBuilder();
			sb.append("Possible").append("\n");
			for (int i = 1; i < idx; i++) {
				sb.append(i).append("\n");
			}
			for (int i = n - 1; i > idx; i--) {
				sb.append(i).append("\n");
			}
			sb.append(idx);
			System.out.println(sb);
		}
	}
}


Measured memory_bytes: 48400
"""
NTC here
"""
 
 
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

profile = 0
pypy = 1
 
 
def iin(): return int(input())


def lin(): return list(map(int, input().split()))


def main():
    # for n in range(1, 1000):
    n = iin()
    ans = []
    rf = ord('a')
    while n :
        x = n%26
        if x == 0:
            x = 26
        n -= 1
        n //= 26
        # print(x, n)
        ans.append(chr(x+rf-1))
    print(''.join(ans[::-1]))






    




                

        

 
 
 
 
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
if pypy:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
    input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    if profile:
        import cProfile
        cProfile.run('main()')
    else:
        main()

Measured memory_bytes: 62792
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n, m;
int a[100011], b[100011];
bool u[511][511], is[511];
bool check(int x, int y){
	if(!is[x] || !is[y])
		return 0;
	for(int i = 1; i <= n; i ++){
		if(u[x][i] && u[y][i])
			return 0;
	}
	return 1;
}
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin >> n >> m;
	for(int i = 1; i <= m; i ++){
		cin >> a[i] >> b[i];
	}
	for(int i = 1; i <= n; i ++){
		u[i][i] = 1;
		is[i] = 1;
		for(int j = m; j >= 1; j --){
			if(u[i][a[j]] && u[i][b[j]]){
				is[i] = 0;
				break;
			}
			if(u[i][a[j]]){	
				u[i][b[j]] = 1;
			}
			if(u[i][b[j]])
				u[i][a[j]] = 1;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++){
		for(int j = i + 1; j <= n; j ++){
			if(check(i, j))
				ans ++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int R, G;
  cin >> R >> G;
  cout << 2 * G - R << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans = max({ A, B, C });
    ans *= exp2(K);
    ans += A + B + C - max({ A, B, C });

    cout << ans << endl;

    return 0;
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s; int n; ll ans=0,mx=0; cin >>n >>s;
	for (int i=0;i<n;i++) {
		if (s[i]=='I') ans++;
		else ans--;
		mx=max(mx,ans);
	}
	cout <<mx;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector <ll> v[100004];
ll dp[100004];
void f (ll n)
{
	if (dp[n]!=-1)
		return;
	if (v[n].size()==0)
	{
		dp[n]=0;
		return;
	}
	else
	{
		ll ans=INT_MIN;
		for (ll i=0;i<v[n].size();i++)
		{
			f(v[n][i]);
			ans=max(ans,dp[v[n][i]]);
		}
		dp[n]=ans+1;
		return;
	}

}
int main()
{
	ll n,m;
	cin>>n>>m;
	for (ll i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
	}
	for (ll i=1;i<=n;i++)
		dp[i]=-1;
	ll ma=INT_MIN;
	for (ll i=1;i<=n;i++)
	{
		f(i);
		ma=max(ma,dp[i]);
	}
	cout<<ma;
}

Measured memory_bytes: 8576
while True:
	a, b = map(int, input().split())
	if a == 0 and b == 0:
		exit()
	for i in range(0,a):
		for j in range(0,b):
			if (i+j)%2 == 0:
				print('#', end='')
			else:
				print('.', end='')
		print()
	print()


Measured memory_bytes: 7004
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 300005;
typedef long long ll;
const int mod = 1000000007;
#define fre(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout); 
using namespace std;

int n, b[N][65], ans, sum0, sum1, res;
ll a[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
	n = read <int> (); 
	for(int i = 1; i <= n; i++)
	{
		a[i] = read <ll> ();
		for(int j = 1; j <= 60; j++, a[i] >>= 1)
			b[i][j] = a[i] & 1; 
	}
	for(int tmp = 1, i = 1; i <= 60; i++, tmp = 1ll * tmp * 2 % mod)
	{
		sum0 = sum1 = res = 0; 
		for(int j = n; j; j--)
		{
			if(b[j][i])
				res = (1ll * res + sum0) % mod, sum1++; 
			else res = (1ll * res + sum1) % mod, sum0++;  
		}
		ans = (1ll * ans + 1ll * res * tmp % mod) % mod; 
	}
	printf("%d\n", ans); 
	return 0; 
}


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

int main(){
  string s,t;
  cin >> s >> t;

  int n = s.size();
  bool ok = true;
  for (int i = 0; i < n; i++)
  {
    if(s[i]!=t[i]) ok = false;
  }
  if(ok) puts("Yes");
  else puts("No");
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,l;
string s[110];
signed main(){
	cin>>n>>l;
	rep(i,n)cin>>s[i];
	sort(s,s+n);
	rep(i,n)cout<<s[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=2e3;
int a[MAXN+5];
int tmp1,tmp2,n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=j+1;k<=n;k++)
			{
				if(a[i]+a[j]>a[k])
					ans++;
				else
					break;
			}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int64_t ans=1000;
  for(int i=0;i<N-1;i++){
  if(A.at(i)<A.at(i+1)){
  ans=A.at(i+1)*(ans/A.at(i))+(ans%A.at(i));
  }
  }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
c = [i-1 for i in na()]
g = [[] for i in range(n)]

for i in range(n-1):
    a,b = na()
    a,b = a-1,b-1
    g[a].append(b)
    g[b].append(a)

def EulerTour(n, X, i0):
    # Xは破壊してXとPができる
    P = [-1] * n
    Q = [~i0, i0]
    ct = -1
    x = [0]*n
    y = [0]*n
    z = [0]*n
    ET = []
    ET1 = [0] * n
    ET2 = [0] * n
    DE = [0] * n
    de = -1
    ans = [n*(n+1)//2]*n
    while Q:
        i = Q.pop()
        if i < 0:
            i = ~i
            ET2[i] = ct
            de -= 1
            x[c[i]] += 1 + z[i]
            if i:
                p = P[i]
                k = ET2[i] - ET1[i] + 1 - x[c[p]] + y[i]
                ans[c[p]] -= k*(k+1)//2
                z[p] += k
            continue
        if i >= 0:
            ET.append(i)
            ct += 1
            if i:
                y[i] = x[c[P[i]]]
            if ET1[i] == 0: ET1[i] = ct
            de += 1
            DE[i] = de
        for a in X[i][::-1]:
            if a != P[i]:
                P[a] = i
                for k in range(len(X[a])):
                    if X[a][k] == i:
                        del X[a][k]
                        break
                Q.append(~a)
                Q.append(a)
    for i in range(n):
        ans[i] -= (n - x[i])*(n - x[i]+1)//2
    return ans

print(*EulerTour(n,g,0), sep='\n')

Measured memory_bytes: 160448
#include<stdio.h>

int main(){
  int n, i; 
  int M[50];

  scanf("%d", &n);

  M[0] = M[1] = 1;
  for ( i = 2; i <= n; i++ )
    M[i] = M[i-1] + M[i-2];
  
  printf("%d\n", M[n]);

  return 0;
}



Measured memory_bytes: 2112
s = input()
t = input()
snum = []
tnum = []
for c in range(ord('a'), ord('z') + 1):
    snum.append([i for i, x in enumerate(s) if x == chr(c)])
for c in range(ord('a'), ord('z') + 1):
    tnum.append([i for i, x in enumerate(t) if x == chr(c)])
snum.sort()
tnum.sort()
print('Yes' if snum == tnum else 'No')

Measured memory_bytes: 19648
from collections import deque
N, X, Y = map(int, input().split())

# G[v]: 頂点vに隣接する頂点list
# N: 頂点数
G = [[] for i in range(N)]
G[X - 1].append(Y - 1)
for i in range(N - 1):
    G[i].append(i + 1)
    G[i + 1].append(i)
# print(G)


def bfs(start):
    dist = [-1] * N
    que = deque([start])
    dist[start] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for w in G[v]:
            if dist[w] > -1:
                continue
            dist[w] = d + 1
            que.append(w)
    return dist


ans = [0] * N

for i in range(N - 1):
    # print(bfs(i))
    for ele in bfs(i)[i + 1:]:
        ans[ele] += 1
for a in ans[1:]:
    print(a)


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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,c,j;
	cin >> a >> b >> c >> k;
	if(k<=a)
		m=k;
	else if (k<=a+b)
		m=a;
	else
		m=a-(k-a-b);
	cout << m << "\n";
	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int al[30][30];
int lnk[30];

int main() {
	int n;
	string str;
	IL {
		cin >> n;
		if (n == 0) break;
		memset(al, 0, sizeof(al));
		rep (i, n) {
			cin >> str;
			++al[str[0] - 'a'][str[sz(str) - 1] - 'a'];
		}
		bool ok = true;
		rep (i, 30) {
			int count = 0;
			rep (j, 30) count += al[i][j] - al[j][i];
			ok = ok && (count == 0);
		}
		memset(lnk, 0, sizeof(lnk));
		queue<int> que;
		rep (i, 30) {
			rep (j, 30) {
				if (al[i][j] > 0) {
					que.push(i);
					break;
				}
			}
			if (!que.empty()) break;
		}
		while (!que.empty()) {
			int now = que.front();
			que.pop();
			if (lnk[now] > 0) continue;
			lnk[now] = 1;
			rep (i, 30) {
				if (al[now][i] > 0) {
					que.push(i);
				}
			}
		}
		rep (i, 30) {
			rep (j, 30) {
				if (al[i][j] == 0) continue;
				ok = ok && (lnk[i] > 0);
			}
		}
		cout << (ok ? "OK" : "NG") << endl;
	}
	return 0;
}

Measured memory_bytes: 920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()) {
			int H = scan.nextInt(), W = scan.nextInt();
			if(H == 0 && W == 0) {
				break;
			}else {
				for(int i = 0 ; i < H ; i++) {
					for(int j = 0 ; j < W ; j++) {
						if(j == 0 || j == W - 1 || i == 0 || i == H - 1) {
							System.out.print("#");
						}else {
							System.out.print(".");
						}
					}
					System.out.println();
				}
				System.out.println();
			}
		}
		scan.close();
	}

}



Measured memory_bytes: 32772
N=int(input())
n=[0]*5
for i in range(N):
    s=input()
    if s[0]=="M":
        n[0]+=1
    elif s[0]=="A":
        n[1]+=1
    elif s[0]=="R":
        n[2]+=1
    elif s[0]=="C":
        n[3]+=1
    elif s[0]=="H":
        n[4]+=1
ans=0
for i in range(3):
    for j in range(3-i):
        for k in range(3-i-j):
            ans+=n[i]*n[i+j+1]*n[i+j+k+2]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

struct Node
{
    Node()
    {
        parent = brother = -1;
        height = depth = 0;
    };
    int parent, depth, height, brother;
    vector<int> children;
};

void calcDepth(vector<Node> &G, int root)
{
    repi(i, G.at(root).children.size(), 0)
    {
        G.at(G.at(root).children.at(i)).depth = G.at(root).depth + 1;
        calcDepth(G, G.at(root).children.at(i));
    }
}

void calcHeight(vector<Node> &G, int height, int parent)
{
    G.at(parent).height = max(G.at(parent).height, height + 1);
    if (G.at(parent).parent != -1)
    {
        calcHeight(G, height + 1, G.at(parent).parent);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<Node> G(n);
    repi(i, n, 0)
    {
        int node,left, right;
        cin >> node >> left >> right;
        if (left != -1)
        {
            G.at(node).children.push_back(left);
            G.at(left).parent = node;
        }
        if (right != -1)
        {
            G.at(node).children.push_back(right);
            G.at(right).parent = node;
        }
        if (right != -1 && left != -1)
        {
            G.at(left).brother = right;
            G.at(right).brother = left;
        }
    }
    int root = 0;
    repi(i, n, 0)
    {
        if (G.at(i).parent == -1)
        {
            root = i;
            break;
        }
    }
    if (n > 1)
    {
        calcDepth(G, root);
            repi(i, n, 0)
            {
                //最下層からスタート
                if (G.at(i).children.size() == 0)
                {
                    calcHeight(G, 0, G.at(i).parent);
                }
            }
    }

    repi(i, n, 0)
    {
        if (G.at(i).parent == -1)
        {
            cout << "node " << i << ": parent = " << G.at(i).parent << ", sibling = " << G.at(i).brother << ", degree = " << G.at(i).children.size() << ", depth = " << G.at(i).depth << ", height = " << G.at(i).height << ", root" << endl;
        }
        else if (G.at(i).children.size() != 0)
        {
            cout << "node " << i << ": parent = " << G.at(i).parent << ", sibling = " << G.at(i).brother << ", degree = " << G.at(i).children.size() << ", depth = " << G.at(i).depth << ", height = " << G.at(i).height << ", internal node" << endl;
        }
        else
        {
            cout << "node " << i << ": parent = " << G.at(i).parent << ", sibling = " << G.at(i).brother << ", degree = " << G.at(i).children.size() << ", depth = " << G.at(i).depth << ", height = " << G.at(i).height << ", leaf" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3168
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

//--------------
//#define DEBUG
//--------------

#ifdef DEBUG
	#define debugprint(x) cout<<x<<" "
	#define debugendl cout<<endl
#else
	#define debugprint(x)
	#define debugendl
#endif

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

zahyo ways[4];

int board[1000][1000]={};
int main(){
	ways[0].x=1;
	ways[1].x=-1;
	ways[2].y=1;
	ways[3].y=-1;
	int h,w;
	cin>>h>>w;
	queue<zahyo> widesearch;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char temp;
			cin>>temp;
			if(temp=='#'){
				zahyo black(i,j);
				widesearch.push(black);
				board[i][j]=1;
			}
			else{
				board[i][j]=0;
			}
		}
	}
	int ans=0;
	while(widesearch.size()>0){
		ans++;
		int size=widesearch.size();
		for(int i=0;i<size;i++){
			zahyo now=widesearch.front();
			widesearch.pop();
			for(int j=0;j<4;j++){
				zahyo temp=now+ways[j];
				if(temp.x>=0 and temp.x<h and temp.y>=0 and temp.y<w){
					if(board[temp.x][temp.y]==0){
						board[temp.x][temp.y]=1;
						widesearch.push(temp);
					}
				}
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				debugprint(board[i][j]);
			}
			debugendl;
		}
		debugendl;
	}
	cout<<ans-1<<endl;
	return 0;
}


Measured memory_bytes: 15096
# C

X, N = map(int,input().split())

P = list(map(int,input().split()))

ans = X

for i in range(200):
  temp1 = X - i
  temp2 = X + i
  if not temp1 in P:
    ans = temp1
    break
  elif not temp2 in P:
    ans = temp2
    break

print(ans)





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

int main()
{
    int n,i,count=0;
    scanf("%d",&n);
    char str[n];
    scanf("%s",&str);
    for(i=0;i<n;i++)
    {
        if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')
        count++;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

    if (a == b && a ==c) {
        cout << 0 << endl;
        return 0;
    }

    if (abs(a-b) >= pow(10,18)) {
        cout << "Unfair" << endl;
        return 0;
    }
    if (k % 2 == 0) {
        cout << a - b << endl;
    } else {
        cout << b - a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define LL long long
#define INF (LL)(1LL<<60)

using namespace std;

void solve(long long N, long long M_a, long long M_b, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c){
    vector<vector<vector<LL>>> dp(N+1, vector<vector<LL>>(500, vector<LL>(500, INF)));
    dp[0][0][0]=0;
    for(LL i=0; i<N; i++){
        for(LL j=0; j<500; j++){
            for(LL k=0; k<500; k++){
                if(dp[i][j][k]<INF){
                    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                    dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
                }
            }
        }
    }

    LL d=1, ans=INF;
    while(max(M_a, M_b)*d<=400){
        ans = min(ans, dp[N][d*M_a][d*M_b]);
        d++;
    }

    cout << (ans < INF ? ans : -1) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M_a;
    scanf("%lld",&M_a);
    long long M_b;
    scanf("%lld",&M_b);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    std::vector<long long> c(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, M_a, M_b, std::move(a), std::move(b), std::move(c));
    return 0;
}


Measured memory_bytes: 83072
#include <stdio.h>

int calc(int d);

int main()
{
	int sum, d;
	while (scanf("%d", &d) != -1) {
		sum = calc(d);
		printf("%d\n", sum);
	}
	return 0;
}

int calc(int d)
{
	int x, sum;
	sum = 0;
	for (x=0; x<600; x+=d)
	{
		sum += d * x * x;
	}
	return sum;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
const ll INF = 1001001001;
const int mod = 1000000007;

int main() {
    int n, x;
    cin >> n >> x;
    ll sum = 0;
    ll count = 0;
    rep(i, n) {
        int l;
        cin >> l;
        sum += l;
        count++;
        if (sum > x) {
            cout << count << endl;
            return 0;
        }
    }

    cout << count + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int a,b; cin >> a >> b;
	if(a%3==0 || b%3==0 ||(a+b)%3==0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main(){

   
  long ac = 0;
  long wa = 0;
  long tle = 0;
  long re = 0;

    long N;
    string S;


    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> S;
        if(S == "AC")
        ac++;
        else if(S == "WA")
        wa++;
        else if(S == "TLE")
        tle++;
        else if(S == "RE")
        re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;

}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
	
		System.out.println(Math.sin(Math.toRadians(c))*a*b/2);
		System.out.println(Math.sqrt(Math.pow(a,2)+Math.pow(b,2)-2*a*b*Math.cos(Math.toRadians(c)))+a+b);
		System.out.println(Math.sin(Math.toRadians(c))*b);
	}
}

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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int n, w, base;

bool visited[100][100][100][100] = {};

llong solve(priority_queue<int> que[4], llong sum, llong weight, int num[4]){
  llong res = 0;
  bool pushed = false;
  REP(i,4){
    num[i]++;
    if(!que[i].empty() && weight + base + i <= w && !visited[num[0]][num[1]][num[2]][num[3]]){
      visited[num[0]][num[1]][num[2]][num[3]] = true;
      pushed = true;
      int tmp = que[i].top();
      que[i].pop();
      res = max(solve(que, sum + tmp, weight + base + i, num), res);
      que[i].push(tmp);
    }
    num[i]--;
  }

  if(!pushed){
    return sum;
  }
  
  return res;
}

int main(){

  scanf("%d %d", &n ,&w);

  priority_queue<int> que[4];
  REP(i,n){
    int t1, t2;
    scanf("%d %d", &t1, &t2);
    if(i == 0){
      base = t1;
    }
    que[t1 - base].push(t2);
  }

  int num[4] = {};
  printf("%lld\n", solve(que, 0, 0, num));
  
  return 0;
}



Measured memory_bytes: 94464
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	string s; cin >> s;
	int c = 700;
	rep(i, 0, s.size()) {
		if (s[i] == 'o') c += 100;
	}
	cout << c << endl;

	return 0;
}

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

int main(void) {

	int N, K, S;
	cin >> N >> K >> S;

	std::vector<long long int> A(N);

	// SをK個埋めて、他はそれ以上の数にする
	if (S != 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10) {
		for (int i = 0; i < N; i++) {
			if (i < K) {
				A[i] = S;
			}
			else {
				A[i] = S + 1;
			}
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i < K) {
				A[i] = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10;
			}
			else {
				A[i] = 1;
			}
		}
	}
	
	// 確認用
	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N - 1) {
		cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<iomanip>
#include<vector>
#include<algorithm>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define MAX 200100


int temp[MAX];
signed main(){
	cout<<fixed<<setprecision(7);
	int n, m, count = 0, ans = 0;
	string str;
	int k, a;
	vector<int> hoge;
	
	cin>>n>>k;
	
	rep(i,n){
		cin>>a;
		if(temp[a] == 0) count++;
		temp[a]++;
	}
	for(int i = 1; i < MAX; i++){
		if(temp[i])hoge.push_back(temp[i]);
	}
	sort(hoge.begin(), hoge.end());
	
	for(int y : hoge){
		if(count <= k)break;
		count--;
		ans += y;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3956
h,w = (int(i) for i in input().split())
s = [input() for i in range(h)]
x,v,ans = [[] for i in range(h*w)],[1]*(h*w),0
for i in range(h):
    for j in range(w):
        if i!=h-1 and s[i][j]!=s[i+1][j]:
            x[i*w+j].append((i+1)*w+j)
            x[(i+1)*w+j].append(i*w+j)
        if j!=w-1 and s[i][j]!=s[i][j+1]:
            x[i*w+j].append(i*w+j+1)
            x[i*w+j+1].append(i*w+j)
for i in range(h*w):
    if v[i]:
        q,a,b,v[i] = [i],0,0,0
        while q:
            p = q.pop()
            if s[p//w][p%w]=="#": a+=1
            else: b+=1
            for j in x[p]:
                if v[j]:
                    q.append(j)
                    v[j] = 0
        ans+=a*b
print(ans)

Measured memory_bytes: 44276
A, B, K = map(int, input().split())
l = []

if B - A + 1 > 2 * K:
  for i in range(K):
    l.append(A + i)
    l.append(B - i)
else:
  l = list(range(A, B+1))
  
l.sort()

for i in l:
  print(i)

Measured memory_bytes: 3060
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}

//cout << setprecision(123)<<ans;
//a=atoi(S.c_str());
//S=to_string(a);
int main(){
  int N;
  ll a=998244353,ans=1,ansans;
  bool ok=false;
  cin>>N;
  vector<ll>v(N);
  vector<ll>V(N,0);
  REP(i,N){
    cin>>v[i];
    V[v[i]]++;
  }
  REP(i,N){
    if(V[i]==0){
      for(int j=i+1;j<N;j++){
        if(V[j]!=0)ok=true;
      }
      break;
    }
  }
      
      
  if(v[0]!=0||V[0]>1||ok){
    cout<<0<<endl;
    return 0;
  }
  
  for(int i=1;i<N;i++){
    if(V[i+1]==0)break;
    if(V[i]>1){
      ll c=1;
      REP(j,V[i+1]){
      c*=V[i];
        c=c%a;
       } 
        ans*=c;
      if(ans>a)ans=ans%a;
    }
    
  }
  
  
  
  ansans=ans%a;
  cout<<ansans<<endl;
  
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,m,x,ans;
vector<int> v,cnt;

main() {
    cin >> n >> m;
    rep(i,m) cin >> x,v.pb(x)
    sort(all(v));
    rep1(i,m-1) cnt.pb(v[i]-v[i-1])
    sort(all(cnt));
    rep(i,m-n) ans += cnt[i];
    ct(ans)
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<algorithm>
using ll = long long;
constexpr ll mod = 998244353;
char s[300001]={};
int order[100000][3];
int main(){
    int n;
    scanf("%d%s",&n,s);
    int r_itr=0,g_itr=0,b_itr=0;
    for(int i=0;i<n;++i){
        while(s[r_itr]!='R')r_itr++;
        while(s[g_itr]!='G')g_itr++;
        while(s[b_itr]!='B')b_itr++;
        order[i][0]=r_itr;
        order[i][1]=g_itr;
        order[i][2]=b_itr;
        std::sort(order[i],order[i]+3);
        //printf("%d %d %d\n",order[i][0],order[i][1],order[i][2]);
        ++r_itr;
        ++g_itr;
        ++b_itr;
    }
    //printf("\n");
    ll ans=1;
    int min_itr=0,max_itr=0;
    for(int i=0;i<n;i++){
        ans=(ans*(i+1))%mod;
        while(min_itr<n&&order[min_itr][0]<order[i][1])min_itr++;
        ans=(ans*(min_itr-i))%mod;
        while(max_itr<n&&order[max_itr][2]<order[i][1])max_itr++;
        ans=(ans*(1+i-max_itr))%mod;
        //printf("%d %d\n",min_itr-i,1+i-max_itr);
    }
    printf("%lld\n",ans);
    return 0;
}

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



int main() {
    int n;
    cin>>n;
    bool bo=false;
    if(n>=2100) bo=true;
    if(100<=n){
        int a=n%100,b=n/100;
        if(a<=b*5) bo=true;
    }
    cout<<bo;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 200000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf1, uf2;
#include<map>
typedef pair<int, int>pii;
int main()
{
	int num, w1, w2;
	scanf("%d%d%d", &num, &w1, &w2);
	uf1.init(), uf2.init();
	for (int i = 0; i < w1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		uf1.unite(za, zb);
	}
	for (int i = 0; i < w2; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		uf2.unite(za, zb);
	}
	map<pii,int>ma;
	for (int i = 0; i < num; i++)ma[make_pair(uf1.find(i), uf2.find(i))]++;
	for (int i = 0; i < num; i++)printf("%d\n", ma[make_pair(uf1.find(i), uf2.find(i))]);
}

Measured memory_bytes: 16768
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    Fast;
    long long t,n,m,i,j,k,x=0,y=0,z;
    cin>>n>>m;
    vector<long long>v;
    for(i=0;i<n;i++){
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());

    for(i=0;i<n-m;i++){
        y=y+v[i];
    }
    cout<<y<<endl;

}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 201;
struct data {
  int nt, to;
} a[N << 1];
int head[N], cnt = 0;

void add(int x, int y) {
  a[++cnt].to = y;
  a[cnt].nt = head[x];
  head[x] = cnt;
}

int sz[N], w[N];
ll s[N];
void dfs(int u, int fa) {
  sz[u] = 1, s[u] = w[u];
  for(int i = head[u]; i; i = a[i].nt) {
    int to = a[i].to;
    if(to == fa) continue;
    dfs(to, u);
    sz[u] += sz[to];
    s[u] += s[to];
  }
}

ll f[N * N * N];
int c[N], p[N];

bool cmp(int x, int y) {
  return s[x] * sz[y] < s[y] * sz[x];
}

int main() {
  int n, x, d;
  cin >> n >> x >> d;
  scanf("%d", &w[1]);
  for(int i = 2, y; i <= n; ++i) {
    scanf("%d%d", &w[i], &y);
    add(y, i);
  }
  dfs(1, 0);
  int mx = min(n, d), tot = mx * n * n;
  memset(f, 0x3f, sizeof f);
  f[0] = 0;
  int pos = 1, now = mx, res = 0;
  for(; ; pos <<= 1) {
    if(now <= pos) {
      c[++res] = now;
      break;
    } else {
      c[++res] = pos;
      now -= pos;
    }
  }
  for(int i = 1; i <= n; ++i) 
   for(int o = 1; o <= res; ++o) {
    int nm = c[o];
    for(int j = tot; j >= sz[i] * nm; --j) {
      f[j] = min(f[j], f[j - sz[i] * nm] + s[i] * nm);
    } 
  }
  for(int i = 1; i <= n; ++i) p[i] = i;
  sort(p + 1, p + 1 + n, cmp);
  ll ans = 0;
  for(int o = 0; o <= tot; ++o) {
//    if(f[o] != f[100]) printf("%d %lld\n", o, f[o]); 
    if(f[o] > x) continue;
    ll pos = x - f[o];
    ll tmp = o;
    for(int i = 1; i <= n; ++i) {
      if(!pos) break;
      int u = p[i];
      ll num;
      if(u == 1) num = pos;
      else num = d - mx;
      ll Ad = min(pos / s[u], num);
      tmp += Ad * sz[u], pos -= s[u] * Ad;
    }
    ans = max(ans, tmp);
  }
  printf("%lld\n", ans);  
  return 0;
}

Measured memory_bytes: 63744
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define int ll
#define MOD (ll)(1e9+7)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	cout<<(n*(n-1)/2)<<"\n";
	return 0;
}












Measured memory_bytes: 256
import * as fs from 'fs';

const main = (inp: string) => {
    let ans: string = 'Yes';
    for (let i: number = 0; i < inp.length; i++) {
        if ((i + 1) % 2 === 1) {
            // only R U D
            if (inp[i] === 'L') {
                ans = 'No';
                break;
            }
        } else {
            // only L U D
            if (inp[i] === 'R') {
                ans = 'No';
                break;
            }
        }
    }
    console.log(ans);
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 11468
import sys

l = []
for i in sys.stdin:
    l.append(i)

for i in range(0,len(l)):
    l[i] = l[i].split()

for i in range(0,len(l)-1):
    for j in range(0,int(l[i][0])):
        print('#'*int(l[i][1]))
    print()


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	int a[N], b[N], c[N];
	rep(i, 0, N) cin >> a[i] >> b[i] >> c[i];

	int dp[N + 1][401][401];
	rep(i, 0, N + 1) rep(j, 0, 401) rep(k, 0, 401) dp[i][j][k] = 1e9;
	dp[0][0][0] = 0;

	rep(i, 0, N) rep(j, 0, 401) rep(k, 0, 401) {
		if(j - a[i] >= 0 and k - b[i] >= 0) dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
		else dp[i + 1][j][k] = dp[i][j][k];
	}

	int rsl = 1e9;
	rep(j, 1, 401) rep(k, 1, 401) {
		if(j * Mb == k * Ma) {
			if(dp[N][j][k] != 1e9) {
				rsl = min(rsl, dp[N][j][k]);
			}
		}
	}

	if(rsl != 1e9) cout << rsl << endl;
	else cout << -1 << endl;

}


Measured memory_bytes: 25984
#include<stdio.h>
#include<string.h>
#define N 10000000
#define L 13

int getChar(char);
long long int getkey(char *);
int h1(int);
int h2(int);
int insert(char *);
int find(char *);

char HashTable[N][L];

int main(){
  int i;
  int num;
  char str_in[L];
  char str_order[10];

  for(i=0;i<N;i++){
    HashTable[i][0]='\0';
  }
  
  scanf("%d",&num);
 
  for(i=0;i<num;i++){
    scanf("%s %s",str_order,str_in);

    if(str_order[0]=='i'){
      insert(str_in);
    }else{
      if(find(str_in)==1){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
 
  return 0;
}

int getChar(char ch){
  if(ch=='A')return 1;
  else if(ch=='C')return 2;
  else if(ch=='G')return 3;
  else if(ch=='T')return 4;
  else return 0;
}

long long int getkey(char str[]){
  long long int sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}

int h1(int key){
  return key%N;
}

int h2(int key){
  return 1+(key%(N-1));
}

int insert(char str[]){
  long long int key,i=0,h;

  key = getkey(str);

  while(1){
    h=(h1(key)+i*h2(key))%N;
    if(strlen(HashTable[h])==0)break;
    i++;
  }

  strcpy(HashTable[h],str);
  return 0;
}

int find(char str[]){
  long long int key,i=0,h;
 
  key=getkey(str);

  while(1){
    h=(h1(key)+i*h2(key))%N;
    if(strcmp(HashTable[h],str)==0){
      return 1;
    }else if(strlen(HashTable[h])==0){
      return 0;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 127560
#ABC088D
H,W=map(int,input().split())
MAP=[]
brack=0
for i in range(H):
    line=input()
    brack+=line.count('#')
    MAP.append([line[j] for j in range(W)])
    

def bfs(H,W,MAP):
    dist=[[-1 for j in range(W)] for i in range(H)]
    dist[0][0]=1
    check=[(0,0)]
    while len(check)>0:
        now=check.pop(0)
        dnow=dist[now[0]][now[1]]
        for x in [(now[0]+1,now[1]),(now[0]-1,now[1]),(now[0],now[1]+1),(now[0],now[1]-1)]:
            if x[0]>=0 and x[1]>=0 and x[0]<H and x[1]<W:
                if x==(H-1,W-1):return dnow+1
                if MAP[x[0]][x[1]]=='.' and dist[x[0]][x[1]]==-1:
                    dist[x[0]][x[1]]=dnow+1
                    check.append(x)
    return dist[H-1][W-1]

ans=bfs(H,W,MAP)
if ans==-1:print(-1)
else:print(H*W-brack-ans)

Measured memory_bytes: 3188