akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;


int main() {
    double N ;
    cin >> N ;
    double ans =  N/3 * N/3 * N/3 ;
    printf("%.6f", ans )  ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100000
#define LL long long
int fa[maxn+5],a[maxn+5],b[maxn+5],c[maxn+5];
int Find(int x){
	return fa[x]==x?x:fa[x]=Find(fa[x]);
}
int main(){
	int n,q,u,v,cnt;LL m;scanf("%d%lld%d",&n,&m,&q),cnt=n;
	for(int i=0;i<n;i++)fa[i]=i;
	bool fl=0;
	for(int i=0;i<q;i++)scanf("%d%d%d",a+i,b+i,c+i),fl|=c[i];
	if(fl&&m==n-1){puts("No");return 0;}
	for(int i=0;i<q;i++){
		if(c[i])continue;
		int x=Find(a[i]),y=Find(b[i]);
		if(x!=y)fa[x]=y,cnt--;
	}
	for(int i=0;i<q;i++){
		if(!c[i])continue;
		int x=Find(a[i]),y=Find(b[i]);
		if(x==y){puts("No");return 0;}
	}
	if(fl&&cnt==2||m>(n-cnt)+1ll*cnt*(cnt-1)/2){puts("No");return 0;}
	puts("Yes");
	return 0;
} 

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
	int K, N;

	cin >> K >> N;

	int* A = new int [N];
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}

	int result = K - A[N - 1] + A[0];

	for (int i = 1; i < N; ++i) {
		result = max(result, A[i + 1]-A[i]);
	}

	cout << K-result << endl;
	
	delete[] A;
}

Measured memory_bytes: 3996
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   String s=kbd.next();
   if(s.equals("A")||s.equals("B")||s.equals("C")||s.equals("D")||s.equals("E")||s.equals("F")||s.equals("G")||s.equals("H")||s.equals("I")||s.equals("J")||
   s.equals("K")||s.equals("L")||s.equals("M")||s.equals("N")||s.equals("O")||s.equals("P")||s.equals("Q")||s.equals("R")||s.equals("S")||s.equals("T")||
   s.equals("U")||s.equals("V")||s.equals("W")||s.equals("X")||s.equals("Y")||s.equals("Z")){
     System.out.println("A");
   }else{
      System.out.println("a");
   }
 }
}


Measured memory_bytes: 35688
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

string s;
int n;

int main() {
    cin >> n >> s;
    string t = s;
    bool flag = true;
    while(flag){
        flag = false;
        REP(i,t.size()){
            if(t[i]=='('&&t[i+1]==')'){
                t.erase(i,2);
                flag = true;
            }
        }
    }
    int cntl = 0;
    int cntr = 0;
    REP(i,t.size()){
        if(t[i]==')'){
            cntr++;
        }else{
            cntl++;
        }
    }
    string res = "";
    REP(i,cntr){
        res += '(';
    }
    res += s;
    REP(i,cntl){
        res += ')';
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
object Main extends App{
  import scala.io.StdIn.{readLine}
  type Operator = Option[((Int, Int) ⇒ Int, List[Char])]
  type CharParseResult = Option[(Char, List[Char])]
  type ParseResult = Option[(List[Char], List[Char])]
  type CalResult = Option[(Int, List[Char])]
  type CalMidResult = Option[(Int ⇒ Int, List[Char])]
  for (_ ← 0 until readLine().toInt){
    println(readLine().toList match {
      case value AsExpression '='::Nil ⇒ value
      case _ ⇒ ???
    })
  }
  object AsDigit{
    def unapply(arg: List[Char]):CharParseResult = arg match{
      case h::t if h.isDigit ⇒ Some(h, t)
      case _ ⇒ None
    }
  }
  object AsNumber{
    def unapply(arg: List[Char]):ParseResult = arg match{
      case digit AsDigit (number AsNumber rest) ⇒ Some(digit::number, rest)
      case digit AsDigit rest ⇒ Some(digit::Nil, rest)
      case _ ⇒ None
    }
  }
  object AsParenthesis{
    def unapply(arg: List[Char]): CalResult = arg match{
      case '(':: (result AsExpression ')':: rest)⇒ Some(result, rest)
      case _ ⇒ None
    }
  }
  object AsTerm{
    def unapply(arg: List[Char]):CalResult = arg match{
      case number AsNumber rest ⇒ Some(number.mkString.toInt, rest)
      case value AsParenthesis rest ⇒ Some(value, rest)
      case _ ⇒ None
    }
  }
  object AsHighPriorityOperator{
    def unapply(arg: List[Char]):Operator = arg match{
      case '*'::rest ⇒ Some(_ * _ , rest)
      case '/'::rest ⇒ Some(_ / _, rest)
      case _ ⇒ None
    }
  }
  object AsLowPriorityOperator{
    def unapply(arg: List[Char]):Operator = arg match{
      case '+'::rest ⇒ Some(_ + _, rest)
      case '-'::rest ⇒ Some(_ - _, rest)
      case _ ⇒ None
    }
  }
  implicit class BinomialOperator(val operator:(Int, Int) ⇒ Int){
    def <|(num:Int):Int ⇒ Int = operator(_, num)
  }
  implicit class MonomialOperator(val number:Int){
    def |>(op:Int ⇒ Int):Int = op(number)
  }
  object AsHighPriorityOperation{
    def unapply(arg: List[Char]):CalMidResult = arg match{
      case op AsHighPriorityOperator (term AsTerm (converter AsHighPriorityOperation rest)) ⇒ Some(op <| term andThen converter, rest)
      case op AsHighPriorityOperator (term AsTerm rest) ⇒ Some(op <| term, rest)
      case _ ⇒ None
    }
  }
  object AsHighPriorityPartial{
    def unapply(arg: List[Char]):CalResult = arg match{
      case term AsTerm (converter AsHighPriorityOperation rest) ⇒ Some(term |> converter, rest)
      case term AsTerm rest ⇒ Some(term, rest)
      case _ ⇒ None
    }
  }
  object AsLowPriorityOperation{
    def unapply(arg: List[Char]):CalMidResult = arg match{
      case op AsLowPriorityOperator (partial AsHighPriorityPartial (converter AsLowPriorityOperation rest)) ⇒ Some(op <| partial andThen converter, rest)
      case op AsLowPriorityOperator (partial AsHighPriorityPartial rest) ⇒ Some(op <| partial, rest)
      case _ ⇒ None
    }
  }
  object AsExpression{
    def unapply(arg: List[Char]): CalResult = arg match{
      case left AsHighPriorityPartial (right AsLowPriorityOperation rest) ⇒ Some(left |> right, rest)
      case value AsHighPriorityPartial rest ⇒ Some(value, rest)
      case _ ⇒ None
    }
  }
}


Measured memory_bytes: 52088
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

n = i_input()
D = []

for _ in range(n):
    D.append(i_input())

D_set = set(D)

print(len(D_set))

Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

struct UnionFind {
  vector<int> par, weight;
  UnionFind(int n) : par(n, -1), weight(n) {}
  void unite(int x, int y, int w = 0) {
    w += get_weight(x);
    w -= get_weight(y);
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (par[x] > par[y]) swap(x, y), w = -w;
    par[x] += par[y];
    par[y] = x;
    weight[y] = w;
    return;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) {
    if (par[x] < 0) return x;
    int r = find(par[x]);
    weight[x] += get_weight(par[x]);
    return par[x] = r;
  }
  int sizeOf(int x) { return -par[find(x)]; }
  int get_weight(int x) {
    find(x);
    return weight[x];
  }
  int diff(int x, int y) { return get_weight(y) - get_weight(x); }
};

[[maybe_unused]] constexpr ll MOD = 1000000007;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  int n, m, k, a, b;
  cin >> n >> m >> k;
  vector<vector<int>> fr(n);
  vector<vector<int>> bl(n);
  UnionFind uf(n);
  rep(i, 0, m) {
    cin >> a >> b;
    --a, --b;
    fr[a].push_back(b);
    fr[b].push_back(a);
    uf.unite(a, b);
  }
  rep(i, 0, k) {
    cin >> a >> b;
    --a, --b;
    bl[a].push_back(b);
    bl[b].push_back(a);
  }

  rep(i, 0, n) {
    int ans = uf.sizeOf(i);
    for (int e : fr[i])
      if (uf.same(e, i)) --ans;
    for (int e : bl[i])
      if (uf.same(e, i)) --ans;
    cout << ans - 1 << '\n';
  }
  return 0;
}


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

#define rep(i, n) for(long long i=0;i<n;i++)
using ll = long long;
const ll INF = (1LL<<60);

int main(){

    ll n, m; cin >> n >> m;
    ll in, sum = 0;
    rep(i, m){
        cin >> in;
        sum += in;
    }
    
    ll ans = n-sum>=0 ? n-sum : -1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3676
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    string s;
    cin >> s;

    int ans = 0;
    char prev = s[0];
    REP(i, s.size()) {
        if (s[i] != prev) ans++;
        prev = s[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
N, M = map(int, input().split())
k , s = [], []
for m in range(M):
  line = list(map(int, input().split()))
  k.append(line[0])
  s.append(line[1:])
p = list(map(int, input().split()))
light_up = [0] * M
ans = 0

for bit in range(0, 1<<N):
  bit_str = format(bit, 'b').zfill(N)
  for m in range(M):
    counter = 0
    for index in s[m]:
      counter += int(bit_str[index-1])
    if counter%2 == p[m]:
      light_up[m] = 1
    else:
      light_up[m] = 0
  if sum(light_up) == M:
    ans += 1
print(ans)

Measured memory_bytes: 9240
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		sc.close();
		int ans = a;
		if(ans != b){
			if(ans == c)ans = b;
		}
		else{
			ans = c;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

int main()
{
  ll H, W, A, B;
  cin >> H >> W >> A >> B;

  const string s0 = string(A, '0') + string(W - A, '1');
  const string s1 = string(A, '1') + string(W - A, '0');

  for (ll i = 0; i < B; i++)
  {
    cout << s0 << endl;
  }
  for (ll i = 0; i < H - B; i++)
  {
    cout << s1 << endl;
  }
}

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


using namespace std;
using ll = long long;


int main() {
    ll n, q, res = 0;
    unordered_map<ll, ll> mp;
    cin >> n;
    vector<ll> a(n);
    for(auto& x : a) {
      cin >> x;
      mp[x]++;
      res += x;
    }
    cin >> q;
    while(q--) {
      ll b, c;
      cin >> b >> c;
      if(mp.find(b) != mp.end()) {
        res += (c - b) * mp[b];
        mp[c] += mp[b];
        mp.erase(b);
      }
      cout << res << "\n";
    }
  return 0;
}



Measured memory_bytes: 7472
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	ll ans = A - B;

	if (K % 2 == 0) {
		cout << ans;
	}
	else {
		cout << -ans;
	}


}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
//    ifstream in("/Users/hamath/CLionProjects/atcoder/abc/063/b12");
//    cin.rdbuf(in.rdbuf());
    ll n;
    cin>>n;
    ll a,b;
    cin>>a>>b;
    Vec h(n);
    rep(i,n)cin>>h[i];

    ll x = a-b;
    ll l = -1,r = 1e9*9;

    //二分探索
    while(l+1<r){
        ll c = (l+r)/2;
        bool ok = [&]{
            ll need = 0;
            rep(i,n){
                need += (max(0LL,h[i]-c*b)+x-1)/x;
            }
            return need<=c;
        }();
        if(ok){
            r = c;
        }else{
            l = c;
        }
    }
    cout<<r<<endl;
    return  0;
}


Measured memory_bytes: 1024
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int sum = 0;
    rep(i,n){
        cin >> a[i];
        if((i+1)%2 == 1 && a[i]%2 == 1){
            sum++;
        }
    }
    cout << sum << endl;

}

Measured memory_bytes: 3540
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

vector < int > m[100005];
vector < vector<long long> > dp(100005, vector<long long>(2, 0));
vector < int > viz(100005);
void dfs(int nod)
{
    viz[nod] = 1;
    dp[nod][0] = 1;
    dp[nod][1] = 1;

    for (auto i = 0; i < m[nod].size(); i++)
    {
        if (viz[m[nod][i]] == 0)
            {

                dfs(m[nod][i]);
                dp[nod][1] = (dp[nod][1] * dp[m[nod][i]][0]) % MOD;
                dp[nod][0] = (dp[nod][0] * ((dp[m[nod][i]][0] + dp[m[nod][i]][1]) % MOD)) % MOD;
                //cout << m[nod][i];
                //cout << " " << dp[nod][0] << " " << dp[nod][1] << "\n";
            }

    }
}

int main()
{
    int n;

    cin >> n;

    for (int i = 1; i < n; i++)
    {
        int x, y;

        cin >> x >> y;
        m[x].push_back(y);
        m[y].push_back(x);
    }

    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % MOD;
    return 0;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 2147483647;

int  main() {
    int n;
    cin >> n ;
    vector<ll> a(n+1);
    vector<ll> b(n+1);
    vector<ll> c(n+1);
    for (int i=0;i<n;++i){
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }
    ll dp[100010][3];
    for (int i=0;i<3;++i){
        dp[0][i] = 0;
    }
    for (int i=1;i<n;++i){
        for (int j=0;j<3;++j)
        dp[i][j] = -INF;
    }
    for (int i=0;i<n;++i){
            dp[i+1][0] = max(dp[i][1]+a.at(i),dp[i][2]+a.at(i));
            dp[i+1][1] = max(dp[i][0]+b.at(i),dp[i][2]+b.at(i));
            dp[i+1][2] = max(dp[i][0]+c.at(i),dp[i][1]+c.at(i));
    }
    ll nax =-INF;
    for (int i=0;i<3;++i){
        nax = max (dp[n][i],nax);
    }
    cout << nax << endl;
    return 0;
}


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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

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

    vector<int>cnt(3);
    rep(i,s.size()){
        if(s[i]=='a')cnt[0]++;
        else if(s[i]=='b')cnt[1]++;
        else  cnt[2]++;
    }

    if(abs(cnt[0]-cnt[1])>1||abs(cnt[0]-cnt[2])>1||abs(cnt[1]-cnt[2])>1){
        cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;

}


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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}

  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if(data[y] < data[x]) {
        swap(x, y);
      }
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }

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

  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
};

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

  UnionFind uf(N);

  vector<int> p;
  for(int i = 0; i < N; ++i) {
    int buf;
    cin >> buf;
    p.emplace_back(buf);
  }

  for(int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    uf.unionSet(x-1, y-1);
  }

  int ans = 0;
  for(int i = 0; i < N; ++i) {
    if(uf.findSet(i, p[i]-1)) ++ans;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1276
X = input()

if X[0] == 1:
	X2 = [9]*(len(X) - 1)
elif X[1:].count("9") == len(X[1:]):
	X2 = X
else:
	tmp = int(X[0])-1
	X2 = [str(tmp)] + ["9"]*(len(X)-1)


print(sum(list(map(int, X2))))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define coutif(a,b,c) cout<<(a?b:c)
#define all(x) (x).begin(), (x).end()
#define uint usigned int
typedef vector <ll> vi;
ll MOD = 1e9+7;
ll l[1000111];
//vi v1[200005],v2;
//bool visit[200005]={false};
/*void bfs(ll n){
    queue<ll> q;
    q.push(n);
    visit[n]=true;
    while(!q.empty()){
        ll t=q.front();
        q.pop();
        v2.pb(t);
        for(ll i=0;i<v1[t].size();i++){
            if(visit[v1[t][i]]==false){
                q.push(v1[t][i]);
                visit[v1[t][i]]=true;
            }
        }
    }
}*/
/*void dfs(ll n){
    for(ll i=0;i<v1[n].size();i++)
    {
        ll y=v1[n][i];
        if(visit[y]==0)
        {
            v2.pb(y);
            visit[y]=1;
            dfs(y);
        }
    }
}*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    ll n,m,x=0,y=0,i,ans=0;
    string s;
	cin>>n>>m;
	cin>>s;
	if(s[m-1]=='A') s[m-1]='a';
	if(s[m-1]=='B') s[m-1]='b';
	if(s[m-1]=='C') s[m-1]='c';
	cout<<s;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
   string a,b;
   cin>>a>>b;
   int len=a.size();
   int len1=b.size();
   if(len==len1)
   {
       for(int i=0;i<len;i++)
       {
           cout<<a[i];
           cout<<b[i];
       }
   }
   else if(len>len1)
   {
       for(int i=0;i<len1;i++)
       {
           cout<<a[i];
           cout<<b[i];
       }
       cout<<a[len-1];
   }
}



Measured memory_bytes: 3620
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
r = int(input())
print(3*r*r)

Measured memory_bytes: 10512
def prime_table(n):
    prime = [True] * (n+1)
    for i in range(2,n+1):
        if not prime[i]: continue
        for j in range(i+i, n+1, i):
            prime[j] = False
    return prime

X = int(input())
is_prime = prime_table(10**6)
for i in range(X, 10**6):
    if is_prime[i]:
        print(i)
        break

Measured memory_bytes: 74908
import java.util.Scanner;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[] map = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextInt();
			sum += map[i];
		}
		
		int ave = Math.round((float)sum / (float)N);
		
		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += (map[i] - ave) * (map[i] - ave);
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
def f_absolute_minima(Q, Queries, INF=float('inf')):
    import heapq

    left, right = [], []
    current_ans, current_median = 0, 0
    bias_total = 0
    heapq.heappush(left, INF)
    heapq.heappush(right, INF)
    ans = []

    for query in Queries:
        if query[0] == 1:  # 更新クエリ
            _, a, b = query
            bias_total += b

            # leftからは最大値を、rightからは最小値を取り出したい
            last_left, last_right = -left[0], right[0]
            heapq.heappush(left, -a)
            heapq.heappush(right, a)
            heapq.heappush(left, -heapq.heappop(right))
            heapq.heappush(right, -heapq.heappop(left))
            current_median = -left[0]
            # 区間外。区間の端点との距離のうち、長くない方を足す
            if a < last_left or last_right < a:
                current_ans += min(abs(last_right - a), abs(last_left - a))
        else:  # 求値クエリ
            ans.append((current_median, current_ans + bias_total))
    return '\n'.join(' '.join(map(str, row)) for row in ans)
    # 参考: https://atcoder.jp/contests/abc127/submissions/5656120

Q = int(input())
Queries = [[int(i) for i in input().split()] for j in range(Q)]
print(f_absolute_minima(Q, Queries))

Measured memory_bytes: 65620
//https://atcoder.jp/contests/abc122/tasks/abc122_c
function setUp(input) {
  input = input.split("\n");
  N = Number(input[0].split(" ")[0]);
  Q = Number(input[0].split(" ")[1]);
  S = input[1];
  lList = input.slice(2, 2 + Q);
  lList = lList.map(function (d, i) {
    var arr = d.split(' ');
    return [Number(arr[0]) - 1, Number(arr[1]) - 1];
  })
  main();
}
function main() {
  ruiseki = [0];
  sLength = S.length;
  count = 0;
  for (var i = 0; i < sLength; i++) {
    var target = S[i] + S[i + 1];
    if (target === 'AC') {
      count++
    }
    ruiseki.push(count);
  }
  lList.forEach(function (d, i) {
    console.log(ruiseki[d[1]] - ruiseki[d[0]]);
  })
}
setUp(require("fs").readFileSync("/dev/stdin", "utf8"));
// setUp('8 3\nACACTACG\n3 7\n2 3\n1 8')

Measured memory_bytes: 60208
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, k;
    cin >> n >> k;
    vll p(n), c(n);
    rep(i, n) {
        cin >> p[i];
        --p[i];
    }
    rep(i, n) cin >> c[i];
    vb visited(n, false);
    ll ans = -INFL;
    for(int i = 0; i < n; i++) {
        if(visited[i]) continue;
        ll now = i;
        visited[now] = true;
        vll history(1, c[now]);
        while(!visited[p[now]]) {
            now = p[now];
            visited[now] = true;
            history.push_back(c[now]);
        }
        ll n_his = history.size();
        vll sum_his(1, 0);
        for(int j = 0; j < n_his; j++) {
            sum_his.push_back(sum_his.back() + history[j]);
        }
        for(int j = 0; j < n_his; j++) {
            sum_his.push_back(sum_his.back() + history[j]);
        }
        ll loop_add = max(sum_his[n_his], 0ll);
        for(int len = 1; len <= min(n_his, k); len++) {
            for(int st = 0; st < n_his; st++) {
                ll _ans = sum_his[st + len] - sum_his[st];
                ll loop_cnt = 0;
                if(k > len) loop_cnt = (k - len) / n_his;
                _ans += loop_cnt * loop_add;
                chmax(ans, _ans);
            }
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:


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

	int one = 0,two = 0, four = 0;

	rep(i,n){
		int a;
		cin >> a;
		if(a % 4 == 0)
			four++;
		else if(a%2==0)
			two++;
		else
			one++;
	}

	bool ok = true;
	const int rest = four + 1 - one;
	if(rest < 0) ok = false;
	if(rest == 0 and two > 0) ok = false;

	if(ok)
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define all(a)  a.begin(), a.end()
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define sz(a) ((int)(a.size()))
#define pb(a) push_back(a)
#define ins(a) insert(a)
#define mp make_pair
#define newln cout<<"\n";
#define bigPrime 1000000007
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;  

int main()
{  
    fip;
    int n,i,a,cnt=0;
    cin>>n;
    int ar[n];
    reptUsual(n)
    {
        cin>>ar[i];
    }
    for(i=1;i<n-1;i++)
    {
        if( (ar[i]>ar[i-1] & ar[i]<ar[i+1]) || (ar[i]<ar[i-1] & ar[i]>ar[i+1]) )
            cnt++;
    }
    cout<<cnt;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int c[102];
    int n;
    char ch2[10];

    int max;
    int len, len2;

    

    

    int max2;

    int i, j, x;

    while (scanf("%d", &n) && n)
    {
            int v[30]={0};

            len=len2=-1;
            max=max2=0;
        
            for (int z=0; z<n; z++)
            {
                
                scanf("%s", ch2);

                c[z] = *ch2-'A';
            }

            // judge
            

            for (i=0, j=n; i<n; )
            {
                x = c[i];
                i++,j--;
                v[x]++;

                if (v[x] > max) 
                {
                    if (len < 0 || x == len)
                        max=v[x], len=x;
                    else max2 = max, len2 = len, max = v[x], len = x;
                
                }
                else if (v[x] > max2) max2= v[x], len2=x;
                //printf("%d + %d < %d\n", max2, j, max);
                if (max2 + j< max) break;
                
            }

            if (max==max2) puts("TIE");
            else printf("%c %d\n", len+'A', i);
        
    }
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <string.h>
using namespace std;

int main(){
	int a, b;
	bool flag = true;
	string s;
	a = b = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(flag && s[i] == 'A'){
			a = i;
			flag = false;
		}
		if(s[i] == 'Z') b = i;
	}
	cout << b-a+1 << endl;
	return 0;
}


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

using namespace std;

int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int n, k;
	string s;
	
	cin >> n >> k >> s;
	
	s[k-1] = tolower(s[k-1]);
	
	cout << s;

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int p[n];
	int pp[n+1] = {0};
	for(int i = 0; i < n; i++){
		cin >> p[i];
		pp[p[i]] = max(pp[p[i]-1]+1, pp[p[i]]);
	}
	sort(pp, pp+n+1);
	cout << n-pp[n] << endl;
	return 0;
}

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

int main()
{
  double x[3],y[3],tx,ty,ans=0;
  int count=0;
  for(;~scanf("%lf,%lf",&tx,&ty);)
    {
      //      cout<<"line "<<count<<endl;
      if(count<3)
	{
	  x[count]=tx;
	  y[count]=ty;
	}
      else
	{
	  x[1]=x[2];
	  y[1]=y[2];
	  x[2]=tx;
	  y[2]=ty;
	}
      if(count>1)
	{
	  double a,b,c,z;
	  a=sqrt(pow(x[0]-x[1],2)+pow(y[0]-y[1],2));
	  b=sqrt(pow(x[1]-x[2],2)+pow(y[1]-y[2],2));
	  c=sqrt(pow(x[0]-x[2],2)+pow(y[0]-y[2],2));
	  z=(a+b+c)/2;
	  // cout<<a<<" "<<b<<" "<<c<<" "<<z<<endl;
	  ans+=sqrt(z*(z-a)*(z-b)*(z-c));
	}
      count++;
    }
  printf("%.6lf\n",ans);
}

Measured memory_bytes: 1240
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    A = list(sorted(list(map(int, input().split()))))
    print((A[2] - A[1]) + (A[1] - A[0]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 51
 
struct Point{
    int x,y;
    double dist(const Point &p){
	return abs(x-p.x)+abs(y-p.y);
    }
};
 
int N,m[MAX];
vector<Point> lines[MAX];
 
int getDir(Point &p1,Point &p2){
    if(p1.x == p2.x){
	return (p1.y < p2.y ? 0 : 2);
    }
    return (p1.x < p2.x ? 3 : 1);
}
 
bool equals(vector<Point> &l1,vector<Point> &l2){
    int s1 = l1.size(), s2 = l2.size();
    if(s1 != s2) return false;
    bool flg = false;
    int d1,d2,diff;
    for(int i = 0 ; i < s1-1 ; i++){
	if(l1[i].dist(l1[i+1]) != l2[i].dist(l2[i+1])){
	    flg = true; break;
	}
	d1 = getDir(l1[i],l1[i+1]);
	d2 = getDir(l2[i],l2[i+1]);
	if(i > 0){
	    if(diff != (d1-d2+4)%4){
		flg = true; break;
	    }
	}else{
	    diff = (d1-d2+4)%4;
	}
    }
    if(!flg) return true;
    flg = false;
    for(int i = s1-1 ; i > 0 ; i--){
	if(l1[s1-i-1].dist(l1[s1-i]) != l2[i].dist(l2[i-1])){
	    flg = true; break;
	}
	d1 = getDir(l1[s1-i-1],l1[s1-i]);
	d2 = getDir(l2[i],l2[i-1]);
	if(i != s1-1){
	    if(diff != (d1-d2+4)%4){
		flg = true;
		break;
	    }
	}else{
	    diff = (d1-d2+4)%4;
	}
    }
    return !flg;
}
 
int main(){
    while(cin >> N,N){
	for(int i = 0 ; i <= N ; i++){
	    cin >> m[i]; lines[i].clear();
	    for(int j = 0 ; j < m[i] ; j++){
		int x,y;
		cin >> x >> y;
		lines[i].push_back((Point){x,y});
	    }
	}
	for(int i = 1 ; i <= N ; i++){
	    if(equals(lines[0],lines[i])){
		cout << i << endl;
	    }
	}
	cout << "+++++" << endl;
    }
    return 0;
}

Measured memory_bytes: 3060
var
   s,t:ansistring;
   i,m,ans,n:longint;
begin
       readln(s);
       n:=length(s);
       m:=0; t:='';
       for i:=1 to n do
       begin
                if(s[i]='T') and (m<>0) and (t[m]='S')then  begin delete(t,m,1); dec(m); end
                else begin inc(m); t:=t+s[i];  end;
       end;
      writeln(m);
end.

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<bool> good(n, true);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (h[a] >= h[b])
      good[b] = false;
    if (h[b] >= h[a])
      good[a] = false;
  }
  int ans = 0;
  rep(i, n) {
    if (good[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, m, k,x1,x2,y11,y2;
vector<vector<char> > a;
vector<vector<int> > dis;
set<int> row[1000009], col[1000009];
queue<pair<int,int> > q;
void del(int x, int y)
{
    row[x].erase(y);
    col[y].erase(x);
    q.push({x,y});
}
void solveR(int x, int y)
{
    while(1)
    {
        auto it=row[x].lower_bound(y);
        if(it==row[x].end()||(*it-y)>k)
            break;
        int newy=*it;
        if(a[x][newy]=='@')
            break;
        dis[x][newy]=dis[x][y]+1;
        del(x,newy);
    }
}
void solveL(int x, int y)
{
    while(1)
    {
        auto it=row[x].lower_bound(y);
        if(it==row[x].begin())
            break;
        it--;
        if((y-*it)>k)
            break;
        int newy=*it;
        if(a[x][newy]=='@')
            break;
        dis[x][newy]=dis[x][y]+1;
        del(x,newy);
    }
}
void solveU(int x, int y)
{
    while(1)
    {
        auto it=col[y].lower_bound(x);
        if(it==col[y].begin())
            break;
        it--;
        if((x-*it)>k)
            break;
        int newx=*it;
        // cout<<newx<<" "<<y<<endl;
        if(a[newx][y]=='@')
            break;
        dis[newx][y]=dis[x][y]+1;
        del(newx,y);
    }
}
void solveD(int x, int y)
{
    while(1)
    {
        auto it=col[y].lower_bound(x);
        if(it==col[y].end()||(*it-x)>k)
            break;
        int newx=*it;
        if(a[newx][y]=='@')
            break;
        dis[newx][y]=dis[x][y]+1;
        del(newx,y);
    }
}
int main()
{
    IO
    cin>>n>>m>>k;
    cin>>x1>>y11>>x2>>y2;
    a.resize(n+9,vector<char>(m+9));
    dis.resize(n+9,vector<int>(m+9, 100000000));

    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            cin>>a[i][j];
            row[i].insert(j);
            col[j].insert(i);
        }

    dis[x1][y11]=0;
    del(x1,y11);
    while(!q.empty())
    {
        pair<int,int> node=q.front();
        q.pop();
        solveR(node.first,node.second);
        solveL(node.first,node.second);
        solveU(node.first,node.second);
        solveD(node.first,node.second);

    }
    if(dis[x2][y2]>1e7)
        dis[x2][y2]=-1;
    cout<<dis[x2][y2];
}


Measured memory_bytes: 239716
n = int(input())
A = list(map(int,input().split()))

A.sort()
mx = A[n-1]
dp = [0]*(mx+1)
for a in A:
    for j in range(a,mx+1,a):
        dp[j]+=1
        
sum = 0
for i in A:
    if dp[i]==1:
        sum+=1
print(sum)

Measured memory_bytes: 32260
using System;

namespace AtCoderSnippet
{
    class Program
    {
        static void Main(string[] args)
        {

            var dts = Console.ReadLine().Split(" ");
            var D = int.Parse(dts[0]);
            var T = int.Parse(dts[1]);
            var S = int.Parse(dts[2]);

            var x = D / S;
            if (D % S > 0) x++;
            if (x <= T)
            {
                Console.Write("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 27492
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>> g(n*n);
  vector<int> p(n*n,0);
  for(int i=0;i<n;i++){
    vector<int> v(n-1);
    for(int j=0;j<n-1;j++){
      int a;
      cin>>a;
      a--;
      v.at(j)=min(i,a)*n+max(i,a);
    }
    for(int j=1;j<n-1;j++){
      g.at(v.at(j-1)).push_back(v.at(j));
      p.at(v.at(j))++;
    }
  }
  vector<int> l(n*n,-1);
  queue<int> q;
  for(int i=0;i<n*n;i++)
    q.push(i);
  for(int i=0;i<n*n&&!q.empty();i++){
    vector<int> s;
    while(!q.empty()){
      int v=q.front();
      q.pop();
      if(p[v]!=0||i<=l[v])
        continue;
      l[v]=i;
      s.push_back(v);
    }
    for(int x:s){
      for(int y:g.at(x)){
        q.push(y);
        p[y]--;
      }
    }
  }
  bool f=1;
  int m=0;
  for(int i=0;i<n*n;i++){
    f=(l[i]==-1?0:f);
    m=max(m,l[i]);
  }
  cout<<(f?m+1:-1)<<endl;
}

Measured memory_bytes: 56240
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct linestruct{
  double a,b;
} line;

int cmpLine(const void *a,const void *b){
  double p=((line *)a)->a;
  double q=((line *)b)->a;
  return p-q>0?-1:1;
}

int calcInversion(double *a,int n,double *tmp){
  if(n<=1) return 0;
  int m=n/2;
  int res=calcInversion(a,m,tmp)+calcInversion(a+m,n-m,tmp);
  memcpy(tmp,a,sizeof(double)*m);
  int i=0,j=m,k=0;
  while(i<m && j<n){
    if(tmp[i]<=a[j]){
      a[k++]=tmp[i++];
    } else {
      a[k++]=a[j++];
      res+=m-i;
    }
  }
  if(i<m) memcpy(a+k,tmp+i,sizeof(double)*(m-i));
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);
  line *l=(line *)calloc(n,sizeof(line));
  int i;
  for(i=0;i<n;i++){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    l[i].a=-(double)a/b;
    l[i].b=(double)c/b;
  }
  qsort(l,n,sizeof(line),cmpLine);
  double *v=(double *)calloc(n,sizeof(double));
  double *tmp=(double *)calloc(n,sizeof(double));
  double ll=-200000000;
  double rr=200000000;
  for(int iter=0;iter<60;iter++){
    double m=(ll+rr)/2;
    for(i=0;i<n;i++) v[i]=l[i].a*m+l[i].b;
    int inv=calcInversion(v,n,tmp);
    if(2*inv<n*(n-1)/2){
      ll=m;
    } else {
      rr=m;
    }
  }
  double ansX=ll;
  for(i=0;i<n;i++){
    double a=l[i].a;
    double b=l[i].b;
    l[i]=(line){1/a,-b/a};
  }
  qsort(l,n,sizeof(line),cmpLine);
  ll=-200000000;
  rr=200000000;
  for(int iter=0;iter<60;iter++){
    double m=(ll+rr)/2;
    for(i=0;i<n;i++) v[i]=l[i].a*m+l[i].b;
    int inv=calcInversion(v,n,tmp);
    if(2*inv<n*(n-1)/2){
      ll=m;
    } else {
      rr=m;
    }
  }
  double ansY=ll;
  printf("%.9lf %.9lf\n",ansX,ansY);
}

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


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

#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 MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false;
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k, l;
	cin >>n >>k >>l;
	
	UF ufa(n), ufb(n);
	rep(i, k){
		int p,q;
		cin >>p >>q;
		ufa.unite(p-1, q-1);
	}
	rep(i, l){
		int p,q;
		cin >>p >>q;
		ufb.unite(p-1, q-1);
	}
	map<ll, int> mp;
	rep(i, n) mp[(ll)ufa.find(i)<<20 | ufb.find(i)]++;
	rep(i, n) cout<<(i? " ":"") << mp[(ll)ufa.find(i)<<20 | ufb.find(i)];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 13568
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<cstdlib>
#include<ctime>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
using namespace std;
 
inline int read() {
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;	
} 

const int N = 2e5+5;
int tot = 0, f[N];
struct node{ int x, y; bool operator < (const node&rhs) const { return x < rhs.x; } } A[N], B[N];
inline bool cmp1(const int&a,const int&b) { return a < b; }
priority_queue<int,vector<int>,greater<int> > q;

int main() {
	int n = read(), m = read(), cnt = 0;
	rep(i,1,n) A[i].x = read(), A[i].y = read();
	sort(A+1,A+n+1);
	rep(i,1,n) { 
		if( q.size() >= A[i].x ) { 
			if( !A[i].x ) f[++tot] = A[i].y;
			else { 
				if( q.top() < A[i].y ) f[++tot] = q.top(), q.pop(), q.push(A[i].y);
				else f[++tot] = A[i].y;
			}
		} else q.push(A[i].y);
	}
	cnt = q.size();
	rep(i,1,tot) f[i] = m + 1 - f[i];
	sort(f+1,f+tot+1);
	int ret = 0;
	rep(i,1,tot) { 
		if( ret + 1 <= min(f[i],m-cnt) ) ret++;
	}
	cout<<n-(ret+cnt)<<endl;
    return 0;
} 

Measured memory_bytes: 3192