akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = yorukatsu13e()

fun yorukatsu13e() = FastIO().exec {
    val n = int()
    val aList = (1..n).map { int() }

    val list = mutableListOf<Int>()

    fun lowerBound(list: List<Int>, key: Int): Int {
        var ok = list.size
        var ng = -1

        while (ok - ng > 1) {
            val mid = (ng + ok) / 2
            if (list[mid] >= key) ng = mid else ok = mid
        }
        return ok
    }

    for (a in aList) {
        val lowerBound = lowerBound(list, a)
        when (lowerBound) {
            in list.indices -> list[lowerBound] = a
            else -> list.add(a)
        }
    }

    val answer = list.size

    println(answer)
}

// region

@Suppress("unused")
class FastIO {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    private var st = StringTokenizer("")
    val pw = PrintWriter(System.out)

    fun string(): String {
        if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
        return st.nextToken()
    }

    fun int() = string().toInt()
    fun long() = string().toInt()
    fun double() = string().toInt()
    fun nextLine() = br.readLine()!!
    fun println() = pw.println()
    fun <T> print(o: T) = pw.print(o)
    fun <T> println(o: T) = pw.println(o)

    inline fun exec(code: FastIO.() -> Unit) {
        code()
        pw.flush()
    }
}
// endregion


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);

  string s;
  cin >> s;

  if ((s[0] != 'A') || (s[1] < 'a' || s[1] > 'z') ||
      (s[s.size() - 1] < 'a' || s[s.size() - 1] > 'z')) {
    cout << "WA" << '\n';
    return 0;
  }

  bool ok = false;
  for (unsigned int i = 2; i < s.size() - 1; ++i) {
    if (s[i] < 'a' || s[i] > 'z') {
      if (!ok && s[i] == 'C') {
        ok = true;
      } else {
        cout << "WA" << '\n';
        return 0;
      }
    }
  }
  if (ok) {
    cout << "AC" << '\n';
  } else {
    cout << "WA" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define IOSF ios::sync_with_stdio(false)
typedef long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const int MAX=10e5+5;
const int MOD=10e9+7;

int a,b,n,flag=1;
LL math[MAX];
LL com[MAX];

LL C(LL m,LL n) {
    LL k=1;//相当于C(m,n)
    LL ans=1;
    while(k<=n) {
        ans=((m-k+1)*ans)/k;
        k++;
    }
    return ans;
}

int main() {
    IOSF;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>math[i];
    }
    sort(math+1,math+n+1);
    for(int i=1;i<=n;i++){
        if(math[i]>(math[n]+1)/2){
            if(i!=1){
                if(math[n]-math[i-1]-math[i]>0)
                    cout<<math[n]<<" "<<math[i];
                else
                    cout<<math[n]<<" "<<math[i-1];
                break;
            }
            else{
                cout<<math[n]<<" "<<math[1];
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        final String t = scanner.next();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();
        final String u = scanner.next();

        if (u.equals(s)) {
            System.out.println((a - 1) + " " + b);
        } else {
            System.out.println(a + " " + (b - 1));
        }
    }
}


Measured memory_bytes: 23636
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    int k =s.nextInt();
	    s.nextLine();
	    String ss = s.nextLine();
	    if(ss.length()>k) {
            String u = "";
            for (int i = 0; i < k; i++) {
                u += ss.charAt(i);
            }
            u += "...";
            System.out.println(u);
        }
	    else{
            System.out.println(ss);
        }
    }
}


Measured memory_bytes: 39728
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(m)); REP(i, n) REP(j, m) cin >> a[i][j], --a[i][j];
  int lb = 0, ub = n;
  while (ub - lb > 1) {
    int mid = (lb + ub) >> 1;
    vector<int> idx(n, 0);
    vector<bool> era(m, false);
    REP(_, m) {
      bool ok = true;
      map<int, vector<int> > mp;
      REP(i, n) {
        while (idx[i] < m && era[a[i][idx[i]]]) ++idx[i];
        if (idx[i] == m) {
          ok = false;
          break;
        }
        mp[a[i][idx[i]]].emplace_back(i);
      }
      if (!ok) break;
      ok = true;
      for (auto &pr : mp) {
        const vector<int> &id = pr.second;
        if (id.size() > mid) {
          era[pr.first] = true;
          for (int e : id) ++idx[e];
          ok = false;
        }
      }
      if (ok) break;
    }
    bool ok = true;
    REP(i, n) ok &= idx[i] < m;
    (ok ? ub : lb) = mid;
  }
  cout << ub << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main()
{
  int N, M;
  std::cin >> N >> M;
  int roads[2*M];
  for ( int i = 0; i < 2 * M; i ++ ) std::cin >> roads[i];

  int b[N] = {0};
  for ( int i = 0; i < 2 * M; i++ ) {
    b[roads[i] - 1]++;
  }

  for ( int i = 0; i < N; i++ ) {
    std::cout << b[i] << std::endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 100, j = 0; i > 0; i-- ){
        j += (a%i == 0 and b%i == 0) ? 1 : 0;
        if(j == k){
            cout << i << endl;
            break; 
        }
    }
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

template <class InputIterator, class T>
bool contains(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// =========ここまでテンプレ============

using route = vector<ll>;

vector<route> next(vector<route> v, ll m)
{
    vector<route> result;
    for (route r : v)
    {
        for (ll j = *(--r.end()); j < m; j++)
        {
            route r2 = r;
            r2.push_back(j);
            result.push_back(r2);
        }
    }
    return result;
};

int main()
{
    ll n, m, q;
    cin >> n >> m >> q;
    vector<array<ll, 4>> abcds;
    for (ll i = 0; i < q; i++)
    {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        --a;
        --b;
        abcds.push_back(array<ll, 4>{a, b, c, d});
    }
    vector<route> routes;
    for (ll i = 0; i < n; i++)
    {
        routes.push_back(vector<ll>{i});
    }

    for (ll i = 0; routes[0].size() < n; i++)
    {
        routes = next(routes, m);
    }

    ll maxScore = 0;

    for (route r : routes)
    {
        ll tempScore = 0;
        for (array<ll, 4> abcd : abcds)
        {
            ll a = abcd[0];
            ll b = abcd[1];
            ll c = abcd[2];
            ll d = abcd[3];

            if (r[b] - r[a] == c)
            {
                tempScore += d;
            }
        }
        maxScore = max(tempScore, maxScore);
    }
    cout << maxScore;
}

// 最大組み合わせ数は19C9 = 92378

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MOD 998244353

int main() {
	int n = ri();
	std::pair<int, int> all[n];
	for (auto &i : all) i.first = ri(), i.second = ri();
	std::sort(all, all + n);
	
	int range[n];
	std::deque<std::pair<int, int> > increasing;
	for (int i = n; i--; ) {
		range[i] = std::lower_bound(all, all + n, std::pair<int, int>{all[i].first + all[i].second, 0}) - all;
		int pos = std::lower_bound(increasing.begin(), increasing.end(), std::pair<int, int>{range[i], -1}) - increasing.begin();
		if (pos) range[i] = increasing[pos - 1].second;
		while (increasing.size() && increasing.front().second <= range[i]) increasing.pop_front();
		increasing.push_front({i, range[i]});
	}
	
	int dp[n];
	int res = 1;
	std::vector<int> child[n];
	std::vector<int> stack;
	for (int i = 0; i <= n; i++) {
		while (stack.size() && (i == n || range[stack.back()] < range[i])) {
			int back = stack.back();
			dp[back] = 1;
			for (auto j : child[back]) dp[back] = (int64_t) dp[back] * dp[j] % MOD;
			if (++dp[back] == MOD) dp[back] = 0;
			if (stack.size() == 1) res = (int64_t) res * dp[back] % MOD;
			stack.pop_back();
		}
		if (i == n) break;
		if (stack.size()) child[stack.back()].push_back(i);
		stack.push_back(i);
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 15092
#include<stdio.h>
#include<math.h>


int prime(int X){
    int i;
    for(i=2;i<=sqrt((double)X); i++){
        if(X%i==0){
            return 1;
        }
    }
    return 0;
}

int main(void){
    int X;
    scanf("%d", &X);
    
    while(1){
        if(!prime(X)){
            printf("%d", X);
            return 0;
        }
        X++;
    }
    
    return 0;
}

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

int main () {
    int n;
	cin >> n;

    ll sum = 0;

    rep(i,n)rep(j,n)rep(k,n) sum += gcd(i, gcd(j,k));

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3644
h, w = map(int, input().split())
ans = [[0 for _ in range(w)] for _ in range(h)]
bom_places = []
for i in range(h):
  s = input()
  for j in range(w):
    add_places = [[i-1, j-1], [i-1, j], [i-1, j+1],\
                [i, j-1], [i, j+1],\
                [i+1, j-1], [i+1, j], [i+1, j+1]]
    add_idx = set(range(8))
    remove_idx = []
    if s[j] == "#":
      bom_places.append([i,j])
      if i == 0:
        remove_idx += [0, 1, 2]
      if i == h-1:
        remove_idx += [5, 6, 7]
      if j == 0:
        remove_idx += [0, 3, 5]
      if j == w-1:
        remove_idx += [2, 4, 7]
      
      for idx in list(add_idx - set(remove_idx)):
        m, n = add_places[idx]
        ans[m][n] += 1

for i, j in bom_places:
  ans[i][j] = "#"

for i in range(h):
  tmp = ""
  for each in ans[i]:
    tmp += str(each)
  print(tmp)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
i64 equality(i64 s1, i64 s2, i64 s3) {
    i64 M = max(max(s1, s2), s3);
    i64 m = min(min(s1, s2), s3);
    return M - m;
}
const i64 INF = 1e14;
int main() {
    i64 H, W;
    cin >> H >> W;
    i64 ans = INF;
    for(int i = 0; i < 2; i++) {
        for(int w = 1; w < W; w++) {
            ans = min(ans, equality(
                w * H, (W - w) * (H / 2), (W - w) * (H - H / 2)
            ));
            ans = min(ans, equality(
                w * H, ((W - w) / 2) * H, (W - w - (W - w) / 2) * H
            ));
        }
        swap(W, H);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
seeds = 'ATCG'
def ng(currents):
  v = 'AGC' in currents
  for k in range(max(1, len(currents) - 3), len(currents)):  # 先頭の方はチェック済み
    v = v or 'AGC' in (currents[:k-1] + currents[k] + currents[k-1] + currents[k+1:])[-4:]
  return v
 
memo = {}  # 今の長さと最新4つだけメモする
def f(index, currents):
  key = '%d:%s' % (index, currents[-4:])
  if key not in memo:
    if ng(currents):
      memo[key] = 0
    else:
      memo[key] = 1 if index == n else sum([f(index+1, currents + s) for s in seeds])
  return memo[key]
 
print(f(0, '') % int(1e9+7))

Measured memory_bytes: 7612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if(N<100)cout << min(9,N) << endl;
  else if (N<10000)cout << min(909,N-90) << endl;
  else cout << min(90909,N-9090) << endl;
}


Measured memory_bytes: 256
S = list(input())
N = len(S)
lst = []
l = []
i = 0
while i < N:
    if S[i] == 'A':
        l.append(0)
        i += 1
    elif S[i] == 'B' and i+1 < N and S[i+1] == 'C':
        l.append(1)
        i += 2
    else:
        lst.append(l)
        l = []
        i += 1
if len(l):
    lst.append(l)
ans = 0
for l in lst:
    cnt = 0
    for x in l:
        if x == 0:
            cnt += 1
        else:
            ans += cnt
print(ans)

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

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p-1;
    for(int j = i+1; j < r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main(){
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++)  cin >> A[i];
    int qIndex = partition(A, 0, n-1);
    for(int i = 0; i < n; i++){
        if(i != 0)  cout << " ";
        if(i == qIndex){
            cout << "[" << A[i] << "]";
        }else{
            cout << A[i];
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3468
#include <iostream>

using namespace std;

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

int lcm(long long int a, long long int b)
{
    return a * b / gcd(a, b);
}
//9999900000
//1409965408
int main()
{
    long long int a, b;
    cin >> a >> b;
    long long int lcm_n = lcm(a,b);

    if (lcm_n % a == 0 && lcm_n % b == 0) {
        cout << lcm_n;
    }
    else {
        cout << a*b;
    }

//    cout << 1409965408 % 100000;
//    cout << lcm(a, b) << endl;
//    cout << "最大公約数:" << gcd(a, b) << endl;
//    cout << "最小公倍数:" << lcm(a, b) << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#include<math.h>
#include <string.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;





using namespace std;

int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;

  int n;

  cin >> n;

  int a;

  vector<int>v(n);

  for (int i = 1; i < n; i++)
  {
    cin >> a;
    v[a - 1]++;
  }

  for (auto x : v)
  {
    cout << x << endl;
  }


  return 0;
}





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

using namespace std;

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

int main() {
    int n = 0;
    cin >> n;

    int res = 0;

    rep(i,n){
        int l,r = 0;
        cin >> l >> r;
        res += r - l + 1;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
i,j,N,p,P,t[36],c[36],T[36],C[36];
B(){
    for(i=0;i<N;i++)
    for(j=N-1;j>0;j--)
        if(t[j-1]>t[j]){
            t[j]^=t[j-1]^=t[j]^=t[j-1];
            c[j]^=c[j-1]^=c[j]^=c[j-1];
        }
}
S(){
    for(i=0;i<N;i++){
        for(j=p=i;j<N;j++)if(T[j]<T[p])p=j;
        P=T[p];T[p]=T[i];T[i]=P;
        P=C[p];C[p]=C[i];C[i]=P;
    }
}
main(){
    for(scanf("%d",&N);i<N;scanf(" %c%d",&c[i],&t[i]),T[i]=t[i],C[i]=c[i],i++);
    B();S();
    for(i=0;i<N;printf("%c%d%s",c[i],t[i],i==N-1?"\nStable\n":" "),i++);
    for(i=0;i<N;printf("%c%d%s",C[i],T[i],i==N-1?"\n":" "),i++);
    for(i=p=0;i<N;i++)
        if(c[i]==C[i]&&t[i]==T[i])p++;
    puts(p==N?"Stable":"Not stable");
}

Measured memory_bytes: 1804
import heapq
from collections import defaultdict
v_num = int(input())
edges = defaultdict(list)
for i in range(v_num):
    data = [int(n) for n in input().split(" ")[1:]]
    for j in range(i + 1, v_num):
        if data[j] != -1:
            edges[i].append([data[j], j])
            edges[j].append([data[j], i])
queue = []
heapq.heapify(queue)
for c in edges[0]:
    heapq.heappush(queue, c)
visited = {0}
answer = 0
while len(visited) < v_num:
    q = heapq.heappop(queue)
    weight, one = q[0], q[1]
    if one in visited:
        continue
    answer += weight
    for e in edges[one]:
        if e[1] not in visited:
            heapq.heappush(queue, e)
    visited |= {one}
print(answer)

Measured memory_bytes: 8740
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a[4][14] = {};
    int n;
    cin >> n;
    REP(i,n){
        char c;
        int x;
        cin >> c >> x;
        if (c == 'S') a[0][x] = 1;
        else if (c == 'H') a[1][x] = 1;
        else if (c == 'C') a[2][x] = 1;
        else a[3][x] = 1;
    }
    string s = "SHCD";
    REP(i,4) FOR(j,1,13) if (!a[i][j]) cout << s[i] << " " << j << endl;
    return 0;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int solve(vs32& t)
{
    int ret = 12;
    int n = t.size();
    rep (i, n)
    {
        for (int j = i + 1; j < n; ++j)
        {
            int dM = MAX(t[i], t[j]);
            int dm = MIN(t[i], t[j]);
            int gap = MIN(24 - dM + dm, dM - dm);
            ret = MIN(ret, gap);
        }
    }
    return ret;
}

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

    int n;
    cin >> n;

    vs32 d(n + 1);
    d[0] = 0;
    vs32 cnt(13,  0);
    cnt[0] = 1;
    rep (i, n)
    {
        cin >> d[i + 1];
        ++cnt[d[i + 1]];
    }

    rep (i, 13)
    {
        if ((i == 0 && cnt[i] > 1) || (i == 12 && cnt[i] > 1) || cnt[i] > 2)
        {
            cout << "0\n";
            return 0;
        }
    }

    int ans = 0;
    rep (i, 1 << 11)
    {
        vs32 time;
        int temp = i << 1;
        rep (j, 13)
        {
            if ((j == 0 && cnt[j] > 0) || (j == 12 && cnt[j] > 0))
            {
                time.push_back(j);
            }
            else if (cnt[j] == 0)
            {
                continue;
            }
            else if (cnt[j] == 2)
            {
                time.push_back(j);
                time.push_back(24 - j);
            }
            else if (temp & 1)
            {
                time.push_back(24 - j);
            }
            else
            {
                time.push_back(j);
            }
            temp >>= 1;
        }
        ans = MAX(ans, solve(time));
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, y, z;
  cin >> x >> y;
  if(x!=1 && y!=1)cout << 1 << endl;
  if(x!=2 && y!=2)cout << 2 << endl;
  if(x!=3 && y!=3)cout << 3 << endl;
  return 0;
}

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

int n;
double x;
int main() {
	cin >> n;
	x = n / 1.08;
	for(int i=x; i<x+5; i++) {
		if(int(i*1.08) == n) {cout << i; return 0;}
	}
	puts(":(");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  st s;
  cin >> s;
  if(s.size()==3){
    swap(s[0],s[2]);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let n:i32 = procon_read()[0];
	let mut a:Vec<i32> = procon_read();
	a.sort();
	println!("{}", a[(n-1) as usize] - a[0]);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

// #define DEBUGGING
#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

const ll MOD = 1e9 + 7;

int main() {
    init_io();
    ll N;
    cin >> N;
    string S;
    cin >> S;
    V<ll> dp(5010, 0);
    dp[0] = 1;
    for(ll i = 0; i < N; i++) {
        V<ll> ndp(5010, 0);
        for(ll pre_len = 0; pre_len <= N; pre_len++) {
            (ndp[pre_len + 1] += dp[pre_len]) %= MOD;
            if(pre_len == 0) (ndp[0] += dp[0]) %= MOD;
            else (ndp[pre_len - 1] += dp[pre_len] * 2 % MOD) %= MOD;
        }
        dp = move(ndp);
    }
    cout << dp[S.size()] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cassert>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

typedef long long ll;

const int N = 1000 + 5;

int n;
int x[N], y[N];

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const char dir[4] = {'R', 'L', 'U', 'D'};

ll dist(ll x, ll y, ll tx, ll ty) {
  return abs(x - tx) + abs(y - ty);
}

int main() {
  scanf("%d", &n);
  int sig = 0, par = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    sig |= ((x[i] ^ y[i]) & 1);
    par |= !((x[i] ^ y[i]) & 1);
  }
  if (sig && par) {
    puts("-1");
    return 0;
  }
  if (par) {
    printf("32\n1 ");
  } else {
    printf("31\n");
  }
  for (int i = 30; i >= 0; i--) {
    printf("%d ", (int)pow(2, i));
  }
  puts("");
  for (int i = 1; i <= n; i++) {
    ll sx = 0, sy = 0;
    if (par) {
      putchar('L');
      sx--;
    }
    for (int j = 30; j >= 0; j--) {
      for (int k = 0; k < 4; k++) {
        ll nx = sx + dx[k] * pow(2, j);
        ll ny = sy + dy[k] * pow(2, j);
        ll d = dist(nx, ny, x[i], y[i]);
        if (d <= pow(2, j) - 1 && !((d ^ ((int)pow(2, j) - 1)) & 1)) {
          sx = nx;
          sy = ny;
          putchar(dir[k]);
          break;
        }
      }
    }
    assert(sx == x[i] && sy == y[i]);
    puts("");
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
    println(if(isBingo()) "Yes" else "No")
}

fun isBingo():Boolean {
    val card = (1..3).map { readLine()!!.split(" ").map { it.toInt() } }
    val logCount = readLine()!!.toInt()
    val log = (1..logCount).map { readLine()!!.toInt() }

    val flag = (1..3).map { (1..3).map { false }.toMutableList() }

    for(i in card.indices) {
        for(j in card[i].indices) {
            if(log.contains(card[i][j])) {
                flag[i][j] = true
            }
        }
    }

    if(flag.any { it.all { it } }) {
        return true
    }
    if((0 until 3).any { idx -> flag.all { it[idx] } }) {
        return true
    }
    if((0 until 3).all { flag[it][it] }) {
        return true
    }
    if((0 until 3).all { flag[2-it][it] }) {
        return true
    }
    return false
}

Measured memory_bytes: 36648
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

N = int(input())
adj = [[] for _ in range(N)]
rtree = [None] * N

def dfs(v,parent,dist):
    rtree[v] = dist
    for u, c in adj[v]:
        if u == parent:
            continue
        dfs(u,v,dist+c)

def main():
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        adj[a-1].append((b-1,c))
        adj[b-1].append((a-1,c))
    Q, K = map(int, input().split())

    # Kを頂点とする根付き木を作成する
    dfs(K-1,-1,0)

    for _ in range(Q):
        x, y = map(lambda x: int(x)-1, input().split())
        print(rtree[x] + rtree[y])

if __name__ == "__main__":
    main()


Measured memory_bytes: 136528
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <queue>
#include <tuple>
#include <cassert>

using namespace std;

using PII = pair<int, int>;
using TUP = tuple<int, int, int, int>;
using VL = vector<long long>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;

const long long inf = 1e18;

const vector<int> dc = {1, 0, -1, 0};
const vector<int> dr = {0, 1, 0, -1};

int main() {
	int h, w, k;
	int sx, sy, gx, gy;
	cin >> h >> w >> k;
	cin >> sx >> sy >> gx >> gy;
	sx--;
	sy--;
	gx--;
	gy--;

	vector<string> grid(h);
	for (int i = 0; i < h; i++) {
		cin >> grid[i];
	}

	grid[sx][sy] = 'S';
	grid[gx][gy] = 'G';

	// printf("hwk %d %d %d\n", h, w, k);
	// for (auto s: grid) {
	// 	cout << s << endl;
	// }

	VVVL dist(4, VVL(h, VL(w, inf)));
	priority_queue<TUP, vector<TUP>, greater<TUP>> que;  // cost, dir, row, col

	auto push = [&](long long cost, int dir, int row, int col) {
		if (row < 0 || h <= row || col < 0 || w <= col) {
			return;
		}
		if (grid[row][col] == '@') {
			return;
		}

		if (cost < dist[dir][row][col]) {
			que.emplace(cost, dir, row, col);
			dist[dir][row][col] = cost;
		}
	};


	for (int i = 0; i < 4; i++) {
		push(0, i, sx, sy);
	}

	int dir, r, c;
	long long cost;
	while (!que.empty()) {
		tie(cost, dir, r, c) = que.top();
		que.pop();

		if (cost != dist[dir][r][c]) {
			continue;
		}

		if (grid[r][c] == 'G') {
			break;
		}

		for (int dir2 = 0; dir2 < 4; dir2++) {
			long long cost2 = (cost + k - 1) / k * k;
			push(cost2, dir2, r, c);
		}
		push(cost + 1, dir, r+dr[dir], c+dc[dir]);

	}

	long long ans = inf;
	for (int i = 0; i < 4; i++) {
		ans = min(ans, dist[i][gx][gy]);
	}
	if (ans == inf) {
		cout << -1 << endl;
	} else {
		ans = (ans + k - 1) / k;
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 51184
/**
 *	Author: houtaru
 *	Create: 27.05.2018 16:31:49
 */

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

long long a, b, c, k;

int main() {
    while (cin >> a >> b >> c >> k) {
        k %= 2;
        cout << (k ? b - a : a - b) << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll dp[205][205];
ll INF = 1e+18;
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m,r;cin >> n >> m >> r;
    int rr[10];
    rep(i,0,r){
        cin >> rr[i];
        rr[i]--;
    }
    sort(rr,rr+r);

    Fill(dp, INF);
    rep(i,0,n) dp[i][i] = 0;
    rep(i,0,m){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;
        dp[a][b] = dp[b][a] = c;
    }

    rep(k,0,n){
        rep(i,0,n){
            rep(j,0,n){
                if(dp[i][k] == INF || dp[k][j] == INF) continue;
                chmin(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    ll ans = 1e+18;
    do{
        ll tmp = 0;
        rep(i,0,r-1){
            tmp += dp[rr[i]][rr[i+1]];
        }
        chmin(ans, tmp);
    }while(next_permutation(rr,rr+r));

    cout << ans << endl;
    return 0;
}

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

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

int main(){
  int n, d;
  cin >> n >> d;

  vector<vector<int>> x(n, vector<int>(d));
  rep(i, n)rep(j, d) cin >> x.at(i).at(j);

  int ans = 0;

  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      int sum=0;
      float dis=0;
      rep(k, d) sum += (x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
      dis = sqrt(sum);
      //cout << dis << endl;
      if(dis == int(dis)) ans++;
    }
  }

  cout << ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<string, string> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    for(int i = 1; i <= 360; ++i){
        if((x*i)%360 == 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

int main(){
long long a,b,tmp;
cin >> a >> b;

if(a < b){
tmp = a;
a = b;
b = tmp;
 }
int i = 1;
while(true){
    if(a*i%b == 0){
        break;
    }
    i++;
}
cout << a*i << endl;
}


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

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A, B, K;
    cin >> A >> B >> K;
    
    if (K >= (A + B)) {
        cout << 0 << " " << 0;
    } else if (K >= A) {
        cout << 0 << " " << B - (K - A);
    } else if (K < A) {
        cout << A - K << " " << B;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque

queue = deque()
n=int(input())

for i in range(n):
    command=input()
    if command == 'deleteFirst':
        queue.popleft()
    elif command == 'deleteLast':
        queue.pop()
    else:
        ope, num = command.split()
        if ope == 'delete':
            try:
                queue.remove(num)
            except:
                pass
        else:
            queue.appendleft(num)
result=list(queue)
print(*result)


Measured memory_bytes: 69736
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#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(a) (a).begin(),(a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
int main(){
      int n;
      cin>>n;
      vector<P> a(n);
      REP(i,n)cin>>a[i].first>>a[i].second;
      int mi=INF;
      sort(a.begin(),a.end());
      REP(i,n)FOR(j,i+1,n){
            int dx=a[i].first-a[j].first;
            int dy=a[i].second-a[j].second;
            if(dx*dx>=mi)break;
            mi=min(mi,dx*dx+dy*dy);
      }
      cout<<mi<<endl;
}

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

int main(){
	int n;
	cin >> n;
	map<string,int> mp1;
	rep(i,n){
		string s;
		cin >> s;
		mp1[s]++;
	}
	int m;
	cin >> m;
	map<string,int> mp2;
	rep(i,m){
		string t;
		cin >> t;
		mp2[t]++;
	}
	int ans = 0;
	for (auto p : mp1){
		int temp = 0;
		temp = p.second - mp2[p.first];
		ans = max(temp,ans);
	}
	
	cout << max(ans,0) << endl;
    return 0;
}




Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
ans = 1
for i in range(1,int(M**(1/2))+1):
    if M % i == 0 and i*N <= M:
        ans = max(ans, i)
for i in range(N,int(M**(1/2))+1):
    if M % i == 0 :
        ans = max(ans,M//i)
print(ans)

Measured memory_bytes: 3060
s = input()

cntg = 0
cntp = 0
score = 0
for c in s:
    if c == 'g' and cntg>cntp:
        cntp += 1
        score += 1
    elif c == 'g' and cntg<=cntp:
        cntg += 1
    elif c == 'p' and cntg>cntp:
        cntp += 1
    elif c == 'p' and cntg<=cntp:
        cntg += 1
        score -= 1
print(score)


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

using namespace std;
typedef long long ll;

const ll mod=1000000007;
const int N=100005;
vector<int> v[N];

array<ll,2> dfs(int a,int p=-1)
{
    array<ll,2> now={1,1};
    for(int to:v[a])
    {
        if(to==p) continue;
        array<ll,2> nxt=dfs(to,a);
        now[0]=(now[0]*(nxt[0]+nxt[1]))%mod;
        now[1]=(now[1]*nxt[0])%mod;
    }
    return now;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    array<ll,2> a=dfs(1);
    cout << (a[0]+a[1])%mod << "\n";
    return 0;
}


Measured memory_bytes: 12672
#include <iostream>
using namespace std;
int main(void){
    int X;
    cin >> X;
     
    if(X%7 == 0) cout << "thu" << endl;
    else if(X%7 == 1) cout << "fri" << endl;
    else if(X%7 == 2) cout << "sat" << endl;
    else if(X%7 == 3) cout << "sun" << endl;
    else if(X%7 == 4) cout << "mon" << endl;
    else if(X%7 == 5) cout << "tue" << endl;
    else if(X%7 == 6) cout << "wed" << endl;
    
}


Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main()
{
    int N, M, A[55] = {0}, a, b;
    cin>>N>>M;
    for(int i = 1; i <= M; i++)
    {
        cin>>a>>b;
        A[a]++;
        A[b]++;
    }
    for(int i = 1; i <= N; i++)
    {
        cout<<A[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s;
    cin>>t;
    bool flag=true;
    for(int i=0;i<s.length();++i)
    {
        if(s[i]!=t[i])
        {
            flag=false;
            break;
        }
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";
    cout<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N, K;
  cin >> N >> K;
  i64 cnt = 0;
  for(int i = 0;i < N;i++) {
    i64 h;
    cin >> h;
    if(K <= h) cnt++;
  }
  cout << cnt << endl;
}


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

const int INF = 100000000;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
    for (int j = 0; j < m; j++)
      cin >> a.at(i).at(j);
  }
  
  int res = INF;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<12> s(tmp);
  
    vector<int> v(m);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (s.test(i)) {
        sum += c.at(i);
        for (int j = 0; j < m; j++)
          v.at(j) += a.at(i).at(j);
      }
    }
      
    for (int i = 0; i < m; i++) {
      if (v.at(i) < x)
        break;
      else if (i == m - 1)
        res = min(res, sum);
    }
  }
  
  if (res != INF)
    cout << res << endl;
  else
    cout << -1 << endl;
    
  return 0;
}

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

#define pii pair<int, int>
#define pll pair<LL, LL>
#define F first
#define S second
#define B begin()
#define E end()
#define MOD 1000000007
#define itt iterator
#define ritt reverse_iterator
#define LL long long

#define PI (4 * atan(1))

using namespace std;

int n, a, b;

int main()
{
	// freopen("/Users/oakchawit/Documents/Computer/TestingArea/test.in", "r", stdin);
	// freopen("/Users/oakchawit/Documents/Computer/TestingArea/test.out", "w", stdout);

    scanf("%d %d %d", &n, &a, &b);
    if(abs(a - b) % 2 == 1 || (a == 1 && b == 2))
    	printf("Borys\n");
    else
    	printf("Alice\n");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var ab = new int[h[1]].Select(_ => Read()).ToArray();
		var cd = new int[h[2]].Select(_ => Read()).ToArray();

		var uf = new UF(n + 1);
		foreach (var x in ab)
			uf.Unite(x[0], x[1]);

		var roots = Enumerable.Range(0, n + 1).GroupBy(uf.GetRoot).ToDictionary(g => g.Key, g => g.Count());
		var c = Enumerable.Range(0, n + 1).Select(uf.GetRoot).Select(x => roots[x] - 1).ToArray();

		foreach (var x in ab)
		{
			c[x[0]]--;
			c[x[1]]--;
		}
		foreach (var x in cd)
		{
			if (!uf.AreUnited(x[0], x[1])) continue;
			c[x[0]]--;
			c[x[1]]--;
		}
		Console.WriteLine(string.Join(" ", c.Skip(1)));
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
}


Measured memory_bytes: 59932
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        char[] c = br.readLine().toCharArray();
        
        out.println(++c[0]);
        out.close();
        
    }
}

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

signed main() {
	int n,k;
	cin>>n>>k;
	pair<int,int>ab[n];
	for(int i=0;i<n;i++){
		cin>>ab[i].first>>ab[i].second;
	}
	sort(ab,ab+n);
	int cnt=k;
	for(int i=0;i<n;i++){
		k-=ab[i].second;
		if(k<=0){
			cout<<ab[i].first<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;
vector<vector<P>> graph;
int n;
bool chk(int bit){
    for(int i=0; i<n; i++){
        if(!(bit&(1<<i))) continue;
        for(int j=0; j<graph[i].size(); j++){
            int x = graph[i][j].first;
            int y = graph[i][j].second;
            if(y==1 && !(bit&(1<<x))) return false;
            if(y==0 && (bit&(1<<x))) return false;

        }
    }
    return true;
}


int main(){
    
        cin >> n;
        graph.resize(n);
        for(int i=0; i<n; i++){
            int a;
                cin >> a;
                graph[i].resize(a);
                for(int j=0; j<a; j++){
                    cin >> graph[i][j].first >> graph[i][j].second;
                    graph[i][j].first--;
                }
        }
    int res=0;

        for(int bit=0; bit<(1<<n); bit++){
            if(chk(bit)){
                int cnt=0;
                for(int i=0; i<n; i++){
                    if(bit & (1<<i)) cnt +=1;
                }
                res = max(res, cnt);
            }
        }
    cout << res << endl;


}

Measured memory_bytes: 256
f=lambda:map(int,input().split())
N,M=f()
*H,=f()

g = [[] for _ in range(N)]
    
for _ in range(M):
 a,b=f()
 g[a-1].append(b-1)
 g[b-1].append(a-1)
print(sum(all(H[j]<H[i]  for j in g[i]) for i in range(N)))

Measured memory_bytes: 29360
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	// 入力
	int n = sca.nextInt();  // n問出題される
	int m = sca.nextInt();  // m回提出
	int[] pi = new int[m]; // i番目の問題番号
	String[] si = new String[m];  // i番目の提出の結果ACかWA

	for(int i = 0; i < m; i++) {
		pi[i] = sca.nextInt();
		si[i] = sca.next();
	}
	boolean[] flg = new boolean[n+1];
	for(int i = 0; i <= n; i++) {
		flg[i] = false;
	}
	int seito = 0;
	int penal = 0;
	int[] penal_loop = new int[n+1];



	for(int j = 0; j < m; j++) {
		// i番目の問題がまだ正解していないとき
		if(flg[pi[j]] == false) {
			if(si[j].equals("AC")) {
				seito++;
				flg[pi[j]] = true;
			}
			else if(si[j].equals("WA")) {
				penal_loop[pi[j]]++;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		if(flg[i] == true) {
			penal = penal + penal_loop[i];
		}
	}

	System.out.print(seito);
	System.out.print(" ");
	System.out.println(penal);

	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 72004
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    int ans=0;
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<k;i++)ans+=a[i];
    cout << ans << endl;
}

int main(){
    solve();
    return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>
#include <queue>

using namespace std;

typedef pair<string, int> P;

int main() {
	string s;
	while (cin >> s) {
		if (s == "0") {
			break;
		}
		map<string, int> mp;
		queue<P> q;
		q.push(P(s, 0));
		int count = -1;
		int sz = s.size();
		char cc = s[0];
		bool hantei = true;
		for (int i = 1; i < sz; i++) {
			if (s[i] != cc) {
				hantei = false;
				break;
			}
		}
		mp[s]++;
		if (hantei) {
			cout << 0 << endl; 
		} else {
			while (!q.empty()) {
				P aa = q.front();
				q.pop();
				string a = aa.first;
				for (int i = 0; i < sz-1; i++) {
					if (a[i] == a[i+1]) {
					} else {
						string b = a;
						if ((a[i] == 'r' && a[i+1] == 'g')||(a[i] == 'g' && a[i+1] == 'r')) {
							b[i] = b[i+1] = 'b';
						} else if ((a[i] == 'g' && a[i+1] == 'b')||(a[i] == 'b' && a[i+1] == 'g')) {
							b[i] = b[i+1] = 'r';
						} else {
							b[i] = b[i+1] = 'g';
						}
						//cout << b << endl;
						mp[b]++;
						if (mp[b] > 1) {
						} else {
							char ccb = b[0];
							bool hantei2 = true;
							for (int i = 1; i < sz; i++) {
								if (b[i] != ccb) {
									hantei2 = false;
									break;
								}
							}
							if (hantei2) {
								count = aa.second+1;
								break;
							} else {
								q.push(P(b, aa.second+1));
							}
						}
					}
				}
				if (count != -1) {
					break;
				}
			}
			if (count != -1) {
				cout << count << endl;
			} else {
				cout << "NA" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ll long long
using namespace std;

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

int main()
{
  int n;
  int a[100001], l[100001], r[100001];
  cin >> n;
  REP(i, n)cin >> a[i];
  l[0] = a[0];
  REP(i, n - 1) l[i + 1] = gcd(l[i], a[i + 1]);
  r[n - 1] = a[n - 1];
  for(int i = n - 1; i > 0; i--) r[i - 1] = gcd(r[i], a[i - 1]);
  int ans = max(l[n - 2], r[1]);
  FOR(i, 1, n - 1) ans = max(ans, gcd(l[i - 1], r[i + 1]));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408