akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,m;
    vector<int > v1;
    vector<int > v2;
    cin>>n;
    while(n--)
    {
        int t;
        cin>>t;
        v1.push_back(t);
    }
    cin>>m;
    while(m--)
    {
        int t;
        cin>>t;
        v2.push_back(t);
    }
    if(lexicographical_compare(v1.begin(),v1.end(),v2.begin(),v2.end()))
    {
        cout<<1<<endl;
    }
    else cout<<0<<endl;
}


Measured memory_bytes: 3148
#include<iostream>
#include<cmath>
#include<vector>


using namespace std;
int N,ans=0,s=0;
vector<int>A(100001,0);
vector<int>a(100001,0);

int main(){
    
    
    cin>>N;
    
    for(int i=1;i<=N;i++){
        cin>>A[i];
    }
    
    A[0]=0; A[N+1]=0;
	for(int i=1;i<=N+1;i++){
		s+=abs(A[i-1]-A[i]);
	}
    for(int i=1;i<=N;i++){
        ans=s+abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]));
		cout<<ans<<endl;
		ans=0;
    }
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	bool flag=true;
	int t=0,x=0,y=0;
	rep(i,n){
		int nt,nx,ny;
		cin>>nt>>nx>>ny;
		int dt=nt-t;
		int dl=abs(nx-x)+abs(ny-y);
		t=nt,x=nx,y=ny;
		if(!(dt-dl>=0 && (dt-dl)%2==0)){
			flag=false;
		}
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

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

using namespace std;

int p[66666];
int joint[66666];

int main(void){
	int n;
	while(scanf("%d", &n),n){
		rep(i,n)
			scanf("%d", &p[i]);
		rep(i,n-1)
			scanf("%d", &joint[i]);
		
		sort(joint, joint+n-1);
		reverse(joint, joint+n-1);
		
		long long leng = 0;
		rep(i,n)leng+=p[i];
		
		long long maxR = leng * n;
		
		rep(i,n-1){
			leng+=joint[i];
			maxR = max(maxR, leng*(n-i-1));
		}
		
		printf("%lld\n", maxR);
	}
	
	return 0;
}

Measured memory_bytes: 1552
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

vector<int> G[10001];
ll val[10001];
bool vsd[10001];
vector<ll> C;
int ind = 0;

void dfs(int n){
  //cout << "hoge" << endl;
  if(vsd[n]) return;
  vsd[n] = true;
  val[n] = C[ind];
  ind++;
  for(int i=0;i<G[n].size();i++){
    dfs(G[n][i]);
  }
  return;
}

int main(){
  int N;
  cin >> N;
  int a[N - 1], b[N - 1];
  for(int i=0;i<N - 1; i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }

  ll c[N];
  for(int i=0;i<N;i++) cin >> c[i];
  sort(c, c + N);
  ll M = 0LL;
  for(int i=0;i<N-1;i++) M += c[i];
  for(int i=N-1;i>=0;i--) C.push_back(c[i]);


  /*for(int i=0;i<N;i++){
    cout << i << "    ";
    for(int j=0;j<G[i].size();j++){
      cout << G[i][j] << " ";
    }
    cout << endl;
  }*/

  //dfs
  fill(vsd, vsd + 10001, false);
  val[0] = c[N - 1];
  dfs(0);



  cout << M << endl;
  for(int i=0;i<N;i++) cout << val[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
double gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
double lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int count=0;
  double n,bunshi,bunbo=0;
  cin>>n;
  vector<double>a(n);

  rep(i,n){
    cin>>a[i];
    bunshi=lcm(a[i-1],a[i]);
    count++;
  }
  rep(i,n){
    bunbo+=bunshi*(1/a[i]);
  }

if(count>1)cout<<bunshi/bunbo;
else cout<<a[0];
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>

using namespace std;

#include <vector>

class UnionFind{
 private:
  std::vector<int> p_gs_; //正なら親ノードの番号で負なら自身がルートで値は-groupsize
  int groups_;            //groupの数

 public:
  const int nodes;        //ノードの数

  UnionFind(int size):p_gs_(size, -1),groups_(size),nodes(size){}

  bool unite(int x, int y){
    int rx = root(x), ry = root(y);
    if(rx!=ry){
      --groups_;
      if(p_gs_[ry] < p_gs_[rx]) std::swap(rx, ry); //rx<ryにしてrxにryを連結
      p_gs_[rx] += p_gs_[ry];
      p_gs_[ry] = rx;
    }
    return rx != ry;
  }

  bool same(int x, int y){ return root(x)==root(y); }
  int root(int x){ return p_gs_[x]<0 ? x : p_gs_[x]=root(p_gs_[x]); }
  int gsize(int x){ return -p_gs_[root(x)]; }
  int groups() const{ return groups_; }
};

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

    int n, k, l;
    cin >> n >> k >> l;
    UnionFind a(n), b(n);

    vector<int> p(k), q(k);
    for(int i = 0; i < k; ++i){
        cin >> p[i] >> q[i];
        p[i] -= 1;
        q[i] -= 1;
        a.unite(p[i], q[i]);
    }

    vector<int> r(l), s(l);
    for(int i = 0; i < l; ++i){
        cin >> r[i] >> s[i];
        r[i] -= 1;
        s[i] -= 1;
        b.unite(r[i], s[i]);
    }

    UnionFind c(n);
    for(int i = 0; i < k; ++i){
        // aのやつ
        if(b.same(p[i], q[i])) {
            c.unite(p[i], q[i]);
        }
    }

    for(int i = 0; i < l; ++i){
        // bのやつ
        if(a.same(r[i], s[i])) {
            c.unite(r[i], s[i]);
        }
    }


    map<tuple<int, int>, int> answers;

    for(int i = 0; i < n; ++i){
        answers[make_tuple(a.root(i), b.root(i))] += 1;
    }
    for(int i = 0; i < n; ++i){
        if(i != 0){
            cout << " ";
        }
        cout << answers[make_tuple(a.root(i), b.root(i))];
    }
    cout << endl;

    return 0;
}

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

static const int MAX = 200000;


int main() {
  string s,t;
  cin >> s;
  t = s;
  reverse(t.begin(), t.end());
  int ans = 0;
  rep(i,s.size()) {
    if (s.at(i) != t.at(i)) ans++;
  }
  cout << ans / 2 << endl;
}


Measured memory_bytes: 3572
use std::io::{BufRead, Write};

struct MP {
    next: Vec<i32>,
}

impl MP {
    fn new(s: &Vec<usize>) -> MP {
        let n = s.len();
        let mut next = Vec::with_capacity(n + 1);
        next.push(-1);
        let mut j = -1;
        for i in 0..n {
            while j >= 0 && s[i] != s[j as usize] {
                j = next[j as usize];
            }
            j += 1;
            next.push(j);
        }

        MP { next }
    }
}

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let n: usize = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let a: Vec<usize> = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };
    let b: Vec<usize> = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let c: Vec<usize> = {
        let mut c = Vec::with_capacity(n * 2);
        for i in 0..(n * 2) {
            c.push(a[i % n] ^ a[(i + 1) % n]);
        }
        c
    };
    let d: Vec<usize> = {
        let mut d = Vec::with_capacity(n);
        for i in 0..n {
            d.push(b[i % n] ^ b[(i + 1) % n]);
        }
        d
    };

    let mp = MP::new(&d);
    
    let mut i = 0;
    for j in 0..(c.len() - 1) {
        while i >= 0 && c[j] != d[i as usize] {
            i = mp.next[i as usize];
        }
        i += 1;
        if i == n as i32 {
            let k = j - (n - 1);
            writeln!(writer, "{} {}", k, a[k] ^ b[0]).unwrap();
            i = mp.next[i as usize];
        }
    }
}

Measured memory_bytes: 12660
#include <iostream>

using namespace std;
typedef long long ll;

ll n;

ll f(ll x){
    x>>=1;
    ll ans=0;
    for(ll i=5;i<=n;i*=5){
        ans+=x/i;
    }
    return ans;
}

int main()
{
    cin>>n;
    if(n&1) cout<<0;
    else{
        cout<<f(n);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin>>n;
    long ft,fa,sum;
    for(int i=0; i<n; i++){
        long t,a;
        cin>>t>>a;
        if(i>0){
            int j=0;
            while((ft+j)%t!=0)
                j++;
            sum+=j;
            ft+=j;
            j=0;
            while((fa+j)%a!=0)
                j++;
            sum+=j;
            fa+=j;
            if(ft/t*a>=fa){
                sum+=ft/t*a-fa;
                fa=ft/t*a;
            }
            else{
                sum+=fa/a*t-ft;
                ft=fa/a*t;
            }
        }
        else{
            ft=t;
            fa=a;
            sum=t+a;
        }
    }
    cout<<sum;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		if(x == 0){
			System.out.println(1);
		}
		else{
			System.out.println(0);
		}
		stdIn.close();
	}
}

Measured memory_bytes: 35596
#include<stdio.h>
#define MAX 100005
#define NIL -1

void Print(int);
int depth(int, int);

struct Node{
  int parent, left, right;
};

struct Node Tree[MAX];

int Depth[MAX];

int main(){
  int n,i,j,num,dep,c,l,key;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    Tree[i].parent = Tree[i].left = Tree[i].right = NIL;
  }
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&num,&dep);
    for(j = 0 ; j < dep ; j++){
      scanf("%d",&c);
      if(j == 0) Tree[num].left = c;
      else Tree[l].right = c;
      l = c;
      Tree[c].parent = num;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    if(Tree[i].parent == NIL) key = i;
  }

  depth(key,0);
 
  for(i = 0 ; i < n ; i++) Print(i);
  
  return 0;
}

void Print(int x){
  int i,y;

  printf("node %d: ",x);
  printf("parent = %d, ",Tree[x].parent);
  printf("depth = %d, ",Depth[x]);

  if(Tree[x].parent == NIL) printf("root, ");
  else if(Tree[x].left == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i = 0, y = Tree[x].left ; y != NIL ; i++, y = Tree[y].right){
    if(i > 0) printf(", ");
    printf("%d",y);
  }
  printf("]\n");
}

int depth(int x, int y){
  Depth[x] = y;
  if(Tree[x].right != NIL) depth(Tree[x].right, y);
  if(Tree[x].left != NIL) depth(Tree[x].left ,y+1);
}




Measured memory_bytes: 6408
#include <stdio.h>
#include <stdlib.h>

int f = 0;

void op(char e[], int s, int a, int b, int c, int d, int p)
{
  if ( f ) { return; }
  if ( s == 7 && p == 3 ) {
    f = 1;
    return;
  }
  if ( p < 3 ) { e[p*2+1] = '+'; }
  switch ( p ) {
  case 0:
    op(e, s+b, a, b, c, d, 1);
    break;
  case 1:
    op(e, s+c, a, b, c, d, 2);
    break;
  case 2:
    op(e, s+d, a, b, c, d, 3);
    break;
  }
  if ( f ) { return; }
  if ( p < 3 ) { e[p*2+1] = '-'; }
  switch( p ) {
  case 0:
    op(e, s-b, a, b, c, d, 1);
    break;
  case 1:
    op(e, s-c, a, b, c, d, 2);
    break;
  case 2:
    op(e, s-d, a, b, c, d, 3);
    break;
  }
}

int main(void)
{
  char expr[10];
  char abcd[5];
  int a, b, c, d;

  scanf("%s", abcd);
  a = abcd[0] - '0';
  b = abcd[1] - '0';
  c = abcd[2] - '0';
  d = abcd[3] - '0';
  expr[0] = abcd[0];
  expr[2] = abcd[1];
  expr[4] = abcd[2];
  expr[6] = abcd[3];

  op(expr, a, a, b, c, d, 0);
  printf("%s=7\n", expr);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
int main(){
	long long int A, B; cin >> A >> B; 
	long long int G = gcd(A, B); 
	int ans = 1; 
	for(long long int i = 2; i <= 1000000; i++){
		if(G % i == 0){
			ans ++; 
			while(G % i == 0){
				G /= i; 
			}
		}
		if(G == 1) break;
	}
	if(G > 1) ans ++; 
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 10;
LL a[N];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    sort(a,a+n);
    LL x=0,y=0;
    for(int i=n-1;i>=0;i--) {
        if(a[i]==a[i-1]&&x==0) {
            x=a[i];
            i--;
        }
        else if(a[i]==a[i-1]&&x!=0) {
            y=a[i];
            break;
        }
    }
    printf("%lld\n",x*y);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    string A;
    cin >> A;
    vector<long long> num(26, 0);
    for (char c : A) {
        num[c - 'a']++;
    }

    long long ans = (A.size() * (A.size() - 1)) / 2 + 1;
    for (int i = 0; i < 26; i++) {
        ans -= (num[i] * (num[i] - 1)) / 2;
    }
    cout << ans << endl;
}


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

using namespace std;
using LL = long long;

constexpr int MAXN = 3e3 + 3;

LL R, C, K;
LL dp[MAXN][MAXN][5], mp[MAXN][MAXN];

int main () {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> R >> C >> K;
    for (int i = 1; i <= K; i++) {
        int r, c, v;
        cin >> r >> c >> v;
        mp[r][c] = v;
    }
    for (int i = 1; i <= R; i++)
        for (int j = 1; j <= C; j++) {
            for (int cnti = 0; cnti < 4; cnti++) {
                    //不选
                    dp[i][j][cnti] = max(dp[i][j][cnti], dp[i][j - 1][cnti]);
                    for (int cntj = 0; cntj < 4; cntj++)
                        dp[i][j][cnti] = max(dp[i][j][cnti], dp[i - 1][j][cntj]);
                    //选
                    dp[i][j][cnti + 1] = max(dp[i][j][cnti + 1], dp[i][j - 1][cnti] + mp[i][j]);
                    for (int cntj = 0; cntj < 4; cntj++)
                        dp[i][j][cnti + 1] = max(dp[i][j][cnti + 1], dp[i - 1][j][cntj] + mp[i][j]);
            }
        }
    LL ans = 0;
    for (int i = 0; i < 4; i++) ans = max(ans, dp[R][C][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 425940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位
vector<ll> c(1000, 0);
vector<ll> use(100, 0);
ll n;
string s;
void func(ll cnt, string a){
    vector<ll> d(10, 0);
    for(ll i = cnt+1; i < n; i++){
        char b = s[i];
        if(d[b-48]!=0) continue;
        string t = a + s.substr(i, 1);
        if(t.length()==2) {
            ll check = stoi(t);
            if(use[check]==0){
                func(i, t);
                use[check]++;
            }
        }
        else if(t.length()==3){
            ll check = stoi(t);
            c[check]++;
        }
        d[b-48]++;
    }
}
int main(void){
    cin >> n;
    cin >> s;
    for(ll i = 0; i < s.length()-2; i++){
        string t = s.substr(i, 1);
        func(i, t);
    }
    ll ans = 0;
    for(ll i = 0; i < 1000; i++){
        if(c[i]>0) ans++;
    }
    cout << ans << endl;
    //for(ll i = 0; i < 100; i++)
      //  cout << i << " " << use[i] << endl;
    return 0;
}


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

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

#define mod 1000000007
typedef long long ll;

int main() {
    int n;
    string s;
    cin>>n>>s;
    vector<vector<int>> rgb(3,vector<int>(n+1,0));
    for(int i=n-1;i>=0;i--){
        rgb[0][i]=rgb[0][i+1];rgb[1][i]=rgb[1][i+1];rgb[2][i]=rgb[2][i+1];
        if(s[i]=='R') rgb[0][i]++;
        if(s[i]=='G') rgb[1][i]++;
        if(s[i]=='B') rgb[2][i]++;
    }
    ll ans =0;
    map<char,int> mp;
    mp['R']=0;mp['G']=1;mp['B']=2;
    rep(i,n){
        rept(j,i+1,n-1){
            if(s[i]==s[j]) continue;
            int cl = 3-mp[s[i]]-mp[s[j]];
            ans+=rgb[cl][j+1];
            if(j*2-i<=n-1){
                if(mp[s[j*2-i]]==cl) ans--;
            }
        }
    }

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


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
    vector<int> rate(9, 0);
    int N, a, r, ansmin = 0, ansmax;
    cin >> N;
    rep(N){
        cin >> a;
        r = min(8, a / 400);
        if(rate[r] == 0 && r < 8){
            ansmin++;
        }
        rate[r]++;
    }
    if(ansmin == 0){
        ansmin = 1;
        rate[8]--;
    }

    if(rate[8] > 0){
        ansmax = ansmin+rate[8];
    }else{
        ansmax = ansmin;
    }
    cout << ansmin << " " << ansmax;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
const long INF = 1000000009;

long n;
long name[5];

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		std::string s;
		std::cin >> s;
		if(s[0] == 'M'){
			name[0]++;
		}else if(s[0] == 'A'){
			name[1]++;
		}else if(s[0] == 'R'){
			name[2]++;
		}else if(s[0] == 'C'){
			name[3]++;
		}else if(s[0] == 'H'){
			name[4]++;
		}
	}
	long ans = 0;
	for(int i = 0; i < 5; i++){
		for(int j = i+1; j < 5; j++){
			for(int k = j+1; k < 5; k++){
				ans += name[i]*name[j]*name[k];
			}
		}
	}
	/*for(int i = 0; i < 5; i++){
		printf("%ld ", name[i]);
	}
	printf("\n");
	* //*/
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)
var mod uint64 = 998244353

var maxfac uint64 = 200000
var fac []uint64  // n! % mod
var ifac []uint64 // k!^(mod-2) % mod

func initCombination() {
	fac = make([]uint64, maxfac+1)
	ifac = make([]uint64, maxfac+1)
	fac[0] = 1
	ifac[0] = 1
	var i uint64
	for i = 0; i < maxfac; i++ {
		fac[i+1] = fac[i] * (i + 1) % mod
		ifac[i+1] = ifac[i] * powMod(i+1, mod-2) % mod
	}
}
func combination(n, r uint64) uint64 {
	if n == 0 && r == 0 {
		return 1
	}
	if n < r || n < 0 {
		return 0
	}
	return (fac[n] * (ifac[r] * ifac[n-r] % mod) % mod)
}

func powMod(n, m uint64) uint64 {
	var ans uint64 = 1
	for m != 0 {
		if (m % 2) != 0 {
			ans = ans * n % mod
			if m == 1 {
				break
			}
		}
		n = n * n % mod
		m = m / 2
	}
	return ans
}

func main() {
	list := getStdinIntArr64()
	var N uint64 = uint64(list[0])
	var M uint64 = uint64(list[1])
	var K uint64 = uint64(list[2])

	initCombination()

	var ans uint64 = 0
	var k uint64 = 0
	for k = 0; k <= K; k++ {
		var tmp uint64 = 0
		tmp = M * combination(N-1, k) % mod
		tmp = tmp * powMod(M-1, N-1-k) % mod
		ans = (ans + tmp) % mod
	}

	fmt.Printf("%d", ans)
	fmt.Printf("\n")
}

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
int main()
{
        char a[3][3];
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
            cin>>a[i][j];
        cout<<a[0][0]<<a[1][1]<<a[2][2];
   return 0;
   }

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010


//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    cin>>s;
    if(s[2]==s[3] && s[5]==s[4])
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))

int a[100010],b[100010];
int main(){
	//ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n,k,x,cnt=0;
	cin>>n;
	repeat(i,1,n+1)cin>>a[i];
	repeat(i,1,n+1)b[a[i]]=i;
	repeat(i,1,n+1)cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<queue>
#include<sstream>
#include<iomanip>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}
int c[50][50];
int main(){
	int w,h;
	int dx[] = {-1,  0,  1, -1, 1, -1, 0, 1};
	int dy[] = {-1, -1, -1,  0, 0,  1, 1, 1};
	while(cin >> w >> h, w){
		rep(i,h) rep(j,w) {
			cin >> c[i][j];
		}
		int cnt = 2;
		rep(i,h) rep(j,w){
			if(c[i][j] != 1) continue;
			c[i][j] = cnt;
			queue<pii> q;
			q.push(pii(i, j));
			while(!q.empty()){
				int x = q.front().sc, y = q.front().fs;
				q.pop();
				rep(k,8){
					int cx = x + dx[k], cy = y+dy[k];
					if(cx >= 0 && cy >= 0 && cy < h && cx < w && c[cy][cx] == 1){
						q.push(pii(cy, cx));
						c[cy][cx] = cnt;
					}
				}
			}
			cnt ++;
		}
		cout << cnt - 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
N = int(input())
V = list(map(int, input().split()))
h = N//2

from collections import Counter
A = Counter(V[::2])
B = Counter(V[1::2])

ac = sorted(A.items(), key=lambda x: -x[1])
bc = sorted(B.items(), key=lambda x: -x[1])

if len(ac) == 1 and len(bc) == 1:
    if ac[0][0] == bc[0][0]:
        print(h)
    else:
        print(0)
elif len(ac) == 1:
    print(h-bc[0][1])
elif len(bc) == 1:
    print(h-ac[0][1])
elif ac[0][0] == bc[0][0]:
    if ac[0][1]-ac[1][1] == bc[0][1]-bc[1][1]:
        if ac[0][1] >= bc[0][1]:
            print((h-ac[0][1]) + (h-bc[1][1]))
        else:
            print((h-ac[1][1]) + (h-bc[0][1]))
    elif ac[0][1]-ac[1][1] > bc[0][1]-bc[1][1]:
        print((h-ac[0][1]) + (h-bc[1][1]))
    else:
        print((h-ac[1][1]) + (h-bc[0][1]))
else:
    print((h-ac[0][1]) + (h-bc[0][1]))

Measured memory_bytes: 65516
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define P(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  ll a,b,c,d,x,y;
  IN(a);
  IN(b);
  IN(c);
  IN(d);
  x = a < b ? a : b;
  y = c < d ? c : d;

  OUT(x+y);
}


Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    for i in range(len(s)-1):
        if s[i:i+2] == "AC":
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int s[10]={0};

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<10;i++)
            scanf("%d",&s[i]);
        int a=0;
        int b=0;
        bool flag=0;
        for(int i=0;i<10;i++)
        {
            if(s[i]<a&&s[i]<b)
            {
                flag=1;
                break;
            }
            else if(s[i]<a&&s[i]>b)b=s[i];
            else if(s[i]>a&&s[i]<b)a=s[i];
            else
            {
                a=a>b?s[i]:a;
                b=a<b?s[i]:b;
                if(a==b)a=s[i];
            }
        }
        if(flag)printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, d;
    cin >> n >> d;
    int t = n / (d * 2 + 1);
    if(n % (d * 2 + 1) != 0 ) ++t;
    cout << t << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>
#include <iomanip>

using namespace std;

int main() {
	int n, m,p;
	
	cin >> n >> m;

	vector<int> h(n+1);
	
	for (int i = 0; i < n; i++)cin >> h[i+1];

	vector<vector<int> > arr(m, vector<int>(2));

	for (int i = 0; i < m; i++) {
		for (int j = 0; j < 2; j++) {
			cin >> arr[i][j];
		}
	}

	vector<int> point(n+1);

	//arr[i][j]の関連を判定
	//小さいほう基準で選ぶ
	//高さを比較して、一致するものがあれば、フラグを1にする

	for (int i = 0; i < m; i++) {
		if (h[arr[i][0]]>h[arr[i][1]]) {
			point[arr[i][1]]++;
		}

		if (h[arr[i][0]] < h[arr[i][1]]) {
			point[arr[i][0]]++;
		}

		if (h[arr[i][0]] == h[arr[i][1]]) {
			point[arr[i][0]]++;
			point[arr[i][1]]++;
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (point[i] == 0)ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9556
#include <iostream>
#include <algorithm>
#define INF 1000000000
using namespace std;
int mp[2][101][101];
int n,m;
 
int visit(int p,int q,int r) {
 
 
  bool flg[101] = {};
  long long dis[101];
  for(int i=1;i<=m;i++) dis[i] = INF;
 
  dis[p] = 0;
  
  while(1) {
    int mindis = INF;
    int ima;
    for(int i=1;i<=m;i++) 
      if(mindis > dis[i] && flg[i] == 0) {
    mindis = dis[i];
    ima = i;
      }
 
    flg[ima] = 1;
    if(ima == q) return dis[ima];
 
    for(int i=1;i<=m;i++) 
      if(dis[i] > mp[r][ima][i]+dis[ima]) 
    dis[i] = dis[ima] + mp[r][ima][i];
     
  }
 
 
}
 
 
int main (){
 
  while(1) {
    cin >> n >> m;
    if(n == 0 && m == 0) break;
   
  for(int k=0;k<2;k++) 
    for(int i=0;i<=m;i++) 
      for(int j=0;j<=m;j++)
    mp[k][i][j] = INF;
 
     
  for(int i=0;i<n;i++){
  int a , b , cost,time;
  cin >> a >> b >> cost >> time;
  mp[0][a][b] = min(mp[0][a][b] ,cost);
  mp[0][b][a] = min(mp[0][b][a] ,cost);
  mp[1][a][b] = min(mp[1][a][b] ,time);
  mp[1][b][a] = min(mp[1][b][a] ,time);
  }
 
  int qu;
  cin >> qu;
  int p,q,r;
 
  for(int i=0;i<qu;i++) {
    cin >> p >> q >> r;
 
    int ans = visit(p,q,r);
    cout << ans << endl;
  }
  }
   
  return 0;
}

Measured memory_bytes: 1240
# from bisect import bisect_left
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

resid = M
i = 0
pi = 0
pif = True
while resid:
    A[i] //= 2
    resid -= 1
    if i < N-1 and A[i] < A[i+1]:
        if A[pi] > A[i+1]:
            A.sort(reverse=True)
            i = 0
            pi = 0
            pif = True
            continue
        if pif:
            pi = i
            pif = False
        i += 1
    else:
        i = pi
        pif = True

print(sum(A))


Measured memory_bytes: 63856
N = int(input())

info = []
for i in range(N):
    info.append(list(map(int,input().split())))

ans = []
ans_c = 0
for i in range(101):
    for j in range(101):
        H = -1
        judge = True
        for k in range(N):
            if info[k][2] == 0:
                continue
            dis = abs(i - info[k][0]) + abs(j - info[k][1])
            if H == -1:
                H = info[k][2] + dis
            else:
                if H != (info[k][2] + dis):
                    judge = False
        if judge == True:
            for k in range(N):
                if info[k][2] == 0:
                    h = max(H - (abs(i - info[k][0]) + abs(j - info[k][1])), 0)
                    if h != 0:
                        judge = False
        if judge == True:
            print("{} {} {}".format(i,j,H))
            exit()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

bool primes[60000];
void make_prime(){
	primes[0]=primes[1]=true;
	for(int i=2; i*i<=60000; i++)if( !primes[i] )
		for(int j=i*2; j<60000; j+=i)primes[j]=true;
}
int main(){
	int n,min_p,max_p;
	make_prime();
	while(~scanf("%d",&n)){
		//min
		for(int i=n-1; i>1; i--)if( !primes[i] ){	min_p = i; break; }
		//max
		for(int i=n+1; i<60000; i++)if( !primes[i] ){ max_p=i; break; }
		printf("%d %d\n",min_p,max_p);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
template < typename T > 
inline T read( )
{
 T x = 0;
 char ch = getchar( );
 while( !isdigit( ch ) )
  ch = getchar( );
 while( isdigit( ch ) )
  x = x * 10 + ch - '0',
  ch = getchar( );
 return x;
}
template < typename T >
void print( T x )
{
 if( x < 0 )
  putchar( '-' ),
  x = -x;
 if( x < 10 )
 {
  putchar( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 putchar( x % 10 + 48 );
}
#define rdi( ) read < int > ( )
#define pti( i ) print < int > ( i )
using std::pair;
using std::vector;
#ifdef ONLINE_JUDGE
const int N = 1e4 + 1;
#else
const int N = 1e2 + 1;
#endif
int n, cnt, rt, top, num, dep, ls[ N * 4 ], rs[ N * 4 ], low[ N * 4 ], dfn[ N * 4 ], sta[ N * 4 ], col[ N * 4 ];
pair < int, int > x[ N * 2 ];
bool fsta[ N * 4 ];
inline int op( int i )
{
 return i <= n ? i + n: i - n;
}
vector < int > v[ N * 4 ];
inline void Add_Edge( int a, int b )
{
 v[ a ].push_back( b );
 return;
}
void Build( int &k, int l, int r )
{
 if( l == r )
 {
  k = op( x[ l ].second );
  return;
 }
 k = ++cnt;
 Build( ls[ k ], l, ( l + r ) / 2 );
 Build( rs[ k ], ( l + r ) / 2 + 1, r );
 Add_Edge( k, ls[ k ] );
 Add_Edge( k, rs[ k ] );
 return;
}
void Link( int k, int l, int r, int x, int y, int LYZ )
{
 if( y < x )
  return;
 if( x <= l && r <= y )
  return Add_Edge( LYZ, k );
 int mid = l + r >> 1;
 if( x <= mid )
  Link( ls[ k ], l, mid, x, y, LYZ );
 if( mid < y )
  Link( rs[ k ], mid + 1, r, x, y, LYZ );
 return;
}
void Dfs( int u )
{
 dfn[ u ] = low[ u ] = ++dep;
 fsta[ sta[ ++top ] = u ] = 1;
 for( auto &to: v[ u ] )
 {
  if( dfn[ to ] )
  {
   if( fsta[ to ] )
    low[ u ] = std::min( dfn[ to ], low[ u ] );
   continue;
  }
  Dfs( to );
  low[ u ] = std::min( low[ to ], low[ u ] );
 }
 if( low[ u ] == dfn[ u ] )
 {
  num++;
  while( fsta[ u ] )
  {
   col[ sta[ top ] ] = num;
   fsta[ sta[ top-- ] ] = 0;
  }
 }
 return;
}
bool check( int val )
{
 std::memset( dfn, 0, sizeof dfn );
 std::memset( low, 0 ,sizeof low );
 std::memset( col, 0, sizeof col );
 std::memset( fsta, 0, sizeof fsta );
 For( i, 1, n * 4 )
  v[ i ].clear( );
 Build( rt, 1, cnt = 2 * n );
 dep = num = 0;
 bool flag = 1;
 For( i, 1, 2 * n )
 {
  int l = std::upper_bound( x + 1, x + 2 * n + 1, std::make_pair( x[ i ].first - val, 0x3f3f3f3f ) ) - x,
   r = std::lower_bound( x + 1, x + 2 * n + 1, std::make_pair( x[ i ].first + val, 0 ) ) - x - 1;
  Link( rt, 1, 2 * n, l, i - 1, x[ i ].second );
  Link( rt, 1, 2 * n, i + 1, r, x[ i ].second );
 }
 Dfs( rt );
 For( i, 1, n )
  flag &= col[ i ] != col[ i + n ];
 return flag;
}
int main( )
{
 n = rdi( );
 For( i, 1, n )
  x[ i ].first = rdi( ),
  x[ i + n ].first = rdi( ),
  x[ i ].second = i,
  x[ i + n ].second = i + n;
 std::sort( x + 1, x + 2 * n + 1, std::less < pair < int, int > > ( ) );
 int l = 0, r = x[ 2 * n ].first - x[ 1 ].first, ans = -1;
 while( l <= r )
 {
  int mid = l + r >> 1;
  if( check( mid ) )
   ans = mid, l = mid + 1;
  else
   r = mid - 1;
 }
 pti( ans );
 return 0;
}

Measured memory_bytes: 13320
#include <iostream>

using namespace std;

int main(){
  long long N,A,B,i;
  cin >> N >> A >> B;
  int a[N];
  if (A>N || B > N || A+B >N+1 || (N+A-1)/A > B) {
    cout << -1;
  } else {
    int m=N+1-A-B;
    for (i=0;i<A;i++) {
      a[i]=N-A+i+1;
    }
    int k=1;
    while (m>=A) {
      for (i=A*k;i<A*(k+1);i++) {
        a[i]=N-(2*A*k)-A+i+1;
      }
      m-=A-1;
      k+=1;
    }
    int j=A*k;
    for (i=j;i<j+m+1;i++) {
      a[i]=N-(A*k)-m+i-j;
    }
    j+=m+1;
    for (i=j;i<N;i++) {
      a[i]=N-i;
    }

    for (i=0;i<N;i++) {
      cout << a[i];
      if (i<N-1) cout << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 3328
//	-*- mode: C++ -*-
// Partition
//	Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q.
//
//	In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r).
//
//	Your task is to read a sequence A and perform the Partition based on the following pseudocode:
//
// Partition(A, p, r)
// 1 x = A[r]
// 2 i = p-1
// 3 for j = p to r-1
// 4     do if A[j] <= x
// 5        then i = i+1
// 6            exchange A[i] and A[j] 
// 7 exchange A[i+1] and A[r]
// 8 return i+1
// Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].
// Input
//	The first line of the input includes an integer n, the number of elements in the sequence A.
//
//	In the second line, Ai (i = 1,2,...,n), elements of the sequence are given separated by space characters.
//
// Output
//	Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by [  ].
//
// Constraints
//	1 ≤ n ≤ 100,000
//	0 ≤ Ai ≤ 100,000
// Sample Input 1
//	12
//	13 19 9 5 12 8 7 4 21 2 6 11
// Sample Output 1
//	9 5 8 7 4 2 6 [11] 21 13 19 12

#include <iostream>
#include <algorithm>
#include <vector>

unsigned int	Partition(std::vector<unsigned int>&	A,
						  unsigned int					p,
						  unsigned int					r)
{
	auto	x	= A[r];
	int		i	= p - 1;

	for(int j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			std::swap(A[i], A[j]);
		}
	}

	std::swap(A[i + 1], A[r]);

	return	i + 1;
}

int	main()
{
	std::vector<unsigned int>	A	{};
	unsigned int				n	{0};
	std::cin >> n;

	for(unsigned int i = 0; i < n; i++){
		unsigned int	Ai	{0};
		std::cin >> Ai;
		A.push_back(Ai);
	}

	unsigned int	j	= Partition(A, 0, n - 1);

	for(unsigned int i = 0; i < n; i++){
		if(i > 0){
			std::cout << ' ';
		}

		if(i == j){
			std::cout << '[' << A[i] << ']';
		}
		else{
			std::cout << A[i];
		}
	}

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



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int A, B, C, D; cin >> A >> B >> C >> D;
    while(A>0 || C>0){
        C -= B;
        if(C<=0) break;
        A -= D;
        if(A<=0) break;
    }
    if(A>0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include <string>
#include <typeinfo>
using namespace std;
int main(){
  string raw;
  cin >> raw;
  
  int year = 0;
  year = ((int)raw[0]-48) * 1000;
  year += ((int)raw[1]-48)* 100;
  year += ((int)raw[2]-48) *  10;
  year += ((int)raw[3]-48) *   1;
  
  int month = 0;
  month = ((int)raw[5]-48) * 10;
  month += ((int)raw[6]-48) * 1;
  
  if (year < 2019){
    cout << "Heisei";
    return 0;
  } else if (year == 2019 && month <=4){
    cout << "Heisei";
    return 0;
  } else {
    cout << "TBD";
    return 0;
  }
  //cout << typeid((int)raw[0]).name();
  //cout << (int)raw[0];
  //cout << year;
  //cout << ans;
  return 0;
}

Measured memory_bytes: 256
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  (function(x) {
    //????????????????????????
    console.log(Math.pow(x,3));
  }(parseInt(inputs.trim(),10))); //????°??????????????¶?????????°?????????
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.diverta2019_2
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            if (k == 1)
            {
                WriteLine(0);
            }
            else
            {
                WriteLine(n - k);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
from collections import deque
n,m,k=map(int,input().split())
fr=[[]]
for i in range(n-1):
  fr.append([])
for i in range(m):
  a,b=map(int,input().split())
  fr[a-1].append(b)
  fr[b-1].append(a)

belong=[0]*n
anslist=[0]*n
count=0
def bfs(k):
  global count
  if belong[k-1]==0:
    count+=1
    use=deque()
    use.append(k)
    ans=0
    aldic={}
    while use:
      check=use.popleft()
      if check not in aldic:
        aldic[check]=1
        for x in fr[check-1]:
          use.append(x)
    for x in aldic:
      belong[x-1]=count
      anslist[x-1]=len(aldic)-len(fr[x-1])-1

for i in range(1,n+1):
  bfs(i)
for i in range(k):
  a,b=map(int,input().split())
  if belong[a-1]==belong[b-1]:
    anslist[a-1]-=1
    anslist[b-1]-=1
for i in range(0,len(anslist)):
  if i!=len(anslist)-1:
    print(anslist[i],end=" ")
  else:
    print(anslist[i])

Measured memory_bytes: 34136
import numpy as np
n=int(input())
a=[0,0,0,0,0]
a[0]=int(input())
a[1]=int(input())
a[2]=int(input())
a[3]=int(input())
a[4]=int(input())
k=np.argmin(a)
if n%a[k]==0:
    l=n//a[k]
else:
    l=n//a[k]+1
print(4+l)


Measured memory_bytes: 21532
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 100005
int vis[MAX];
int main()
{
    int n,m,x,y;
    scanf("%d%d",&n,&m);
    memset(vis,0,sizeof(vis));
    while(m--)
    {
        scanf("%d%d",&x,&y);
        vis[x]++;
        vis[y]++;
    }
    int flag=1;
    for(int i=1;i<=n;i++)
        if(vis[i]%2)
        flag=0;
        if(flag)
            printf("YES\n");
        else
            printf("NO\n");
    return 0;
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 500006
#define mod 1000000007
#define mod2 998244353
#define inf 1e17

int dp[2][100001];
int w[101],v[101];
int n,W;

// int solve(int id,int val)
// {
//     if(val<=0)
//         return 0;
//     if(id<0)
//         return inf;
    
//     int &ans=dp[id][val];
//     if(ans!=-1)
//         return ans;
//     //ans=0;
//     ans=min(solve(id-1,val),w[id]+solve(id-1,val-v[id]));
//     return ans;


// }


int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif
    
    

    cin >> n >> W;

    
    //memset(dp,-1,sizeof dp);
    int i,j;
    
    for(i=1;i<=n;i++)
    {
        cin >> w[i] >> v[i];
    }


    for(i=0;i<2;i++)
    {
        for(j=0;j<100001;j++)
        {
            dp[i][j]=inf;
        }
    }


    dp[0][0]=0;
    dp[1][0]=0;

    for(i=1;i<=n;i++)
    {
        int p=i%2;
        for(j=100000;j>=0;j--)
        {
            if(j>=v[i])
            {
                dp[p][j]=min(dp[1-p][j],w[i]+dp[1-p][j-v[i]]);
            }
            else
            {
                dp[p][j]=dp[1-p][j];
            }
        }
    }

    for(i=100000;i>=0;i--)
    {
        if(dp[n%2][i]<=W)
        {
            cout << i << endl;
            return 0;
        }
    }

   


}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL ans = N * (2 * L + N - 1) / 2;
    if (0 < L) {
        ans -= L;
    } else if (L < 1 - N) {
        ans -= (L + N - 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import *
from copy import *
H,W = map(int,input().split())
S = [(W+2)*["#"]]+[["#"]+list(input())+["#"] for h in range(H)]+[(W+2)*["#"]]
D = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 0
P = deque([])
Q = deque([])
 
for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w]==".":
      P+=[[h,w]]
 
while P:
  T = deepcopy(S)
  sx,sy = P.popleft()
  T[sx][sy] = 0
  Q = deque([[sx,sy]])
  while Q:
    x,y = Q.popleft()
    for dx,dy in D:
      if T[x+dx][y+dy]==".":
        T[x+dx][y+dy] = T[x][y]+1
        Q+=[[x+dx,y+dy]]
        ans = max(ans,T[x+dx][y+dy])
 
print(ans)

Measured memory_bytes: 9576
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c,d;cin>>a>>b>>c>>d;
  int ans;
  if(a>c && a>d){
    ans=0;
  }else if(a>c && a<=d &&d<b){
    ans=d-a;
  }else if(a>c && b<=d){
    ans=b-a;
  }else if(a<=c && c<b && d<b){
    ans=d-c;
  }else if(a<=c && c<b && b<=d){
    ans=b-c;
  }else{
    ans=0;
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256