akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = 1e9;
const ll MOD = 998244353;

int dp[2][186][186][186];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W;cin>>H>>W;
  vector<string> A(H);
  repeat(i,H){
    cin>>A[i];
  }
  repeat(r1,H){
    repeat(c1,W){
      for(int r2=r1;r2<H;r2++){
        dp[0][r1][r2][c1]=c1;
      }
      for(int c2=c1;c2<W;c2++){
        dp[1][c1][c2][r1]=r1;
      }
    }
  }
  repeat(r1,H){
    repeat(c1,W){
      for(int c2=c1;c2<W&&A[r1][c1]==A[r1][c2];c2++)dp[0][r1][r1][c1]++;
      for(int r2=r1;r2<H&&A[r1][c1]==A[r2][c1];r2++)dp[1][c1][c1][r1]++;
    }
  }
  repeat(r1,H){
    repeat(c1,W){
      for(int r2=r1+1;r2<H&&A[r1][c1]==A[r2][c1];r2++){
        dp[0][r1][r2][c1] = min(dp[0][r1][r2-1][c1],dp[0][r2][r2][c1]);
      }
      for(int c2=c1+1;c2<W&&A[r1][c1]==A[r1][c2];c2++){
        dp[1][c1][c2][r1] = min(dp[1][c1][c2-1][r1],dp[1][c2][c2][r1]);
      }
    }
  }
/*
  repeat(r1,H){
    debug(r1);
    repeat(c1,W){
      debug(c1);
      for(int r2=r1;r2<H;r2++){
        debug(r2);
        debug(dp[0][0][r1][r2][c1]);
      }
    }
  }
*/
  //cerr<<"!!"<<endl;
  int ans=20;
  repeat(i,20){
    //debug(dp[0][i][0][H-1][0]);
    //debug(dp[0][i][0][H-1][6]);
    if(dp[0][0][H-1][0]>=W||dp[1][0][W-1][0]>=H){
      ans=i;
      break;
    }
    repeat(r1,H){
      repeat(c1,W){
        for(int r2=r1;r2<H;r2++){
          dp[0][r1][r2][c1] = dp[0][r1][r2][c1]<W?dp[0][r1][r2][dp[0][r1][r2][c1]]:W;
        }
        for(int c2=c1;c2<W;c2++){
          dp[1][c1][c2][r1] = dp[1][c1][c2][r1]<H?dp[1][c1][c2][dp[1][c1][c2][r1]]:H;
        }
        int r2=r1,c2=c1;
        for(c2=W-1;c2>=c1;c2--){
          for(;r2<dp[1][c1][c2][r1];r2++){
            dp[0][r1][r2][c1]=max(dp[0][r1][r2][c1],c2+1);
          }
        }
        c2=c1;
        for(r2=H-1;r2>=r1;r2--){
          for(;c2<dp[0][r1][r2][c1];c2++){
            dp[1][c1][c2][r1]=max(dp[1][c1][c2][r1],r2+1);
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 49408
object Main extends App{ 
  val in = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val x = in(0)
  val y = in(1)
  val sum = x + y
 
    if(sum >= 10){
      println("error")
    }else{
      println(sum)
  }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

const int INF = exp(2, 31) - 1;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void solve() {
  int n, q;
  cin >> n >> q;
  int m = 1;
  for (; m * m < n; m++);
  vi32 layer1(m, INF);
  vector<vi32> layer2(m, vi32(m, INF));
  rep(qi, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      int i = x / m;
      int j = x % m;
      layer2[i][j] = y;
      int ans = INF;
      rep(k, m) amin(ans, layer2[i][k]);
      layer1[i] = ans;
    }
    if (com == 1) {
      int ans = INF;
      if (x / m == y / m) {
        repic(i, x % m, y % m) {
          amin(ans, layer2[x / m][i]);
        }
      } else {
        repi(i, x % m, m) {
          amin(ans, layer2[x / m][i]);
        }
        repi(i, 0, y % m + 1) {
          amin(ans, layer2[y / m][i]);
        }
        repic(i, x / m + 1, y / m - 1) {
          amin(ans, layer1[i]);
        }
      }
      cout << ans << endl;
    }
  }
}



Measured memory_bytes: 3412
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i;
    static int map[NUM_MAX+1];
    for(i = 0; i < num; i++) {
        map[arr[i]]++;
    }

    int ans = 0;
    for(i = 1; i < NUM_MAX; i++) {
        ans = max(ans, map[i-1] + map[i] + map[i+1]);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  string t;
  cin>>t;
  int n = t.size();
  string ans = "";
  REP(i, n){
    if(t[i] == '?'){
      ans += 'D';
    }else{
      ans += t[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3980
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
n,a,b = LI()
ans = [min(a,b),max(0,a+b-n)]
print(ans[0],ans[1])
"""

#B
n = II()
a = S()
b = S()
c = S()
ans = 0
for i in range(n):
    if a[i] == b[i]:
        if b[i] == c[i]:
            continue
        else:
            ans += 1
    else:
        if b[i] == c[i] or c[i] == a[i]:
            ans += 1
        else:
            ans += 2
print(ans)

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 3444
/*
 * Author       : YangDavid
 * Created Time : 2019年07月14日 星期日 17时46分36秒
 */

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

const int maxn = 222222;
ll n, l, a[maxn];
int main() {
    scanf("%lld%lld", &n, &l);
    rep(i, n) scanf("%d", &a[i]);
    for(int i = 1; i < n; ++i) {
        if(a[i] + a[i + 1] >= l) {
            puts("Possible");
            for(int j = 1; j < i; ++j)
                printf("%d\n", j);
            for(int j = n - 1; j > i; --j)
                printf("%d\n", j);
            printf("%d\n", i);
            return 0;
        }
    }
    puts("Impossible");

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>

using tree_t = std::vector<std::vector<int>>;

int main() {
  int N;

  std::cin >> N;

  tree_t tree(N);
  std::vector<std::pair<int, int>> edges;
  edges.reserve(N-1);

  for (int i=0; i<N-1; i++) {
    int a, b;
    std::cin >> a >> b;

    edges.emplace_back(a-1, b-1);

    tree[a-1].push_back(b-1);
    tree[b-1].push_back(a-1);
  }

  std::vector<int> C(N);

  for (int i=0; i<N; i++) {
    std::cin >> C[i];
  }

  std::sort(C.begin(), C.end(), std::greater<int>());

  int root = std::distance(tree.cbegin(),
                           std::max_element(tree.cbegin(), tree.cend(),
                                            [](auto a, auto b) {
                                              return a.size() < b.size();
                                            }));
  std::queue<int> que;
  std::vector<int> ans(N);

  que.push(root);
  int i = 0;

  while(! que.empty()) {
    auto cur = que.front();
    que.pop();

    ans[cur] = C[i];
    i++;

    for (auto n: tree[cur]) {
      if (ans[n] == 0) que.push(n);
    }
  }

  int score = 0;

  for (auto p: edges) {
    int a, b;
    std::tie(a, b) = p;
    score += std::min(ans[a], ans[b]);
  }

  std::cout << score << std::endl;

  for (int i=0; i<N; i++) {
    std::cout << ans[i];
    if (i < N-1)
      std::cout << ' ';
    else
      std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 1152
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
// $%D%$.$%M%$.$%Y%$
// $%h%$:$%m%$:$%s%$

#pragma GCC optimize("O3")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define ld long double
#define rep(i,a,n) for (int i=(int)(a);i<(int)(n);i++)
#define per(i,a,n) for (int i=(int)(n-1);i>=(int)(a);i--)
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define fi first
#define se second


const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};


template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int main() {
    int n;
    cin >> n;
    ll cnt0 = 1, cnt1 = 1, cnt2 = 1;
    for (int i = 0; i < n; ++i) {
        cnt0 = (1ll * cnt0 * 10) % MOD;
        cnt1 = (1ll * cnt1 * 9) % MOD;
        cnt2 = (1ll * cnt2 * 8) % MOD;
    }

    cout << ((cnt0 - (cnt1 - cnt2) - (cnt1 - cnt2) - cnt2) % MOD + MOD) % MOD << '\n';
}

Measured memory_bytes: 3616
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars,
        t: chars
    }
    let mut ans = 0;
    for i in 0..3 {
        if s[i] == t[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int i = 0;
  int c = 0;
  if(b==1){
    cout << 0 << "\n";
    return 0;
  }
  while(c<b){
    if(i != 0){
      c -= 1;
    }
    i++;
    c += a;
  }
  cout << i << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std ;

char s[100];
int n , res ;

int main ()
{
    int i , j , k ;
    gets(s+1),n=strlen(s+1);
    for ( i=1 ; i<=n ; i++ ) 
        for ( j=i ; j<=n ; j++ ) 
        {
            int flag=1 ;
            for ( k=i ; k<=j ; k++ ) flag&=(s[k]=='A'||s[k]=='T'||s[k]=='C'||s[k]=='G');
            if ( flag ) res=max(res,j-i+1);
        }
    printf("%d\n",res);
    return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int n;
int ba[365][4][4];
bool memo[365][3][3][7*7*7*7];
bool visited[365][3][3][7*7*7*7];

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

int hogex[] = {0, 0, 2, 2};
int hogey[] = {0, 2, 0, 2};

bool solve(int day, int y, int x, int S) {
  if (visited[day][y][x][S]) return memo[day][y][x][S];
  visited[day][y][x][S] = 1;
  
  REP(i, 2) 
    REP(j, 2)
      if (ba[day][y+i][x+j]) return memo[day][y][x][S]=0;

  if (day == n-1) return memo[day][y][x][S]=1;

  // l÷ÌîñvZ
  int tmp = S;
  int norain[4];
  REP(i,4) {
    norain[i] = tmp%7;
    tmp /= 7;
  }
  // ÌúÖ
  REP(i, 4) {
    int xx = x, yy = y;
    if (i) {
      xx+=dx[i]; yy+=dy[i];
    }
    while(0<=xx&&xx<=2&&0<=yy&&yy<=2) {
      int nextS = 0;
      int tmp = 1;
      bool f = 0;
      REP(j, 4) {
        if (!(xx==hogex[j] && yy==hogey[j])) {
          if (norain[j] == 6) f = 1;
          nextS += tmp * (norain[j] + 1);
        }
        tmp *= 7;
      }
      if (!f && solve(day+1, yy, xx, nextS))
        return memo[day][y][x][S]=1;
      yy += dy[i];
      xx += dx[i];
    }
  }
  return memo[day][y][x][S]=0;
}

int main() {
  while(cin>>n,n) {
    REP(i, n) REP(j,4) REP(k,4) 
      cin >> ba[i][j][k];
    memset(visited,0,sizeof(visited));
    cout <<  (solve(0, 1, 1, 400)? 1: 0) << endl;
  }
}

Measured memory_bytes: 15000
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  double xa,ya,ra,xb,yb,rb;
  int n;
  cin >> n;
  while(n--){
    cin >>  xa >> ya >> ra >> xb >> yb >> rb;
    double d = sqrt(pow(xa - xb,2) + pow(ya - yb,2));
    if(d>ra+rb)cout<<0<<endl;
    else if(ra-rb>d)cout<<2<<endl;
    else if(rb-ra>d)cout<<-2<<endl;
    else cout<<1<<endl;

  }
  return 0;
}

Measured memory_bytes: 1232
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int p[]=new int[n];
		for(int i=0;i<n;i++) {
			p[i]=sc.nextInt();
		}
		int count=0;
		sc.close();
		for(int j=1;j<(n-1);j++) {
			if(p[j-1]<p[j]&&p[j]<p[j+1]) {
				count++;
			}else if(p[j-1]>p[j]&&p[j]>p[j+1]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22868
#include <stdio.h>
#include <stdbool.h>

void doublets_occur(void) {
  bool yes = false;
  int n;
  scanf("%d", &n);
  bool arr[n];
  for (int i = 0; i < n; i++) {
    int d1, d2;
    scanf("%d%d", &d1, &d2);
    if (d1 == d2) {
      arr[i] = true;
    } else {
      arr[i] = false;
    }
  }
  for (int i = 0; i < n - 2; i++) {
    if (arr[i] && arr[i+1] && arr[i+2]) {
      yes = true;
      break;
    }
  }
  if (yes) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}


int main(void) {
  doublets_occur();
  return 0;
}


Measured memory_bytes: 1660
#include<iostream>

int main()
{
    std::string s;
    std::cin >> s;
    int counter = 0;
    if(s[0] == '1') ++counter;
    if(s[1] == '1') ++counter;
    if(s[2] == '1') ++counter;

    std::cout << counter << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int mod=1e9+7;
#define int ll

//Union-Find木の実装（蟻本より）
const int MAX_N=1000000;
int par[MAX_N];//親
int Rank[MAX_N];//木の深さ
int size[MAX_N];//子と自身の合計数（自身が根の時には集合のサイズを表す）

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        Rank[i]=0;
        size[i]=1;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)    return ;
    if(Rank[x]<Rank[y]){
        par[x]=y;
        size[y]+=size[x];
    }else{
        par[y]=x;
        size[x]+=size[y];
        if(Rank[x]==Rank[y])    Rank[x]++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m);
    for(ll i=0;i<m;i++){
        cin >> a[i] >> b[i];
    }
    vector<ll> ans;
    ans.push_back(n*(n-1)/2);
    init(n);
    for(ll i=m-1;i>=1;i--){
        if(!same(a[i],b[i])){
            ans.push_back(ans[ans.size()-1]-size[find(a[i])]*size[find(b[i])]);
        }else{
            ans.push_back(ans[ans.size()-1]);
        }
        unite(a[i],b[i]);
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<m;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12788
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    int brr[n-1];
    rep(i,0,n-1)cin>>brr[i];
    int ans=brr[0];
    rep(i,1,n-1)
    {
        ans+=min(brr[i],brr[i-1]);
    }
    ans+=brr[n-2];
    cout<<ans;


    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    ll ans = GCD(a[0], a[1]);
    for (int i = 0; i < n; i++){
        ans = GCD(ans, a[i]);
    }

    cout << ans << endl;

    return 0;
}





















Measured memory_bytes: 1024
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
#define ll long long
using namespace std;
long long c[51][51];

int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  int a[51];
  bool flag = false;
  REP(i, n) {
    scanf("%d", &a[i]);
    if (a[i] % 2) flag = true;
  }
  ll ans = 1;
  if (flag) {
    REP(i, n - 1) ans *= 2;
    cout << ans << endl;
  } else {
    REP(i, n) ans *= 2;
    if (p == 0)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;
const int mod = 1e9+7;
int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m+1];
  for(int i = 0;i <= n;i++) {
    for(int j = 0;j <= m;j++) {
      if(i==0||j==0) dp[i%2][j] = 0;
      else {
        if(a[i-1] == b[j-1]) dp[i%2][j] = 1 + dp[1-i%2][j-1];
        else dp[i%2][j] = max(dp[i%2][j-1], dp[1-i%2][j]);
      }
    }
  }
  return dp[n%2][m];
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i,2,n+1) ans = (ans*i)%mod;
  return ans;
}

int main() {
  int n;
  cin>>n;
  // int sum = 0;
  int a[n];
  frn(i,n) {
    cin>>a[i];
  }
  int s = accumulate(a,a+n,0);
  int k;
  cin>>k;
  vector<int> ans;
  while(k--) {
    int x,y;
    cin>>x>>y;
    ans.pb(s - a[x-1] + y);
  }
  trav(x,ans) {cout<<x;nl;}
}



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

void Cin(int X[],int N) {
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
}

int main() {
	int N;
	int A[20], B[20], C[19];
	int Score = 0;

	cin >> N;

	Cin(A, N);
	Cin(B, N);
	Cin(C, N - 1);

	Score += B[A[0] - 1];
	
	for (int i = 1; i < N; i++) {
		Score += B[A[i]-1];
		if (A[i] - A[i - 1] == 1) Score += C[A[i - 1] - 1];
	}

	cout << Score << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MOD 1000000007

int c[2001][2001];

int main(void) {
	int n, k;
	scanf("%d%d", &n, &k);

	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= i; j++) {
			if (i == 0 || j == 0) c[i][j] = 1;
			else c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;
		}
	}

	int r = n-k;
	for (int i = 1; i <= k; i++) {
		int rc = c[r+1][i];
		int bc = c[k-1][i-1];
		printf("%lld\n", ((long long int) rc * bc) % MOD);
	}
}


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

string s[11000];

int cnt[10];

int main() {
#ifdef Hwang_Baek_I
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j < s[i].length(); j++) if (s[i][j - 1] == 'A' && s[i][j] == 'B') ans++;
		if (s[i][0] == 'B') cnt[1]++;
		if (s[i][s[i].length() - 1] == 'A') cnt[0]++;
		if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') cnt[2]++;
	}
	cnt[0] -= cnt[2];
	cnt[1] -= cnt[2];
	ans += max(cnt[2] - 1, 0);
	if (cnt[2]) {
		if (cnt[0]) ans++, cnt[0]--;
		if (cnt[1]) ans++, cnt[1]--;
	}
	ans += min(cnt[0], cnt[1]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,sum=0,i;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        cin>>b[i];
    }
    for(i=0;i<n-1;i++){
        cin>>c[i];
    }
    c[n-1]=0;
    for(i=0;i<n;i++){
        
        sum=sum+b[a[i]-1];
        if(i>0&&a[i]==a[i-1]+1)
        sum=sum+c[a[i-1]-1];
    }
    cout<<sum;
    
  return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;
    ll a[110]; 
    rep(i, n) cin >> a[i];
    ll dp[100100];
    rep(j, k+1) {
        ll lose=0, cnt=0;
        rep(i, n) {
            if (j - a[i] >= 0) {
                cnt++;
                if(dp[j - a[i]] == 0) lose++;
            }
        }
        if (cnt == 0 || lose == 0) dp[j] = 0;
        else dp[j] = 1;
    }

    if (dp[k] == 1) cout << "First" << endl;
    else cout << "Second" << endl;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    vector<LL> A(N), B(N);
    FOR(i, 0, N) {
        cin >> A[i];
    }
    FOR(i, 0, N) {
        cin >> B[i];
    }


    bitset<64> ans;
    FOR(k, 0, 30) {
        vector<LL> C(N), D(N);

        LL t = 1LL << k;
        FOR(i, 0, N) {
            C[i] = A[i] % (2 * t);
            D[i] = B[i] % (2 * t);
        }

        sort(ALL(C));
        sort(ALL(D));

        LL num = 0;
        FOR(i, 0, N) {
            num += lower_bound(ALL(D), 2 * t - C[i]) - lower_bound(ALL(D), 1 * t - C[i]);
            num += lower_bound(ALL(D), 4 * t - C[i]) - lower_bound(ALL(D), 3 * t - C[i]);
        }
        ans[k] = num % 2;
    }

    print(ans.to_ulong());
    return 0;
}

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

int main() {
    ll X;
    cin >> X;
    
    ll a = 0, b = 0;
    for (int i = -1000; i <= 1000; i++) {
        for (int j = -1000; j <= 1000; j++) {
            if (pow(i, 5) - pow(j, 5) == X) {
                a = i;
                b = j;
            }
        }
    }
    
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3976
import bisect
a,b,q = map(int,input().split())
s = [-float("infinity")] + [int(input()) for _ in range(a)] + [float("infinity")]
t = [-float("infinity")] + [int(input()) for _ in range(b)] + [float("infinity")]
q = [int(input()) for _ in range(q)]

for x in q:
  i = bisect.bisect(s,x)
  j = bisect.bisect(t,x)
  ans = float("infinity")

  for irange in [s[i],s[i-1]]:
    for jrange in [t[j],t[j-1]]:
      temp1 = abs(irange - x) + abs(jrange - irange)
      temp2 = abs(jrange - x) + abs(jrange - irange)
      ans = min(ans,temp1,temp2)
  print(ans)

Measured memory_bytes: 16144
#include<bits/stdc++.h>
#define MAX_P 1020
#define MAX_V 220
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-15)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

class edge{
  public:
    int to,d,v;
    edge(int to,int d,int v):to(to),d(d),v(v){}
};

int n,m,p;
vector<edge> e[MAX_V];
double dp[MAX_V][MAX_P];

double solve(){
  double res=0.0;
  FOR(i,0,n)FOR(j,0,p+1)dp[i][j]=-1;
  dp[0][0]=0;
  FOR(i,0,p+1){
    FOR(j,0,n){
      if(dp[j][i]==-1)continue;
      FOR(k,0,e[j].size()){
        edge E=e[j][k];
        int t=min(E.d,p-i);
        int d=t+i;
        dp[E.to][d]=max(dp[E.to][d],dp[j][i]+(double)t*E.v/E.d);
      }
    }
  }
  FOR(i,0,n)res=max(res,dp[i][p]);
  return res*2.0;
}

int main()
{
  cin>>n>>m>>p;
  FOR(i,0,m){
    int s,t,d,v;
    cin>>s>>t>>d>>v;
    s--;t--;d*=2;
    e[s].pb(edge(t,d,v));
    e[t].pb(edge(s,d,v));
  }
  pd(solve());
  return 0;
}

Measured memory_bytes: 5136
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  string s; cin >> s;
  
  int a =0 , b = 0;
  rep(i,s.size()){
    if(s[i] == '0') a += 2;
    else b += 2;
  }
  
  cout << min(a,b) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N; cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	ll l = 2,r = 2;
	for(int i = N-1; i >= 0; i--){
		ll d = (ll)(l+A[i]-1)/A[i]*A[i];
		if(d > r || d < l){
			cout << -1 << endl;
			return 0;
		}
		l = d,r = (ll)r/A[i]*A[i]+A[i]-1;
	}
	cout << l << " " << r << endl;
}



Measured memory_bytes: 768
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 998244353;
const int N = int(3e5) + 999;
#define int long long int

int n;
int arr[3001];
int dp[3005][3005];

int solve(int index,int s){

	if(s<0)
		return 0;

	if(index==n)
		if(s==0)
			return 1;
		else
			return 0;

	if(dp[index][s]!=-1)
		return dp[index][s];

	int ans = (solve(index+1,s-arr[index]))%MOD+2*(solve(index+1,s))%MOD;
	ans%=MOD;

	return dp[index][s]=ans;

}


int32_t main(){
    IOS;
    int s;
	memset(dp,-1,sizeof dp);

	cin>>n>>s;

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

	solve(0,s);
	int ans = solve(0,s);
	
	cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 74328
N = int (input ())
l = {}
for i in range (N):
  a = int (input ())
  l[i+1] = a
b = 1
x = 0
for i in range (N+1):
  b = l[b]
  x += 1
  if b == 2:
    print (x)
    x = 0
    break
if x != 0:
  print (-1)

Measured memory_bytes: 22120
res = [[0,0] for i in range(4)]
while True:
    try:
        for i, v in enumerate(map(float, raw_input().split())):
            if 1.1 <= v:
                res[0][i] = res[0][i]+1
            elif 0.6 <= v:
                res[1][i] = res[1][i]+1
            elif 0.2 <= v:
                res[2][i] = res[2][i]+1
            else:
                res[3][i] = res[3][i]+1
    except EOFError:
        for v in res:
            print v[0], v[1]
        break

Measured memory_bytes: 4256
#include<stdio.h>
#define MAX_N 200000
int par[MAX_N];
int original_par[MAX_N];
int rank[MAX_N];
int query_list[MAX_N][2];

void init(int n){
  int i;
  for(i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else {
    return par[x] = find(par[x]);
  }
}
void unite(int x,int y){
 // x =find(x);
//  y =find(y);
  if(x==y){
    return ;
  }
  par[y] = x;
  /*
  if(rank[x] < rank[y]){
    par[x] = y;
  }else {
    par[y] = x;
    if(rank[x] == rank[y])rank[x]++;
  }
  */
}
int same(int x,int y){
  return find(x)==find(y);
}
int main(){
  int N,Q;
  long long int ans;
  int i,j,k;
  int marked_list[MAX_N];
//??¨??¨????????§?????????????????§1?????¬???
  while(1){
    scanf("%d %d",&N,&Q);
    if(N==0&&Q==0)break;
    for(i=0;i<N;i++){
      marked_list[i]=0;
    }marked_list[0]=1;
    original_par[0]=0;
    ans=0;

    for(i=1;i<N;i++){
      scanf("%d\n",&original_par[i]);
      original_par[i]--;
    }
    for(i=0;i<Q;i++){
      char bc;
      scanf("%c %d\n",&bc,&query_list[i][1]);
      query_list[i][0] = bc;
      query_list[i][1]--;
    }

    init(N);
    for(i=0;i<Q;i++){
      if(query_list[i][0]=='M'){
				if(marked_list[query_list[i][1]]==1){
					query_list[i][0]='N';
				}
        marked_list[query_list[i][1]]=1;
      }
    }
    for(i=0;i<N;i++){
      if(0==marked_list[i]){
        unite(original_par[i],i);
      }
    }
    for(i=Q-1;i>=0;i--){
      if(query_list[i][0]=='Q'){
        int q_a = find(query_list[i][1])+1;
        ans += q_a;
      //  printf(":%d\n",ans);
      }else if(query_list[i][0]=='M'){
        int m = query_list[i][1];
        unite(original_par[m],m);
      }
    }
    printf("%lld\n",ans);
  }
  return 0;

}

Measured memory_bytes: 3548
from itertools import permutations

n = int(input())
ppp = tuple(map(int, input().split()))
qqq = tuple(map(int, input().split()))
a, b = -1, -1
for i, rrr in enumerate(permutations(range(1, n + 1))):
    if a == -1 and ppp == rrr:
        a = i
    if b == -1 and qqq == rrr:
        b = i
    if a != -1 and b != -1:
        break
print(abs(a - b))


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
  char ans[30]={};
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++){
    ans[s[i]-'a']++;
  }
  for(int i=0; i<30; i++){
    if(ans[i]%2!=0){cout << "No" <<endl;return 0;}
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

void trace(int a[], int n) {
    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << a[i];
    }
    cout << endl;
}

void bubbleSort(int a[], int n) {
    int count = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int i = n - 1; i > 0; i--) {
            if (a[i] < a[i - 1]) {
                int tmp = a[i];
                a[i] = a[i - 1];
                a[i- 1] = tmp;
                flag = true;
                count++;
            }
        }
    }
    trace(a, n);
    cout << count << endl;
}

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

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

    bubbleSort(a, n);

    return 0;
}


Measured memory_bytes: 3116
program Strawberry_Cakes
  implicit none
  integer :: h, w, k, i, j, x
  integer, dimension(300,300) :: a = 0, b = 0
  character(300) :: s
  read(*,*) h, w, k
  do i = 1, h
    read(*,*) s
    do j = 1, w
      if (s(j:j) == "#") a(i,j) = 1
    end do
  end do
  k = 0
  do j = 1, w
    x = 0
    do i = 1, h
      if (a(i,j) == 0) cycle
      k = k+1
      b(x+1:h,j:w) = k
      x = i
    end do
  end do
  if (b(1,1) == 0) then
    do j = 1, w
      if (b(1,j) == 0) cycle
      do i = 1, h
        b(i,1:j-1) = b(i,j)
      end do
      exit
    end do
  end if
  do i = 1, h
    write(*,'(i0)',advance='no') b(i,1)
    do j = 2, w
      write(*,'(x,i0)',advance='no') b(i,j)
    end do
    write(*,*)
  end do
end program Strawberry_Cakes

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

class UF {
private:
    int par[100000];
    int _size[100000];
public:
    UF(int n) {
        for (int i=0;i<n;i++) {
            par[i]=i;
            _size[i]=1;
        }
    }
    int find(int n) {
        if (par[n]==n)
            return n;
        return par[n]=find(par[n]);
    }
    void unite(int a,int b) {
        a=find(a),b=find(b);
        if (a==b)
            return;
        par[b]=a;
        _size[a]+=_size[b];
    }
    int size(int n) {
        return _size[find(n)];
    }
};

int main() {
    int n,m,k;cin>>n>>m>>k;
    int c[n]{};
    UF uf(n);
    for (int i=0;i<m;i++) {
        int a,b;cin>>a>>b;
        a--,b--;
        uf.unite(a,b);
        c[a]++,c[b]++;
    }
    for (int i=0;i<k;i++) {
        int a,b;cin>>a>>b;
        a--,b--;
        if (uf.find(a)==uf.find(b))
            c[a]++,c[b]++;
    }
    for (int i=0;i<n;i++)
        cout<<uf.size(i)-c[i]-1<<endl;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    ll x, y;
    cin >> x >> y;
    int res = 1;
    while(1){
        x *= 2;
        if(x > y) break;
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
ans = [-1*int(input())]
for i in range(n-1):
  a=int(input())
  a=-1*a
  if ans[-1]<=a:
    ans.append(a)
  else:
    b = bisect.bisect_right(ans,a)
    ans[b]=a
print(len(ans))

Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n; cin >> n;
  const int mx=100;
  vi ans(n+1,0);
  orep(x,mx) orep(y,mx) orep(z,mx) {
    if(x*x + y*y+z*z+x*y+y*z+z*x > n) continue;
    ans[x*x + y*y+z*z+x*y+y*z+z*x]++;
  }
  orep(i,n) cout << ans.at(i) << endl;

  return 0;
}


Measured memory_bytes: 3664
list_alpha = [x for x in 'abcdefghijklmnopqrstuvwxyz']
c_list = ''
    
while True:
    try:
        c_list += input().lower()
    except EOFError:
        break

for l in list_alpha:
    print('{} : {}'.format(l,c_list.lower().count(l)))



Measured memory_bytes: 5568
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
bool pairComparesecond(const p& firstElof, const p& secondElof)
{
    return firstElof.second > secondElof.second;
}
	int a[10];
	string dp[10010];
const string mininf="-";
	
void stringmax(string &a,string b){
	if(a==mininf)a=b;
	else if(a.size()<b.size())a=b;
	else if(a.size()==b.size()){
		if (a<b) a=b;
	}
}

int main(){
	ll n,m;
	cin>>n>>m;
	int d[10]={0,2,5,5,4,5,6,3,7,6};
	rep(i,0,m){
		ll x;
		cin>>x;
		a[x]++;
	}
	rep(i,0,10010)dp[i]=mininf;
	dp[0]="";
	rep(i,0,n+1){
		rep(j,0,10){
			if(a[j]==1){
				int t=j;
				if (dp[i]==mininf) continue;
				stringmax(dp[i+d[t]],dp[i]+(char)('0'+j));
			
			}
		}
	}
	cout<<dp[n]<<endl;
	
}

Measured memory_bytes: 43776
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;

const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    int ans =0;
    for(int i =1;i*i<=m;i++){
        if(i==0)continue;
        if(m%i!=0)continue;
        if (i >= n)
      {
        ans = max(ans, m / i);
      }
        if(m/i<n)continue;
        ans=max(ans,i);
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
count = 0
flag = True
for i in range(n):
    if p[i] != i+1:
        index = p[i]-1
        if p[index] == i+1:
            count += 1
        else:
            flag = False
            break
if flag:
    if count == 0 or count == 2:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
// are
int main() {
	int n,d,l = 0,a = 0;
	cin >> n >> d;
	vector<vector<int>> po(n,vector<int>(d));
	vector<double> pod(n*(n-1)/2);
	for (int i = 0; i < n; i++) {
    	for (int j = 0; j < d; j++) {
			cin >> po.at(i).at(j);
    	}
	}
	for (int i = 0; i < n-1; i++){
		for (int j = i+1; j < n; j++){
			for (int k = 0; k < d; k++){
			pod.at(l) += pow(po.at(i).at(k) - po.at(j).at(k),2);
			}
		pod.at(l) = sqrt(pod.at(l));
		l++;
		}
	}
	for (int i = 0; i < l; i++){
		if(ceil(pod.at(i)) == floor(pod.at(i))) a++;
	}
	
	cout << a <<endl;
}

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

bool between(ll a, ll b, ll c){
	if(a <= b && b <= c) return true;
	if(a >= b && b >= c) return true;
	return false;
}

ll long_abs(ll a){
	if(a < 0) return -a;
	return a;
}

int main(void){
	int N, K;
	ll x[50], y[50];
	scanf("%d %d", &N, &K);
	for(int i = 0; i < N; i++) scanf("%lld %lld", &x[i], &y[i]);
	ll ans = LONG_MAX;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			ll width = long_abs(x[i] - x[j]);
			for(int k = 0; k < N; k++){
				for(int l = 0; l < N; l++){
					ll height = long_abs(y[k] - y[l]);
					int num_inside_point = 0;
					for(int m = 0; m < N; m++){
						if(between(x[i], x[m], x[j]) && between(y[k], y[m], y[l])) num_inside_point++;
					}
					if(num_inside_point >= K && width * height < ans) ans = width * height;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384