akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
map<int, int> mp1, mp2;
int a[100010], n, r;
pair<int, int> m1, m2, n1, n2;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", a + i);
	for (int i = 0; i < n; i += 2) {
		mp1[a[i]]++;
	}
	for (int i = 1; i < n; i += 2) mp2[a[i]]++;
	r = n;
	for (auto &it : mp1) {
		if (m2.second < it.second) {
			m2 = it;
		}
		if (m1.second < m2.second) {
			swap(m1, m2);
		}
	}
	for (auto &it : mp2) {
			if (n2.second < it.second) {
				n2 = it;
			}
			if (n1.second < n2.second) {
				swap(n1, n2);
			}
	}
	if (m1.first != n1.first) {
		printf("%d", n - m1.second - n1.second);
	}
	else {
		printf("%d", min(n - m1.second - n2.second, n - m2.second - n1.second));
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  for(int i=0; i<3; i++) {
    if(s.at(i) == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3600
//解説AC
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define ALL(v) v.begin(), v.end()
#define INF 1e9 + 7

ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

ll count(ll a, ll b, ll n){
    if(a>b) swap(a, b);
    ll ans = 0;
    ans += n / a;
    ans += n / b;
    ans -= n / lcm(a,b);
    
    return n - ans;
}

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

    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    
    ll to_b = count(c, d, b);
    ll before_a = count(c, d, a-1);
    
    cout << to_b - before_a << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
            using namespace std;
             
            int main(){
              int n;
              cin>>n;
              
              int a[n];
              for(int i=0; i < n; i++){
                cin>>a[i];
              }
              
              int ans = 0;
              int active = 0;
              for(int i;i<n;i++){
                if(active>=a[i]){
                  active = a[i];
                }else{
                  ans += a[i]-active;
                  active = a[i];
                }
              }
              cout << ans << endl;
              return 0;
            }

Measured memory_bytes: 256
n,m=map(int,input().split())
s=[[0]  for i in range(m)]
c=[[0]  for i in range(m)]
for i in range(m):
    s[i],c[i]=map(int,input().split())

ans=10000
for i in range(1000):
    flag=0
    if len(str(i))==n:
        flag=1
        for j in range(m):
            if str(i)[s[j]-1]!=str(c[j]):flag=0
        if flag==1:ans=min(i,ans)
            
if ans==10000:
    print(-1)
else:
    print(ans)

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


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector< pair<int,int> >edges;
vector<int>outdegree,dp;
bool visited[100002];
vector<int>grp[100002];
void topo(){
	queue<int>q;
	for(int i=1;i<=n;i++){
		if(outdegree[i]==0){
			q.push(i);
			dp[i]=1;
		}
	}
	while(!q.empty()){
		int node=q.front();
		visited[node]=true;
		q.pop();
		for(int i=0;i<grp[node].size();i++){
			if(--outdegree[grp[node][i]]==0)
				q.push(grp[node][i]);
			dp[grp[node][i]]=max(dp[grp[node][i]],dp[node]+1);
		}
	}
}
int main(){
	cin>>n>>m;
	dp.resize(n+1);
	outdegree.resize(n+1);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		edges.push_back(make_pair(u,v));
		outdegree[u]++;
		grp[v].push_back(u);
	}
	topo();
	int res=0;
	for(int i=1;i<=n;i++){
		res=max(res,dp[i]);
	}
	cout<<res-1<<endl;


}

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

using namespace std;

int main(){
	string str;
  	cin>>str;
  	sort(str.begin(),str.end());
  	if(str[0]=='A' && (str[1]=='B' || str[2]=='B'))
      	cout<<"Yes"<<endl;
  	else
      	cout<<"No"<<endl;
}

Measured memory_bytes: 256
/* Nurgazy Zhandos */

#include <bits/stdc++.h>
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <streambuf>	
#include <exception>
#include <typeinfo>
#include <valarray>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <istream>
#include <iomanip>
#include <fstream>
#include <complex>
#include <utility>
#include <ostream>
#include <numeric>	
#include <sstream>
#include <utility>
#include <bitset>
#include <iosfwd>
#include <string>
#include <limits>
#include <vector>
#include <cstdio>
#include <locale>
#include <memory>	
#include <string>	
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <stack>
#include <list>	
#include <map>
#include <set>
#include <ios>
#include <new>
//#include <unordered_set>
//#include <unordered_map> 

#define F first
#define S second

#define pf push_front
#define pb push_back
#define mp make_pair
#define pp pop_back
#define in insert

#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define sz(a) a.size()
#define STOP return 0

#define nl '\n'

#define int long long

using namespace std;

typedef pair <int, pair <int, int > > pIii;
typedef pair < pair <int, int >, int> piiI;
typedef pair <long long, long long> pll;
typedef pair <int, long double> pid;
typedef pair <long double, int> pdi;
typedef pair <int, long long> pil;
typedef pair <long long, int> pli;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double ld;
typedef long long ll;

const int MAX_N = 1e5 + 123;
const int inf = 1e9 + 123;
const ll INF = 1e18 + 123;
const int NN = 2e6 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;

inline void fre() {
	#ifdef TEZZY
//	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	#endif
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

int a[6];

main () {
	fre();
	boost();

	int n;
	cin >> n;

	string s;

	for(int i = 1; i <= n; i++) {
	    cin >> s;
		if(s[0] == 'M') a[1]++;
		else if(s[0] == 'A') a[2]++;
		else if(s[0] == 'R') a[3]++;
		else if(s[0] == 'C') a[4]++;
		else if(s[0] == 'H') a[5]++;
	}	

	ll ans = 0;
	
	for(int i = 1; i <= 5; i++) {
	 	for(int j = i + 1; j <= 5; j++) {
	 		if(i != j) {
             	for(int k = j + 1; k <= 5; k++) {
             	 	if(i != k && j != k) {
             	 		ans += 1ll * a[i] * a[j] * a[k];
             	 	}
             	}
            }
	 	}
	}
	
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll x,y,ans=0;
    cin>>x>>y;
    if (x==1)
        ans+=300000;
    if (y==1)
        ans+=300000;
    if (x==1 &&y==1)
        ans+=400000;
    if (x==2)
        ans+=200000;
    if (y==3)
        ans+=100000;
    if (x==3)
        ans+=100000;
    if (y==2)
        ans+=200000;
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll A; cin >> A;
    string b; cin >> b;

    ll B = 0;
    {
        for(size_t i=0; i<b.size(); i++) {
            if(b[i] == '.') continue;
            B = B * 10 + (b[i] - '0');
        }
    }

    ll M = A * B;
    M /= 100;
    cout << M << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  ll n;cin>>n;
  if(n%2==1){
    cout<<0<<endl;
    return 0;
  }
  ll ans = 0;
  ll p = 10;
  while(p <= n){
    ans += n/p;
    p *= 5;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  vector<Int> a(3),b(3);
  Int c[3][3];
  for(Int i=0;i<3;i++)
    for(Int j=0;j<3;j++)
      cin>>c[i][j];

  auto check=[&](){
    for(Int j=0;j<3;j++) b[j]=c[0][j]-a[0];
    for(Int i=0;i<3;i++)
      for(Int j=0;j<3;j++)
	if(a[i]+b[j]!=c[i][j]) return;
    cout<<"Yes"<<endl;
    exit(0);
  };

  const Int MAX = 200;
  for(Int x=0;x<=MAX;x++)
    for(Int y=0;y<=MAX;y++)
      for(Int z=0;z<=MAX;z++)
	a[0]=x,a[1]=y,a[2]=z,check();

  cout<<"No"<<endl;
  return 0;
}


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

int main() {
	FREOPEN();
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	cout << (n * m) - ((a * m) + (b * n) - (a * b));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") cout << "Cloudy" << endl;
	if (s == "Cloudy") cout << "Rainy" << endl;
	if (s == "Rainy") cout << "Sunny" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (M1, D1) = listOfInt();
    val (M2, D2) = listOfInt();
    println(if (D2 == 1) 1 else 0)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 38040
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int f[N],q[N];
int n,k;
int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) cin >> q[i];
	for(int i = 2; i <= n; ++i)
	{
		f[i] = f[i-1] + abs(q[i] - q[i-1]);
		for(int j = i; j >= 1 && j >= i - k; j--)
		{
			f[i] = min(f[i],f[j] + abs(q[i]-q[j]));
		}
	}
	cout << f[n] << endl;
} 


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#pragma GCC optimize("Ofast")
#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native" )
#define endl "\n"
#define int long long
#define debug(x) cout << #x << " is " << x << endl;
using namespace std;
int fastpow(int a, int b) {
	if (!b) return 1ll;
	if (b % 2 == 1) return fastpow(a, b - 1) * a;
	int t = fastpow(a, b / 2);
	return t * t;
}
void solve() {
	int n, k; cin >> n >> k;
	vector <int> a(n);
	for (auto& x : a) cin >> x;
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < k; ++i) ans += a[i];
	cout << ans << endl;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(15);
	int t; t = 1;
	while (t--) {
		solve();
	}
	return 0;
}


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

int divceil(int a, int b) {
  return (a+b-1)/b;
}

int main() {
  int k, q;
  cin >> k >> q;
  int d[k];
  for (int i = 0; i < k; ++i) cin >> d[i];
  
  for (int i = 0; i < q; ++i) {
    int n, x, m;
    cin >> n >> x >> m;
    ll last = x, eq = 0;
    for (int i = 0; i < k; ++i) {
      ll num = divceil(n-1-i, k);
      last += (d[i]%m)*num;
      if (d[i]%m == 0) eq += num;
    }
    ll ans = (n-1) - (last/m - x/m) - eq;
    cout << ans << endl;
  }
  return 0;
}

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

int sum[100000];
int n, m, k;

void solve(int i, int now) {
    if(i == n){
        sum[max(now-k, 1)]++;
        return;
    }
    for(int j=1;j<=m;j++){
        solve(i+1, now+j);
    }
}

int main() {
    while(true){
        cin >> n >> m >> k;
        if(n == 0) break;
        memset(sum, 0, sizeof(sum));
        solve(0, 0);
        double ans = 0;
        double sub = 1;
        for(int i=0;i<n;i++){
            sub *= m;
        }
        //cout << sub << endl;
        for(int i=0;i<=n*m;i++){
            //cout << sum[i] << " ";
            ans += (double)sum[i]*i/sub;
        }
        //cout << endl;
        printf("%.9lf\n", ans);
    }
    return 0;
}

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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LONG_LONG_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    for(int i = 0; i < 1e8; i++) {
        if(i*a % b == c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int int64_t
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define S second
#define F first

using namespace std;

const int N=100;
int n,m,a[N],x,y;

int32_t main(){
	ibsws(true==false);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        a[x]++;
        a[y]++;
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<'\n';
    }
}


Measured memory_bytes: 256
n = int(input())
a = sorted([int(input()) for _ in range(n)])

l = a[0]
r = a[0]
ixl = 1
ixr = n-1

s = 0
d = -1

while ixl < ixr:
    if d == 1:
        nl = a[ixl]
        nr = a[ixl+1]
        ixl += 2
    else:
        nl = a[ixr]
        nr = a[ixr-1]
        ixr -= 2
    s += ((l+r)-(nl+nr))*d
    l = nl
    r = nr
    d *= -1
if ixl == ixr:
    s += (l-a[ixl])*d
s1 = s

a.reverse()

l = a[0]
r = a[0]
ixl = 1
ixr = n-1

s = 0
d = 1

while ixl < ixr:
    if d == -1:
        nl = a[ixl]
        nr = a[ixl+1]
        ixl += 2
    else:
        nl = a[ixr]
        nr = a[ixr-1]
        ixr -= 2
    s += ((l+r)-(nl+nr))*d
    l = nl
    r = nr
    d *= -1
if ixl == ixr:
    s += (l-a[ixl])*d
s = max(s, s1)

print(s)



Measured memory_bytes: 8300
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	ll X;
	scanf("%lld",&X);

	printf("%lld\n",(X/500)*1000+((X%500)/5)*5);

	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++)


int main() {
    int a,b,c,d;cin >> a >> b >> c >> d;
    
    cout << max(0,min(b,d) - max(c,a)) << endl;

  }       

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3 = x2 + (y1 - y2);
    int y3 = y2 - (x1 - x2);
    int x4 = x3 + (y2 - y3);
    int y4 = y3 - (x2 - x3);

    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
    #define sz(a) a.size()
    #define all(a) a.begin(),a.end()
    #define F first
    #define S second
    #define pb push_back
    #define eb emplace_back
    typedef long long ll;
    typedef vector<int> vi;
    typedef pair<int,int> pi;
     
     
    template <typename A, typename B>
    istream& operator>>(istream& input,pair<A,B>& x){
    	input>>x.F>>x.S;
    	return input;
    }
     
    template <typename A>
    istream& operator>>(istream& input,vector<A>& x){
    	for(auto& i:x)
    		input>>i;
    	return input;
    }
     
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
     
    const int mod=1e9+7;
     
    int mul(int a,int b)
    {
    	return (a*1ll*b)%mod;
    	}
    	
    void add(int &a,int b)
    {
    	a+=b;
    	if(a>=mod)a-=mod;
    	}
    int powz(int a,int b)
    {
    	int res=1;
    	while(b)
    	{
    		if(b&1)res=mul(res,a);
    		b/=2;
    		a=mul(a,a);
    		}
    	return res;
    	}
    const int N=100005;
     
     
    int connected;
    int root[N], sz[N];
     
    void init(int n)
    {
    	for(int i=0;i<n;i++)
    	{
    		root[i]=i;
    		sz[i]=1;
    	}
    	connected=n;
    }
     
    int rt(int k)
    {
    	while(k!=root[k])
    	{
    		root[k]=root[root[k]];
    		k=root[k];
    	}
    	return k;
    }
     
    void merge(int u, int v)
    {
    	int rt1=rt(u);
    	int rt2=rt(v);
     
    	if(rt1==rt2)
    		return;
     
    	connected--;
     
    	if(sz[rt1]>sz[rt2])
    		swap(rt1, rt2);
     
    	sz[rt2]+=sz[rt1];
    	sz[rt1]=0;
    	root[rt1]=root[rt2];
    }
     
     
    void solve()
    {
    int n,m;
    cin>>n>>m;
    init(n);
    int ans=0;
    for(int i=0;i<m;i++)
    {
    	int x,y,z;
    	cin>>x>>y>>z;
    	x--;y--;
    	merge(x,y);
    	
    	
    	}
    	
    	
    	for(int i=0;i<n;i++)
    	{
    		if(rt(i)==i)ans++;
    		}
    		cout<<ans;
    	}
       
    	
    	
     
    int main()
    {   
        ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	int t=1;
    	//cin>>t;
        while(t--)
    	{
            solve();
    		}
    	
    	}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <queue>


using namespace std;

int main(){

  int n,q;
  cin >> n >> q;

  int total_t= 0;
  typedef pair<string, int> pro;
  queue<pro> pq ;

  for (int i = 0; i < n; ++i)
  {
    /* code */
    pro p;
    cin >> p.first >> p.second;
    pq.push(p);
  }

  while(!pq.empty()){
    pro p = pq.front();pq.pop();
    if(p.second > q){
      total_t += q;
      p.second -= q;
      pq.push(p);
    }else{
      total_t += p.second;
      cout << p.first << " " << total_t << endl;
    }
  }

}


Measured memory_bytes: 6316
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  vector<bool>dp((int)s.size()+1,0);
  int n=s.size();
  dp.at(0)=1;
  for(int i=0;i<n;++i){
    if(dp.at(i)==0)continue;
    if(i+5<=n && s.substr(i,5)=="dream")dp.at(i+5)=1;
    if(i+7<=n && s.substr(i,7)=="dreamer")dp.at(i+7)=1;
    if(i+5<=n && s.substr(i,5)=="erase")dp.at(i+5)=1;
    if(i+6<=n && s.substr(i,6)=="eraser")dp.at(i+6)=1;
  }
  if(dp.at(n))cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

signed main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        if (S.substr(i, 3) == "ABC") ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;

using namespace std;

int main(void) {
    int N, L;
    cin >> N >> L;
    int min = 1000;
    int sum = 0;

    for (int i = 1; i <= N; i++) {
        int Li = L + i - 1;
        sum += Li;
        if (abs(Li) < min)
            min = abs(Li);
    }
    if (sum >= 0)
        cout << sum - min << endl;
    else
        cout << sum + min << endl;
}

Measured memory_bytes: 256
from collections import deque
import sys 
input = sys.stdin.readline
N, D, A = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(N)]
xh = sorted(xh)
total = 0 # 今与えているダメージの総和
D = 2*D
ans = 0
q = deque()
for i in range(N):
  x, h = xh[i]
  # 今いる場所が前回までの爆撃の範囲外になるならその分totalから引く
  while len(q) >= 1 and q[0][0] < x:
    total -= q.popleft()[1]
  h -= total

  if h > 0:
    num = (h-1)//A+1
    ans += num
    damage = num*A
    total += damage
    q += ([[x+D, damage]])

print(ans)


Measured memory_bytes: 109764
import sys

input = sys.stdin.readline
N = int(input().strip())
blist = list(map(int,input().strip().split()))

alist = []
alist.append(blist[0])
for i in range(N-2):
    addnum = min(blist[i],blist[i+1])
    alist.append(addnum)
alist.append(blist[N-2])

ans = sum(alist)
print(ans)

Measured memory_bytes: 3064
# AtCoder Beginner Contest 124
# https://atcoder.jp/contests/abc124
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main(N, H):
    n = 0
    h = 0
    for i in range(N):
        if h <= H[i]:
            n += 1
            h = H[i]
    print(n)

N = i2n()
H = i2nn()
main(N, H)


Measured memory_bytes: 3064
#include <iostream>
#include <queue>

int N, K;
std::string S;
char prev;
int cnt = 0, sum = 0, ans = 0;
std::queue<int> q;

inline int max(int a, int b) { return a > b ? a : b; }
void check() {
    sum += cnt;
    cnt = 0;
    if(q.size() < 2*K+1)
        ans = max(ans, sum);
    else if(prev == '1' && q.size() == 2*K+1)
        ans = max(ans, sum);
    if(q.size() == 2*K+1)
        sum -= q.front(), q.pop();
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin >> N >> K >> S;

    prev = S[0];
    for (char c : S) {
        if(prev != c) {
            q.push(cnt);
            check();
            prev = c;
        }
        cnt++;
    }
    q.push(cnt);
    check();
    check();
    std::cout << ans;
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = (n-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int N, M, X, Y; cin>>N>>M>>X>>Y;
    int max_x = X, min_y = Y; 
    rep(i, N){
        int x; cin>>x; max_x = max(max_x, x);
    }
    rep(i, M){
        int y; cin>>y; min_y = min(min_y, y);
    }
    string ans;
    if(max_x < min_y) ans = "No War";
    else ans = "War";
    cout << ans << endl;
}

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

using namespace std;

int main(void){
    /*
    string S;
    string T;
    */
    char S[100005], T[100005];
    int N;

    /*cin >> S >> T;*/
    scanf("%s%s", S, T);
    int S_l = strlen(S);
    int T_l = strlen(T);
    cin >> N;

    int s_s, s_e, t_s, t_e;

    int S_asum[100005];
    S_asum[0] = 0;
    for(int j=1;j<=S_l;j++){
        S_asum[j] = S_asum[j-1] + S[j -1] - 'A' + 1;
    }
    int T_asum[100005];
    T_asum[0] = 0;
    for(int j=1;j<=T_l;j++){
        T_asum[j] = T_asum[j-1] + T[j -1] - 'A' + 1;
    }

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

        cin >> s_s >> s_e >> t_s >> t_e;
        int s_tmp = 0;
        int t_tmp = 0;

        s_tmp = S_asum[s_e] - S_asum[s_s-1];
        t_tmp = T_asum[t_e] - T_asum[t_s-1];

        string ans = "NO";
        if((s_tmp - t_tmp) % 3 == 0){
            ans = "YES";
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
a, b = map(int, input().split())
c = input()
d = []
e = 0
for i in range(1, a):
    e += 1
    if c[i] != c[i-1]:
        if c[i] == "0":
            d.append(e)
        else:
            d.append(-e)
        e = 0
    if i == (a-1):
        e += 1
        if c[i] == "1":
            d.append(e)
        else:
            d.append(-e)
        e = 0
f = 0
g = 0
h = 0
for i in range(len(d)):
    g += abs(d[i])
    if d[i] > 0 and f >= b:
        h = max(h, g)
        if i-2*b >= 0:
            g -= abs(d[i-2*b])
    if d[i] < 0 and f >= b:
        g -= abs(d[i-2*b])
    if d[i] < 0 and f < b:
        f += 1
h = max(h, g)
print(h if h != 0 else a)


Measured memory_bytes: 4092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        
    private static Scanner sc;

    private void solve() {
        int N = sc.nextInt();
        long M = 0, A = 0, R = 0, C = 0, H = 0;
        for (int i = 0; i < N; i++) {
            switch(sc.next().charAt(0)){
                case 'M': M++; break;
                case 'A': A++; break;
                case 'R': R++; break;
                case 'C': C++; break;
                case 'H': H++; break;
            }
        }
        System.out.println(
                M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H +
                A*R*C + A*R*H + A*C*H +
                R*C*H        
        );
    }
}

Measured memory_bytes: 32856
X = int(input())

A = 0
while True:
    n = X - A ** 5
    if n == 0:
        print(A, 0)
    elif n > 0:
        B = int(n ** (1 / 5))
        if B ** 5 == n:
            print(A, -B)
            break
        B += 1
        if B ** 5 == n:
            print(A, -B)
            break
        A += 1
    else:
        B = - int((-n) ** (1 / 5))
        if B ** 5 == n:
            print(A, -B)
            break
        B -= 1
        if B ** 5 == n:
            print(A, -B)
            break
        A += 1


Measured memory_bytes: 9464
N = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, len(p) - 1):
    if (p[i - 1] > p[i] and p[i] > p[i + 1]) or (p[i - 1] < p[i] and p[i] < p[i + 1]):
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main(void) {
	int N,D,i,j,k,count=0;
	double tmp,ans;
	scanf("%d%d",&N,&D);
	int x[N][D];
	for(i=0;i<N;i++){
		for(j=0;j<D;j++){
			scanf("%d",&x[i][j]);
		}
	}
	for(i=0;i<N-1;i++){
		for(j=i+1;j<N;j++){
			for(k=0;k<D;k++){
				tmp=tmp+(double)((x[i][k]-x[j][k])*(x[i][k]-x[j][k]));
			}
			ans=sqrt(tmp);
			if(ans==(int)(ans)){
				count++;
			}
			tmp=0;
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn dru(n: u64, m: u64) -> u64 {
    if n % m == 0 {
        return n / m;
    } 
    n / m + 1
}

fn main() {
    let (h, a) = input_tuple();
    println!("{}", dru(h, a));
}


Measured memory_bytes: 4352
from bisect import bisect_left

n, k = [int(i) for i in input().split()]
x_list = [int(i) for i in input().split()]

ans = 10 ** 9
i = bisect_left(x_list, 0)
for j in range(max(i - k, 0), min(i + 1, n - k + 1)):
    if j == i - k:
        temp = abs(x_list[j])
    elif j == i:
        temp = x_list[j + k - 1]
    else:
        temp = x_list[j + k - 1] - x_list[j] + min(-x_list[j], x_list[j + k - 1])
    
    if temp < ans:
        ans = temp
print(ans)

Measured memory_bytes: 14484
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main(){
    int n ;
    int64_t h ;
    cin >> h >> n ;
    vector<int> a(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    int64_t sum = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        sum += a.at(i) ;
    }
    if (sum >= h)
    {
        cout << "Yes" << endl ;
    }else
    {
        cout << "No" << endl ;
    }
    
    
}

Measured memory_bytes: 640
n = int(input())
probs = [float(c) for c in input().split()]

dp = [0] * (n+1)
dp[0] = 1
for coin in range(n):
    for heads in reversed(range(n+1)):
        dp[heads] = dp[heads] * (1 - probs[coin-1])
        if heads > 0:
            dp[heads] += dp[heads-1] * probs[coin-1]

ans = 0
for heads in range(n+1):
    tails = n - heads
    if heads > tails:
        ans += dp[heads]

print(ans)

Measured memory_bytes: 43868
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int a[3];
   rep(i,3)   cin >> a[i];

   sort(a,a+3);

   cout << a[0]+a[1] << endl;





   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

int N;
pair<int, int> p[100005];

int main(void)
{
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p+N);
	
	cout << p[N-1].first + p[N-1].second << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}


vector<vector<ll>> c(51,vector<ll>(51));

void init(){
	rep(i,51) c[i][0] = 1;
	for(int i = 1; i <= 50; i++){
		for(int j = 1; j <= i; j++){
			c[i][j] += c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	init();
	int n,a,b;cin >> n >> a >> b;
	vector<ll> v(n);
	rep(i,n) cin >> v.at(i);
	double sum = 0;
	sort(v.rbegin(),v.rend());
	rep(i,a) sum += v.at(i);
	sum /= a;
	cout << setprecision(20) << fixed << sum << endl;
	ll ans = 0;
	int cnt = 0;
	rep(i,n) if(v.at(i) == v.at(a - 1)) cnt++;
	if(v.at(0) == v.at(a - 1)){
		for(int i = a - 1; i < b; i++){
			if(v.at(i) < v.at(0)) break;
			ans += c[cnt][i + 1];
		}
	}
	else{
		rep(i,a + 1){
			if(v.at(i) == v.at(a - 1)){
				a -= i;
				break;
			}
		}
		ans += c[cnt][a];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 20:45:37 2020

@author: liang
"""
"""
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a%b)
"""
from math import gcd

A, B = map(int, input().split())
if A < B:
    A ,B = B, A
print(A*B//gcd(A,B))

Measured memory_bytes: 9056
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

// 素数判定。計算量はO(√n)
bool isPrime(ll n) {
    if(n == 1) {
        return false;
    }
    for(ll i = 2; i*i <= n; i++) {
        if(n%i == 0) {
            return false;
        }
    }
    return true;
}
 
int main() {
    ll q;
    cin >> q;

    vl v(MAX_N);  // v[i] : i以下の2017に似た数の個数
    for(ll i = 3; i < 100000; i += 2) {
        v[i] = v[i-2];
        if(isPrime(i) && isPrime((i+1)/2)) {
            v[i]++;
        }
    }

    vl ans(q);
    rep(i, q) {
        ll L, R;
        cin >> L >> R;
        if(L > 1) {
            L -= 2;
        }
        ans[i] = v[R] - v[L];
    }

    rep(i, q) {
        out(ans[i]);
    }
    
    re0;
}

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

using namespace std;

int MOD = 1000000000 + 7;

long long modPow(int n, int num) {
    if (num == 0) return 1;
    long long res = modPow(n, num / 2);
    if (num % 2 == 0) res = (res * res) % MOD;
    else res = (((res * res) % MOD) * n) % MOD;
    return res;
}

long long modNck(int n, int k) {
    long long res = 1;
    for (int i = 0; i < k; i++) {
        res = (res * (n - i)%MOD * modPow(i + 1, MOD - 2)) % MOD;
    }
    return res;
}

int getMod(long long num) {
    long long res = num % MOD;
    if (res < 0)res += MOD;
    return res;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
    cout << getMod(modPow(2, n) - 1 - modNck(n, a) - modNck(n, b));
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<ctime>
using namespace std;

const int N=370;
const int M=30;

int D,ans,T,d,q,start;
int s[N][M],lst[M],c[M],t[N],cnt[N][M];

bool time_out(){
	return clock()-start>1950;
}

int calc(){
	int sum=0;
	for (int i=1;i<=26;i++) lst[i]=0;
	for (int i=1;i<=D;i++){
		sum+=s[i][t[i]];
		lst[t[i]]=i;
		for (int j=1;j<=26;j++) sum-=c[j]*(i-lst[j]);
	}
	return sum;
}

int argmx(int d){
	int id=1;
	for (int i=2;i<=26;i++)
		if (s[d][i]>s[d][id]) id=i;
	return id;
}

int main(){
	scanf("%d",&D);
	for (int i=1;i<=26;i++) scanf("%d",&c[i]);
	for (int i=1;i<=D;i++)
		for (int j=1;j<=26;j++) scanf("%d",&s[i][j]);
	for (int i=1;i<=D;i++) t[i]=argmx(i);
	ans=calc();
	start=clock();
	while (!time_out()){
		for (int d=1;d<=D;d++)
			for (int q=1;q<=26;q++){
				int sum,tmp;
				tmp=t[d];
				t[d]=q; sum=calc();
				if (sum>ans) ans=sum;
				else t[d]=tmp;
				if (time_out()){
					for (int i=1;i<=D;i++) printf("%d\n",t[i]);
					return 0;
				}
			}
	}
//	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	LL N;
	cin >> N;
	map<LL,LL> m;
	for(LL i=2; i*i<=N; i++){
		while(N%i==0){
			m[i]++;
			N/=i;
		}
	}
	if(N!=1) m[N]++;
	LL ans=0;
	for(auto itr:m){
		LL num=itr.second;
		LL res=1;
		while(num>=res){
			num-=res;
			ans++;
			res++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
N = int(input())
S = input()

ans = 0
for i in range(10):
    idx0 = S[: N - 2].find(str(i))
    if idx0 != -1:
        for j in range(10):
            idx1 = S[idx0 + 1 : N - 1].find(str(j))
            if idx1 != -1:
                for k in range(10):
                    idx2 = S[idx0 + idx1 + 2 :].find(str(k))
                    if idx2 != -1:
                        ans += 1

print(ans)



Measured memory_bytes: 9008
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))

int main()
{
    int N;
    long long M;

    cin >> N >> M;

    while(N!=0 && M!=0) {
        vector<long long> p;

        long long ans=0;

        for(int i=0; i<N; ++i) {
            long long temp;
            cin >> temp;
            p.push_back(temp);
            ans=MAX(ans,temp);
        }

        sort(p.begin(),p.end());

        for(int i=0; i<N; ++i) {
            for(int j=i; j<N; ++j) {
                if(p[i]+p[j]>M) break;
                p.push_back(p[i]+p[j]);
                ans=MAX(ans,p[i]+p[j]);
            }
        }

        sort(p.begin(),p.end());

        for(int i=0; i<(int)p.size(); ++i) {
            auto itr=upper_bound(p.begin(),p.end(),M-p[i]);
            if(itr==p.begin()) break;
            else --itr;
            ans=MAX(ans,p[i]+*itr);
        }

        cout << ans << endl;
        cin >> N >> M;
        p.clear();
    }
    return 0;
}

Measured memory_bytes: 10760
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define TR(it,c) for( typeof(c.begin()) it = c.begin(); it != c.end(); ++it )
#define TRR(it,c) for( typeof(c.rbegin()) it = c.rbegin(); it != c.rend(); ++it
#define REP(i,a) for (int i = 0; i < (a); i++)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)

#define DRI(a) int a; scanf("%d", &a);
#define DRII(a, b) int a, b; scanf("%d %d", &a, &b);
#define DRIII(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c);
#define RI(a) scanf("%d", &a);
#define RII(a, b) scanf("%d %d", &a, &b);
#define RIII(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define MM(arr, num) memset((arr), (num), sizeof((arr)))
#define DEB(x) cerr << ">>> " << (#x) << " -> " << (x) << endl;
#define DEBA(x,n) cerr << (#x) << " "; deba((x),(n));
void deba(int * a, int n){ cerr << "| "; REP(i,n) cerr << a[i] << " "; cerr << "|" << endl;}


inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

const int INF = 1<<30;
typedef long long ll;
typedef unsigned long long ull;
/*******************************************************/

char s[223456];

int main() {

  scanf("%s",s);
  int len = strlen(s);

  stack<char> st;
  st.push('a');


  REP(i,len){
    if(st.top() == 'S' && s[i] == 'T') st.pop();
    else{ st.push(s[i]); }

  }

  cout << st.size() - 1 << endl;


  return 0;
}


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

using namespace std;

typedef long long int big;

int main(){
	//freopen("pai.txt","r",stdin);
	//freopen("pao.txt","w",stdout);
	big h,n;
	cin>>h>>n;
	vector<big> arr(n);
	big sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum=sum+arr[i];
	}
	if(sum>=h){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	//cout<<ceil((double)(h)/(double)(a));
	return 0;
}

Measured memory_bytes: 1024
def solve(k,abc):
  if len(abc[k])==0:
    return k.upper()
  else:
    kn = abc[k][0]
    abc[k] = abc[k][1:]
    return solve(kn, abc)

abc = {}
for k in ['a','b','c']:
  abc[k] = str(input())
print(solve('a',abc))

Measured memory_bytes: 3188
// ProblemURL : https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_c
// ---------------------------------------------
package main

import "fmt"

func main() {
	var k, a, b int
	fmt.Scan(&k, &a, &b)

	if b-a <= 2 {
		fmt.Println(1 + k)
		return
	}
	if k <= a {
		fmt.Println(1 + k)
		return
	}

	ans := a
	k -= (a - 1)
	ans += (b - a) * (k / 2)
	if k%2 == 1 {
		ans++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 1000005 

char c[5];

int main()
{
	for(int i=1;i<=3;i++) cin>>c[i];
	if(c[1]=='R'&&c[2]=='R'&&c[3]=='R') cout<<3<<endl;
	else if(c[1]=='R'&&c[2]=='R') cout<<2<<endl;
	else if(c[2]=='R'&&c[3]=='R') cout<<2<<endl;
	else for(int i=1;i<=3;i++) if(c[i]=='R'){cout<<1<<endl;break;}
	if(c[1]=='S'&&c[2]=='S'&&c[3]=='S') cout<<0<<endl;
	return 0;
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}

int main(){
    ll l,r; cin >> l >> r;
    ll ans = 10000;
    if(r-l >= 2500){
        cout << 0 << endl;
        return 0;
    }else{
        for(ll i = l;i< r;i++){
            for(ll j = i+1;j <= r;j++){
                ans = min(ans,(i*j)%2019);
            }
        }
    }
    cout << ans;
}



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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;
	int n;
	cin>> n;
	if(n%2 == 1){
		cout<< "No\n";
		return 0;
	}
	string s;
	cin>> s;
	for(int i = 0; i<n/2; ++i){
		if(s[i] != s[n/2+i]){
			cout<< "No\n";
			return 0;
		}
	}
	cout<< "Yes\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();
            int a = N / 500;
            int b = (N % 500) / 5;
            System.out.println(a*1000 + b * 5);
          }
}

Measured memory_bytes: 22996
// Dice4
#include <stdio.h>

int judge1(int d1[], int d2[], int a, int b);

int main(void)
{
    int n, i, j;
    scanf("%d", &n);
    int dice[n][6];
    for(i = 0; i < n; i++){
        for(j = 0; j < 6; j++){
            scanf("%d", &dice[i][j]);
        }
    }
    int *dicet[n];
    for(i = 0; i < n; i++){
        dicet[i] = dice[i];
    }
    int flag = 0;
    for(i = 0; i < n - 1; i++){
        for(j = i + 1; j < n; j++){
            flag = judge1(dicet[i], dicet[j], i, j);
            if(flag == 0){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");

    return 0;
}

int judge1(int d1[], int d2[], int a, int b)
{
    int i, j, k, m;
    
    for(j = 0; j < 4; j++){
        int tmp1 = d1[0];
        d1[0] = d1[4];
        d1[4] = d1[5];
        d1[5] = d1[1];
        d1[1] = tmp1;
        for(k = 0; k < 4; k++){
            int tmp2 = d1[0];
            d1[0] = d1[2];
            d1[2] = d1[5];
            d1[5] = d1[3];
            d1[3] = tmp2;
            for(m = 0; m < 4; m++){
                int tmp3 = d1[1];
                d1[1] = d1[2];
                d1[2] = d1[4];
                d1[4] = d1[3];
                d1[3] = tmp3;
                if(d1[0] == d2[0] && d1[1] == d2[1] && d1[2] == d2[2] && d1[3] == d2[3] && d1[4] == d2[4] && d1[5] == d2[5]){
                    return 0;
                }
            }
        }
    }
    return 1;
}


Measured memory_bytes: 2104