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

int main(){
    int N;
    cin >> N;
    int nx = 1;
    int a, cnt =0;
    rep(i,N){
        cin >> a;
        if(a == nx){
            nx++;
        }else {
            cnt++;
        }
    }
    if(cnt == N) cout << -1 << endl;
    else cout << cnt << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll n,m;
    cin>>n>>m;
    ll a=m/n;
    ll b=m%n;
    if(!b) cout<<a<<endl;
    else{
        ll ans=0;
        for(ll i=1; i<(m+n-1)/n; i++){
            if(i*n<=m&&m%i==0){
                ans = max(ans,i);
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>


#define nmax 100010
const long long MOD = 1000000007;

using namespace std;
long long P[nmax];
int n;
int a[nmax];

int main()
{
	cin >> n;
	for (int i =1 ;i<=n; i++ ) cin >> a[i];
	long long res = 1;
	int k = 0;
	//int j = 0;
	P[0] = 1;
	for (int i =1;i<=n;i++) P[i] = (P[i-1] * i) % MOD;
	for (int i = 1;i<=n;i++)	
	{
		if ((i!=n)&& (a[i] == 2*(i-k) -2 ))
		{
			res = (res * (i-k))% MOD;
			k ++;
		}
		if (i==n)
		{
			res = (res * P[n-k]) % MOD;
		}
	}
	cout <<res;
	return 0 ;
}

Measured memory_bytes: 1408
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

#include <bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

// ------------------------------------------------------------------------------------------------

void func() {
    ll s; cin >> s;
    ll a = ceil(sqrt((double) s));
    ll b = a * a - s;
    cout << a << ' ' << b << ' ' << 1 << ' ' << a << ' ' << 0 << ' ' << 0 << endl;
}

int main() {
    fast_io; cout.precision(32);
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;


void solve(long long A, long long B, long long C, long long K){
    long long ans=0;
    if(A>=K){
        ans=K;
    }else if(A+B>=K)
    {
        ans=A;
    }else if(A+B+C>=K)
    {
        ans=A-(K-(A+B));
    }
    cout<<ans<<endl;
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


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

int main() {
string s; cin>>s;
  ll bcount=0;
  ll bdis=0;
  rep(i, s.size()){
    if(s[i]=='W'){
      bcount+=1;
      bdis+=i;}
  }
    
    cout<<bdis-bcount*(bcount-1)/2<<endl;
  
  
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    string S, T;
    cin >> S >> T;
    vector<string> v;
    for(ll i = 0; i + T.size()  - 1 < S.size(); i++){
        string tmp = S.substr(i, T.size());
        bool ok = 1;
        for(ll j = 0; j < T.size(); j++) ok &= (tmp[j] == '?' || tmp[j] == T[j]);
        if(ok){
            string tmp = S;
            for(ll j = i; j - i < T.size(); j++) tmp[j] = T[j - i];
            for(ll j = 0; j < tmp.size(); j++) if(tmp[j] == '?') tmp[j] = 'a';
            v.push_back(tmp);
        }
    }
    sort(v.begin(), v.end());
    if(v.size()) cout << v[0];
    else cout << "UNRESTORABLE";
    cout << endl;
    return 0;
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 20;

int N, M;
bool Vis[MAX_N];
char Mp[MAX_N][MAX_N];
char Now[MAX_N][MAX_N];
string S[MAX_N];
void chooseH() {
	map<string, set<int>> mp;
	vector<bool> vis(N, false);
	for(int i=0; i<N; i++) {
		S[i] = Now[i];
		//printf("%d : %s\n", i, S[i].c_str());
		mp[S[i]].insert(i);
		string rs = S[i]; reverse(ALL(rs));
	}
	puts("");
	bool used = false;
	if(N % 2 == 0) used = true;
	for(int i=0; i<N; i++) if(!vis[i]) {
		vis[i] = true;
		string s = S[i];
		mp[S[i]].erase(i);
		string rs = s;
		reverse(ALL(rs));
		if(SZ(mp[rs]) == 0) {
			if(rs == s) {
				if(used) return;
				used = true;
			}else{
				return;
			}
		}else{
			auto it = mp[rs].begin();
			vis[*it] = true;
			mp[rs].erase(it);
		}
	}
	puts("YES");
	exit(0);
}
void chooseW(int who, int ix, int cnt) {
	if(who == M) return chooseH();
	if(Vis[who]) return chooseW(who+1, ix, cnt);
	Vis[who] = true;
	for(int k=0; k<N; k++) Now[k][ix] = Mp[k][who];
	for(int i=who+1; i<M; i++) if(not Vis[i]) {
		Vis[i] = true;
		for(int k=0; k<N; k++) Now[k][M-1-ix] = Mp[k][i];
		chooseW(who+1, ix+1, cnt+2);
		Vis[i] = false;
	}
	Vis[who] = false;
}
int main() {
	cin >> N >> M;
	for(int i=0; i<N; i++) scanf("%s", Mp[i]);
	for(int k=0; k<N; k++) Now[k][M] = 0;
	if(M % 2 == 1) {
		for(int i=0; i<M; i++) {
			int who = i;
			Vis[who] = true;
			for(int k=0; k<N; k++) Now[k][M/2] = Mp[k][who];
			chooseW(0, 0, 1);
			Vis[who] = false;
		}
	}else chooseW(0, 0, 0);
	puts("NO");
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
array = Array.new(n+1,0)
sum = 0
ans = []
as.each do |a|
  array[a-1] += 1
end
n.times do |i|
  j = array[i]
  sum += j * (j-1) / 2
end

n.times do |i|
  j = as[i] - 1
  ans << sum - array[j] + 1
end
puts ans

Measured memory_bytes: 26116
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}
int main(void){
  int n,i,sum=0;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),cmp);
  for(i=0;i<n-1;i++) sum += a[i];
  if(sum>a[n-1]) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	char c;
	cin >> c;
	
	if(c >= 65 && c <= 90)cout << 'A';
	else cout << 'a';
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int a,b,k; cin>>a>>b>>k;
	rep(i,0,k){
		if(i%2==0){
			a/=2;
			b+=a;
		}
		else{
			b/=2;
			a+=b;
		}
	}
	cout<<a<<" "<<b<<endl;
	
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(void) {
 
	int n;
    cin >> n;
 
    int b,f,r,v;
	int a[4][3][10] = {};
 
    for(int i=0;i<n;i++) {
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }
 
    for(int i=0;i<4;i++) {
        for(int j=0;j<3;j++) {
            for(int k=0;k<10;k++) {
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if(i != 3) {
            cout << "####################" << endl;
        }
 
    }
 
    return 0;
}	

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    int l = s.size();
    ll ans = 0;
    rep(i, l) {
        if(s[i] == 'W') {
            ans += i - cnt;
            cnt++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int m,f,b;
    cin>>m>>f>>b;
    if(b-m>f){
        cout<<"NA"<<endl;
    }else{
        cout<<max(b-m,0)<<endl;
    }
    return 0;// Your code here!
    
}


Measured memory_bytes: 3100
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
using namespace std;

int main()
{
  const int MAX_NUM = 1000000+1;

  bool p[MAX_NUM];
  for (int i = 0; i < MAX_NUM; ++i)
    p[i] = true;
  p[0] = p[1] = false;
  for (int i = 2; i*i <= MAX_NUM; ++i) {
    if (p[i]) {
      for (int j = i+i; j < MAX_NUM; j += i)
	p[j] = false;
    }
  }

  vector<int> prime;
  vector<long long int> dp(MAX_NUM);
  dp[1] = 2;
  for (int i = 2; i < MAX_NUM; ++i) {
    dp[i] = i;
    if (p[i]) {
      dp[i] -= 1;
      prime.push_back(i);
    }
  }

  for (int i = 2; i < MAX_NUM; ++i) {
    if (!p[i]) {
      int n = i;
      for (int j = 0; prime[j]*prime[j] <= i && j < prime.size(); ++j) {
	if (n%prime[j] == 0) {
	  while (n%prime[j] == 0)
	    n /= prime[j];
	  dp[i] -= dp[i] / prime[j];
	}
      }
      if (n != 1)
	dp[i] -= dp[i] / n;
    }
  }

  for (int i = 2; i < MAX_NUM; ++i)
    dp[i] += dp[i-1];

  int t;
  while (cin >> t) {
    for (int i = 0; i < t; ++i) {
      int n;
      cin >> n;
      cout << dp[n] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mx = 2e5+5;

int n; ll t[mx << 2];

void update(int p, int l, int r, int idx, ll v){
    if(l == r) {t[p] = max(t[p], v); return;}
    int m = (l + r) / 2;
    if(idx <= m)
        update(p<<1, l, m, idx, v);
    else
        update(p<<1|1, m+1, r, idx, v);
    t[p] = max(t[p<<1], t[p<<1|1]);
}

ll query(int p, int l, int r, int i, int j){
    if(l>r || l>j || r<i) return 0;
    if(l>=i && r<=j) return t[p];

    int m = (l+r)/2;
    return max(query(p<<1, l, m, i, j),
        query(p<<1|1, m+1, r, i, j));
}

int main(){

    cin.tie(nullptr);
    ios_base::sync_with_stdio(0);

    cin >> n; vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    for(int i=0, a; i<n; i++){
        cin >> a;
        ll val = query(1, 0, n, 0, h[i]-1);
        update(1, 0, n, h[i], a+val);
    }cout << t[1] << "\n";
    return 0;
}


Measured memory_bytes: 8196
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt

  @annotation.tailrec
  def distance(l: List[Int], r: List[Int], dis: Double): Double = (l, r) match {
    case (hl :: tl, hr :: tr) =>
      distance(tl, tr, dis + Math.pow((hl - hr), 2))
    case _ =>  Math.sqrt(dis)
  }

  def goodDistance(points: List[List[Int]]): Int = {
    points.combinations(2).filter({ comb =>
      val dis = distance(comb.head, comb.tail.head, 0)
      dis == dis.toInt
    }).size
  }

  println(goodDistance(List.fill(n)(List.fill(d)(sc.nextInt))))
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

    lint n, m;
    cin >> n >> m;

    lint ans=n;

    REP(i, m) {
        lint a;
        cin >> a;
        ans -= a;
    }
    if(ans>=0){
        cout << ans << "\n";
    }else{
        cout << -1 << "\n";
    }

    return 0;
}

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

const int MAX_V = 1e5 + 1;
const int INF = 1e9 + 1;

typedef pair< int, int > P;

// O(|E||V|^2)
struct Edge {
  Edge(int _to, int _cap, int _cost, int _rev)
    : to(_to), cap(_cap), cost(_cost), rev(_rev) {}
  int to, cap, cost, rev; // 逆辺
};

int V;
vector< Edge > G[MAX_V]; // グラフの隣接リスト表現
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int _from, int _to, int _cap, int _cost) {
  G[_from].emplace_back(Edge(_to, _cap, _cost, G[_to].size()));
  G[_to].emplace_back(Edge(_from, 0, -_cost, G[_from].size() - 1));
}

// sからtへの流量fの最小費用流を求める
// 流せない場合は-1を返す
int min_cost_flow(int s, int t, int f) {
  int res = 0;
  fill(h, h + V, 0);
  while (f > 0) {
    // ダイクストラ法を用いてhを更新する
    priority_queue< P, vector< P >, greater< P > > q;
    fill(dist, dist + V, INF);
    dist[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
      P p = q.top(); q.pop();
      int v = p.second;
      if (dist[v] < p.first) continue;
      for (int i = 0; i < (int)G[v].size(); ++i) {
	Edge &e = G[v][i];
	if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
	  dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
	  prevv[e.to] = v;
	  // cout << "v:" << v << endl;
	  preve[e.to] = i;
	  // cout << "i:" << i << endl;
	  q.push(P(dist[e.to], e.to));
	}
      }
    }
    if (dist[t] == INF) {
      return -1;
    }
    
    for (int v = 0; v < V; ++v) h[v] += dist[v];

    // cout << "f:" << f << endl;
    // s-t間最短経路に沿って目一杯流す
    int d = f;
    for (int v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
      /*
      cout << G[prevv[v]][preve[v]].cap << endl;
      cout << prevv[v] << endl;
      cout << "d:" <<  d << endl;
      */
    }
    f -= d;
    // cout << "f:" << f << endl;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      Edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
    // cout << "d:" <<  d << endl;
    // cout << 1 << endl;
  }
  return res;
}



int main()
{
  int E, F;
  cin >> V >> E >> F;
  for (int i = 0; i < E; ++i) {
    int u, v, c, d;
    cin >> u >> v >> c >> d;
    add_edge(u, v, c, d);
  }
  cout << min_cost_flow(0, V - 1, F) << endl;
  return 0;
}



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

using namespace std;

#define N 1000
#define B 40

vector<long long> cur, aux;
long long a[N + 1];
long long sum[N + 1];

long long query(int l, int r){
	return sum[r] - sum[l - 1];
}

int main(){
	long long ans, b;
	int n, k, freq, i, j;

	scanf("%d%d", &n, &k);

	for (i = 1; i <= n; i++){
		scanf("%lld", a + i);
		sum[i] = sum[i - 1] + a[i];
	}

	// All beauties.
	for (i = 1; i <= n; i++){
		for (j = i; j <= n; j++){
			cur.push_back(query(i, j));
		}
	}

	ans = 0;

	for (b = B; b >= 0; b--){
		freq = 0;

		for (i = 0; i < (int)cur.size(); i++){
			if ((cur[i] >> b) & 1ll){
				freq++;
			}
		}

		if (freq >= k){ // Can set the b'th bit.
			ans |= (1ll << b);

			for (i = 0; i < (int)cur.size(); i++){
				if ((cur[i] >> b) & 1ll){
					aux.push_back(cur[i]);
				}
			}
			
			cur = aux;
			aux.clear();
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 6548
#include <iostream>
#include <string>

int main()
{
	int number;

	std::string word;

	std::cin >> number >> word;

	if (number % 2 == 1)
	{
		std::cout << "No" << std::endl;
		return 0;
	}

	char a = word[0];
	char b = word[number / 2];

	for (int count = 0; count < number / 2; count++)
	{
		if (word[count] != word[count + number / 2])
		{
			std::cout << "No" << std::endl;
			return 0;
		}		
	}

	std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n = n_in()
L = l_in()


from itertools import combinations

print(sum(i + j > k and j + k > i and k + i > j and i != j and j != k and k != i for i,j,k in combinations(L, 3)))
    


Measured memory_bytes: 68012
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n,s,t;
  cin>>n>>s>>t;
  cout<<"? "<<s<<' '<<t<<endl;
  int d;
  cin>>d;
  vector<pair<int,int>> v;
  FOR(i,1,n+1) {
    if(i==s || i==t) continue;
    cout<<"? "<<s<<' '<<i<<endl;
    int d1;
    cin>>d1;
    cout<<"? "<<i<<' '<<t<<endl;
    int d2;
    cin>>d2;
    if (d1+d2 == d) {
      v.emplace_back(d1, i);
    }
  }
  sort(ALL(v));
  int m=v.size();
  auto old = v[0];
  vector<int> res;
  res.push_back(s);
  res.push_back(old.second);
  REP(i,m-1) {
    int d1,i1,d2,i2;
    tie(d1,i1) = old;
    tie(d2,i2) = v[i+1];
    cout<<"? "<<i1<<' '<<i2<<endl;
    int d3;
    cin>>d3;
    if (d2 == d1 + d3) {
      res.push_back(i2);
      old = v[i+1];
    }
  }
  res.push_back(t);
  cout<<"!";
  for(int i : res) {
    cout<<' '<<i;
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 4652
N,M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    E[a-1].append((b-1, -c))
    
    
#ベルマンフォード法:負閉路の検出とある一点から他のすべての点への最短距離の算出

def BellmanFord(E, N, source):
    #E:E[a]は頂点aを始点とする辺のリストであり、辺の終点bと辺の重みwが(b, w)の形で格納されている
    #N:頂点の数
    #source:始点
    #グラフの初期化
    inf = 10**20
    d = [inf for _ in range(N)]
    d[source] = 0
    
    #辺の緩和
    for i in range(N):
        for j in range(N):
            e = E[j]
            if len(e) == 0:
                continue
            for edge in e:
                if d[edge[0]] > d[j] + edge[1]:
                    d[edge[0]] = d[j] + edge[1]
                    if i == N-1 and edge[0] == N-1:
                        return -1
    
    return d

dist = BellmanFord(E, N, 0)
if dist == -1:
    print("inf")
else:
    print(-dist[N-1])

Measured memory_bytes: 3444
li = []
count = 1
li.append(int(input()))
while len(li) == len(set(li)):
    if li[-1] % 2 == 0:
        li.append(li[-1]//2)
        count += 1
    else:
        li.append(li[-1]*3+1)
        count += 1
print(count)

Measured memory_bytes: 3060
<?php

fscanf(STDIN, "%d", $num_count);
$target_num = array_map("intval", explode(" ", trim(fgets(STDIN))));

fscanf(STDIN, "%d", $search_count);
$keys = array_map("intval", explode(" ", trim(fgets(STDIN))));

$count = 0;

foreach ($keys as $key) {
    if (in_array($key, $target_num)) ++$count;
}

echo $count, "\n";



Measured memory_bytes: 12408
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

ah = len(a)
aw = len(a[0])
bh = len(b)
bw = len(b[0])

for i in range(ah - bh + 1):
    for j in range(aw - bw + 1):
        tmp = []
        for k in range(bh):
            tmp.append(a[i + k][j : j + bw])
        if b == tmp:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(((a==b && b != c)||(a==c && a != b)||(b==c && a != c))&&(a<10 && b<10 && c<10 && a>0 && b > 0 && c>0)){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

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

int main(void) {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const long double INF = 1e15;
const ll MOD = 1e9 + 7;

const int MAXN = 1e3 + 5;

long double g[MAXN][MAXN];
long double dis[MAXN];

ll x[MAXN], y[MAXN], r[MAXN];

int used[MAXN];

void solve(){
	int n;
	scanf("%lld%lld%lld%lld%d", &x[0], &y[0], &x[1], &y[1], &n);
	REP(i, 2, 2 + n){
		scanf("%lld%lld%lld", &x[i], &y[i], &r[i]);
	}
	REP(i, 0, 2 + n){
		REP(j, i + 1, 2 + n){
			long double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			d = max((long double)0.0, d - r[i] - r[j]);
			g[i][j] = g[j][i] = d;
		}
	}
	REP(i, 1, 2 + n){
		dis[i] = INF;
	}
	for(int ind = 0; ind != -1; ){
		used[ind] = 1;
		REP(i, 0, 2 + n){
			if (!used[i] && dis[i] > dis[ind] + g[ind][i]){
				dis[i] = dis[ind] + g[ind][i];
			}
		}
		long double mn_dis = INF;
		ind = -1;
		REP(i, 0, 2 + n){
			if (!used[i] && dis[i] < mn_dis){
				ind = i;
				mn_dis = dis[i];
			}
		}
	}
	printf("%.12lf\n", (double)dis[1]);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 16000
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull modpow(ull a, ull b, ull m) {
  if (b==0) return 1;
  ull tmp = modpow(a*a%m,b/2,m);
  if (b&1) tmp = tmp*a%m;
  return tmp;
}

int main() {
  ull n,k,mod = (1e+9)+7;
  cin>>n>>k;
  cout<<modpow(k,n,mod)<<endl;
  return 0;
}


Measured memory_bytes: 3096
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S; cin >> S;

    set<char> st;
    for (char c : S) st.insert(c);

    string ans = "None";
    for (char c='a'; c<='z'; c++) {
        if (st.count(c)==0){
            ans = c;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
int N;cin>>N;
string S;cin>>S;
  int count=0;
  for(int i=0;i<N-2;i++)
  {
   char cha1= S[i];
    if(cha1=='A')
    {
      char cha2=S[i+1];
      if(cha2=='B')
      {
       char cha3=S[i+2];
        if(cha3=='C')
        {
         count++;
        }
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int n,m,ans,cnt[1054];
int main() {
	n=_; m=_;
	for( int i=1;i<=n;i++ ) {
		int k=_;
		for( int j=1;j<=k;j++ ) cnt[_]++;
	}
	for( int i=1;i<=m;i++ ) 
		if(cnt[i]==n) ans++;
	cout<<ans;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n,m;
vector<llint>H;
vector<bool>f;
void solve(){
	cin >> n >> m;
	H.resize(n);
	f.resize(n);
	llint a,b;
	for(int i=0;i<n;i++){
		cin >> H[i];
		f[i]=true;
	}
	for(int i=0;i<m;i++){
		cin >> a >> b;
		a--;b--;
		if(H[a]>H[b])f[b]=false;
		if(H[b]>H[a])f[a]=false;
		if(H[a]==H[b]){
			 f[a]=false;
			 f[b]=false;
		}
	}
	llint cnt=0;
	for(int i=0;i<n;i++){
		if(f[i])cnt++;
	}
	cout << cnt << endl;


}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

int w[100], v[100];
ll dp[100001];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, W;
  cin >> n >> W;
  for (int i = 0; i < n; i++)
    cin >> w[i] >> v[i];
  ll ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = W; j >= w[i]; j--)
      ans = max(ans, dp[j] = max(dp[j], dp[j-w[i]]+v[i]));
  cout << ans << endl;
}


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


int main(){

    
    int h, w, n, i, j, t;

    int f = 1;

    map<int, int> mp;

    int a[101][101];


    cin >> h >> w >> n;

    for( i = 1 ; i <= n ; i = i + 1 ){

         cin >> t;

         mp[i] = t;

         }


    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              if( mp[f] > 0 ){ 

                  a[i][j] = f;

                  mp[f] -= 1;

                  }

               else if( mp[f] == 0 ){

                        f += 1;

                        a[i][j] = f;

                        mp[f] -= 1;

                        }

               }

          }


 
    for( i = 0 ; i < h ; i = i + 1 ){

         for( j = 0 ; j < w ; j = j + 1 ){

              if( i % 2 == 1 ) cout << a[i][w - 1 - j] << " " ;

              else cout << a[i][j] << " " ;

              }

         cout << endl;

         }



    return 0;

    }

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int main(){
  string s;cin >> s;
  int n=s.size();
  int d;cin >> d;
  ll dp[n+1][2][d];
  memset(dp,0,sizeof(dp));
  dp[0][0][0]=1;
  for(int i=0;i<n;i++){
    int p=s[i]-'0';
    for(int j=0;j<2;j++){
      for(int k=0;k<d;k++){
        for(int l=0;l<=(j?9:p);l++){
          dp[i+1][j||(l<p)][(k+l)%d]+=dp[i][j][k];
          dp[i+1][j||(l<p)][(k+l)%d]%=mod;
        }
      }
    }
  }
  cout << (dp[n][0][0]+dp[n][1][0]-1+mod)%mod << endl;
}

Measured memory_bytes: 15872
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int s[100100];
int dis[100100];

int main() {
	int n,m;
	cin>>n>>m;
	int i;
	for(i=1;i<n;i++)cin>>s[i];
	for(i=1;i<n;i++)dis[i]=dis[i-1]+s[i];
	int x=0,res=0,next;
	for(i=0;i<m;i++){
		next=x+in();
		res+=abs(dis[next]-dis[x]);
		res%=100000;
		x=next;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

int N, M;

map<int, int> mp1, mp2;
vector<pair<int, int>> vp;
int main() {
    //cout << fixed << setprecision(15);

    int N, K; cin >> N >> K;

    if(N%K==0){
        cout << 0 << endl;
    }else{
        cout << N%K << endl;
    }


    return 0;
}

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

int main() {
  long long hp,hissatu;
  int atk = 0;
  bool chk = false;
  
  cin >> hp >> hissatu;
  
  for(int i = 0; i < hissatu; i++){
    cin >> atk;
    hp -= atk;
    if(hp <= 0){
      chk = true;
      break;
    }
  }
  
  if(chk == true)  cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 384
N,K=map(int,input().split())
S=list(input())
if S[K-1]=="A":
  S[K-1]="a"
elif S[K-1]=="B":
  S[K-1]="b"
elif S[K-1]=="C":
  S[K-1]="c"
S="".join(S)
print(S)

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N,M; cin >> N >> M;
    ll INF = (1LL<<58);

    vector<ll> a(M), b(M), c(M);
    for(int i=0; i<M; i++){
        ll A,B,C; cin >> A >> B >> C;
        a[i] = A, b[i] = B, c[i] = -C;
    }

    vector<ll> dist(N+1, INF);
    dist[1] = 0;

    for(int loop=0; loop<N; loop++){

        for(int i=0; i<M; i++){
            if(dist[a[i]] == INF) continue;

            if(dist[a[i]]+c[i] < dist[b[i]]){
                dist[b[i]] = dist[a[i]]+c[i];
            }
        }
    }

    ll ans = dist[N];

    vector<bool> negative(N+1, false);

    for(int loop=0; loop<N; loop++){
        for(int i=0; i<M; i++){
            if(dist[a[i]] == INF) continue;

            if(dist[a[i]]+c[i] < dist[b[i]]){
                dist[b[i]] = dist[a[i]]+c[i];
                negative[b[i]] = true;
            }

            if(negative[a[i]] == true) negative[b[i]] = true;
        }
    }

    if(negative[N]) cout << "inf" << endl;
    else cout << -ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

typedef unsigned long long ull;
const ull B=100000007;

ull powMod(ull x, ull k) {
  if (k == 0)     return 1;
  if (k % 2 == 0) return powMod(x*x, k/2);
  else            return x*powMod(x, k-1);
}

int main(){
	ull n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	vector<ull> h(s.size());
	h[0]=s[0];
	FOR(i,1,s.size()){
		h[i]=h[i-1]*B+s[i];
	}
	set<ull> st;
	int l=0,r=0;
	for(ull i=0;i<m;i++){
		string q;
		cin>>q;
		if(q=="R++"){
			r++;
		}
		if(q=="L++"){
			l++;
		}
		if(q=="R--"){
			r--;
		}
		if(q=="L--"){
			l--;
		}
		st.insert(h[r]-(l>0?h[l-1]:0)*powMod(B,r-l+1));
	}
	cout<<st.size()<<endl;
}

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

// #define ANS  //for answer
#define CMP  //for compe
#ifdef CMP
using namespace std;
#else
#endif

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x, (x)
#define ncv(x) #x, ":", (x)
#define ncvc(x) #x, ":", (x), ","
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) { pPRINT(std::cout, t...); }
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  REP(i, size)
  PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  REP(i, size)
  PRINTl(i, ":", t[i]);
}
#ifndef DBG
#define DEBUG(...)
void init() {}
#else
#define DEBUG(...)                                                     \
  {                                                                    \
    PRINT("##DEBUG##", "file :", __FILE__, ", line :", __LINE__, "["); \
    PRINT(__VA_ARGS__);                                                \
    PRINTl("]");                                                       \
  }
void init() {
  DEBUG("INIT");
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char* argv[]) {
  DEBUG("MAIN");
  init();
  solve();

  return 0;
}

void solve() {
  DEBUG("SOLVE START");

  ll N;
  cin >> N;
  bool flag = false;

  ll factor = 1;

  if (N < 82) {
    for (int i = 2; i < 10; i++) {
      if (factor * i > 9) break;
      while (N % i == 0 && factor * i < 10) {
        factor *= i;
        N = N / i;
        DEBUG(factor, N);
      }
    }
    flag = factor <= 9 && N <= 9;
  }
  PRINT(flag ? "Yes" : "No");

  return;
}

Measured memory_bytes: 256
#include <stdio.h>

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

	scanf("%d", &n);
	for (i = 0; i <= n/4; ++i) {
		for (j = 0; j <= n/7; ++j) {
			if (((4*i)+(7*j)) == n) {
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(){ 
	const int MAX_V=999999;
	int prime[MAX_V+1];
	int i,k,v,n,sum[MAX_V+1];
	prime[0]=0;
	prime[1]=0;
	for(i=2;i<=MAX_V;i++){
		prime[i]=1;
	}
	for(i=2;i*i<=MAX_V;i++){
		if(prime[i]){
			for(k=2*i;k<=MAX_V;k+=i){ 
				prime[k]=0;
			}
		}
	}
	sum[0]=0;
	for(i=0;i<=MAX_V;i++){ 
		sum[i+1]=sum[i]+prime[i]; 
	}
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",sum[n+1]);
	}
	return 0; 
}

Measured memory_bytes: 9560
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, N0, N1, N2, N3, N4, N5, N6, N7, N8,
      M1, M2, M3, M4, M5, M6, M7, M8, sum;
  cin >> N;
  N8=N/100000000;
  M8=N8*100000000;
  N7=(N-M8)/10000000;
  M7=N7*10000000;
  N6=(N-M8-M7)/1000000;
  M6=N6*1000000;
  N5=(N-M8-M7-M6)/100000;
  M5=N5*100000;
  N4=(N-M8-M7-M6-M5)/10000;
  M4=N4*10000;
  N3=(N-M8-M7-M6-M5-M4)/1000;
  M3=N3*1000;
  N2=(N-M8-M7-M6-M5-M4-M3)/100;
  M2=N2*100;
  N1=(N-M8-M7-M6-M5-M4-M3-M2)/10;
  M1=N1*10;
  N0=N-M8-M7-M6-M5-M4-M3-M2-M1;
  sum=N0+N1+N2+N3+N4+N5+N6+N7+N8;

  if(N%sum==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
S=str(input())
N=len(S)
numA=0
numBC=0
ans=0
counter=0
while counter<N-1:
    if(S[counter]=="A"):
        numA+=1
    elif(S[counter]=="B" and S[counter+1]=="C"):
        #BCよりも前にあるAの分だけ答えをたす
        ans+=numA
        counter+=1
    else:
        numA=0
    counter+=1
print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int v, e;
    cin >> v >> e;
    auto dist = make_vec<ll>(v, v);
    const ll inf = 1LL<<60;
    fill_v<ll>(dist, inf);
    rep(i, v) dist[i][i] = 0;
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    rep(k, v) rep(i, v) rep(j, v) chmin(dist[i][j], dist[i][k] + dist[k][j]);
    rep(i, v) if (dist[i][i] < 0) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    rep(i, v) rep(j, v) {
        if (dist[i][j] < inf/2) cout << dist[i][j];
        else cout << "INF";
        cout << (j == v-1 ? '\n' : ' ');
    }
}



Measured memory_bytes: 3312
import sys
sys.setrecursionlimit(100000)

h,w=map(int,input().split())
INF=10**10
s_org=[list(input()) for _ in range(h)]
s=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s_org[i][j]=="#":
      s[i][j]=1
dp=[[-1]*w for _ in range(h)]
dp[0][0]=s[0][0]
def func(i,j):
  if i<0 or j<0: return INF
  if dp[i][j]!=-1:return dp[i][j]
  a=func(i,j-1)+s[i][j]
  b=func(i-1,j)+s[i][j]
  if s[i][j]==1 and s[i][j-1]==1:
    a-=1
  if s[i][j]==1 and s[i-1][j]==1:
    b-=1
  val=min(a,b)
  #print([i,j])
  #print(val)
  dp[i][j]=val
  return val
print(func(h-1,w-1))
#for a in dp:
#  print(a)
#print(s)
#print(dp)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  string a, b;
  cin >> a >> b;
  int n = stoi(a + b);
  for(int i = 0; i * i <= n; ++i)
  {
    if (i * i == n)
    {
      cout << "Yes";
      return;
    }
  }
  cout << "No";
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3616
n = int(input())
p = list(map(int, input().split()))

def bubble(input_list):
    cnt = 0
    flg = 0
    for i in range(len(input_list)):
        if i+1 != input_list[i]:
            cnt +=1
            flg = 1
    if flg == 1:
        return False, cnt
    else:
        return True, 0
a, b = bubble(p)

if b <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9124
def resolve():
	n = input()
	c = [False] * 8
	p = 0
	for i in list(map(int, input().split())):
		if i >= 3200:
			p += 1
		else:
			c[i//400] = True
	print(sum(c) or 1, sum(c) + p)
resolve()

Measured memory_bytes: 3060
import java.io.*
import java.util.*

fun solve(S: String){
    val l = S.length / 2 - 1
    (0..l).count{ S[it] != S[S.length - it - 1] }.let{ println(it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    solve(S)
}



Measured memory_bytes: 31396
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D;
  str S1,S2,S3;
  str N;
  cin>>S1>>S2>>S3;
  cout<<S1[0]<<S2[1]<<S3[2]<<endl;
}


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

using ll = long long;

using namespace std;

int main() {
    while (true) {
        int m, nmi, nma;
        cin >> m >> nmi >> nma;
        if (m == 0) break;
        int prev, ans, dma = 0;
        for (int i=0, ai; i<m; i++) {
            cin >> ai;
            if (i >= nmi && i <= nma) {
                if (dma >= ai - prev) {
                    ans = i;
                    dma = ai - prev;
                }
            }
            prev = ai;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 3068
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10
# print("-----------")
# print(center)

for i in range(n-1):
    if abs(center - a[i]) <= diff and aj < a[i]:
        diff = abs(center - a[i])
        aj = a[i]
        # print(diff)
        # print(aj)
        # print("----")


print(str(ai) + " " + str(aj))

Measured memory_bytes: 14428
#include <iostream>
#include <cstdio>
#include <queue>
#define N 55
using namespace std;

typedef long long ll;
ll n;
priority_queue<double> pq;
int main()
{
	ll i, j, t;
	double t1, t2;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld", &t), pq.push(-t);
	while (pq.size() > 1) {
		t1 = -pq.top(), pq.pop();
		t2 = -pq.top(), pq.pop();
		pq.push(-(t1 + t2) / 2.0);
	}
	printf("%.9f", -pq.top());
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

 int n ;
 string ans = "" ;
 vector<char> v(10);

void DFS (int depth ,string s  ){
  if( depth == n ){
    cout << s <<endl ;
    return;
  }
  else{
    int NOW = 0;
    rep(i,s.size()){
       NOW = max(NOW,s.at(i)-96);
    }
    for(int i=0;i<=NOW ;i++){
       DFS (depth+1 , s+v.at(i));
    }
  }
  

}


int main() {
  cin >> n ;
  for(int i=0;i<10;i++){
   v.at(i) = (char)i+97;
 }
  DFS(0,ans);
  
  
  
  
    


}


Measured memory_bytes: 1536
#include <stdio.h>
int main(void)
{
  int a,b,ans=0;
  scanf("%d%d",&a,&b);
  if(b%a==0)
  {
    ans=a+b;
  }
  else
  {
    ans=b-a;
  }
  printf("%d\n",ans);
  return 0;
}


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

int main() {
  int N;
  int sum;
  int P = 0, G = 0, W = 0, Y = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    string H;
    cin >> H;
    if (H == "P")
    {
      P = 1;
    }
    else if (H == "G")
    {
    G = 1;
    }
    else if (H == "W")
    {
    W = 1;
    }
    else if (H == "Y")
    {
    Y = 1;
    }
    
  }
	sum = P + G + W + Y;
  if(sum == 3) cout << "Three" << endl;
  else cout<< "Four" << endl;
}


Measured memory_bytes: 256
module Ss = Set.Make(String)

let s = read_line ()
let len = String.length s
let k = read_int ()

let f i j set =
  let sub = String.sub s i j in
  if (Ss.mem sub set) then set
  else (Ss.add sub set)

let rec inner i j set =
  if j > (len-i) || j > k then
    set
  else
    let set' = f i j set in
    inner i (succ j) set'

let rec outer i set =
  if i <= (len - 1) then
    let set' = inner i 1 set in
    outer (succ i) set'
  else
    set

let () =
  let ls = outer 0 Ss.empty |> Ss.elements in
  let ar = Array.of_list ls in
  let () = Array.fast_sort String.compare ar in
  print_endline ar.(k-1)


Measured memory_bytes: 5376