akhauriyash/Code-Regression huggingface dataset:
// インクルード(GCC only)
#include <bits/stdc++.h>

// 長い型名
using namespace std;
typedef long long LL;

// 省略記法
#define INF 1e9
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i##_len=(n), i=(i##_len-1); i>=0; ++i)
#define FOR(i,m,n) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sizei(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define printvector(x) rep(i,sizei(x)){cout << x[i] << endl;}
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; }

// mod付き四則演算(mod関数のオーバーヘッドが重いかも)
// TODO: 二項係数、離散対数、平方剰余の実装
#define MOD 1000000007
inline LL mod(LL const &a) { return (a % MOD + MOD) % MOD; }
inline LL madd(LL const &a, LL const &b) { return mod(mod(a) + mod(b)); }
inline LL msub(LL const &a, LL const &b) { return mod(mod(a) - mod(b)); }
inline LL mmul(LL const &a, LL const &b) { return mod(mod(a) * mod(b)); }
inline LL mpow(LL a, LL b) {
  LL r = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) (r *= a) %= MOD;
    (a *= a) %= MOD;
  }
  return r;
}
inline LL minv(LL const &a) { return mpow(a, MOD-2); }
inline LL mdiv(LL const &a, LL const &b) { return mod(mod(a) * minv(b)); }


// デバッグ用
#ifdef LOCAL
    #define eprint(...) fprintf(stderr, __VA_ARGS__)
    #define eprintvector(x) printvector(x)
#else
    #define eprint(...) 42
    #define eprintvector(x) 42
#endif

/**************** 便利な関数 ****************/
// 文字列の分割
vector<string> split_impl(string &&s, regex &&r) { return { sregex_token_iterator{s.begin(), s.end(), r, -1}, sregex_token_iterator{} }; }
auto split(string s, string pattern) { return split_impl(move(s), regex{pattern}); }


int main(void)
{
    pair<char, int> p;
    vector<pair<char, int>> v;

    p.first = 'A';
    cin >> p.second;
    v.push_back(p);
    
    p.first = 'B';
    cin >> p.second;
    v.push_back(p);
    
    p.first = 'C';
    cin >> p.second;
    v.push_back(p);

    sort(all(v), [](pair<char, int> a, pair<char, int> b){ return a.second < b.second; });

    if (v[1].first == 'C') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

bool IsPrime(int x){
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int n;
int main(){
    cin>>n;
    int x=0;
    for(int i=2;x<n;i+=5){
        if(IsPrime(i)){
            if(x)cout<<" ";
            cout<<i;
            x++;
        }
    }
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int,input().split()))
M = int(input())
P = []
X = []
for _ in range(M):
  p,x = map(int,input().split())
  P.append(p)
  X.append(x)

sumT = sum(T)

for p,x in zip(P,X):
  print(sumT - (T[p-1]-x))


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n, m;
  cin >> n >> m;
  vector<int> xs(m);
  int odd_count = 0;
  for (int i = 0; i < m; i++) {
    cin >> xs[i];
    if (xs[i] % 2 == 1) {
      odd_count++;
    }
  }

  if (odd_count >= 3) {
    cout << "Impossible" << endl;
    return 0;
  }

  int processed_odd_count = 0;
  for (int i = 0; i < m; i++) {
    if (xs[i] % 2 == 1) {
      if (processed_odd_count == 0) {
        swap(xs[i], xs[0]);
      } else {
        swap(xs[i], xs[m - 1]);
      }
      processed_odd_count++;
      if (processed_odd_count == odd_count) break;
    }
  }

  for (int i = 0; i < m; i++) {
    cout << xs[i] << " ";
  }
  cout << endl;

  vector<int> ys;
  if (odd_count == 0) {
    if (xs[0] > 1) {
      ys.push_back(xs[0] - 1);
    }
    for (int i = 1; i < m; i++) {
      ys.push_back(xs[i]);
    }
    ys.push_back(1);
  } else if (odd_count == 1) {
    if (xs[0] > 1) {
      ys.push_back(xs[0] - 1);
    }
    for (int i = 1; i < m; i++) {
      ys.push_back(xs[i]);
    }
    ys.push_back(1);
  } else {
    if (xs[0] > 1) {
      ys.push_back(xs[0] - 1);
    }
    for (int i = 1; i < m - 1; i++) {
      ys.push_back(xs[i]);
    }
    ys.push_back(xs[m - 1] + 1);
  }

  cout << ys.size() << endl;
  for (int y : ys) {
    cout << y << " ";
  }
  cout << endl;
}

Measured memory_bytes: 3636
// lannisters don't act like fools
#include <bits/stdc++.h>
using namespace std;
#define yah_faster_baby ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


void solve() {

    int n;
    cin >> n;
    int i = 1000;
    while (i < n) {
        i += 1000;
    }

    cout << i - n << endl;
}



int main() {
    yah_faster_baby
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif // ONLINE_JUDGE
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;


ll gcd(ll m, ll n){
  ll x = min(m,n);
  ll y = max(m,n);
  if(x==0){
    return y;
  }else{
    return gcd(x, y%x);
  }
}

int main(){
  ll a,b;
  cin >> a >> b;
  cout << a*b/gcd(a,b) << endl;
}

Measured memory_bytes: 256
def main():
    N, X, M = map(int, input().split())
    Set = {X}
    A = [X]
    for i in range(1,M+1):
        nextA = A[i-1]**2 % M
        if nextA in Set:
            loop = A[A.index(nextA):]
            break
        else:
            Set.add(nextA)
            A.append(nextA)

    lenloop = len(loop)
    x, y = divmod(N-len(A), lenloop)
    ans = sum(A) + x*sum(loop) + sum(loop[0:y])
    print(ans)

main()


Measured memory_bytes: 13712
n, m, q = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
pq = [list(map(int, input().split())) for _ in range(q)]

sq = [[0] * n for _ in range(n)]

for i in range(m):
    l = lr[i][0]
    r = lr[i][1]
    sq[l-1][r-1] += 1

c = [[0] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if j == 0:
            c[i][j] = sq[i][j]
        else:
            c[i][j] = sq[i][j] + c[i][j-1]
            
for i in range(q):
    p = pq[i][0]
    q = pq[i][1]
    ans = 0
    for j in range(p, q + 1):
        if p != 1:
            ans += c[j-1][q-1] - c[j-1][p-2]
        else:
            ans += c[j-1][q-1]
    print(ans)



Measured memory_bytes: 116056
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
LL f(LL n) {
  static vector<int> res(9, -1);
  if (n <= 0) return 1;
  if (res[n] != -1) return res[n];
  res[n] = f(n - 1) + f(n - 2);
  return res[n];
}

const LL M = 1000000007;
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  auto dp = MATINIT(LL, H + 1, W + 1, 0);
  dp[0][1] = 1;
  REP(h, 1, H + 1) {
    REP(w, 1, W + 1) {
      dp[h][w] = (dp[h - 1][w] * (f(w - 2) * f(W - w - 1)) % M) % M;
      // cerr << dp[h][w] << "=" << dp[h - 1][w] << "*" << f(w - 2) << "*" << f(W - w - 1) << endl;
      if (w - 1 > 0)
        dp[h][w] =
            (dp[h][w] + (dp[h - 1][w - 1] * (f(w - 3) * f(W - w - 1))) % M) % M;
      if (w + 1 <= W)
        dp[h][w] =
            (dp[h][w] + (dp[h - 1][w + 1] * (f(w - 2) * f(W - w - 2))) % M) % M;
    }
  }
  // REP(i, 0, 9) cerr << f(i) << endl;
  // REP(i, 0, H + 1) cerr << dp[i] << endl;
  cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct stack_tag stack_t;
 
struct stack_tag {
  int32_t *data;
  size_t max_len;
  size_t size;
};

static bool check_is_null(const void *const p)
{
  if (p == NULL) {
    return true;
  }

  return false;
}

stack_t *stack_create(const size_t len)
{
  int32_t *data = (int32_t *)malloc(sizeof(int32_t) * len);
  stack_t *stack = (stack_t *)malloc(sizeof(stack_t));

  if (check_is_null(data) || check_is_null(stack)) {
    perror("memory is full\n");
    exit(1);
  }

  stack->data = data;
  stack->size = 0;
  stack->max_len = len;
  return stack;
}

void stack_destroy(stack_t *const stack)
{
  if (stack != NULL) {
    free(stack->data);
    free(stack);
  }
}

size_t stack_get_size(const stack_t *const stack)
{
  if (check_is_null(stack)) {
    return 0;
  }

  return stack->size;
}

bool stack_push(stack_t *const stack, const int32_t data)
{
  if (check_is_null(stack)) {
    return false;
  }

  if (stack->max_len <= stack->size) {
    return false;
  }

  stack->data[stack->size] = data;
  stack->size++;
  return true;
}

bool stack_pop(stack_t *const stack, int32_t *const data)
{
  if (check_is_null(stack)) {
    return false;
  }

  if (stack->size < 1) {
    return false;
  }

  stack->size--;
  *data = stack->data[stack->size];

  return true;
}

#if !defined(TEST)
#define STACK_SIZE 256
#define BUF_SIZE 128

static int32_t stack_pop_with_check(stack_t *const stack)
{
  int32_t data;
  bool ret = stack_pop(stack, &data);
  if (!ret) {
    perror("stack is full");
    exit(1);
  }

  return data;
}

static int32_t stack_push_with_check(stack_t *const stack, int32_t data)
{
  bool ret = stack_push(stack, data);
  if (!ret) {
    perror("stack is full\n");
    exit(1);
  }

  return data;
}

int32_t main(void)
{
  char str[BUF_SIZE];

  stack_t *s = stack_create(STACK_SIZE);

  while (scanf("%s", str) != EOF) {
    if (str[0] == '-') {
      int32_t b = stack_pop_with_check(s);
      int32_t a = stack_pop_with_check(s);
      stack_push_with_check(s, a - b);
    } else if (str[0] == '+') {
      int32_t b = stack_pop_with_check(s);
      int32_t a = stack_pop_with_check(s);
      stack_push_with_check(s, a + b);
    } else if (str[0] == '*') {
      int32_t b = stack_pop_with_check(s);
      int32_t a = stack_pop_with_check(s);
      stack_push_with_check(s, a * b);
    } else {
      bool ret = stack_push(s, atoi(str));
      if (!ret) goto err;
    }
  }

  printf("%d\n", stack_pop_with_check(s));

  stack_destroy(s);

  return 0;

err:
  perror("stack is full\n");
  exit(1);
}
#endif

Measured memory_bytes: 580
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public static class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var acc = new ModInt[N + 1];
        for (int i = 0; i < N; i++)
        {
            acc[i + 1] = acc[i] + A[i];
        }

        var sum = new ModInt(0);
        for (int j = 1; j < N; j++)
        {
            sum += acc[j] * A[j];
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 49488
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll D, N; cin >> D >> N;
    
    ll M = 1;
    REP(i, D) M *= 100;

    ll ans = N%100==0 ? N+1 : N;
    ans *= M;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int p[n + 1]; rrep(i, 1, n + 1) cin >> p[i];
    int c = 0;
    rrep(i, 1, n) if (p[i] == i) {swap(p[i], p[i + 1]); c++;}
    if (p[n] == n) {swap(p[n], p[n - 1]); c++;}
    cout << c << endl;
}


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

int main() {
  int X, N;
  cin >> X >> N;

  set<int> ps;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    ps.insert(p);
  }

  int diff = 0;
  while(true) {
    if(ps.count(X-diff)==0) {
      cout << X-diff << endl;
      return 0;
    }
    if(ps.count(X+diff)==0) {
      cout << X+diff << endl;
      return 0;
    }
    diff++;
  }

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    ll L[100010], R[100010];
    rep(i,0,Q){
        cin >> L[i]>> R[i];
        L[i]--; R[i]--;
    }
    ll cnt[100010] = {};
    rep(i,1,N){
        if(S[i] == 'C' && S[i-1] == 'A') cnt[i]++;
    }
    ll sum[100010] = {};
    rep(i,0,N) sum[i+1] = sum[i] + cnt[i];
    rep(i,0,Q){
        ll v = sum[R[i]+1] - sum[L[i]];
        if(cnt[L[i]] == 1) v--;
        print(v);

    }


}

Measured memory_bytes: 4176
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, k, n) for (int i=k; i<n; i++)
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> data(n);
    rep(i, 0, n) cin >> data.at(i);

    vector<string> BubbleSort(vector<string> data);
    vector<string> SelectionSort(vector<string> data);

    vector<string> bubble_ans = BubbleSort(data);
    vector<string> selection_ans = SelectionSort(data);
    
    rep(i, 0, bubble_ans.size()-1) cout << bubble_ans[i] << " ";
    cout << bubble_ans[bubble_ans.size()-1] << endl;
    cout << "Stable" << endl;

    rep(i, 0, selection_ans.size()-1) cout << selection_ans[i] << " ";
    cout << selection_ans[selection_ans.size()-1] << endl;
    cout << (bubble_ans==selection_ans ? "Stable": "Not stable") << endl;
}

vector<string> BubbleSort(vector<string> data) {
    int size = data.size();
    rep(i, 0, size-1) for(int j=size-1; j>i; j--) {
        if (data[j][1] < data[j-1][1]) swap(data[j-1], data[j]);
    }
    return data;
}

vector<string> SelectionSort(vector<string> data) {
    int size = data.size();
    rep(i, 0, size) {
        int tmp = i;
        rep(j, i, size) {
            if (data[tmp][1] > data[j][1]) tmp = j;
        }
        if (tmp != i) {
            swap(data[i], data[tmp]);
        }
    }
    return data;
}


Measured memory_bytes: 3212
using System;

class Program
{
    static void Main()
    {
        string[] i = Console.ReadLine().Split(' ');
        int a = int.Parse(i[0]);
        int b = int.Parse(i[1]);

        double x = double.Parse(i[0]);
        double y = double.Parse(i[1]);

        int d = a / b;
        int r = a % b;
        double f = x / y;

        Console.WriteLine("{0} {1} {2}", d, r, f.ToString("f5"));
    }
}



Measured memory_bytes: 17952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 85;
ll a[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ll mn = 1000;
    ll cr = 0;
    for(int i=1;i<n;i++){
        if(a[i]<a[i+1]){
            ll x =(mn)/a[i];
            cr+=x;
            mn-=x*a[i];
        }
        else if ( a[i]>a[i+1]){
            mn+=cr*a[i];
            cr = 0;
        }
    }
    mn+=cr*a[n];
    cr = 0;
    cout<<mn<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<int> compose(const vector<int> &a, const vector<int> &b){
	int len = a.size();
	vector<int> r(len);
	for(int i = 0; i < len; i++)
		r[i] = a[b[i]];
	return r;
}
vector<int> inverse(const vector<int> &a){
	int len = a.size();
	vector<int> r(len);
	for(int i = 0; i < len; i++)
		r[a[i]] = i;
	return r;
}
void show(const vector<int> &a){
	int len = a.size();
	for(int i = 0; i < len; i++)
		cout << a[i] << " ";
	cout << endl;
}
vector<int> pwr(vector<int> a, int k){
	int len = a.size();
	vector<int> r(len);
	for(int i = 0; i < len; i++)
		r[i] = i;
	for(; k; k >>= 1, a = compose(a, a))
		if(k&1)
			r = compose(r, a);
	return r;
}
/**
0 = p
1 = q
2 = qp-1
3 = qp-1q-1
4 = qp-1q-1pq-1
5 = qp-1q-1pq-1qpq-1 = qp-1q-1ppq-1
6 = qp-1q-1ppq-1qp-1qpq-1 = qp-1q-1p qpq-1

0 = (I, p)
1 = (I, q)
2 = (I, qp-1)
3 = (q, p-1)
4 = (qp-1, q-1)
5 = (qp-1, q-1p)
**/
int main(){
	int n, k; cin >> n >> k;
	vector<int> p(n), q(n);
	for(int i = 0; i < n; i++) cin >> p[i], p[i]--;
	for(int i = 0; i < n; i++) cin >> q[i], q[i]--;
	vector<int> fold = compose(q, compose(inverse(p), compose(inverse(q), p)));
	k--;
	fold = pwr(fold, k / 6); k %= 6;
	if(k == 0){
		fold = compose(fold, compose(p, inverse(fold)));
	} else if(k == 1){
		fold = compose(fold, compose(q, inverse(fold)));
	} else if(k == 2){
		fold = compose(fold, compose(compose(q, inverse(p)), inverse(fold)));
	} else if(k == 3){
		fold = compose(compose(fold, q), compose(inverse(p), inverse(compose(fold, q))));
	} else if(k == 4){
		vector<int> a = compose(q, inverse(p));
		fold = compose(fold, a);
		fold = compose(fold, compose(inverse(q), inverse(fold)));
	} else {
		vector<int> a = compose(q, inverse(p));
		fold = compose(fold, a);
		fold = compose(fold, compose(compose(inverse(q), p), inverse(fold)));
	}
	for(int i = 0; i < n; i++) cout << fold[i] + 1 << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 4312
S = int(input())

# 2点を(0, 0), (10**9, 1)と決め打ちしても構築可能
ans = '{} {} {} {} {} {}'.format(
    0,
    0,
    10**9,
    1,
    (
        0 if S == 10**18 else
        10**9 - S % 10**9
    ),
    min(S // 10**9 + 1, 10**9)
)

print(ans)


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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String tap = scan.next();
		int count = 0;

		for(int i=0;i<tap.length();i++) {
			if(i%2==0) {
				String kaku = tap.substring(i, i+1);
				if(kaku.equals("R") || kaku.equals("U") || kaku.equals("D")) {
					count++;
				}
			}else {
				String kaku = tap.substring(i, i+1);
				if(kaku.equals("L") || kaku.equals("U") || kaku.equals("D")) {
					count++;
				}
			}
		}

		System.out.println(count == tap.length()?"Yes":"No");
		scan.close();

	}

}


Measured memory_bytes: 23892
import java.math.BigDecimal;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        long a = sc.nextLong();
        double b = sc.nextDouble();
        long lb = 0;
        for (int i=0; i<1000; i++) {
            double tmp = (double)i / (double)100;
            if (tmp==b) {
                lb = i;
            }
        }

//        System.out.println(lb);

        System.out.println((a*lb)/(long)100);
    }
}


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

const long long MOD = 1e9 + 7;
char S[200009];

int main() {
    long long ans = 1;
    int N; scanf("%d",&N);
    for(int i=1; i<=2*N; i++) scanf(" %c", &S[i]);
    int op = 0;
    for(int i=1; i<=2*N; i++) {
        if((S[i] == 'B') ^ (op & 1)) ++op;
        else {
            ans *= 1LL * op;
            ans %= MOD;
            --op;
        }
        if(op < 0) return !printf("0");
    }
    if(op != 0) return !printf("0");
    for(int i=1; i<=N; i++) ans *= 1LL * i, ans %= MOD;
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
char s[11][11];
bool vis[11][11];

int main(int argc, char const *argv[])
{
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	int x = 0;
	int y = 0;
	do {
		vis[x][y] = true;
		if(x < n-1 && s[x+1][y] == '#') {
			x += 1;
		} else if (y < m-1 && s[x][y+1] == '#') {
			y += 1;
		} else {
			puts("Impossible");
			exit(0);
		}
	} while (x != n-1 || y != m-1);
	vis[n-1][m-1] = true;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(!vis[i][j] && s[i][j] == '#') {
				puts("Impossible");
				exit(0);
			}
		}
	}
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,y,i,j,x;
	cin>>n>>y;
	for(i=0;i<=y/10000;i++)
		for(j=0;j<=y/5000;j++){
			x=n-i-j;
			if(x>=0 && i*10000+j*5000+x*1000==y){
				cout<<i<<' '<<j<<' '<<x<<endl;
				return 0;
			}
		}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

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

#define PI 3.141592653589793238
int N;

int main()
{
    double x = 0.0, y = 0.0;
    int N, L;
    cin >> N;
    cin >> L;
    vector<int> T(N);
    for (int i = 0; i < N; i++)
        cin >> T[i];
    //for (int i = 0; i < N ; i++){
    //    fprintf(stderr, "%f, %f\n", cos(2 * PI * T[i]/(double)L), sin(2 * PI * T[i]/(double)L));
        
    //}
    for (int i = 0; i < N - 1; i++){
        for (int j = i + 1; j < N; j++){
            int coef2 = j - i - 1;
            int coef1 = N - 2 - coef2;
            double x0 = (coef1 - coef2) * cos(2 * PI * (T[i] + T[j])/(double)(2*L))/(double)(N-2);
            double y0 = (coef1 - coef2) * sin(2 * PI * (T[i] + T[j])/(double)(2*L))/(double)(N-2);
            //fprintf(stderr, "%d, %d: %f, %f\n", i, j, x0, y0);
            x += x0;
            y += y0;
        }
    }
    x /= N *(N - 1)/6.0;   
    y /= N *(N - 1)/6.0;
    //x *= 3.0;
    //y *= 3.0;
    //cout<<setprecision(10)<<x<<' '<<y<<endl;
    fprintf(stdout, "%.15f %.15f\n", x, y);
    //cout << x << " " << y << endl;
    return 0;    
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	int sum = 0;

	for (int i = 0; i < 2; i++) {
		if (A >= B) {
			sum += A;
			A--;
		}
		else {
			sum += B;
			B--;
		}
	}

	cout << sum << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <queue>

using namespace std;



int main() {
  //
  int N, v, lim = 3;
  cin >> N;
  vector<vector<long long>> V(N, vector<long long>(lim));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < lim; ++j) {
      cin >> v;
      V[i][j] = v;
    }
  }

  //
  vector<vector<long long>> sum(N+1, vector<long long>(lim, 0));
  for (int j = 0; j < lim; ++j) {
    sum[0][j] = V[0][j];
  }

  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < lim; ++j) {
      for (int k = 0; k < lim; ++k) {
        if(j == k) continue;
        sum[i][j] = max(sum[i][j], sum[i-1][k] + V[i][j]);
      }
    }
  }

  long long max_sum = 0;
  for (int j = 0; j < lim; ++j) {
    max_sum = max(max_sum, sum[N-1][j]);
  }

  cout << max_sum << endl;

  return 0;
}




Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;

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

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
vector<vector<int>> color;
vector<vector<char>> S;
string ALL;
int N;
void bfs(int a, int b) {
    bool flag; //縦
    if(a == 0) {
        if(S[a][b] == S[a + 1][b]) {
            flag = true;
        } else {
            flag = false;
        }
    } else {
        if(S[a][b] == S[a - 1][b]) {
            flag = true;
        } else {
            flag = false;
        }
    }
    if(flag) {
        ALL.push_back('X');
        if(b == N - 1) {
            return;
        }
        bfs(a, b + 1);
    } else {
        ALL.push_back('Y');
        if(b + 2 >= N) {
            return;
        }
        bfs(a, b + 2);
    }
}

int main() {
    cin >> N;
    color.resize(2);
    S.resize(2);
    REP(i, 2) {
        color[i].resize(N);
        S[i].resize(N);
    }
    for(int i = 0; i < N; i++) {
        cin >> S[0][i];
    }
    for(int i = 0; i < N; i++) {
        cin >> S[1][i];
    }

    REP(i, 2) {
        REP(j, N) { color[i][j] = -1; }
    }
    bfs(0, 0);
    // cout << ALL << endl;
    long long res = 1;
    for(int i = 0; i < ALL.size(); i++) {
        if(i == 0) {
            if(ALL[i] == 'X') {
                res *= 3;
            } else {
                res *= 6;
            }
        } else {
            if(ALL[i] == 'Y') {
                if(ALL[i - 1] == 'X') {
                    // XY
                    res *= 2;
                } else {
                    // YY
                    res *= 3;
                }

            } else {
                // X
                if(ALL[i - 1] == 'X') {
                    // XX
                    res *= 2;
                } else {
                    // YX
                    res *= 1;
                }
            }
        }
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int H, W;
  cin >> H >> W;
  rep(i, W + 2) {
    cout << "#";
  }
  cout << " " << endl;
  string S;
  rep(i, H) {
    cout << "#";
    cin >> S;
    cout << S;
    cout << "#" << endl;
  }
  rep(i, W + 2) {
    cout << "#";
  }
}
    


Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){
			//??????????¨?????????° m
			int  m = sc.nextInt();
			//??????????¨?????????° f
			int  f = sc.nextInt();
			//???????¨?????????° r
			int  r = sc.nextInt();
			//??¨??????????¨????-1?????´??? ??????
			if(m == -1 && f == -1 && r == -1){
				break;
			}
			//?????¶??? ??????????¨? ??????????¨?????¬????(-1)?????´???
			if(m == -1 || f== -1){
				System.out.println("F");
				//?????¶??? ??????????¨???¨??????????¨????80?????\????????´???A
			}else if((m + f) >= 80){
				System.out.println("A");
				//?????¶??? ??????????¨???¨??????????¨????80????????? 65?????\???????????°B
			}else if(80 > (m+ f ) && (m + f) >= 65 ){
				System.out.println("B");
				//?????¶??? ??????????¨???¨??????????¨????65????????? 50?????\???????????°C
			}else if(65 > (m+ f ) && (m + f) >= 50 ){
				System.out.println("C");
				//?????¶??? ??????????¨???¨??????????¨????50????????? 30?????\???????????°D
			}else if(50 > (m+ f ) && (m + f) >= 30 ){
				//?????¶??? ????????? ???????¨????50?????\???????????°C
				if(r >= 50){
					System.out.println("C");
				}else{
					System.out.println("D");
				}
			}else if(30 >(m+ f)){
				//?????¶??? ??????????¨???¨??????????¨????30?????????????????°F
				System.out.println("F");
			}
		}
	}
}

Measured memory_bytes: 26180
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;

using namespace std;

int main()
{
    float d,t,s;
    cin>>d>>t>>s;
    
    float an = d/s;
    
    if(an<=t){
        cout<<"Yes"<<"\n";
    }
    else{
        cout<<"No"<<"\n";
    }

    return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll test[1234567];
signed main() {
	ll n, mae = 0, ato = 0; cin >> n;
	rep(i, 3 * n) { cin >> test[i]; }

	priority_queue<ll, vector<ll>, greater<ll>> que1;
	rep(i, n) { que1.push(test[i]); mae += test[i]; }
	vector<ll> v1(n * 3); v1[n] = mae;
	for (int h = n; h < 2 * n; h++) {
		mae += test[h]; que1.push(test[h]);
		mae -= que1.top(); que1.pop();
		v1[h + 1] = mae;
	}

	priority_queue<ll, vector<ll>, less<ll>> que2;
	for (int h = 3 * n - 1; h >= 2 * n; h--) { que2.push(test[h]); ato += test[h]; }
	vector<ll> v2(n * 3); v2[2 * n] = ato;
	for (int h = 2 * n - 1; h >= n; h--) {
		ato += test[h]; que2.push(test[h]);
		ato -= que2.top(); que2.pop();
		v2[h] = ato;
	}
	ll ans = 0 - INF;
	for (int h = n; h <= 2 * n; h++) {
		ans = max(ans, v1[h] - v2[h]);
		//cout << v1[h] << ' ' << v2[h] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11888
#include<iostream>
#include<ctype.h>
#include<cstdio>
#include<algorithm>
using namespace std;
inline long long read(){
	long long x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
    long long n=read(),m=read();
    cout<<(m-(n<<1)<0?m>>1:n+(m-(n<<1)>>2))<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

double f[3000][3000];
double p[3000];
int n;

inline void work() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }

    f[0][0] = 1.;
    for (int i = 1; i <= n; ++i) {
        f[i][0] = f[i - 1][0] * (1. - p[i]);
        for (int j = 1; j <= i; ++j) {
            f[i][j] = f[i - 1][j] * (1. - p[i]) + f[i - 1][j - 1] * p[i];
        }
    }
    double ans = 0.;
    for (int i = (n + 1) / 2; i <= n; ++i) {
        ans += f[n][i];
    }
    cout << setprecision(10) << ans << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 68992
import sys
import math
#import cython

def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    #N: cython.longlong = 0
    A,B,H,M=map(int, input().split())
     
    a=math.pi*(H+M/60)/6
    b=math.pi*M/30
     
    s=abs(a-b)
     
    C=math.sqrt(A**2+B**2-2*A*B*math.cos(s))
     
    print(C)
 
if __name__ == "__main__":
    main()

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

using namespace std;

int dp[100005];
int k, n;
vector<int> as;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    int j=0;
    for(int i=0;i<=n;i++){
        int a;
        if(i==n) a = k+1;
        else cin>>a;
        as.push_back(a);
        while(j<a) {
            bool first_flag = false;
            for (int z: as) {
                if(j-z>=0 && dp[j-z]){
                    first_flag = true;
                    break;
                }
            }
            if(first_flag){
                dp[j] = 0;
            }else{
                dp[j] = 1;
            }
            j++;
        }
    }

    if(dp[k]){
        cout<<"Second";
    }else{
        cout<<"First";
    }
    return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <ctime>
using namespace std;
 
int const MAX_N = 128 * 1024;
 
int s[MAX_N], used[MAX_N];

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
 
    int n;
	cin>>n;
	for (int i=0; i<n; i++) cin>>s[i];

	int AA = 0, BB = 0;
	for (int i=0; i<n; i++) {
		int mx = -1, ind = -1;
		for (int j=0; j<n; j++)
			if (!used[j])
				if (s[j]>mx) {mx = s[j]; ind = j;}
		if (i%2==0)
			AA += mx;
		else
			BB += mx;
		used[ind] = 1;
	}
	cout<<(AA-BB);
    return 0;
}  


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,tune=native")
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define I(x, a) for(auto x : (a))
#define ins insert
#define F(i, l, r) for(auto i = (l); i < (r); i++)
#define DF(i, l, r) for(auto i = (l); i >= (r); i--)
#define E(i, l, r) for(auto i = (l); i <= (r); i++)
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define ret return
#define brk break
#define cont continue
#define move fjgjgjgjghd

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

const int N = 222;

string gr[N];
int n;
int ans = 0;
int d[N];

void check(int start){
    queue<int> q;
    q.push(start);
    fill(d, d + n, -1);
    d[start] = 0;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        ans = max(ans, d[v] + 1);
        F(u, 0, n){
            if(gr[v][u] == '0')cont;
            if(d[u] == -1){
                d[u] = d[v] + 1;
                q.push(u);
            }
            else{
                if(d[u]%2 == d[v]%2){cout << -1; exit(0);}
            }
        }
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    F(i, 0, n)
        cin >> gr[i];
    F(i, 0, n)
        check(i);
    cout << ans;
    return 0;
}


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

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




Measured memory_bytes: 256
X, Y = map(int, input().split())
M = 10**9+7
if (X + Y) % 3:
    print(0)
else:
    m = (2 * X - Y)//3
    n = (2 * Y - X)//3
    if m < 0 or n < 0:
        print(0)
    else:
        a = 1
        for i in range(1, n+m+1):
            a =  a * i % M
        b = 1
        for i in range(1, n+1):
            b = b * i % M
        c = 1
        for i in range(1, m+1):
            c = c * i % M
        print(a * pow(b, M-2, M) * pow(c, M-2, M) % M)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner in=new Scanner(System.in);
        int d=in.nextInt();
        int n=in.nextInt();
        if(d==0){
            if(n<100)
            System.out.println(n);
            else if(n==100){
                System.out.println(101);
            }
        }else if(d==1){
            if(n<100)
            System.out.println((long)n*(long)100);
            else if(n==100){
                System.out.println(10100);
            }
        }else{
            if(n<100)
            System.out.println((long)n*(long)10000);
            else if(n==100){
                System.out.println(1010000);
            }
        }

    }

}

Measured memory_bytes: 21844
import java.util.Scanner

object Main extends App  {
  val sc = new Scanner(System.in)
  val n  = sc.nextInt
  val hl = List.fill(n)(sc.nextInt)

  val res = hl.foldLeft((0, 0)){case ((count,hMax),h) =>
      if (h >= hMax) (count + 1, h)
      else (count, hMax)
  }._1

  println(res)

}


Measured memory_bytes: 25920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    ll n,w;
    cin>>n>>w;
    vector<ll> c(n);
    vector<ll> v(n);
    rep(i,n)cin>>c[i]>>v[i];

    ll dp[101][100001];
    rep(i,w+1)dp[0][i]=0;
    rep(i,n){
        for(int j=0;j<=w;j++){
            if(j>=c[i]){
                dp[i+1][j]=max(dp[i][j-c[i]]+v[i],dp[i][j]);
                
            }else{
                dp[i+1][j]=dp[i][j];
            }    
        }
    }
    cout<<dp[n][w]<<endl;

    
    return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  vector<int> a(3);
  r(i,3)cin>>a.at(i);

  sort(a.rbegin(),a.rend());

  cout<<a.at(0)*10+a.at(1)+a.at(2)<<endl;







return 0;}


Measured memory_bytes: 256
n,m = map(int, input().split())

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        print(self.root)
        return -self.root[self.Find_Root(x)]
    
    def Output(self):
        return [i for i in self.root if i < 0]

uf = UnionFind(n)
for i in range(m):
    ab = list(map(int, input().split()))
    uf.Unite(ab[0],ab[1])

#print(uf.Output())
print(len(uf.Output())-2)


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

using namespace std;

int i=0,n=0,s=0,cnt=0,ans=0;
int combination(int a,int b,int c);


int combination(int a,int b,int c) 
//0-9テ」ツ?ョテヲツ閉ーテ・ツュツ療」ツつ誕,テ」ツ?敕」ツつ古」ツ?ァティツィツ暗ァツョツ療」ツ?療」ツ?淌ヲツ閉ーテ・ツ?、テ」ツつ鍛,テヲツ。ツ?ヲツ閉ーテ」ツつ団テ」ツ?ィテ」ツ?凖」ツつ?
{
	if(b == s && c == n){	//ティツィツ暗ァツョツ療」ツ?療」ツ?淌ヲツ閉ーテ・ツ?、テ」ツ?凝」ツ?、テ・ツ青暗ィツィツ?テ」ツ?ィテヲツ。ツ?ヲツ閉ーテ」ツ?古・ツ?・テ・ツ環崚」ツ?ィテ、ツクツ?ィツ?エテ」ツ?療」ツ?淌・ツ?エテ・ツ青?
		ans++;				//1テゥツ?堙」ツつ甘ィツヲツ凝」ツ?、テ」ツ?凝」ツ?」テ」ツ?淌」ツ?ョテ」ツ?ァテッツシツ妥ゥツ?堙」ツつ甘」ツδ療」ツδゥテ」ツつケテ」ツ?凖」ツつ?
	}
	if(a == 10 || c == n){	//0-9テ」ツ?ョテヲツ閉ーテ・ツ?、テ」ツつ津ヲツ篠「テ」ツ?療ァツオツづ」ツつ湘」ツ?」テ」ツ?淌」ツ?凝」ツ??ヲツ。ツ?ヲツ閉ーテ」ツ?古・ツ?・テ・ツ環崚」ツ?ィテ、ツクツ?ィツ?エテ」ツ?療」ツ?淌・ツ?エテ・ツ青?
		return 0;
	}
	combination(a+1,b,c);	//テヲツ閉ーテ・ツ?、テ」ツつ?1テ」ツ?療」ツ?ヲテ・ツ?催ィツ?ε」ツ?凖」ツつ?
	combination(a+1,b+a,c+1);	//テヲツ閉ーテ・ツ?、テ」ツつ?1テ」ツ?療」ツ??・ツ青暗ィツィツ暗」ツ?ォテヲツ閉ーテ・ツ?、テ」ツつ津ィツカツウテ」ツ?療」ツ??ヲツ。ツ?ヲツ閉ーテ」ツつ津・ツ「ツ療」ツつ?」ツ?療」ツ?ヲテ・ツ?催ィツ??
}
int main()
{
	while(cin >> n >> s && n && s>=0){
		ans=0;
		combination(0,0,0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
#include <algorithm>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector <int> vec;
const int N = 2000 + 5;
int a[N], dsu[N];
int n;
int vis[N];
vec G[N], idx[N], ans;
int find(int x){
	return x == dsu[x] ? x : dsu[x] = find(dsu[x]);
}
void unite(int x, int y){
	if(find(x) < find(y)){
		dsu[find(y)] = find(x);
	}else if(find(x) > find(y)){
		dsu[find(x)] = find(y);
	}
}
vec mer(vec a, vec b){
	vec ret;
	for(int i = 0, j = 0; i < a.size() || j < b.size(); ){
		if(i < a.size() && j < b.size()){
			if(a[i] >= b[j]) ret.push_back(a[i ++]);
			else ret.push_back(b[j ++]);
		}else if(i < a.size()){
			ret.push_back(a[i ++]);
		}else{
			ret.push_back(b[j ++]);
		}
	}
	return ret;
}
vec dfs(int o){
	vec ret;
	//printf("o = %d\n", o);
	vis[o] = 1;
	for(int i = 0; i < G[o].size(); i ++){
		if(vis[G[o][i]] == 1) continue;
		ret = mer(ret, dfs(G[o][i]));
	}
	ret.insert(ret.begin(), a[o]);
	return ret;
}
int main(){
	int u, v;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%d", &a[i]), dsu[i] = i;
	sort(a+1,a+n+1);
	for(int i = 1; i <= n; i ++){
		for(int j = i+1; j <= n; j ++){
			if(__gcd(a[i], a[j]) != 1){
				G[i].push_back(j);
				G[j].push_back(i);
				unite(i, j);
			}
		}
	}
	for(int i = 1; i <= n; i ++){
		if(dsu[i] == i) ans = mer(ans, dfs(i));
	}
	for(int i = 0; i < ans.size(); i ++){
		printf("%d ", ans[i]);
	}puts("");
	return 0;
}

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

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++){ cin >> h[i];}
  
  vector<int> dp(N,0);
  
  if( N == 2){ cout << abs(h[1] - h[0]) << endl; return 0;}
  else{
    dp[1] = abs( h[1] - h[0]);
  
  for(int i = 2; i < N; i++){
    if( dp[i] != 0){ continue;}
    dp[i] = min( dp[i-1] + abs( h[i] - h[i-1]), dp[i-2] + abs( h[i] - h[i-2]));}
    
    cout << dp[ N - 1] << endl;
    return 0;}
}
      
  

Measured memory_bytes: 1024
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int int64_t
#define pb push_back
#define ibswsct ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd __gcd
#define s second
#define f first
#define mp make_pair
typedef std::pair<int,int> pii ;

using namespace std;

int a;
string s;

int32_t main(){
	ibswsct
	cin>>a>>s;
	cout<<((a<3200)?"red":s);
}


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

int d1[550], d2[550];
char s[50], p[50], g[50], a[50], b[50];
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		unordered_map<string, int>mp;
		vector<P>E[550];
		scanf("%s%s%s", s, p, g);
		mp[s] = 0; mp[p] = 1; mp[g] = 2;
		rep(i, m) {
			int d, t; scanf("%s%s%d%d", a, b, &d, &t);
			if (mp.find(a) == mp.end())mp[a] = mp.size();
			if (mp.find(b) == mp.end())mp[b] = mp.size();
			E[mp[a]].push_back(P(d / 40 + t, mp[b]));
			E[mp[b]].push_back(P(d / 40 + t, mp[a]));
		}
		priority_queue<P, vector<P>, greater<P>>que;
		memset(d1, 0x3f, sizeof(d1));
		d1[0] = 0; que.push(P(0, 0));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (d1[p.second] != p.first)continue;
			for (P u : E[p.second]) {
				if (d1[u.second] > p.first + u.first) {
					d1[u.second] = p.first + u.first;
					que.push(P(d1[u.second], u.second));
				}
			}
		}
		memset(d2, 0x3f, sizeof(d2));
		d2[1] = 0; que.push(P(0, 1));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (d2[p.second] != p.first)continue;
			for (P u : E[p.second]) {
				if (d2[u.second] > p.first + u.first) {
					d2[u.second] = p.first + u.first;
					que.push(P(d2[u.second], u.second));
				}
			}
		}
		printf("%d\n", d1[1] + d2[2]);
	}
}

Measured memory_bytes: 3468
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	string s; cin >> s;
	int cnt_char[26] = {};
	rep (i, s.length())	{
		cnt_char[s[i] - 'a']++;
	}
	char ans = 'a';
	rep (i, sizeof(cnt_char) / sizeof(cnt_char[0])) {
		if (cnt_char[i] != 0) {
			ans++;
		} else {
			cout << ans << endl;
			return;
		}
	}
	cout  << "None" << endl;
	return;
}

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

Measured memory_bytes: 512