akhauriyash/Code-Regression huggingface dataset:
<?php
$N = int();
for($i = 1; $i < $N; ++$i){
  list($from, $to, $d) = array_map("intval", explode(" ", trim(fgets(STDIN))));
  $G[$from][$to] = $d;
  $G[$to][$from] = $d;
}
list($Q, $K) = ints();
$distance = array_fill(1, $N, PHP_INT_MAX);
$current[] = $K;
$distance[$K] = 0;
while($current){
    $f = array_pop($current);
    foreach($G[$f] as $next => $dd){
        if($distance[$next] == PHP_INT_MAX){
            $distance[$next] = $distance[$f] + $dd;
            $current[] = $next;
        }
    }
}

while($Q--){
    list($from, $to) = ints();
    $result[] = $distance[$from]+$distance[$to];
}
echo implode("\n", $result),"\n";


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 63088
public class Main {
  private static void solve() {
    int n = ni();
    int[] h = na(n);
    int ret = 0;
    int last = 0;
    for (int v : h) {
      if (last < v) {
        ret += v - last;
      }
      last = v;
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using namespace std;

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


typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;


const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

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


int main(){
  ll n,count=0;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  
  rep(i,n){
	if(a[i]!=i+1){
		count++;
    }
  }
  
  cout<<((count==0||count==2)?"YES":"NO")<<endl;

  
}
  
  
  
  


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,a[SZ],s[SZ];
bool ok(int x)
{
	for(int i=1;i<n+n;++i) s[i]=a[i]>=x;
	if(s[n-1]==s[n]||s[n]==s[n+1]) return s[n];
	int l=n,r=n;
	while(l>1&&s[l]!=s[l-1]) --l;
	while(r<n+n-1&&s[r]!=s[r+1]) ++r;
	if(l+r>=n+n) return s[l];
	else return s[r];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n+n;++i) scanf("%d",a+i);
	int l=1,r=n+n;
	while(l<r)
	{
		int m=(l+r+1)>>1;
		if(ok(m)) l=m; else r=m-1;
	}
	printf("%d\n",l);
}



Measured memory_bytes: 3200
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 10000007;
const int inf = 1001001001;



int main(void) {
  int n,k,s;
  cin >> n >> k >> s;
  vi a(n);
  rep(i,k){
    a[i] = s;
  }
  rep2(i,k,n){
    if(s!=1000000000){
      a[i] = 1000000000;
    }
    else a[i] = 999999999;
  }
  rep(i,n) cout << a[i] << endl;
}


Measured memory_bytes: 1664
#include <stdio.h>
int main(){
	int q,t[500],i,j=0,cnt=0,s[10000],n;
	
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&s[i]);

	scanf("%d",&q);
	for(i=0;i<q;i++) scanf("%d",&t[i]);
	
/*	for(i=0;i<q;i++){
		while(s[j]!=t[i]) j++;
		if(j!=n) cnt++;	
	}
	*/
	for(i=0;i<q;i++){
		for(j=0;j<n;j++){
			if(s[j]==t[i]){
				cnt++;
				break;
			}
		}
	}

	printf("%d\n",cnt);
	
	return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main(){
  int n, c;
  cin >> n >> c;
  int col[c][c];
  for(int i=0; i<c; ++i) for(int j=0; j<c; ++j) cin >> col[i][j];
  int cnn[n][n];
  for(int i=0; i<n; ++i) for(int j=0; j<n; ++j){
    cin >> cnn[i][j];
    --cnn[i][j];
  }
  vector<vector<int>> d(c, vector<int>(3,0));
  for(int i=0; i<c; ++i) for(int j=0; j<n; ++j) for(int k=0; k<n; ++k){
    if((j+k)%3 == 0) d[i][0] += col[cnn[j][k]][i];
    if((j+k)%3 == 1) d[i][1] += col[cnn[j][k]][i];
    if((j+k)%3 == 2) d[i][2] += col[cnn[j][k]][i];
  }
  
  int ans = INF;
  for(int i=0; i<c; ++i) for(int j=0; j<c; ++j){
    if(j == i) continue;
    for(int k=0; k<c; ++k){
      if(k == i || k == j) continue;
      int nans = d[i][0] + d[j][1] + d[k][2];
      ans = min(ans, nans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4612
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
int n;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll sum[n+1];
    ll sum1=0;
    for (int i = 0; i < n; i++)
    {
        sum[i]=sum1;
        ll temp;
        cin >> temp;
        sum1+=temp;
        a.push_back(temp);
    }
    sum[n]=sum1;
    map<ll,ll> m;
    ll ans = 0;
    for(int i=0;i<=n;i++){
        m[sum[i]]++;
        ans+=m[sum[i]]-1;
    }
    cout << ans << "\n";
}



Measured memory_bytes: 15856
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from math import gcd
from functools import reduce
def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    if reduce(gcd, A) != 1:
        print("not coprime")
        return

    M = max(A)
    dist = [0] * (M + 1)
    for a in A:
        dist[a] += 1

    sieve = [True] * (M + 1)
    for p in range(2, M + 1):
        if not sieve[p]:
            continue
        c = 0
        for i in range(p, M + 1, p):
            c += dist[i]
            sieve[i] = False
        if c >= 2:
            print("setwise coprime")
            return

    print("pairwise coprime")
resolve()

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

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

  int ans = 0;
  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N; y++) {
      for (int z = 0; z <= N-x-y; z++) {
        if ((x+y+z)==N) {
          int sum = 10000*x + 5000*y + 1000*z;
          if (sum==Y) {
		     cout << x << " " << y << " " << z << endl;
           	 return 0;
          }
        }
      } 
    } 
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int M;
int A[300][300];
int ok[300];
int cnt[300];
int p[300];
int main(){
  int i, t_ynMSdg;
  int res;
  rd(N);
  rd(M);
  for(i=(0);i<(N);i++){
    {
      int Q5VJL1cS;
      for(Q5VJL1cS=(0);Q5VJL1cS<(M);Q5VJL1cS++){
        rd(A[i][Q5VJL1cS]);A[i][Q5VJL1cS] += (-1);
      }
    }
  }
  for(i=(0);i<(M);i++){
    ok[i] = 1;
  }
  for(i=(0);i<(N);i++){
    cnt[A[i][0]]++;
  }
  res = N;
  for(t_ynMSdg=(0);t_ynMSdg<(M-1);t_ynMSdg++){
    {
      int tU__gIr_;
      int a2conNHc;
      if(M==0){
        a2conNHc = 0;
      }
      else{
        a2conNHc = cnt[0];
        for(tU__gIr_=(1);tU__gIr_<(M);tU__gIr_++){
          a2conNHc = max_L(a2conNHc, cnt[tU__gIr_]);
        }
      }
      chmin(res, a2conNHc);
    }
    {
      int YREPHmFM;
      int jZyWAPpY = 0;
      int jbtyPBGc;
      int ZIeRIny5;
      int iMWUTgY_;
      for(YREPHmFM=(0);YREPHmFM<(((M)-1)+1);YREPHmFM++){
        ZIeRIny5 = cnt[YREPHmFM];
        if(jZyWAPpY==0 || jbtyPBGc<ZIeRIny5){
          jbtyPBGc = ZIeRIny5;
          jZyWAPpY = 1;
          iMWUTgY_ = YREPHmFM;
        }
      }
      ok[iMWUTgY_] = 0;
    }
    for(i=(0);i<(N);i++){
      cnt[A[i][p[i]]]--;
      while(ok[A[i][p[i]]]==0){
        p[i]++;
      }
      cnt[A[i][p[i]]]++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// int N, M, A[300][300];
// int ok[300], cnt[300], p[300];
// {
//   int res;
//   rd(N,M);
//   rep(i,N) rd((A[i]--)(M));
//   rep(i,M) ok[i] = 1;
//   rep(i,N) cnt[A[i][0]]++;
//   res = N;
//   rep(M-1){
//     res <?= max(cnt(M));
//     ok[argmax(cnt(M))] = 0;
//     rep(i,N){
//       cnt[A[i][p[i]]]--;
//       while(ok[A[i][p[i]]]==0) p[i]++;
//       cnt[A[i][p[i]]]++;
//     }
//   }
//   wt(res);
// }


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

pair<int, int> mod(int a, int b){
    int d = a/b;
    int r = a%b;
    if(r<0){
        d++;
        r = a-(d*b);
    }


    return make_pair(d, r);
}
int main(){
    int32_t n;
    int bits[32] = {0};
    scanf("%d", &n);
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    int i=32;
    while(n != 0){
        pair<int, int> div = mod(n, -2);
        n = div.first;
        bits[--i] = div.second;
    }

    int prnt = false;
    for(int i=0; i<32; i++){
        if(!prnt && bits[i]) prnt = true;
        if(prnt) cout << bits[i];
    }
    cout << endl;






}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

int n, W;
int weight[5000], value[5000]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
int dp[5000][5000] = {0}; // テーブルの初期値はすべて 0 にしておきます

// 復元用テーブル
int prev_w[5000][5000];

int main() {
  // 入力受け取り
  cin >> n >> W;
  for (int i = 0; i < n; ++i) cin >> weight[i] >> value[i];
  vector<pair<p, int>> tmp(n);
  for (int i = 0; i < n; i++) {
    tmp[i] = {{value[i], weight[i]}, i};
  }

  for (int i = 0; i < n; ++i) {
    for (int w = 0; w <= W; ++w) {
      // i 番目の品物を選ぶ場合を考える
      if (w >= weight[i]) {
        if (dp[i+1][w] < dp[i][w-weight[i]] + value[i]) {
          dp[i+1][w] = dp[i][w-weight[i]] + value[i];
          prev_w[i+1][w] = w - weight[i];
        }
      }

      if (dp[i+1][w] < dp[i][w]) {
        dp[i+1][w] = dp[i][w];
        prev_w[i+1][w] = w;
      }
    }
  }

  // 最適値の出力
  // cout << dp[n][W-1] << endl;


  int cur_w = W-1;
  vector<int> used;
  for (int i = n-1; i >= 0; --i) {
    if (prev_w[i+1][cur_w] == cur_w - weight[i]) {
      used.push_back(i);

      // cout << i << " th item (weight = " << weight[i] << ", value = " << value[i] << ")" << endl;
    }

    // 復元テーブルをたどる
    cur_w = prev_w[i+1][cur_w];
  }
  ll res = dp[n][W-1];
  sort(RALL(tmp));

  for (int i = 0; i < n; i++) {
    bool flag = true;
    for(auto a : used){
      if(a == tmp[i].second){
        flag = false;
        break;
      }
    }
    if(flag){
      res += tmp[i].first.first;
      break;
    }
  }
  cout << res << endl;


}


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

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      int N = Integer.parseInt(br.readLine());
      String[] S = br.readLine().split(" ");
      int[] val = new int[N];
      for(int i = 0; i < N-1; i++){
        int A = Integer.parseInt(S[i])-1;
        val[A]++;
      }
      for(int i : val){
        System.out.println(i);
      }
    }catch(Exception e){
      System.out.println(e.toString());
    }
  }
}

Measured memory_bytes: 64212
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int min = N;

  // 各iでの、それより左側でWの人の数を数える
  int W[300010];
  W[0] = 0;
  //cout << 0 << "," << W[0] << endl;
  if (S[0] == 'W') {
    W[1] = 1;
  } else {
    W[1] = 0;
  }
  //cout << 1 << "," << W[1] << endl;
  for (int i = 2; i < N; i++) {
    int w = 0;
    if (S[i-1] == 'W') {
      w = 1;
    }
    W[i] = W[i-1] + w;
    //cout << i << "," << W[i] << endl;
  }
  //cout << "--------------" << endl;
  // 各iでの、それより右側でEの人の数を数える
  int E[300010];
  E[N-1] = 0;
  //cout << N-1 << "," << E[N-1] << endl;
  if (S[N-1] == 'E') {
    E[N-2] = 1;
  } else {
    E[N-2] = 0;
  }
  //cout << N-2 << "," << E[N-2] << endl;
  for (int i = N-3; i >= 0; i--) {
    int e = 0;
    if (S[i+1] == 'E') {
      e = 1;
    }
    E[i] = E[i+1] + e;
    //cout << i << "," << E[i] << endl;
  }

  //cout << "--------------" << endl;
  for (int i = 0; i < N; i++) {
    int count = 0;
    count = W[i] + E[i];
    if (count < min) {
      min = count;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 3068
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x)
#define dump_l(x) dump(x) << endl
#else
const bool test = false;
#define dump(x)
#define dump_l(x)
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}

string reverse_str(string input) {
  string res = input;
  reverse(all(res));
  return res;
}

vector<int> sorted(vector<int> a) {
  vector<int> b = a;
  sort(all(b));
  return b;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}

int H = 20, W = 30;

bool ng(int y, int x) {
  return y < 0 || H <= y || x < 0 || W <= x;
}

void solve();

class Solver {
public:
  int N;
  vector<int> X;

  void solve() {
    cin >> N;
    X.resize(N);
    rep(i, N) cin >> X[i];
    vector<int> Y = sorted(X);
    rep(i, N) {
      int res = [&](){
        if (X[i] < Y[N/2]) return Y[N/2];
        else return Y[N/2-1]; 
      }();
      cout << res << endl;
    }
  }
};
 
signed main()
{
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {
  //   auto ptr = new Solver();
  //   ptr->solve();
  //   delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'
 


Measured memory_bytes: 5348
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
typedef boost::multiprecision::cpp_int bigint;


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int  n,a,b;
	cin >>n >>a >>b;
	map<ll,int> mp;
	vector<ll> v(n), sm(n);
	rep(i,n){
		cin >>v[i];
		mp[v[i]]++;
	}
	sort(v.rbegin(), v.rend());
	sm[0]=v[0];
	rep2(i,1,n) sm[i]=sm[i-1]+v[i]; 
	//for(auto x :sm) cout <<x <<" "; puts("");
	double mx = 1.0* sm[a-1]/a;
	
	bigint ans=0;
	rep(i,n) if(a<=i+1 && b>=i+1 ){
		double w = 1.0*sm[i]/(i+1);
		//printf("%d:%f\n", i,w);
		//if( abs(mx  - w)> 1e-10) continue;
		if(sm[a-1]*(i+1) != sm[i] * a) continue;
		
		ll cr=v[i]; int ct=0;
		repr(j,i,0) if(v[j] == cr)ct++; else break;
		bigint s=1, r=1,z=1;
		rep(q, mp[cr]) s *= (q+1);
		rep(q, mp[cr]-ct) s /= (q+1);
		rep(q, ct) s /= (q+1);
		
		//cout << s <<"\n";
		ans +=s;
	}
	printf("%.14f\n", mx);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    for (i, c) in s.trim().chars().enumerate() {
        if (i % 2 == 0 && c == 'L') || (i % 2 == 1 && c == 'R') {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

fn main() {
    run();
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC098A
{
	class Program
	{
		static void Main(string[] args)
		{
			int A, B, max;

			var word = Console.ReadLine().Split(' ');

			A = int.Parse(word[0]);
			B = int.Parse(word[1]);

			max = A + B;
			if(max < A - B) max = A - B;
			if(max < A * B) max = A * B;
			


			Console.WriteLine(max);

			Console.ReadKey();

		}
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <string.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

typedef long long int ll;



void pre_process(string p, int *back_table){
    int i = 0, j = -1, length = p.length();
    back_table[0] = -1;

    while(i <= length) { 
        while(j != -1 && p[i] != p[j]) j = back_table[j];
        i++; j++;
        back_table[i] = j;
    }

}

void _search(string p, string t, int *back_table){
    int i = 0, j = 0, length = t.length(), m = p.length();

    while(i <= length){
        while(j != 0 && t[i] != p[j]) j = back_table[j];
        i++; j++;
        if(j == m) { cout << "Pattern at: " << i - j << endl; j = back_table[j]; }
    }
}

int func(int arr[],int n,int m) {
    int maxsum;
    int incl[n];
    int excl[n];
    incl[0] = arr[0];
    excl [0] = 0;
    for(int i=1;i<n;i++) {
        if(i-m-1 >=0) {
            incl[i] = max(incl[i-m-1],excl[i-m-1]) + arr[i];
        }
        else
            incl[i] = arr[i];
        
        excl[i] = max(excl[i-1],incl[i-1]);
        maxsum = max(maxsum,max(incl[i],excl[i]));
    }

    return maxsum;
}

int show(int x, float y){
    return x + y;
}


int show(int x){ return x; }

float fn_(int x = show(2, 3.3)){
    return x;
}

int fn(int x = show(2)){
    return x;
}

int solve(string s, int n){
    int dp[n + 1];
    dp[0] = 0;

    for(int i = 1; i <= n; i++){
        if(i > 1 && s[i - 2] <= '2' && s[i - 1] <= '6')
            dp[i] = dp[i - 1] + dp[i - 2] + 1;
        else
            dp[i] = dp[i - 1];
    }

    for(int i : dp) cout << i << ' ';
    cout << endl;

    return dp[n] + 1;
}

int main() {

    string s;
    cin >> s;

    for(int i = s.length() - 2; i >= 0; i-= 1){
        if(i % 2 == 1){
            int mid = i >> 1;
            if(s.substr(0, mid + 1) == s.substr(mid + 1, i - mid)){
                cout << s.substr(0, mid + 1).length() * 2 << flush;
                return 0;
            }
        }
         
    }
    return 0;
}

// akasakaakas 
// akasakaakas


// akasakaakasaka

Measured memory_bytes: 764
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
int you[111111];
int vis[111111];
int n, ans;
int main(void)
{
	cin>>n;
	for(int i=1 ; i<=n ; i++)
	{
		scanf("%d",&you[i]);
	}
	for(int i=1 ; i<=n ; i++)
	{
		if(vis[you[i]]==0 && you[you[i]]==i)
		{
			ans++;
			vis[you[i]]=1;
			vis[i]=1;
		}
		vis[i]=1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define inf 1000000007
#define pb push_back
#define sz(v) (v).size()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,mod,p1,p2,num1,num2,a[200005];
int qpow(const int &x,int y)
{
	if(y==0) return 1;
	ll res=qpow(x,y/2);
	ll ret=(res*res)%mod;
	if(y%2) ret+=ret,ret%=mod;
	return ret;
}

int solve(int number)
{
	if(number==0) return 0;
	int tot=__builtin_popcount(number);
	return solve(number%tot)+1;
}

int calc(int ind)
{
	if(a[ind]==1)
	{
		mod=p1;
		if(mod==0) return -1;
		return solve((num1+mod-qpow(2,n-ind-1))%mod);
	}
	else
	{
		mod=p2;
		return solve((num2+qpow(2,n-ind-1))%mod); 
	}
}

string s;
int main()
{
	cin>>n>>s;
	int cnt=0;
	for(int i=0;i<n;i++)
		if(s[i]=='1')
			cnt++;
	p1=cnt-1,p2=cnt+1;
	for(int i=0;i<n;i++)
	{
		num1*=2;
		num1+=s[i]-'0';
		if(p1>0) num1%=p1;
		num2*=2;
		num2+=s[i]-'0';
		num2%=p2;
		a[i]=s[i]-'0';
	}
	for(int i=0;i<n;i++)
		printf("%d\n",calc(i)+1);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; i++) {
        cin >> a.at(i);
    }
    vector<int> b(100010);
    int ans = 0;
    for(int i=0; i<N; i++) {
        b.at(a.at(i))++;
    }
    for (int i=1; i<100001; i++) {
        int X = i;
        int cnt = b.at(X-1) + b.at(X) + b.at(X+1);
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
open System

[<EntryPoint>]
let main argv =
    let inputs = stdin.ReadLine().Split(' ') |> Array.map int

    let r = inputs.[0]
    let d = inputs.[1]
    let x_init = inputs.[2]

    let calc x r d = r * x - d

    let rec makeResult x n = 
        if n <= 0 then
            []
        else
            let next = r * x - d
            [next] @ makeResult next (n-1)

    for i in (makeResult x_init 10) do
        printfn "%d" i

    0 // return an integer exit code

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  double a,b;
  cin>>a>>b;

  for(double i=1.0;i<=10000;i+=1.0){
    double ai = i/100*8;
    double bi = i/100*10;
    if(int(ai)==int(a)&&int(bi)==int(b)){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{
    int n, k, x[110];

    cin >> n >> k;

    int res = 0;
    REP(i, n)
    {
        cin >> x[i];
        res += min(x[i] * 2, abs(x[i] - k) * 2);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] == a[i - 1]) {
                count++;
                i++;
            }
        }
        System.out.println(count);
    }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

int n;

int dfs(long long x, int t = 0, int f = 0, int s = 0) {
  if (x > n) return 0;
  return (t && f && s)
       + dfs(x*10+3, t+1, f, s)
       + dfs(x*10+5, t, f+1, s)
       + dfs(x*10+7, t, f, s+1);
}

void solve() {
  scanf("%d", &n);
  printf("%d", dfs(0));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int n,k,p,r,s;
    cin>>n>>k>>r>>s>>p;
    string str;
    cin>>str;
    int score=0;
    vector<char> prev(n);
    for(int i=0;i<k;i++)
    {
      if(str[i]=='r')
        score+=p,prev[i]='p';
      else if(str[i]=='p')
        score+=s,prev[i]='s';
      else
      {
        score+=r,prev[i]='r';
      }      
    }

    for(int i=k;i<n;i++)
    {
      if(str[i]=='r')
      {
        if(prev[i-k]!='p')
          score+=p,prev[i]='p';
        else if(i+k<n)
        {
          prev[i]=str[i+k];
        }        
      }
      else if(str[i]=='p')
      {
        if(prev[i-k]!='s')
          score+=s,prev[i]='s';
        else if(i+k<n)
        {
          prev[i]=str[i+k];
        }        
      }
       else 
      {
        if(prev[i-k]!='r') 
          score+=r,prev[i]='r';
        else if(i+k<n)
        {
          prev[i]=str[i+k];
        }        
      }
    }

    cout<<score;

  }
  //time("");
  return 0;
}

Measured memory_bytes: 512
def gcd(a, b)
  a, b = b, a if a > b
  until a == 0
    a, b = b%a, a
  end
  return b
end

def lcm(a, b)
  a*b/gcd(a, b)
end

while gets do
  a, b = $_.chomp.split(' ').map(&:to_i)
  puts "#{gcd(a, b)} #{lcm(a, b)}"
end


Measured memory_bytes: 6844
N = int(input())
H = list(map(int, input().split()))
step = 0
ans = 0
for i in range(N-1):
  if H[i] < H[i+1]:
    ans = max(step, ans)
    step = 0

  else:
    step += 1
#  print(step, ans)
print(max(step, ans))
  

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  string s;
  cin >> a;
  cin >> s;
  //cout << a << s << endl;
  if(a>=3200){
    cout << s << endl;
  }else{
    cout << "red" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a < 1) {
		cout << "-1" << endl;
	}
	else if (9 < a) {
		cout << "-1" << endl;
	}
	else if (b < 1) {
		cout << "-1" << endl;
	}
	else if (9 < b) {
		cout << "-1" << endl;
	}
	else cout << a * b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i < (b); i++)
int main(){
  int arr[26];
  memset(arr, 0 , sizeof(arr));
  string str;
  cin>>str;
  rep(i, 0, str.size()){
     arr[str[i] - 'a']++;
  }
  bool check = true;
  rep(i, 0, 26){
     if(arr[i]%2 != 0)check = false;
  }
  if(!check)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define mod 1000000000000000000
        #define MOD 		1000000007
        #define ll long long
        #define ull unsigned ll
        #define mp 		make_pair
        #define pb 		push_back
        #define forn(i,n) 	for(ll i=0;i<n;i++)
        #define for1(i,n) 	for(ll i=1;i<=n;i++)
        #define forn1(i,n) 	for(int i=1;i<n;i++)
        #define rep(i,x,n)  for(ll i=x;i<=n;i++)
        #define repr(i,x,j) for(ll i=x;i>=j;i--)
        #define vi vector<ll>
        #define mii map<ll,ll>
        #define vii vector<pair<ll,ll>>
        #define vvi vector<vector<ll>>
        #define pii pair<ll,ll>
        #define F first
        #define S second
        #define fill(a,x) memset(a,x,sizeof a);
        #define all(x) x.begin(),x.end()
        #define test ll t;cin>>t;while(t--)
        #define yes cout<<"YES"<<endl
        #define no cout<<"NO"<<endl
        #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        ll flag[100000];
        #define R return 0
        int main()
        {
           IOS;
           ll n,ans=0;
           cin>>n;
           rep(i,1,n-1)
           {
               for(ll j=1;i*j<n;j++)
               ans++;
           }
           cout<<ans<<endl;
           R;

        }
        
        /// Happy coding ):
        ///Thanks to repl.it -_-

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

class UnionFind {
public:
	vector<ll> parent;

	UnionFind(int n) {
		parent = vector<ll>(n, -1);
	}

	int root(int a) {
		if (parent[a] < 0) return a;
		return parent[a] = root(parent[a]);
	}

	int size(int a) {
		return -parent[root(a)];
	}

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

	bool unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}

		if (size(a) < size(b)) swap(a, b);

		parent[a] += parent[b];
		parent[b] = a;

		return true;
	}
};

int main(){

    ll n, m;
    cin >> n >> m;

    UnionFind uf(n+m);
    rep(i, n){
        int k; cin >> k;
        rep(j, k){
            int l; cin >> l;
            uf.unite(i, n-1+l);
        }
    }

    rep(i, n-1){
        if(!uf.same(i, i+1)){
            NO();
            return 0;
        }
    }
    YES();

    return 0;
}


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

int main(){
    long long N,K;
    cin>>N>>K;
    vector<int> A(N+1,0);
    for(int i=1;i<=N;i++) cin>>A[i];

    for(int i=1;i<=N-K;i++){
        if(A[K+i]>A[i]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 4024
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
const ll LINF=(1LL<<60)-1LL;
int ask(vector<int> a){
	cout<<"? ";
	for(int i=0;i<a.size();i++){
		cout<<a[i];
		if(i+1<a.size()){
			cout<<" ";
		}
	}
	cout<<endl;
	string s;
	cin>>s;
	if(s=="Red"){
		return 0;
	}else if(s=="Blue"){
		return 1;
	}
	return -1;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n),s(2*n+1);
	for(int i=0;i<n;i++){
		a[i]=i+1;
	}
	int b=ask(a);
	int ok=n+1,ng=1;
	while(ok-ng>1){
		int mid=(ok+ng)/2;
		for(int i=mid;i<=mid+n;i++){
			a[i-mid]=i;
		}
		int t=ask(a);
		if(t!=b){
			ok=mid;
		}else{
			ng=mid;
		}
	}
	s[ng]=b;
	s[ok+n-1]=(b^1);
	vector<int> c;
	for(int i=1;i<=2*n;i++){
		if(ng<=i&&i<ng+n){
			a[i-ng]=i;
		}else{
			c.push_back(i);
		}
	}
	for(int i=1;i<=2*n;i++){
		if(i==ng||i==ok+n-1){
			continue;
		}
		int id;
		if(ng<=i&&i<ng+n){
			for(int j=0;j<n;j++){
				if(c[j]==ok+n-1){
					c[j]=i;
					id=j;
				}
			}
			int t=ask(c);
			s[i]=t;
			c[id]=ok+n-1;
		}else{
			for(int j=0;j<n;j++){
				if(a[j]==ng){
					a[j]=i;
					id=j;
				}
			}
			int t=ask(a);
			s[i]=t;
			a[id]=ng;
		}
	}
	cout<<"! ";
	for(int i=1;i<=2*n;i++){
		if(s[i]==0){
			cout<<"R";
		}else{
			cout<<"B";
		}
	}
	cout<<endl;
	return 0;
}	


Measured memory_bytes: 724
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class t> inline string to_str(t x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, dp[1024][1024];
	string a, b;
	cin >> n;
	
	while(n)
	{
		n--;
		memset(dp, 0, sizeof(dp));

		cin >> a;
		cin >> b;

		for(int i = 0; i < a.size(); i++)
		{
			for(int j = 0; j < b.size(); j++)
			{
				if(a[i] == b[j])
				{
					dp[i+1][j+1] = max(dp[i][j] + 1, max(dp[i+1][j], dp[i][j+1]));
				}
				else
				{
					dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
				}
			}
		}
		/*
		for(int i = 0; i <= a.size()+1; i++)
		{
			for(int j = 0; j <= b.size()+1; j++)
			{
				printf("%3d ",dp[i][j]);
			}
			puts("");
		}
		*/

		cout << dp[a.size()][b.size()] << endl;
	}
}

Measured memory_bytes: 5304
#include <iostream>

int main() {
    int num_people[4][3][10];
    for (int i=0;i<4;++i)
        for (int j=0;j<3;++j)
            for (int k=0;k<10;++k)
                num_people[i][j][k] = 0;
    int num_input;
    std::cin >> num_input;
    for (int i=0;i<num_input;++i) {
        int b, f, r, v;
        std::cin >> b >> f >> r >> v;
        num_people[b-1][f-1][r-1] += v;
    }
    for (int i=0;i<4;++i) {
        for (int j=0;j<3;++j) {
            for (int k=0;k<10;++k) {
                std::cout << " " << num_people[i][j][k];
            }
            std::cout << std::endl;
        }
        if (i<3) std::cout << "####################" << std::endl;
    }
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int h,w; cin >> h >> w;
    vii grid(h, vi(w));
    char ch;
    rep(i,h)rep(j,w) {
            cin >> ch;
            if(ch == '#') grid[i][j] = 1;
        }

    // DP
    vec<vll> dp(h, vll(w, infll));  // そのマスに到達するまでの白->黒移動の数の最小値
    dp[0][0] = 0;
    rep(i,h) rep(j,w) {
            if(0 <= i-1) chmin(dp[i][j], dp[i-1][j] + (grid[i][j]==1 && grid[i-1][j]==0 ? 1 : 0));
            if(0 <= j-1) chmin(dp[i][j], dp[i][j-1] + (grid[i][j]==1 && grid[i][j-1]==0 ? 1 : 0));
        }
    ll cnt = dp[h-1][w-1];
    if(grid[0][0]) ++cnt;

    cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 384
import heapq
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
heap = []
ans = 0
j = 0

for i in range(1, M+1): # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i): # 支払いがi日以内
        heapq.heappush(heap, -X[j][1]) # 候補の追加。最大の値が欲しいためマイナスに
        j += 1
    if len(heap):
        ans += - heapq.heappop(heap) # 候補があるとき、候補から最大値を取り出す
print(ans)

Measured memory_bytes: 31908
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int a = 1;
		int b = 1;
		while ( sc.hasNext() ) {
			a = sc.nextInt();
			b = sc.nextInt();
			System.out.println( gcd(a, b) + " " + lcm(a, b) );
		}
	}

	public static int gcd(int a, int b) {
		int r;
		int max = Math.max(a, b);
		int mini = Math.min(a, b);
		do {
			r = max % mini; // max = q*mini + r , mini > r
			max = mini;
			mini = r;
		} while (r != 0);
		return max;
	}

	public static int lcm(int a, int b) {
		int d = gcd(a, b);
		return a/d * b;
	}
}

Measured memory_bytes: 26180