akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
#include <deque>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;

int main(){
    int a,b,c;
    cin >>a>>b;
    vector<int>l;
    fol(i,a){
        cin >>c;
        l.push_back(c);
    }
    sort(l.rbegin(),l.rend());
    int ans = accumulate(l.begin(),l.begin()+b,0);
    cout << ans <<endl;
    return 0;
}


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

int main() {
  int N,M;
  int sum = 0;

  cin >> N;
  vector<int> T(N);
  for(int i=0;i<N;++i){
    cin >> T.at(i);
    sum += T.at(i);
  }

  cin >> M;
  for(int i=0;i<M;++i){
    int P,X;
    cin >> P >> X;
    cout << sum - (T.at(P-1) - X) << endl;
  }
  return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;

  if(a<=b){
    if(c <= a) cout << c << " " << a << " " << b << endl;
    else if(b <= c) cout << a << " " << b << " " << c << endl;
    else cout << a << " " << c << " " << b << endl;
  }
  else{
    if (c <= b) cout << c << " " << b << " " << a << endl;
    else if(a <= c) cout << b << " " << a << " " << c << endl;
    else cout << b << " " << c << " " << a << endl;
  }

  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int,int>
#define scl(n) scanf("%d",&n);
#define pcl(n) printf("%d\n", n)
#define pcl1(n) printf("%lld ", n)
#define FastRead                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
bool comp(ppi a,ppi b)
{
	return a.first<b.first;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

//35A
int main(void) {
	ll s;
	cin >> s;
	ll e9 = 1000000000;
	ll div = s / e9;
	ll amari = s % e9;
	ll y = amari == 0 ? div : div + 1;
	ll x = e9 * y - s;
	cout << 0 << " " << 0 << " " << 1000000000 << " " << 1 << " " << x << " " << y << endl;
	// 1e9 * div + amari = 1e9 * y - x
	// amari > 0
	// 1e9 (y-div) - amari = x
	// y <= div => x < 0
	// y > div, x < 1e9 => y = div+1

	/*
	ll sq = (ll)sqrt(s) + 1;
	for (ll i = sq; i >= 1; --i) {
		if (s % i == 0 && s / i <= 1e9) {
			cout << 0 << " " << 0 << " " << 0 << " " << i << " " << s / i << " " << 0 << endl;
			break;
		}
	}
	*/
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int x, k, d;
	cin >> x >> k >> d;
	if(x == 0) {
		if(k & 1) {
			cout << d;
		}
		else {
			cout << 0;
		}
	}
	else {
		x = abs(x);
		if(k >= (x / d)) {
			k -= (x / d);
			x -= d * (x / d);
			if(k & 1) {
				cout << abs(x - d);
			}
			else {
				cout << x;
			}
		}
		else {
			x -= k * d;
			cout << x;
		}
	}

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

vector<vector<int>> g;

bool dfs(vector<bool> &v,const int par, const int cnt, const pii b) {
    cerr << cnt << endl;
    v[cnt] = true;
    bool ret = true;
    REP(i,v.size()) {
        if(!v[i]) {
            ret = false;
            break;
        }
    }
    if (ret) return ret;

    for(auto x:g[cnt]) {
        if (x == par) continue;
        if (v[x]) continue;
        if (cnt == b.first && x == b.second) continue;
        if (cnt == b.second && x == b.first) continue;
        if (dfs(v,cnt,x,b)) return true;
    }

    return false;
}

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<pii> ab(m);
    g.resize(n);
    REP(i,m) {
        cin >> ab[i].first >> ab[i].second;
        ab[i].first--; ab[i].second--;
        g[ab[i].first].push_back(ab[i].second);
        g[ab[i].second].push_back(ab[i].first);
    }

    int ans = 0;
    REP(i,m) {
        vector<bool> v(n);
        if (!dfs(v,-1,0,ab[i])) {
            ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
string N;
int K;
int dp[100][2][4];// digit DP, [|N|: 0 origin][notLessThen?][k:0~3], init = 0
int lt = 0, eq = 1;//lt: <, eq: =

int solve(){
	int dn = N.size();
	int di = N[0] - '0';
	dp[0][lt][0] = 1;
	dp[0][lt][1] = di>0? di-1:di;
	dp[0][eq][1] = 1;

	rp(i,1,dn){
		di = N[i] - '0';
		int lt0 = 1, ltn = 9;//lt <
		int eq0 = di? 1:0, eqn = max(0, di-1);//eq =

		// lt <
		rp(k,0,4){
			int x = dp[i-1][lt][k] * lt0 + dp[i-1][eq][k] * eq0;
			if(k) x += dp[i-1][lt][k-1] * ltn + dp[i-1][eq][k-1] * eqn;
			dp[i][lt][k] = x;
		}

		// eq =
		irp(k,2,-1){
			if(dp[i-1][eq][k]){
				if(di) dp[i][eq][k+1] = di>0;
				else dp[i][eq][k] = 1;
			}
		}

	}

	return dp[dn-1][lt][K] + dp[dn-1][eq][K];
}

int main(){
	cin>>N>>K;
	cout<< solve() <<endl;
}


Measured memory_bytes: 256
package main

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

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Split(bufio.ScanWords)
	A := nextInt()
	B := nextInt()
	// if A >= B {
	// 	fmt.Println(1)
	// } else {
	// 	// ceil( (B-A)/(A-1) )  + 1
	// 	fmt.Println((B + A - 3) / (A - 1))
	// }
	fmt.Println((B + A - 3) / (A - 1))
}

func nextInt() int {
	stdin.Scan()
	i, err := strconv.Atoi(stdin.Text())
	if err != nil {
		panic(err)
	}
	return i
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;
int dp[2][100000003];
int main(){
    string S;
    cin >> S;
    int n = S.size();
    rep(i, n) {
        int j = S[i] - '0';
        if (i == 0) {
            dp[0][1] = j;
            dp[1][1] = 10 - j;
        } else {
            dp[0][i+1] = min(dp[0][i] + j, dp[1][i] + 1 + j);
            dp[1][i+1] = min(dp[0][i] + 10 - j, dp[1][i] + 9 - j);
        }
    }

    cout << min(dp[0][n], dp[1][n] + 1) << endl;

}

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

int main()
{
    uint64_t N;
    uint64_t p = 1000000007;
    cin >> N;
    uint64_t A[300000];
    uint64_t b[60];
    for(int i=0; i<60; i++){
        b[i] = 0;
    }
    for(int n=0; n<N; n++){
        cin >> A[n];
        for(int i=0; i<60; i++){
            b[i] += ((A[n] >> i) & 0x01ULL);
        }
    }

    uint64_t res = 0;
    for(int i=0; i<60; i++){
        res += (N-b[i]) * b[i] % p * ((0x01ULL << i) % p) % p;
        res %= p;
    }

    cout << res << endl;

	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(void)
{
	int n,p[21],x=0,i;
	scanf("%d", &n);
	for(i=0; i<n; i++)
	scanf("%d", &p[i]);
	for(i=1; i<n-1; i++)
	{
		if(p[i-1]>p[i]&&p[i+1]<=p[i])
		x++;
		if(p[i-1]<=p[i]&&p[i+1]>p[i])
		x++;
	}
	printf("%d\n", x);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;

    for(int i=100;i>=1;i--){
        if(a % i == 0 && b % i == 0){
            cnt++;
            if(cnt == k){
                cout << i << endl;
                break;
            }
        }

    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  
  int i;
  int sum=0;
  
  for(i=0;i<2;i++){
  if(a>=b){
    sum=sum+a;
    a=a-1;
  }
  
  else{
    sum=sum+b;
    b=b-1;
  }
  }
  
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define ll long long
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define Outerloop int q;cin>>q;while(q--)
#define Mod 1000000007
#define N 1e5

    int32_t main()
    {
    	int n;
    	cin >> n ;
    	int dp[n+1][3]={0};
    	memset(dp,0,sizeof dp);
    	f(i,1,n+1) 
    	{
    		int a,b,c;
    		cin >> a >> b >> c;
    		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
    		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
    		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c;
    	}
    	
    	cout<<max({dp[n][0],dp[n][1],dp[n][2]});
    	
    	
    return 0;
    }

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
template<typename T>
T gcd(T x, T y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}

ll goch(ll a){
    for (ll i = 0; i*i*i*i*i <= a; i++) {
        if (i*i*i*i*i == a) {
            return i;
        }
    }
    return -1;
}


int main() {
    IN(int, n);
    vector<vector<pair<int, int>>> a(n);
    REP(i, n){
        IN(int, k);
        REP(j, k){
            IN(int, hoge);
            IN(int, hogehoge);
            a[i].emplace_back(MP(hoge-1, hogehoge));
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1<<n); bit++) {
        bool flag = true;
        int ninzu = 0;
        REP(i, n){
            if (bit & (1<<i)) {
                ninzu++;
                REP(j, a[i].size()){
                    bool aja = (1<<a[i][j].first)&bit;
                    if (!(aja==a[i][j].second)) {
                        flag = false;
                    }
                }
            }
        }
        if (flag) {
            ans = max(ninzu, ans);
        }
    }
    COUT(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
 
  const int N=1e9+7;

  
  int32_t main()
  { 
   /* #ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
   
    IOS
  int n;
  cin >> n;
  vector<int> x(n);
  long long sum = 0;
  for (int&v : x) {
    cin >> v;
    sum += v;
  }

  vector<vector<long long>> dp(n,vector<long long>(n));
  for (int l = n-1; l >= 0; l--) {
    for (int r = l; r < n; r++) {
      if (l == r) {
  dp[l][r] = x[l];
      } else {
  dp[l][r] = max(x[l]-dp[l+1][r],
           x[r]-dp[l][r-1]);
      }
    }
  }
  cout <<dp[0][n-1] << endl;

  return 0;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;


int main()
{
    int n, m;
    cin >> n >> m;
    priority_queue<lli>pq;
    vector<pi> v;
    for(int i=0; i<n; i++){
        lli a, b;
        cin >> a >> b;
        v.push_back({a, b});
    }
    sort(v.begin(), v.end());
    int j=0;
    lli ans = 0;
    for(int i=1; i<=m; i++){
        while(j<n && v[j].first <= i){
            pq.push(v[j].second);
            j++;
        }
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << "\n";

    return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long t1,t2;
	cin >> t1 >> t2;
	long long a1,a2,b1,b2;
	cin >> a1 >> a2 >> b1 >> b2;
	a1-=b1;
	a2-=b2;
	long long s1=a1*t1,s2=a2*t2;
	//cout << s1 << " " << s2 << "\n";
	if((s1+s2)==0){
		cout << "infinity" << "\n";
	}else{
		long long res=0;
		if(s1>0 && s2>0){
			cout << 0 << "\n";
			return 0;
		}
		if(s1<0 && s2<0){
			cout << 0 << "\n";
			return 0;
		}
		if(s1<0){
			s1*=-1;
			s2*=-1;
		}
		long long del=s1+s2;
		if(del>0){
			cout << 0 << "\n";
			return 0;
		}
		del*=-1;
		res+=(s1/del+1);
		res*=2;
		if(s1%del==0) res--;
		res--;
		cout << res << "\n";
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())

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

const int N = 1 << 18, inf = 1e9;
char dir[N];
int x[N], y[N];

#define f first
#define s second

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

	int n; cin >> n;

	map<int, vector<pair<int, char>>> diagl, diagr, horiz, vert;
	rep(i, 0, n) {
		cin >> x[i] >> y[i] >> dir[i];
		x[i] *= 10;
		y[i] *= 10;
		diagl[x[i] + y[i]].eb(x[i], dir[i]);
		diagr[x[i] - y[i]].eb(x[i], dir[i]);
		horiz[y[i]].eb(x[i], dir[i]);
		vert[x[i]].eb(y[i], dir[i]);
	}

	int ans = inf + 1;
	trav(z, diagl) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (
				(v[i].s == 'R' && v[i + 1].s == 'U') ||
				(v[i].s == 'D' && v[i + 1].s == 'L')
			)
				ckmin(ans, v[i + 1].f - v[i].f);
	}

	trav(z, diagr) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (
				(v[i].s == 'U' && v[i + 1].s == 'L') ||
				(v[i].s == 'R' && v[i + 1].s == 'D')
			)
				ckmin(ans, v[i + 1].f - v[i].f);
	}

	trav(z, horiz) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'R' && v[i + 1].s == 'L')
				ckmin(ans, (v[i + 1].f - v[i].f) / 2);
	}
	
	trav(z, vert) {
		auto &v = z.s;
		sort(all(v));
		rep(i, 0, sz(v) - 1)
			if (v[i].s == 'U' && v[i + 1].s == 'D')
				ckmin(ans, (v[i + 1].f - v[i].f) / 2);
	}
	
	if (ans > inf) cout << "SAFE";
	else cout << ans;
}

Measured memory_bytes: 71404
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int n;

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

  int cnt = 0;
  while(true){
    for(int i=0; i<n+2; i++){
      if(h[i] == 0){
        for(int j=i+1; j<n+2; j++){
          if(h[j] == 0){
            if(i+1 == j) break;
            int mn = 1e9;
            for(int k=i+1; k<j; k++){
              mn = min(mn, h[k]);
            }
            for(int k=i+1; k<j; k++){
              h[k] -= mn;
            }
            cnt += mn;
          }
        }
      }
    }
    if(*max_element(h.begin(), h.end()) == 0) break;
  }
  cout << cnt << endl;
  
  return 0;
}



///


Measured memory_bytes: 256
##mod M における　aの逆元を求めてくれる
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
#すなわちax==1(mod m)なる自然数xを返してくれる関数 動作時間:logM
def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

n,p=map(int,input().split())
ans=0
s=list(input())
import collections
if p!=2 and p!=5:
    modlist=[0 for i in range(n+1)]
    modlist[0]=0
    modlist[1]=int(s[0])%p  
    for i in range(2,n+1):
        modlist[i]=(10*modlist[i-1]+int(s[i-1]))%p
    K=pow(10,p-2,p)
    invlist=[0 for i in range(n+1)]
    invlist[0]=1
    invlist[1]=K
    for i in range(2,n+1):
        invlist[i]=(invlist[i-1]*K)%p
    uselist=[0 for i in range(n+1)]
    for i in range(n+1):
        uselist[i]=(modlist[i]*invlist[i])%p
    ANS=dict(collections.Counter(uselist))
    for some in ANS.values():
        ans+=(some*(some-1)//2)
    print(ans)
else:
    q=0
    for i in range(n):
        q+=1
        if int(s[i])%p==0:
            ans+=q
    print(ans)


Measured memory_bytes: 66760
import collection.mutable.Stack


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val symbols = sc.nextLine.split("""\s+""")
    val stack = Stack[Int]()

    symbols foreach {
      case "*" => stack.push(stack.pop * stack.pop)
      case "+" => stack.push(stack.pop + stack.pop)
      case "-" => stack.push(- stack.pop + stack.pop)
      case num => stack.push(num.toInt)
    }

    println(stack.pop)
  }
}

Measured memory_bytes: 45068
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#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(); }

//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 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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int a[200005];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%d", &a[i]);
	int l=0, r=0;
	LL ret = 0;
	int mask = 0;
	while (r != n) {
		while (!(a[r] & mask)) {
			mask |= a[r++];
			ret += (LL)(r - l);
			if (r == n)break;
		}
		while (a[r] & mask) {
			mask ^= a[l++];
		}
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 1024
e=Hash.new [];n=gets.to_i;(n-1).times{|i|a,b=gets.split;e[a]+=[i];e[b]+=[i]};a=[0]*(n-1);(1..n).map{|w|u={};e[v=w.to_s].map{|j|u[a[j]]=1};t=1;e[v].map{|j|1>a[j]&&(t+=1until$\==u[t];a[j]=t;t+=1)}};p a.max;$><<a*$/

Measured memory_bytes: 187476
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;
  vll v(4);
  REP(i, 0, 4) {
    ll c = stol(S.substr(i, 1));
    v[i] = c;
  }

  if (v[0] + v[1] + v[2] + v[3] == 7) {
    cout << v[0] << "+" << v[1] << "+" << v[2] << "+" << v[3];
  } else if (v[0] + v[1] + v[2] - v[3] == 7) {
    cout << v[0] << "+" << v[1] << "+" << v[2] << "-" << v[3];
  } else if (v[0] + v[1] - v[2] + v[3] == 7) {
    cout << v[0] << "+" << v[1] << "-" << v[2] << "+" << v[3];
  } else if (v[0] - v[1] + v[2] + v[3] == 7) {
    cout << v[0] << "-" << v[1] << "+" << v[2] << "+" << v[3];
  } else if (v[0] + v[1] - v[2] - v[3] == 7) {
    cout << v[0] << "+" << v[1] << "-" << v[2] << "-" << v[3];
  } else if (v[0] - v[1] + v[2] - v[3] == 7) {
    cout << v[0] << "-" << v[1] << "+" << v[2] << "-" << v[3];
  } else if (v[0] - v[1] - v[2] + v[3] == 7) {
    cout << v[0] << "-" << v[1] << "-" << v[2] << "+" << v[3];
  } else {
    cout << v[0] << "-" << v[1] << "-" << v[2] << "-" << v[3];
  }
  cout << "=7" << endl;

  return 0;
}


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

int main() {
  string str;
  cin >> str;
  
  if (str == "SUN") {
    cout << 7 << endl;
  } else if (str == "MON") {
    cout << 6 << endl;
  } else if (str == "TUE") {
    cout << 5 << endl;
  } else if (str == "WED") {
    cout << 4 << endl;
  } else if (str == "THU") {
    cout << 3 << endl;
  } else if (str == "FRI") {
    cout << 2 << endl;
  } else if (str == "SAT") {
    cout << 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
////*24-AUG-19*///
//Why do we fall?//
// So we can learn to pick ourself up!//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n) {fr(j, 1, m) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
    }
//z function -  z[i] is the length of the longest common prefix between s and the suffix of s starting at i
vector<int>z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
const int maxn=2e5+5;
int t[4*maxn];
void update(int id, int l, int r, int u, int v)
	{
		if (u>r||v<l) return;
		if (u<=l && r<=v)
		{
			t[id]++;
			return;
		}

		int mid=(l+r)/2;
		update(id*2, l, mid, u, v); update(id*2+1, mid+1, r, u, v);
	}

	int get(int id, int l, int r, int u)
	{
		if (u<l || u>r) return 0;
		if (l==r) return t[id];

		int mid=(l+r)/2;
		int ret=t[id]+get(2*id, l, mid, u)+get(2*id+1, mid+1, r, u);
//		cerr<<id<<' '<<l<<' '<<r<<' '<<ret<<"\n";
		return ret;
	}
	vector <pair <int, int> >v;
signed main()
{
  int n;
  cin>>n;
  cout<<(int)(((n-1)*n)/2)<<endl;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
  static int n;
  static int m[][];
  static int p[];
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    n = Integer.parseInt(br.readLine());
    String s[] = new String[2];
    m = new int[n+1][n+1];
    p = new int[n+1];
    for(int i = 0; i<n; i++){
      s = br.readLine().split("\\s+");
      p[i] = Integer.parseInt(s[0]);
      p[i+1] = Integer.parseInt(s[1]);

    }
    System.out.println(matrixChainOrder());
  }
  static int matrixChainOrder(){
    int q;
    int j;
    for(int i = 1; i<=n; i++){
      m[i][i] = 0;
    }
    for(int l =1; l<n; l++){
      for(int i = 1; i<=n-l; i++){
        j = i+l;
        m[i][j]= (int)Double.POSITIVE_INFINITY;
        for(int k = i; k<j; k++){
          q = m[i][k] + m[k+1][j] + p[i-1] *p[k] *p[j];
          m[i][j] = Math.min(m[i][j],q);
        }
      }
    }
    return m[1][n];
  }
}


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

using namespace std;
using   ll=long long;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll				pair<int , int>
#define int             long long int
#define endl            "\n"

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(int a , int m)
{
	return mod_pow(a , m - 2 , m);
}

void solve() {
	string s;
	
	cin >> s;
	
	cout << s;
	
	if(s.back() == 's') {
		cout << "es";
	}
	else {
		cout << "s";
	}
}

signed main() {
	fast;
   
    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


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

using namespace std;

#define int long long

int pm(int n) {
  if (n)
    return -1;
  else
    return 1;
}

signed main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> abc(8, vector<int>(n));
  for (int i = 0; i < n; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    for (int j = 0; j < 8; ++j) {
      abc[j][i] = x * pm((j >> 2) & 1) + y * pm((j >> 1) & 1) + z * pm(j & 1);
    }
  }
  int ans = 0;
  for (int i = 0; i < 8; ++i) {
    sort(abc[i].begin(), abc[i].end(), greater<int>());
    int a = 0;
    for (int j = 0; j < m; ++j) {
      a += abc[i][j];
    }
    ans = max(ans, a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
module Main where
import qualified Control.Monad as CM
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A
import qualified Data.Ord as O

int = read :: String -> Int
long = read :: String -> Integer
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser :: String -> [[Integer]]
parser = map (map long . words) . tail . lines
printer :: Integer -> String
printer = (++"\n") . show

solver :: [[Integer]] -> Integer
solver abs = answer
  where tabs = map (\[a,b]->[a+b,a,b]) abs
        pairs = L.sortBy (\[t1,a1,b1] [t2,a2,b2]->O.comparing (*(-1)) t1 t2) tabs
        answer = takahashi pairs 0 0

--takahashi :: [Integer] -> Integer -> Integer -> Integer
takahashi [] sa sb = sa - sb
takahashi ([t,a,b]:pairs) sa sb
  = aoki pairs (sa+a) sb

aoki [] sa sb = sa - sb
aoki ([t,a,b]:pairs) sa sb
  = takahashi pairs sa (sb+b)




Measured memory_bytes: 45436
import sys
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if(4*h*n-N*n-N*h == 0):
            continue
        w = (N*h*n)/(4*h*n-N*n-N*h)
        if(w.is_integer() and w > 0):
            print(h, n, int(w))
            sys.exit(0)


Measured memory_bytes: 42652
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, r = LI()
    if n <= 10:
        ans = r + (100*(10-n))
    else:
        ans = r
    print(ans)
    return


# Solve
if __name__ == "__main__":
    solve()


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

int l[11],r[11],n[11];
int N;
int final;

void dfs(int i,int ll,int rr)
{
	if(i==11)
	{
		final=1;
		return;
	}
	if(n[i]>l[ll-1])
	{
		l[ll]=n[i];
		dfs(i+1,ll+1,rr);
	}
	if(n[i]>r[rr-1])
	{
		r[rr]=n[i];
		dfs(i+1,ll,rr+1);
	}
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		for(int j=1;j<=10;j++)
		{
			cin>>n[j];
		}
		final=0;
		dfs(1,1,1);//从1开始比0更好 
		if(final)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3004
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      tas: [(usize, usize); n],
    }
    let mut nt = tas[0].0;
    let mut na = tas[0].1;

    for i in 1..n {
        let (t, a) = tas[i];
        let tf = (nt+t-1)/t;
        let af = (na+a-1)/a;
        let factor = max(tf, af);
        nt = t*factor;
        na = a*factor;
        debug!(t, a, tf, af, factor, nt, na);
    }
    println!("{}", nt+na);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

typedef long long ll;
ll max(ll a, ll b){ return ( a > b )?a:b;}
ll min(ll a, ll b){ return ( a < b )?a:b;}

int main(){
        ll N;
        scanf("%lld",&N);
        int ans = 0;
        for(int n = 1; n <= N; n++){
                int cnt = 0;
                for(int i = 1; i <= n; i++){
                        if(n % i == 0) cnt++;
                }
                if(n % 2 == 1 && cnt == 8) ans++;
        }
        printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int i, j;
	int n, d, k;
	cin >> n >> d;
	int x[n][d];
	for (i = 0; i < n; i++) {
		for (j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			int norm = 0;
			for (k = 0; k < d; k++) {
				int diff = abs(x[i][k] - x[j][k]);
				norm += myPower(diff, 2);
			}

			int flag = 0;
			for (k = 0; k <= norm; k++) {
				if (myPower(k, 2) == norm) {
					flag = 1;
				}
			}
			if (flag == 1) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int input[100];
	for (int a=0;a<3;a++){
		scanf ("%d",&input[a]);
	}
	int jarak1=input[0]-input[1];
	int jarak2=input[0]-input[2];
	if (jarak1<0){
		jarak1*=-1;
	}
	if (jarak2<0){
		jarak2*=-1;
	}
	if(jarak2<jarak1){
		printf ("B\n");
	}
	else if (jarak1<jarak2){
		printf ("A\n");
	}

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>

using namespace std;

int main()
{
    int n,t;
    int result = 0;
    cin>>n;
    vector<int> a;
    for(int i=0;i<n;i++){
        cin>>t;
        a.push_back(t);
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            result+=a.at(i)*a.at(j);
        }
    }
    cout<<result;
}


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

using namespace std;

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

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

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

typedef vector<bool> vb;

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

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

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

void solve() {
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0, now = a[0];
    rep(i, n) {
        if(now > a[i]) ans += now - a[i];
        chmax(now, a[i]);
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 4780
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		char[] charSet = scanner.nextLine().toCharArray();
		int len = charSet.length;

		List<Character> zeroStart = new ArrayList<Character>();
		List<Character> oneStart = new ArrayList<Character>();
		int zcnt = 0;
		int ocnt = 0;
		for(int i = 0; i < len; i++){
			zeroStart.add(Integer.toString(i%2).toCharArray()[0]);


			if(!zeroStart.get(0).equals(charSet[i])){
				zcnt++;
			}else{
				ocnt++;
			}
			zeroStart.clear();
		}
		int min = Math.min(zcnt, ocnt);


		System.out.println(min);
		scanner.close();
	}

}


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

using namespace std;

int main() {
	int s;
	cin >> s;
	
	int i, j;
	vector<int> a;
	int n = 1;
	a.push_back(s);
	bool flag = false;
	for(i = 0; i < n; i++) {
		if(a[n-1] % 2 == 0) a.push_back(a[n-1]/2);
		else a.push_back(3*a[n-1] + 1);
		for(j = 0; j < n; j++) {
			if(a[n] == a[j]) {
				cout << n+1 << endl;
				return 0;
			}
		}
		n++;
	}
}


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

using namespace std;


constexpr int MODULO = 1e9 + 7;

int Sum(int a, int b) {
  return (a + b) % MODULO;
}


int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  string arr[3];
  cin >> n;
  cin.get();
  getline(cin, arr[1]);
  arr[1] = ' ' + arr[1];
  getline(cin, arr[2]);
  arr[2] = ' ' + arr[2];

  
  int dp[53][3][3] = {{{}}};
  
  if(arr[1][1] == arr[2][1]) {
    dp[1][0][0] = dp[1][1][1] = dp[1][2][2] = 1;
  }
  else {
    dp[1][0][1] = dp[1][1][0] = dp[1][0][2] = dp[1][2][0] = dp[1][1][2] = dp[1][2][1] = 1;
  }

  for(int i = 2; i <= n; ++i) {
    if(arr[1][i] == arr[2][i]) {
      for(int x = 0; x < 3; ++x) {
        int y, z;
        if(x == 0) {
          y = 1;
          z = 2;
        }
        else if(x == 1) {
          y = 0;
          z = 2;
        }
        else {
          y = 0;
          z = 1;
        }
        dp[i][x][x] = Sum(dp[i][x][x], dp[i - 1][y][z]) +
                      Sum(dp[i][x][x], dp[i - 1][z][y]) +
                      Sum(dp[i][x][x], dp[i - 1][y][y]) +
                      Sum(dp[i][x][x], dp[i - 1][z][z]);
      
      }
    }
    else {
      bool s1 = (arr[1][i] == arr[1][i - 1]);
      bool s2 = (arr[2][i] == arr[2][i - 1]);
      for(int x = 0; x < 3; ++x) {
        for(int y = 0; y < 3; ++y) {
          if(x != y) {
            for(int x1 = 0; x1 < 3; ++x1) {
              for(int y1 = 0; y1 < 3; ++y1) {
                bool good = true;
                good = good && ((s1 && x1 == x) || (!s1 && x1 != x));
                good = good && ((s2 && y1 == y) || (!s2 && y1 != y));
                if(good) {
                  dp[i][x][y] = Sum(dp[i][x][y], dp[i - 1][x1][y1]);
                }
              }
            }
          }
        }
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < 3; ++i) {
    for(int j = 0; j < 3; ++j) {
      ans = Sum(ans, dp[n][i][j]);
    }
  }

  cout << ans;
}

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

long long int arr[21][21];
long long int dp[1<<21];
long long int n;

const long long int mod = 1e9 + 7;

long long int foo(long long int mask)
{
   if(mask == 0) return 1;

   if(dp[mask] != -1) return dp[mask];

   long long int no_of_men = __builtin_popcount(mask);
   no_of_men--;
   
   dp[mask] = 0;
   for (long long int i = 0; i <= n-1; ++i)
   {
       if(mask & (1<<i))
       {
          if(arr[no_of_men][i] == 1)
          {
             dp[mask] += foo(mask ^ (1<<i));
             dp[mask] %= mod;
          }
       }
   }

   return dp[mask];

}

int main()
{
    for (long long int i = 0; i < (1<<21); ++i)
    {
        dp[i] = -1;
    }
    
    cin >> n;
    for (long long int i = 0; i < n; ++i)
    {
        for (long long int j = 0; j < n; ++j)
        {
            cin >> arr[i][j];
        }
    }

    cout << foo((1<<n)-1);



    return 0;
}

Measured memory_bytes: 16640
import bisect
import copy
import heapq
import sys
import itertools
import queue
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


class UF:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
    
    def get_parent(self, a):
        p = self.parent[a]
        if a == p:
            return a
        
        q = self.get_parent(p)
        self.parent[a] = q
        return q

    def make_pair(self, a, b):
        pa = self.get_parent(a)
        pb = self.get_parent(b)
        if pa == pb:
            return
        
        self.parent[pa] = pb
        self.parent[a] = pb
    
    def is_pair(self, a, b):
        return self.get_parent(a) == self.get_parent(b)


def main():
    N, M = read_values()
    uf = UF(N + M)
    for i in range(N):
        L = read_list()
        for l in L[1:]:
            uf.make_pair(i, l - 1 + N)

    for n in range(1, N):
        if not uf.is_pair(0, n):         
            print("NO")
            return
    print("YES")


if __name__ == "__main__":
    main()


Measured memory_bytes: 50032
def resolve():
    N = int(input())
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))
    C_list = list(map(int, input().split()))

    point = 0

    i_minus = None

    for i in A_list:
        point += B_list[i-1]
        if i_minus is not None:
            if (i - i_minus) == 1:
                point += C_list[i_minus-1]
        i_minus = i

    print(point)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();
constexpr ll I_MAX = numeric_limits<int>::max();
constexpr ull UI_MAX = numeric_limits<unsigned int>::max();

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}



struct edge {
	int from;
	int to;
	int cost=1;
};


auto dijkstra(vector<vector<edge>> &g, int start = 0) {
	vector<int> d(g.size(), I_MAX);
	d[start] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> nodes;//first dist, second edgenum
	nodes.push(pair<int, int>(0, start));


	while (!nodes.empty()) {
		pair<int, int> n = nodes.top();
		int s_node = n.second;
		nodes.pop();
		if (n.first > d[n.second])continue;
		rep(i, 0, g[s_node].size()) {
			int new_dist = d[s_node] + g[s_node][i].cost;
			int n_num = g[s_node][i].to;
			if (new_dist < d[n_num]) {
				nodes.push(make_pair(new_dist, n_num));
				d[n_num] = new_dist;
			}
		}
	}
	return d;
}

int main() {

	int n, k;
	cin >> n >>k;
	vector<int> h(n);
	vector<int> dp(n, I_MAX);
	dp[0] = 0;
	rep(i, 0, n) {
		cin >> h[i];
	}

	rep(i, 0, n) {
		
		rep(j, 1, k+1) {
			if (i + j >= n)break;
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}




	cout << dp[n-1] << endl;

	return 0;
}

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

using namespace std;

int main()
{
    long long int n,m;
    cin>>n>>m;
    long long int a[n],i,sum=0,c=0;
    for(i=0;i<n;i++)
        cin>>a[i];
        for(i=0;i<n;i++)
            sum=sum+a[i];
        for(i=0;i<n;i++)
        {
            if(4*m*a[i]>=sum)
                c++;
        }
    if(c>=m)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int[] li = new int[s.length];
        long ans = 0;
        int chainDec = 0;
        int now = 0;
        int i = 0;
        for(char c : s){
            if(c == '<'){
                now++;
                ans += now;
                chainDec = 0;
            }else{
                chainDec++;
                if(now > 0){
                    li[i-1] = now;  
                    now = 0;
                }else{
                    if(i-chainDec >= 0 && li[i-chainDec] >= chainDec){
                        ans += chainDec-1;
                    }else{
                        ans += chainDec;
                    }
                }
            }
            i++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 30856
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n;
    int a[100];
    cin>>n;
    while(n!=0){
        for(int i=0;i<100;i++)
            a[i]=1001;
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        int sum=0;
        for(int i=1;i<n-1;i++)
            sum+=a[i];
        cout<< sum/(n-2) <<"\n";
        cin>>n;}
}

Measured memory_bytes: 1180