akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long
const int MAXN = 200005;
const LL INF = (LL)1e18;
using namespace std;

struct Segment_tree {
	LL add, minv[4*MAXN];
	
	void init(int l, int r, int idx) {
		add = 0;
		minv[idx] = INF;
		if (l == r) return;
		int m = (l + r) >> 1;
		init(l, m, idx << 1);
		init(m + 1, r, idx << 1 | 1);
	}
	LL universal_add(LL num) {
		add += num;
	}
	void take_min(int pos, LL val, int l, int r, int idx) {
		if (l == r) {
			if (val < minv[idx] + add) {
				minv[idx] = val - add;
			}
			return;
		}
		int m = (l + r) >> 1;
		if (pos <= m) take_min(pos, val, l, m, idx << 1);
		else take_min(pos, val, m + 1, r, idx << 1 | 1);
		minv[idx] = min(minv[idx << 1], minv[idx << 1 | 1]);
	}
	LL RMQ(int ql, int qr, int l, int r, int idx) {
		if (ql <= l && r <= qr) return minv[idx] + add;
		int m = (l + r) >> 1;
		LL res = INF;
		if (ql <= m) res = min(res, RMQ(ql, qr, l, m, idx << 1));
		if (qr >  m) res = min(res, RMQ(ql, qr, m + 1, r, idx << 1 | 1));
		return res;
	}
} tree1, tree2;

int N, Q, A, B, X[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> Q >> A >> B;
	
	X[0] = A;
	for (int i = 1; i <= Q; i++) {
		cin >> X[i];
	}
	
	tree1.init(1, N, 1);
	tree2.init(1, N, 1);
	tree1.take_min(B, -B, 1, N, 1);
	tree2.take_min(B, B, 1, N, 1);
	
	for (int i = 1; i <= Q; i++) {
		LL cost = abs(X[i] - X[i - 1]);
		LL result = min(tree1.RMQ(1, X[i], 1, N, 1) + X[i], tree2.RMQ(X[i], N, 1, N, 1) - X[i]);
		tree1.universal_add(cost);
		tree2.universal_add(cost);
		tree1.take_min(X[i - 1], result - X[i - 1], 1, N, 1);
		tree2.take_min(X[i - 1], result + X[i - 1], 1, N, 1);
//		cout << "At " << i << ":";
//		for (int j = 1; j <= N; j++) {
//			cout << ' ' << tree1.RMQ(j, j, 1, N, 1) + j;
//		}
//		cout << '\n';
	}
	
	LL ans = INF;
	for (int i = 1; i <= N; i++) {
		ans = min(ans, tree1.RMQ(i, i, 1, N, 1) + i);
	}
	
	cout << ans << '\n';
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
const int mxN = 1e5 + 7;
bool visited[mxN];
vector<int> adj[mxN];

void dfs(int i){
	if(!visited[i]){
		visited[i] = 1;
		for(int neigh : adj[i]) dfs(neigh);
	}
}

void solve(){
	int n,m; cin >> n >> m;
	map<int,int> mp;
	FOR(m){
		int x,y,z; cin >> x >> y >> z;
		--x,--y;
		++mp[x];
		++mp[y];
		adj[x].pb(y);
		adj[y].pb(x);
	}
	set<pair<int,int>> s;
	FOR(n){
		s.insert({mp[i],i});
	}
	auto itr = s.end();
	int ans = 0;
	while(itr != s.begin()){
		--itr;
		if(!visited[(*itr).second]){
			++ans;
			dfs((*itr).second);
		}
	}
	cout << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll n, m;

int return_zero_one_n(int i)
{
    ll d;
    ll temp;
    ll r;
    ll devider = (ll)pow(2, i);

    d = n / devider;
    r = n % devider;
    if (d % 2 == 1)
    {
        temp = devider - r;
        if (temp % 2 == 0)
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    else
    {
        return 0;
    }
}

int return_zero_one_m(int i)
{
    ll d;
    ll temp;
    ll r;

    ll devider = (ll)pow(2, i);

    d = m / devider;
    r = m % devider;
    if (d % 2 == 1)
    {
        temp = r + 1;
        if (temp % 2 == 0)
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
    else
    {
        return 0;
    }
}

ll odd_counter(ll num)
{
    if (num % 2 == 0)
    {
        return num / 2;
    }
    else
    {
        return (num + 1) / 2;
    }
}

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

    ll ans = 0;

    ll temp = odd_counter(m) - odd_counter(n);

    ans += (n % 2) ^ (temp % 2);

    for (int i = 1; i < 41; i++)
    {
        //cout << return_zero_one_n(i) << " " << return_zero_one_m(i) << endl;
        ll multi = (ll)pow(2, i);
        ans += (return_zero_one_n(i) ^ return_zero_one_m(i)) * multi;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string str;
    cin>>str;
    int N=str.size();
    int bl[200001]={};
    for(int i=0;i<N;i++){
        if(str[i]=='B'){
            bl[i+1]=bl[i]+1;
        }else{
            bl[i+1]=bl[i];
        }
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        if(str[i]=='W'){
            ans += (ll)bl[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1412
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;

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

ll prime[100010];
ll kaijo[200010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i <= 200000;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}

ll Comb(ll n, ll k) {
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd)%N) + N) % N;
}

bool d[5][5];
int main(void) {
	int n, k;
	for (int i = 1;i <= 4;i++) {
		for (int j = 1;j <= 4;j++)d[i][j] = false;
	}
	for (int i = 0;i < 3;i++) {
		cin >> n >> k;
		d[n][k] = true;
		d[k][n] = true;
	}
	int ray[4] = { 1,2,3,4 };
	do {
		if (d[ray[0]][ray[1]] && d[ray[1]][ray[2]] && d[ray[2]][ray[3]]) {
			cout << "YES" << endl;
			return 0;
		}
	} while (next_permutation(ray, ray + 4));
	cout << "NO" << endl;
	return 0;
}

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

int n, a[100], cost = 100*200*200;

int s(int y)
{
    int ans = 0;
    for(int i = 0; i < n; i++) ans += (a[i]-y)*(a[i]-y);
    return ans;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int y = -100; y <= 100; y++) cost = min(cost, s(y));
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
  int a;
 string b,c;
      
  cin >> a;
    cin >>b;
    cin >>c;
  
   for(int i=0;i<a;i++){
     
       if(b.substr(i) ==c.substr(0,a-i)){
         
         cout << i+a << endl;
       
     return 0;
       }
     
   }
   
  
  cout << 2*a << endl;
}


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

#define all(x) (x).begin(), (x).end()
#define szof(x) int32_t((x).size())
#define str(x) to_string(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = 1e9;
const ll LLINF = 1e18;

mt19937_64 rng((uint) chrono::steady_clock::now().time_since_epoch().count());

template <class T>
T rnd(T l, T r) {
	return uniform_int_distribution<T>(l, r)(rng);
}

void run() {
	int n, W;
	cin >> n >> W;
	vector<pair<int, int>> a(n);
	for (auto &x : a) {
		cin >> x.first >> x.second;
	}
	const int MAXC = 100000;
	vector<ll> dp(MAXC + 1, LLINF);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		vector<ll> new_dp = dp;
		for (int c = a[i].second; c <= MAXC; c++) {
			new_dp[c] = min(new_dp[c], dp[c - a[i].second] + a[i].first);
		}
		dp.swap(new_dp);
	}
	for (int c = MAXC; c >= 0; c--) {
		if (dp[c] <= W) {
			cout << c << "\n";
			return;
		}
	}
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout.precision(10); cout << fixed;
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		run();
	}
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
	return 0;
}


Measured memory_bytes: 1888
n = int(input())

a = 1

def digitlen(i):
	t = i
	ret = 0	
	while t > 0 :
		t /= 10
		ret += 1
	return ret


ans = float("inf")

while a**2 <= n:
	if n%a == 0:
		b = n/a
		ans = min(ans, max(digitlen(a),digitlen(b)))

	a += 1

print ans


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

int main(){
  int end;
  cin >> end;
  for(int ining=0;ining<end;ining++){
    int score=0;
    string input;
    bool runner[3];
    for(int i=0;i<3;i++) runner[i]=false;
    int runnum=0;
    int out=0;
    while(1){
      cin >> input;
      if(input=="HIT"){
	if(runner[2]){
	  runner[2]=false;
	  score++;
	  runnum--;
	}
	if(runner[1]){
	  runner[1]=false;
	  runner[2]=true;
	}
	if(runner[0]){
	  runner[0]=false;
	  runner[1]=true;
	}
	runner[0]=true;
	runnum++;
      }
      else if(input=="HOMERUN"){
	score+=runnum+1;
	for(int i=0;i<3;i++) runner[i]=false;
	runnum=0;
      }
      else if(input=="OUT"){
	out++;
      }
      if(out==3) break;
    }
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll  long long int
#define N 200002
#define M 1000000007
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define po pop_back
#define pb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Sawlani
  *
  */

  int main()
  {
      string s,t;
      cin >> s >> t;
      t+=s;
      cout << t ;

  }


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    string W, T;
    cin >> W;
    int c = 0;
    while(1) {
        cin >> T;
        if(T == "END_OF_TEXT")
            break;
        transform(T.cbegin(), T.cend(), T.begin(), ::tolower);
        if(W == T)
            c++;
    }
    cout << c << endl;
}


Measured memory_bytes: 3164
#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;

int main() {
	while(1) {
		int n, add = 0, max = 0, min = 1000, s, avg;
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++) {
			cin >> s;
			if(s <= min) min = s;
			if(s >= max) max = s;
			add += s;
		}
		cout << (add - max - min)/ (n-2) <<endl;
	}
	return 0;
}

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

#define fi first
#define se second

const int N = 200200;
const int mod = 1e9 + 7;

using namespace std;

int n;
int G;
int c[N][2];
long long L;
long long res;

long long f(long long x)
{
        long long res = 1;
        while(!(x & res)){
                res += res;
        }
        return res;
}

void dfs(int x, long long g = 0)
{
        if(c[x][0] && c[x][1]){
                dfs(c[x][0], g + 1);
                dfs(c[x][1], g + 1);
                return;
        }
        if(!c[x][0] && !c[x][1]){
                return;
        }
        res ^= f(L - g);
        if(c[x][0]){
                dfs(c[x][0], g + 1);
        }
        if(c[x][1]){
                dfs(c[x][1], g + 1);
        }
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);


        /*
        int n = 100;
        vector < int > m(100);
        m[0] = 0;
        for(int i = 1; i < n; i++){
                set < int > s;
                s.insert(0);
                for(int j = i - 1, h = 0; j >= 1; j--){
                        h ^= m[j];
                        s.insert(h);
                }
                while(s.find(m[i]) != s.end()){
                        m[i] += 1;
                }
                int expected = 0;
                while(!((m[i] >> expected) & 1)){
                        expected += 1;
                }
                cout << i << " " << m[i] << ' ' << (1 << expected) << "\n";
        }

        */

        cin >> n >> L;
        for(int i = 1; i <= n; i++){
                string s;
                cin >> s;

                int x = 0;
                for(char j: s){
                        if(!c[x][j - '0']){
                                c[x][j - '0'] = (++G);
                        }
                        x = c[x][j - '0'];
                }
        }

        dfs(0);

        cout << (!res ? "Bob" : "Alice") << "\n";

}


Measured memory_bytes: 6844
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int par[1002];
int rk[1002];
 
void init(int n){
	for(int i=0; i<n; i++){
		par[i]=i;
	}
}
 
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
 
void unite(int x, int y){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rk[x]==rk[y]) rk[x]++;
	}
}
 
bool same(int x, int y){
	return find(x)==find(y);
}
int main()
{
	int n, h; cin>>n>>h;
    init(2*h);
    int cnta[220]={}, cntb[220]={}, cntc[220]={}, cntd[220]={};
    bool used[420]={};
    for(int i=0; i<n; i++){
        int a, b, c, d; cin>>a>>b>>c>>d;
        int x, y;
        if(c==0) cnta[a-1]++, x=a-1;
        else cntc[c-1]++, x=c-1+h;
        if(d==0) cntb[b-1]++, y=b-1+h;
        else cntd[d-1]++, y=d-1;
        used[x]=used[y]=1;
        unite(x, y);
    }
    int da[420]={}, db[420]={};
    for(int i=0; i<h; i++){
        if(cnta[i]<cntd[i]){
            cout<<"NO"<<endl; return 0;
        }
        da[find(i)]+=(cnta[i]-cntd[i]);
        if(cntb[i]<cntc[i]){
            cout<<"NO"<<endl; return 0;
        }
        db[find(i+h)]+=(cntb[i]-cntc[i]);
    }
    for(int i=0; i<2*h; i++){
        if(!used[i]) continue;
        if(!(da[find(i)]==db[find(i)] && da[find(i)]>0)){
            cout<<"NO"<<endl; return 0;
        }
    }
    cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 384
l,r = gets.chomp.split(" ").map(&:to_i);

count = 0

arr = []
l.upto(r) do |i|
  count += 1
  break if count > 2019
  arr << i
end
min = (arr[0] * arr[1])%2019
arr.combination(2) do |a,b|
  n = (a * b)%2019
  min = n if n < min
end

puts min

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int l[1000001],r[1000001],sum[1000001];
int main()
{
  int n,m,last;
  cin>>n>>m;
  for (int i=1;i<=n;++i)
    {
      cin>>l[i]>>r[i];
      l[i]--;
      for (int j=1;j<=l[i];j=last+1)
	{
	  last=min(l[i]/(l[i]/j),r[i]/(r[i]/j));
	  if (l[i]/j<r[i]/j)
	    {
	      sum[j]++;
	      sum[last+1]--;
	    }
	}
      sum[l[i]+1]++;
      sum[r[i]+1]--;
    }
  for (int i=1;i<=m;++i)
    {
      sum[i]+=sum[i-1];
      cout<<sum[i]<<endl;
    }
  return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t a, b, x;
  cin >> a >> b >> x;
  b = (b / x) + 1;
  if (a != 0) {
    a = ((a - 1) / x) + 1;
  }
  else {
    a = 0;
  }
  cout << b - a << endl;
  return 0;
}

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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  int x = max(a, b);
  if (x == a) --a;
  else --b;
  cout << x + max(a, b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define repp(i,l,r)for(long long i=(l);i<(r);i++)
    #define rep(i,n) for (long long i = 0; i < (n); ++i)
    #define per(i,n) for (long long i = (n); i >= 0; --i)
    const int INF = 2147483647;//int max
    const long long int MOD = 1000000007;
    using namespace std;
    using ll = long long;
    using P = pair<int,int>;
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
    //ミョ(-ω- ?)
    int main() {
        ll x;
        cin >> x;
        repp(i,-120,120){
            repp(j,-120,120){
                if(i*i*i*i*i - j*j*j*j*j == x){
                    cout << i << " " << j << endl;
                    return 0;
                }
            }
        }
        return 0;
    }

Measured memory_bytes: 3540
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <numeric>
#include <map>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int a, b;
    cin>>a>>b;
    cout<<( (a*b) - b - a + 1)<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0520-input.txt"));

		while (scan.hasNext()) {
			int m = scan.nextInt();

			if (m == 0)
				break;
			Cnstl c = new Cnstl(m);
			for (int i = 0; i < m; i++)
				c.add(i, scan.nextInt(), scan.nextInt());

			int n = scan.nextInt();
			Map map = new Map(n);
			for (int i = 0; i < n; i++)
				map.add(scan.nextInt(), scan.nextInt());

			map.sort();

			Map.Point v = map.search(c);
			System.out.println(v.x + " " + v.y);
		}
		scan.close();
		System.exit(0);
	}
}

class Map {
	class Point {
		int x;
		int y;

		public Point(int _x, int _y) {
			x = _x;
			y = _y;
		}
	}

	class Pcomp implements Comparator<Point> {
		@Override
		public int compare(Point o1, Point o2) {
			if (o1.x > o2.x)
				return 1;
			else if (o1.x == o2.x)
				return 0;
			else
				return -1;
		}

	}

	List<Point> p = new ArrayList<Point>();

	public Map(int n) {
	}

	public Point search(Cnstl c) {
		for (int i = 0; i < p.size(); i++) {
			int dx = p.get(i).x - c.getX(0);
			int dy = p.get(i).y - c.getY(0);
			if (this.match(c, dx, dy)) {
				return (new Point(dx, dy));
			}
		}
		return null;
	}

	private boolean match(Cnstl c, int dx, int dy) {
		for (int i = 1; i < c.size(); i++)
			if (c.getX(i) + dx < 0 || c.getX(i) + dx > 1000000 || c.getY(i) + dy < 0 || c.getY(i) + dy > 1000000)
				return false;
		for (int i = 1; i < c.size(); i++)
			if (!this.exist(c.getX(i) + dx, c.getY(i) + dy))
				return false;
		return true;
	}

	private boolean exist(int x, int y) {
		int si = p.size() / 2;
		int sd = si / 2;
		for (; sd > 5; sd /= 2)
			if (p.get(si).x > x)
				si -= sd;
			else
				si += sd;

		for (int i = si; i < p.size(); i++)
			if (p.get(i).x > x)
				break;
			else if (p.get(i).x == x && p.get(i).y == y)
				return true;

		for (int i = si; i >=0; i--)
			if (p.get(i).x < x)
				break;
			else if (p.get(i).x == x && p.get(i).y == y)
				return true;
		
		return false;
	}

	public void sort() {
		Collections.sort(p, new Pcomp());
	}

	public void add(int x, int y) {
		p.add(new Point(x, y));
	}

}

class Cnstl {
	private int[] x;
	private int[] y;

	public Cnstl(int m) {
		x = new int[m];
		y = new int[m];
	}

	public int size() {
		return x.length;
	}

	public int getX(int i) {
		return x[i];
	}

	public int getY(int i) {
		return y[i];
	}

	public void add(int i, int _x, int _y) {
		x[i] = _x;
		y[i] = _y;
	}

}

Measured memory_bytes: 39256
#ABC164d
def main():
    s = input()
    MOD = 2019
    d = [ 0 for i in range(MOD)]
    # print(d)
    ans = 0
    k = 0
    d[0] = 1
    s = s[::-1]
    # print(s)
    p = 1
    for i in s:
        # print(p,i,k)
        # print('pnosiki')
        # print(p * int(i) + k)
        k = (p * int(i) + k) % MOD
        # print('k:')
        # print(k)
        ans += d[k]
        d[k] += 1
        p = (p * 10) % MOD
    print(ans)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 9344
from bisect import bisect_right
from itertools import accumulate

n, x = map(int, input().split())
arr = list(map(int, input().split()))

arr.sort()
arr = list(accumulate(arr))


happy = bisect_right(arr, x)

if happy == n:
    if arr[-1] != x:
        happy -= 1

print(happy)

Measured memory_bytes: 9160
package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	S, T, D := io.NextInt(), io.NextInt(), io.NextInt()
	w := make([]int, D)
	sum, min := 0, 0
	for i := 0; i < D; i++ {
		w[i] = io.NextInt()
		sum += w[i]
		min = intMin(sum, min)
		if S+sum <= T {
			io.Println(i + 1)
			return
		}
	}
	if sum >= 0 {
		io.Println(-1)
		return
	}
	ans := 0
	for ; S+min > T; ans += D {
		S += sum
	}
	for i := 0; i < D; i++ {
		S += w[i]
		if S <= T {
			io.Println(ans + i + 1)
			return
		}
	}
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 6612
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int K =sc.nextInt();
    int N =sc.nextInt();
    int A[] =new int[N];
    int B[] =new int[N];
    int C =0;int D=0;
    A[0]=sc.nextInt();
    for(int i=1;i<N;i++){
      A[i]=sc.nextInt();
      B[i]=A[i]-A[i-1];
      C =Math.max(C,B[i]);
      if(C==B[i]){D = i;}}
    B[0] =K-A[N-1]+A[0];
    C =Math.max(C,B[0]);
    if(C==B[0]){D=0;}
    long E =K-B[D];
    System.out.println(E);
  }
}

Measured memory_bytes: 84164
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.next());
			int Q = Integer.parseInt(sc.next());
			String S = sc.next();
			int[][] lr = new int[Q][2];
			for(int i = 0; i < Q; i ++) {
				lr[i][0] = Integer.parseInt(sc.next());
				lr[i][1] = Integer.parseInt(sc.next());
			}
			final String AC = "AC";
			int[][] counter = new int[S.length()][2];
			int count = 0;
			for(int i = 0; i < S.length()-1; i++) {
				counter[i][1] = count;
				if(AC.equals(S.substring(i, i +2))) {
					count++;
				}
			}
			
			counter[S.length()-1][1] = count;
			for(int i = 0; i < Q; i++) {
				System.out.println(counter[lr[i][1] -1][1] - counter[lr[i][0] -1][1]);
			}
		} // Scanner Close
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int main() {
	string s;
	cin >> s;
	int ans = 0;
	rep(i,3) if (s[i]=='1') ans++;
	cout << ans << ln;
}

Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b){
	return b != 0 ? gcd(b, a%b) : a;
}

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

#define N_MAX 100000
#define MOD 1000000007
#define A_MAX 100000

lli N, M;
int table[N_MAX];
lli func(int val)
{
	lli ret = 0;
	for (int i = N-1; i >=0; i--){
		int index = lower_bound(table, table + i + 1, val - table[i]) - table;
		if (index < i + 1){
			ret += (lli)((i + 1 - index) * 2 - 1);
		}
	}
	return ret;
}

void solv()
{
	scanf("%lld%lld", &N, &M);
	for (int i = 0; i < N; i++){
		int A; scanf("%d", &A);
		table[i] = A;
	}

	sort(table, table + N);

	lli sum[N_MAX]; sum[0] = table[0];
	for (int i = 1; i<N; i++){
		sum[i] = sum[i - 1] + (lli)table[i];
	}

	lli left = 0, right = A_MAX * 2;
	while (right - left>1){
		int mid = (left + right) / 2;
		if (func(mid) >= M){
			left = mid;
		}
		else{
			right = mid;
		}
	}
	if (func(right) >= M){
		left = right;
	}

	lli ret = 0;
	for (int i = N - 1; i >= 0; i--){
		int index = lower_bound(table, table + i + 1, left - table[i]) - table;
		if (index < i + 1){
			ret += ((lli)(i + 1 - index) * (lli)table[i] + sum[i] - (0 == index ? 0 : sum[index - 1])) * 2 - (lli)table[i] * 2;
		}
	}
	for (lli i = func(left); i > M; i--){
		ret -= left;
	}

	printf("%lld", ret);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, a, b) for (int i = (a); i < ((int)b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= ((int)a); --i)
#define sz(c) ((int)c.size())

using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

void dump_impl(string s) {}
template <class H, class... T>
void dump_impl(string s, H head, T... tail) {
    int p = 0;
    rep(i, 0, s.size()) {
        char x = s[i];
        if (p == 0 && x == ',') {
            cerr << " = " << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << x;
            if (x == '(') p++;
            if (x == ')') p--;
        }
    }
}
#ifdef LOCAL
#define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0)
#else
#define dump(...)
#endif

const int INF = 1e9;

struct Circle {
    pii c;
    int r;
};

int sq(int x) { return x * x; }
int sq_dist(int x1, int y1, int x2, int y2) {
    return sq(x1 - x2) + sq(y1 - y2);
}

void solve(int N) {
    vector<vector<int>> color(4);
    vector<Circle> C;
    rep(i, 0, N) {
        int x, y, r, c;
        cin >> x >> y >> r >> c;
        c--;
        C.emplace_back(Circle {{x, y}, r});
        color[c].emplace_back(C.size() - 1);
    }

    auto over = [&](int i, int j) {
        return sq_dist(C[i].c.first, C[i].c.second, C[j].c.first, C[j].c.second) < sq(C[i].r + C[j].r);
    };

    vvi G(N);
    rep(i, 0, sz(C)) {
        rep(j, i + 1, sz(C)) {
            if (i == j) continue;
            if (over(i, j)) {
                G[i].push_back(j);
            }
        }
    }
    vector<int> mask(N);
    rep(v, 0, N) {
        for (int w : G[v]) {
            mask[w] |= 1 << v;
        }
    }

    // rep(v, 0, N) {
    //     for (int w : G[v]) {
    //         dump(v, w);
    //     }
    //     dump(v, bitset<10>(mask[v]));
    // }

    vector<int> memo(1 << N, INF);
    auto rec = [&](auto fun, int S) -> int {
        auto &MEMO = memo[S];
        if (MEMO != INF) return MEMO;

        int ret = 0;
        rep(c, 0, 4) {
            rep(i, 0, sz(color[c])) {
                if (S & mask[color[c][i]]) continue;
                rep(j, i + 1, sz(color[c])) {
                    if (S & mask[color[c][j]]) continue;
                    if ((S >> color[c][i] & 1) && (S >> color[c][j] & 1)) {
                        int nS = S ^ (1 << color[c][i]) ^ (1 << color[c][j]);
                        ret = max(ret, fun(fun, nS) + 2);
                    }
                }
            }
        }
        return MEMO = ret;
    };
    cout << rec(rec, (1 << N) - 1) << endl;
}

signed main() {
    while (1) {
        int N;
        cin >> N;
        if (N == 0) break;
        solve(N);
    }
}


Measured memory_bytes: 68388
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void){
	char s[1001] = {0};
	char *s2[1000] = {0};
	int i , j , cnt , max = 0 , maxl = 0 , maxn , maxnl;
	scanf("%[^\n]" , s);
	for(i=0;s[i]!='\0';i++){
		if(isupper((int)s[i])) s[i] = (char)tolower((int)s[i]);
	}
	for(i=0;;i++){
		if(i==0){
			s2[i] = strtok(s , " ");
		}else{
			s2[i] = strtok(NULL , " ");
			if(s2[i]==NULL) break;
		}
	}
	for(i=0;s2[i]!=NULL;i++){
		cnt = 0;
		if(strlen(s2[i]) > maxl){
			maxl = strlen(s2[i]);
			maxnl = i;
		}
		for(j=0;j<i;j++){
			if(strcmp(s2[i] , s2[j]) == 0) cnt++;
		}
		if(cnt > max){
			max = cnt;
			maxn = i;
		}
	}
	printf("%s %s\n" , s2[maxn] , s2[maxnl]);
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		String S = sc.next();
		
		// 結果の出力
		if (S.equals("AAA") || S.equals("BBB")) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}

		sc.close();
	}
}


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

int main() {
  int N, K, goal = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (goal * 2 > goal + K) {
      goal += K;
    }
    else {
      goal *= 2;
    }
  }
  cout << goal << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Data.STRef


dex :: Int
dex = 1000000007

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  if m==0
    then print $ solve' n ! n
    else do as <- replicateM m readLn :: IO [Int]
            print $ solve (listArray (1,m) as) n m ! n


solve' :: Int -> UArray Int Int
solve' n = runSTUArray $ do
  dptbl <- newArray (1,n) 0
  forM_ [1..n] $ \i ->
    case i of
      1 -> writeArray dptbl 1 1
      2 -> liftM2 (+) (readArray dptbl 1) (return 1) >>= writeArray dptbl 2
      _ -> liftM2 (\x y -> (x+y)`mod`dex) (readArray dptbl (i-1)) (readArray dptbl (i-2)) >>= writeArray dptbl i
  return dptbl

solve :: UArray Int Int -> Int -> Int -> UArray Int Int
solve xs n m = runSTUArray $ do
  dptbl <- newArray (1,n) 0
  ref   <- newSTRef 1
  forM_ [1..n] $ \i -> do
    p <- readSTRef ref
    if i == (xs!p)
      then writeSTRef ref (if p==m then p else p+1)
      else case i of
             1 -> writeArray dptbl 1 1
             2 -> liftM2 (+) (readArray dptbl 1) (return 1) >>= writeArray dptbl 2
             _ -> liftM2 (\x y -> (x+y)`mod`dex) (readArray dptbl (i-1)) (readArray dptbl (i-2)) >>= writeArray dptbl i

  return dptbl


Measured memory_bytes: 33276
N=raw_input()
n=int(N)

AN=raw_input().split()
an=[int(i) for i in AN]

on = [(i+1,an[i]) for i in range(len(an))]

on = sorted(on, key=lambda x: x[1])

on = [str(i[0]) for i in on]



print " ".join(on)

Measured memory_bytes: 30492
n=int(input())
p=input().rstrip().split(' ')
l=[]
for i in range(0,len(p)):
    if i==0:
        p[i]=int(p[i])-1;
        l.append(int(p[i]))
    else:
        if int(p[i]) > int(p[i-1]):
            p[i] = int(p[i])-1;
            l.append(int(p[i]))
        else:
            l.append(int(p[i]))
#print(p)
l.sort(key=int)
for i in range(0,len(l)):
    if int(l[i])!=int(p[i]):
        print("No")
        break;
else:
    print("Yes")

Measured memory_bytes: 15568
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    cin>>n;
    REP(i,n+1){
        int t=i*108/100;
        if(t==n){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> M;
    M[a]++, M[b]++, M[c]++;
    if (M[a]+M[b]+M[c] == 9) cout << "1\n";
    else if (M[a]+M[b]+M[c] == 5) cout << "2\n";
    else cout << "3\n";
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.chars

n = s.length
ans = 0
a_cnt = 0
b_flag = false

n.times do |i|
  if s[i] == 'A'
    if b_flag
      a_cnt = 0
    end


    a_cnt += 1
    b_flag = false
  end

  if s[i] == 'B'
    # Bが2連続ならa_cntは0にするC
    if b_flag
      a_cnt = 0
    end

    b_flag = true
  end

  if s[i] == 'C'
    unless b_flag
      a_cnt = 0
      next
    end
    
    ans += a_cnt
    b_flag = false
  end
end

puts ans

Measured memory_bytes: 16892
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<int> a(n+1), b(n+1);
    repSE(i,1,n+1) cin >> a[i];
    rrepSE(i,n,n/2) {
        b[i] = a[i];
    }
    rrepSE(i,n/2,0) {
        int sum = a[i];
        repSE(j,2,n/i+1) {
            sum = (sum - b[j*i] + 2) % 2;
        }
        b[i] = sum % 2;
    }
    int m = 0;
    vector<int> ans;
    repSE(i,1,n+1) {
        if (b[i] == 1) {
            m++;
            ans.push_back(i);
        }
    }
    cout << m << "\n";
    rep(i,m) cout << ans[i] << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 5500
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    ls = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                ls[i][int(s[-i-1])] += 1
        else:
            mult = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        ls[i][(k * mult + j) % 13] += ls[i-1][j]
            else:
                st = int(s[-i-1])
                for j in range(13):
                    ls[i][(st * mult + j) % 13] += ls[i-1][j]
        for j in range(13):
            ls[i][j] = ls[i][j] % mod
    print(ls[-1][5])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61788
from collections import Counter

def Get_nC2(n):
    return int(n*(n-1) / 2)


N = int(input())
A_i = list(map(int, input().split()))

c = Counter(A_i)


total = sum(list(map(Get_nC2, c.values())))

for a_i in A_i:
    result =  total - Get_nC2(c[a_i]) + Get_nC2(c[a_i]-1)
    print(result)


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    REP(i,h)cin >> a[i];
    REP(i,w+2)cout << "#";
    cout << endl;
    REP(i,h)cout << "#" << a[i] << "#" << endl;
    REP(i,w+2)cout << "#";
    cout << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

int main() {
  int N;
  cin >> N;
  int countOdd = 0, count2 = 0, count4 = 0;
  rep(i, N) {
    int a;
    cin >> a;
    countOdd += (a % 2 == 1) ? 1 : 0;
    if (a % 4 == 0) {
      count4++;
    } else if (a % 2 == 0) {
      count2++;
    }
  }

  if (count2 > 0 && countOdd > count4) {
    cout << "No" << endl;
  } else if (countOdd > count4 + 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll c[30],s[400][30];
std::vector<P> v;

int main(void){
	int d,i,j,n=26;
	std::cin >> d;
	for(i=0; i<n; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<d; ++i){
		for(j=0; j<n; ++j){
			std::cin >> s[i][j];
			v.push_back(P(s[i][j]+c[j],j+1));
		}
		std::sort(v.begin(),v.end(),std::greater<P>());
		std::cout << v[0].second << std::endl;
		v.clear(); 
	}
	return 0;
}


Measured memory_bytes: 3748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] xyxy = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
            double x1 = xyxy[0];
            double y1 = xyxy[1];
            double x2 = xyxy[2];
            double y2 = xyxy[3];

            double x = x2 - x1;
            double y = y2 - y1;

            Console.WriteLine(Math.Sqrt(x*x+y*y));

        }
    }
}

Measured memory_bytes: 9524
N = int(input())
A = list(map(lambda a : int(a), input().split(" ")))
ans = 1
if A.count(0) > 0:
  ans = 0

for i in range(len(A)):
  ans *= A[i]
  if ans > 10 ** 18:
    ans = -1
    print("-1")
    break
 
if ans != -1:
  print(ans)

Measured memory_bytes: 21620
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<queue<int>> g(n);
	int front,back;
	vector<int> flag(n,0);
	deque<int> path;
	for(int i = 0; i < m; i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push(b);
		g[b].push(a);
		if(i==0){
			front=a;
			back=b;
			flag[a]++;
			flag[b]++;
			path.push_front(front);
			path.push_back(back);
		}
	}

	while(1){
		while(!g[front].empty() && flag[g[front].front()]>0) g[front].pop();
		if(!g[front].empty()){
			int x = g[front].front();g[front].pop();
			front = x;
			flag[x]++;
			path.push_front(x);
		}else break;
	}
	while(1){
		while(!g[back].empty() && flag[g[back].front()]>0) g[back].pop();
		if(!g[back].empty()){
			int x = g[back].front();g[back].pop();
			back = x;
			flag[x]++;
			path.push_back(x);
		}else break;
	}

	cout << path.size() << endl;
	int cnt=0;
	for(auto itr = path.begin(); itr != path.end(); ++itr){
		cnt++;
		cout << *itr+1 << (cnt==path.size()?"\n":" ");
	}


	return 0;
}

Measured memory_bytes: 68864
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin >> n;
    if (n & 1) cout << 0;
    else {
        ll cnt = 0;
        while (n) {
            cnt += n / 10;
            n /= 5;
        }
        cout << cnt;
    }
    
}

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

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

using namespace std;
using ll = long long;

const int AMAX = 10000;

vector<int> counting_sort(vector<int> a) {
    vector<int> counter(AMAX + 1), sorted(a.size());
    for(int x: a) counter[x]++;
    for(int i = 1; i <= AMAX; ++i) counter[i] += counter[i - 1];
    for(int x: a) sorted[--counter[x]] = x;
    return sorted;
}

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

    int n;
    cin >> n;
    vector<int> a(n), sorted(n);
    rep(i, n) cin >> a[i];

    sorted = counting_sort(a);

    rep(i, n) {
        printf("%d", sorted[i]);
        printf(i == n - 1 ? "\n" : " ");
    }

    return 0;
}


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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define pp pop_back
#define pf push_front
#define sqr(a) (a)*(a)
#define mpr(a,b) make_pair(a, b)
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<pair<int, int>> qpi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<pair<int,int>> pqpi;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
template<class T> T lcm(T a, T b){return a*(b/gcd(a,b));}
template<class T, class TT>bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};

int main()
{


	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0 ;i < s.size(); i ++)
	{
		if(s[i] == '+')
			ans ++;
		else
			ans --;
	}
	cout << ans;
	
	getchar();
	getchar();
	return 0;
	//freopen("Ganiyev.txt", "r", stdin);
	//freopen("Asadullo.txt", "w", stdout);
	//ios::sync_with_stdio(0);
	//cin.tie(0);cout.tie(0);
	
	
	
	
	
	
	
	
	
	
}

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

int main(){
    ll N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    int Asum = 0;
    int Bmax = -1;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
        Asum += A[i];
        if (Bmax < B[i])
        {
            Bmax = B[i];
        }
    }
    bool ok = true;
    int time = 0;
    vector<pair<int,int>> pair_P;
    for (int i = 0; i < N; i++)
    {
        pair_P.emplace_back(B[i], A[i]);
    }
    sort(pair_P.begin(), pair_P.end());
    for (int i = 0; i < N;i++)
    {
        time += pair_P[i].second;
        if (time > pair_P[i].first)
        {
            ok = false;
            break;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3956