akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int n;
    cin>>n;
    long long int a[100001];
    long long int b[100000];
    for(long long int i=0;i<n+1;i++)
    {
        cin>>a[i];
    }

    for(long long int i=0;i<n;i++)
    {
        cin>>b[i];
    }


    long long int total=0;
    for(long long int i=0;i<n;i++)
    {
        if(b[i]>a[i])
        {
            b[i]=b[i]-a[i];
            total=total+a[i];
            a[i]=0;


            if(a[i+1]<b[i])
            {
                total=total+a[i+1];
                b[i]=b[i]-a[i+1];
                a[i+1]=0;
            }
            else
            {
                a[i+1]=a[i+1]-b[i];
                total=total+b[i];
                b[i]=0;
            }

        }
        else
        {
              a[i]=a[i]-b[i];
              total=total+b[i];
              b[i]=0;
        }


    }
    cout<<total<<endl;



}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#define R register
#define IN inline
#define W while
#define gc getchar()
#define ll long long
#define MX 405
#define SIZ 100500
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
int n, m, ans;
int a[SIZ], b[SIZ];
std::bitset <MX> st[MX];
bool out[MX];
int main(void)
{
	in(n), in(m);
	for (R int i = 1; i <= m; ++i)
	in(a[i]), in(b[i]);
	for (R int i = 1; i <= n; ++i)
	{
		st[i][i] = true;
		for (R int j = m; j; --j)
		{
			if (st[i][a[j]] && st[i][b[j]])
			{out[i] = true; goto gg;}
			if ((!st[i][a[j]]) && (!st[i][b[j]])) continue;
			st[i][a[j]] = st[i][b[j]] = true;
		}
		gg: ;
	}
	for (R int i = 1; i < n; ++i)
	for (R int j = i + 1; j <= n; ++j)
	ans += (!out[i]) && (!out[j]) && (st[i] & st[j]).none();
	printf("%d", ans);
}

Measured memory_bytes: 1024
import heapq
n, m, s, t = map(int, input().split())
INF = 2**63-1
data = []
for _ in range(m):
    data.append(list(map(int, input().split())))

check = [False for i in range(n+1)]
graph = [[] for i in range(n+1)]

for i in range(m):
    graph[data[i][0]].append([data[i][1], data[i][2], data[i][3]])
    graph[data[i][1]].append([data[i][0], data[i][2], data[i][3]])
city_yen_cost = [INF for i in range(n+1)]
city_yen_cost[s] = 0
queue = []
#[cost, vertex]
heapq.heappush(queue, [0, s])
count = 0
while len(queue) > 0:
    if count == n:
        break
    now = heapq.heappop(queue)
    if check[now[1]]:
        continue
    else:
        count += 1
        check[now[1]] = True
        for path in graph[now[1]]:
            if city_yen_cost[now[1]]+path[1] < city_yen_cost[path[0]]:
                city_yen_cost[path[0]] = min(city_yen_cost[now[1]]+path[1], city_yen_cost[path[0]])
                if not check[path[0]]:
                    heapq.heappush(queue, [city_yen_cost[now[1]]+path[1], path[0]])




check = [False for i in range(n+1)]
city_snuke_cost = [INF for i in range(n+1)]
city_snuke_cost[t] = 0
queue = []
heapq.heappush(queue, [0, t])
count = 0
while len(queue) > 0:
    if count == n:
        break
    now = heapq.heappop(queue)
    if check[now[1]]:
        continue
    else:
        count += 1
        check[now[1]] = True
        for path in graph[now[1]]:
            if city_snuke_cost[now[1]]+path[2] < city_snuke_cost[path[0]]:
                city_snuke_cost[path[0]] = min(city_snuke_cost[now[1]]+path[2], city_snuke_cost[path[0]])
                if not check[path[0]]:
                    heapq.heappush(queue, [city_snuke_cost[now[1]]+path[2], path[0]])


totalcost = [None] * (n+1)
for i in range(n+1):
    totalcost[i] = city_yen_cost[i] + city_snuke_cost[i]
for i in range(n):
    totalcost[-i-2] = min(totalcost[-i-2], totalcost[-i-1])
for i in range(n):
    print(10**15-totalcost[i+1])


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

const int n=1000000;
vector<int> prime;

void GeneratePrime(){
  for(int i=2; i<=n; i++){
    if(prime[i]==1) for(int j=2; j*i<=n; j++){
      prime[i*j]=i;
    }
  }
}

int solve(){
  int x;  cin >> x;
  prime = vector<int>(n, 1);
  GeneratePrime();
  for(int i=x; i<n; i++){
    if(prime[i]==1){
      cout << i << endl;
      break;
    }
  }
}

int main(){
  solve();
  return 0;
}


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

using namespace std;
#define int64 long long int

//15:01~

// 10 1 2
/*
 * num=3
 * len=3
 * mod=1
 *
 * */
int main() {
	int64 N, A, B;
	cin >> N >> A >> B;
	int64 result=0;
	int64 num = (A + B);
	int64 len = N / (num);
	int64 mod = N % num;
	if(mod>A)mod=A;
	result = len * A + mod;

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////

class MaxMinQueue {
public:
	MaxMinQueue() {}
	bool empty() { return elements.empty(); }
	int size() { return elements.size(); }
	void push(int val) {
		elements.push(val);
		while (!maxElements.empty() && val > maxElements.back()) maxElements.pop_back();
		maxElements.push_back(val);
		while (!minElements.empty() && val < minElements.back()) minElements.pop_back();
		minElements.push_back(val);
	}
	int pop() {
		int val = elements.front();
		elements.pop();
		if (val == maxElements.front()) maxElements.pop_front();
		if (val == minElements.front()) minElements.pop_front();
		return val;
	}
	int peekMax() {
		return maxElements.front();
	}
	int peekMin() {
		return minElements.front();
	}
private:
	queue<int> elements;
	deque<int> maxElements;
	deque<int> minElements;
};

int n, m;
string s;
int dp[N];

void solve()
{
	cin >> n >> m;
	cin >> s;
	MaxMinQueue MinQ;
	MinQ.push(0);
	dp[n] = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '1') dp[i] = INF;
		else dp[i] = min(INF, MinQ.peekMin() + 1);
		MinQ.push(dp[i]);
		if (MinQ.size() > m) MinQ.pop();
	}

	if (dp[0] == INF) {
		cout << "-1" << endl;
		return;
	}

	int cur = dp[0] - 1;
	int last = 0;
	for (int i = 1; i <= n; i++) {
		if (dp[i] == cur) {
			cout << (i - last) << " ";
			cur--;
			last = i;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


Measured memory_bytes: 4624
/**
	Language: C++
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'
#define Loop(i, L, U) for (ll i = (L); i <= (U); ++i)
#define RLoop(i, U, L) for (ll i = (U); i >= (L); --i)
#define All(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
//	FastIO();

	int k, n;
	cin >> k >> n;
	vi a(n);
	for (int &x : a) cin >> x;

	sort(All(a));

	int mx = -1, d;
	ll s = 0;
	for (int i = 0, j; i < n; ++i) {
		j = (n + i - 1)%n;
		d = (k + a[i] - a[j])%k;
		mx = max(mx, d);
		s += d;
	}

	cout << s - mx << "\n";

	return 0;
}


Measured memory_bytes: 1024
N = int(input())
S = [0] * N

for i in range(N):
    S[i] = input()

d = {}
for x in S:
    if x in d:
        d[x] += 1
    else:
        d.setdefault(x, 1)

d_sorted = sorted(d.items(), key=lambda x:x[1], reverse=True)
count = d_sorted[0][1]
result = []

for x in d_sorted:
    if x[1] == count:
        result.append(x[0])

result.sort()

for z in result:
    print(z)


Measured memory_bytes: 47328
import sys 
input = sys.stdin.readline

N = int(input())
a = list(map(int,input().split()))
a.insert(0,-1)

for i in range(N,0,-1):
    k=2
    temp=a[i]
    while i*k<=N:
        if a[i*k]==1:
            temp = (temp+1)%2
        k+=1
    a[i] = temp

M=0
b=[]
for i in range(1,N+1):
    if a[i]==1:
        M+=1
        b.append(i)

print(M)
[print(x) for x in b]

Measured memory_bytes: 68088
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(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};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

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



int n, m, dp[5050][5050];
string s;

signed main() {
	cin >> n >> s;
	m = s.size();
	dp[0][0] = 1;
	rep(i,n) rep(j,5040) {
		if (j) (dp[i+1][j-1] += dp[i][j]) %= mod;
		else (dp[i+1][j] += dp[i][j]) %= mod;
		(dp[i+1][j+1] += dp[i][j]*2) %= mod;
	}
	cout << dp[n][m] * mop(mop(2,m),mod-2) %mod << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b;
    cin >> a >> b;
    int flag[3];
    rep(i, 3) {
        flag[i] = 1;
    }
    --a;
    --b;
    flag[a] = 0;
    flag[b] = 0;
    
    rep(i, 3) {
        if(flag[i]) cout << i+1 << endl;
    }
}



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

#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = "  << x << endl

using namespace std;

typedef long long tint;

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{ 
		tint p = tint(v.size());
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

const tint MOVE = 4;
const tint dx[MOVE] = {-1,0,1,0};
const tint dy[MOVE] = {0,1,0,-1};
tint H,W;

bool in_range(tint i, tint j)
{
	return ((0 <= i && i < H) && (0 <= j && j < W));
}

int main()
{
	#ifdef ACMTUYO
		assert(freopen("entrada.in", "r", stdin));
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	while (cin >> H >> W)
	{
		vector<vector<char> > board (H,vector<char> (W));
		
		vector<pair<tint,tint> > neigh;
		forn(i,H)
		forn(j,W)
		{
			cin >> board[i][j];
			if (board[i][j] == '#')
				neigh.push_back({i,j});
		}
		
		
		vector<pair<tint,tint> > new_neigh;
		tint ans = 0;
		while (!neigh.empty())
		{
			pair<tint,tint> actual = neigh.back();
			neigh.pop_back();
			forn(k,MOVE)
			{
				tint new_i = actual.first + dx[k];
				tint new_j = actual.second + dy[k];
				if (in_range(new_i,new_j) && board[new_i][new_j] == '.')
				{
					new_neigh.push_back({new_i,new_j});
					board[new_i][new_j] = '#';
				}
			}
			 
			if (neigh.empty())
			{
				neigh.swap(new_neigh);
				if (!neigh.empty())
					ans++;
			}
		}
		
		cout << ans << "\n";
		
	}
	
	
	return 0;
}






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

int main(){

  int A, B, C;
  double X;
  int count;


  //入力値の代入
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> X;
  
  // 500円玉 0~A枚の総当たり
  for (int i = 0; i <= A; i++) {
    // 100円玉 0~A枚の総当たり
    for (int j = 0; j <= B; j++){
      // 50円玉 0~A枚の総当たり
      for (int k = 0; k <= C; k++){
          int total = 500*i + 100*j + 50*k;
          if(total == X){
              count++;

          }
      }

    }
  }
   //集計結果の出力
  cout << count<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, K;
const ll MAX_N = 100000;
ll a[MAX_N], b[MAX_N];

vll G[MAX_N];
bool used[MAX_N];

ll dfs(ll v, ll two_step, ll one_step) {
  used[v] = true;
  ll res = 1;
  ll ct = one_step;
  for (auto u : G[v]) {
    if(used[u]) continue;
    res = res * dfs(u, ct, 1) % MOD;
    ct++;
  }
  res = res * (K - two_step - one_step) % MOD;
  return res;
}

int main(){
  cin >> N >> K;
  REP(i, N - 1) cin >> a[i] >> b[i];
  REP(i, N - 1) {
    a[i]--;
    b[i]--;
    G[a[i]].pb(b[i]);
    G[b[i]].pb(a[i]);
  }

  REP(i, N) used[i] = false;

  cout << dfs(0, 0, 0) % MOD << endl;


  return 0;
}


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

int main(void)
{
  char text[101];
  int a[26] = {};
  int b, flag = 0;
  scanf("%s", text);
  for(int i = 0; text[i] != '\0'; i++){
    b = text[i] - 'a';
    a[b]++;
  }
  for(int i = 0; i < 26; i++){
    if(a[i] == 0){
      continue;
    }else{
      if(a[i]%2 != 0){
        flag = 1;
        break;
      }
    }
  }
  if(flag == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
void read(int &x)
{
    int f=1;
    x=0;
    char s=getchar();
    while(s<'0'||s>'9')
    {
        if(s=='-')
            f=-1;
        s=getchar();
    }
    while(s>='0'&&s<='9')
    {
        x=x*10+s-'0';
        s=getchar();
    }
    x*=f;
}
void print(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
int n;int ans[10];
int change(string s)
{
	if(s=="AC")return 1;
	else if(s=="WA")return 2;
	else if(s=="TLE")return 3;
	else return 4;
}
signed main()
{
	Very_fast;
	cin>>n;
	while(n--)
	{
		string s;
		cin>>s;
		ans[change(s)]++;
	}
	cout<<"AC x "<<ans[1]<<"\n";
	cout<<"WA x "<<ans[2]<<"\n";
	cout<<"TLE x "<<ans[3]<<"\n";
	cout<<"RE x "<<ans[4]<<"\n";
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e15
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define SETBIT(x) __builtin_popcountll(x)
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;

ll A[N], B[N];


ll exp(ll x, ll n, ll mod){
    ll ans = 1LL, X = x, N = n;
    while(N > 0){
        if(N & 1) ans = (ans * X) % mod;
        X = (X * X) % mod;
        N >>= 1;
    }
    return ans;
}

int main() {
    fast;

    int n; cin >> n;
    memset(A, 0, sizeof(A));

    for(int i = 1; i <= 100; i++) for(int j = 1; j <= 100; j++) for(int k = 1; k <= 100; k++) {
        ll value = i*i + j*j + k*k + i*j + j*k + k*i;
        A[value]++;
    }

    for(int i = 1; i <= n; i++) cout << A[i] << "\n";
    return 0;
}

Measured memory_bytes: 5180
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, C = MAP()
stc = [LIST() for _ in range(N)]
stc.sort(key=lambda x:(x[2], x[0]))

tmp_s = stc[0][0]
tmp_t = stc[0][1]
tmp_c = stc[0][2]

stc = stc[1:]
stc_new = []
for s, t, c in stc:
	if tmp_c != c:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
		tmp_t = t
		tmp_c = c
		
	elif tmp_t != s:
		stc_new.append((tmp_s, tmp_t))
		tmp_s = s
	
	tmp_t = t
stc_new.append((tmp_s, tmp_t))

now = [0]*(10**5+2)
for s, t in stc_new:
	now[s] += 1
	now[t+1] -= 1

now_acc = accumulate(now)
print(max(now_acc))


Measured memory_bytes: 37992
while True:
    n, x= list(map(int, input().split()))
    if n == 0 and x == 0:
        break

    cnt = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if (i + j + k) == x:
                    cnt += 1
                    


    print(cnt)


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

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

typedef long long ll;

int main() {
    ll N,K;
    cin>>N>>K;
    ll A[N];
    rep(i, N) cin>>A[i];

    vector<int> s;
    vector<int> ord(N+1, -1);
    int c = 1;
    int v=1;
    int l = 0;
    while(ord[v] == -1){
        ord[v] = s.size();
        s.push_back(v);
        v = A[v-1];
    }
    c = s.size()-ord[v];
    l = ord[v];

    if(K < l) cout << s[K] << endl;
    else{
        K -= l;
        K %= c;
        cout<< s[l+K] << endl;
    }
}

Measured memory_bytes: 6668
import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)

N, K, L = [int(x) for x in input().strip().split()]
road_par = [n for n in range(N)]
road_rank = [0 for _ in range(N)]
train_par = [n for n in range(N)]
train_rank = [0 for _ in range(N)]

def find(par, x):
    if par[x] == x:
        return x
    par[x] = find(par, par[x])
    return par[x]

def union(par, rank, x, y):
    x = find(par, par[x])
    y = find(par, par[y])
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

for ｋ in range(K):
    p, q = [int(x) - 1 for x in input().strip().split()]
    union(road_par, road_rank, p, q)
for l in range(L):
    r, s = [int(x) - 1 for x in input().strip().split()]
    union(train_par, train_rank, r, s)

d = defaultdict(int)
for n in range(N):
    r = find(road_par, n)
    t = find(train_par, n)
    d[(r, t)] += 1

for n in range(N):
    print(d[(road_par[n], train_par[n])], end=' ')

Measured memory_bytes: 114372
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;

    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v.at(i);
    }

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

    long double out=v.at(0);
    for(int i=1;i<n;i++){
        out=(out+(long double)v.at(i))/2.0;
    }

    cout << fixed << setprecision(15) << out << endl;

    return 0;
}  

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


void solve(int K, int X){
    for (int i = 0; i < K; ++i){
        if(K > 1) cout << X - K + 1 + i << " ";
        else cout << X - K + 1 + i;
    }
    for (int i = 1; i < K; i++){
        if(i == K - 1) cout << X + i;
        else cout << X + i << " ";
    }
    cout << endl;
}

int main(){
    long long K, X;
    cin >> K >> X;
    solve(K, X);
    return 0;
}


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

using namespace std;

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




int ans[100000];
int n;
struct edge { int to, cost; };
vector<edge> G[100000];
void func(int e){
    rep(i, G[e-1].size()){
        if (ans[G[e-1][i].to-1] == -1) {
            if (G[e-1][i].cost % 2 == 0) {
                ans[G[e-1][i].to-1] = ans[e-1];
            }else{
                ans[G[e-1][i].to-1] = ans[e-1]^1;
            }
            func(G[e-1][i].to);
        }
    } 
}

int main(){
    // int n;
    cin >> n;
    int u[n-1], v[n-1], w[n-1];
    rep(i, n-1){
        cin >> u[i] >> v[i] >> w[i];
        edge g;
        g.cost = w[i];
        g.to = v[i];
        G[u[i]-1].push_back(g);
        g.to = u[i];
        G[v[i]-1].push_back(g);
    }

    // rep(j, n){
    //     cout << j + 1 << ";";
    //     rep(i, G[j].size()) cout << "<" << G[j][i].to << ' ' << G[j][i].cost << ">";
    //     cout << endl;
    // }
    rep(i, n) ans[i] = -1;    
    ans[0] = 0;
    func(1);

    rep(i, n) cout << ans[i] << endl;
}

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

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

ll lcm(ll x, ll y)
{
  return x / gcd(x, y) * y;
}

ll solve(ll x, ll a, ll b)
{
  return x - (x / a + x / b - x / lcm(a, b));
}

int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll s, t, st, num;

  cout << solve(b, c, d) - solve(a - 1, c, d) << endl;
}


Measured memory_bytes: 3640
#include<stdio.h>

int main(void){
int i,N,M,answer;

scanf("%d %d",&N,&M);
int L_M[M],R_M[M];

for(i=0;i<M;i++){
  scanf("%d %d",&L_M[i],&R_M[i]);
}
int L_max = 0,R_min = 100001;
for(i=0;i<M;i++){
  if(L_max<L_M[i]){
    L_max = L_M[i];
  }
  if(R_min>R_M[i]){
    R_min = R_M[i];
  }
}
if(L_max>R_min){
  answer = 0;
}else{
answer = R_min - L_max + 1;
}
printf("%d\n",answer);
return(0);

}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 100000
using namespace std;
int main() {
  vector<string> v;
  ll n, l;
  cin >> n >> l;
  while (n--) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  for (auto s : v) {
    cout << s;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

upper = [399, 799, 1199, 1599, 1999, 2399, 2799,3199, 4800]
lower = [1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200]

cnt = 0
tops = 0
for color in range(9)[::-1]:
    for i in range(n):
        if color == 8:
            if lower[color] <= a[i] <= upper[color]:
                tops += 1
        else:
            if lower[color] <= a[i] <= upper[color]:
                cnt += 1
                break

print(max(1, cnt), cnt + tops)

Measured memory_bytes: 9128
R,G,B,N =  map(int, input().split())
ans = 0
for n in range(N+1):
  s = n * R 
  if(s > N):
    break
  for n2 in range(N+1):
    s2 = s + n2 * G
    if(s2 > N):
      break
    if((N-s2) % B == 0):
      ans += 1
print(ans)

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

int main(){
  int A,B,count=0,temp;
  int d5,d4,d3,d2,d1;
  
  cin >> A >> B;
  
  for(int i=A;i<=B;i++){
    temp = i;
	d5 = temp/10000;
    d4 = (temp=temp-d5*10000)/1000;
    d3 = (temp=temp-d4*1000)/100;
    d2 = (temp=temp-d3*100)/10;
    d1 = (temp=temp-d2*10);
    if(d5==d1 && d4==d2) count++;
  }
  
  cout << count << endl;
}
  
  

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split(" "))
    cnt = 0
    
    if n==x==0:
        break
    
    for i in range(1, n+1):
        for j in range (i+1, n+1):
            for k in range(j+1, n+1):
                if i+j+k==x:
                    cnt = cnt + 1
    
    print(str(cnt))

Measured memory_bytes: 7612
import java.util.*;
import java.util.regex.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 入力
        int n = sc.nextInt();
        int[] t = new int[n+1];
        int[] x = new int[n+1];
        int[] y = new int[n+1];
        // 初期値
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        // 入力値
        for (int i = 1; i <= n; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            int dt = t[i+1] - t[i];
            int dist = Math.abs(x[i+1] - x[i]) + Math.abs(y[i+1] - y[i]);
            if (dt < dist || (dist % 2 != dt % 2)) {
                // 出力
                System.out.println("No");
                return;
            }
        }

        // 出力
        System.out.println("Yes");
    }
}


Measured memory_bytes: 90340
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;

string x, y;
int memo[1005][1005];

int dp(int a, int b) {
	if (memo[a][b] != INT_MIN) return memo[a][b];
	if (a == 0 || b == 0) memo[a][b] = 0;
	else if (x[a - 1] == y[b - 1]) {
		memo[a][b] = dp(a - 1, b - 1) + 1;
	}
	else {
		memo[a][b] = max(dp(a - 1, b), dp(a, b - 1));
	}
	return memo[a][b];
}

int main() {
	int q;
	cin >> q;
	Loop(i, q) {
		cin >> x >> y;
		Loop(j, x.size()+1) {
			Loop(k, y.size()+1) {
				memo[j][k] = INT_MIN;
			}
		}
		cout << dp(x.size(), y.size()) << endl;
	}
	return 0;
}

Measured memory_bytes: 7156
n,m=map(int,input().split())
A=[]
for _ in range(m):
    A.append([i-1 for i in list(map(int,input().split()))[1:]])
P=list(map(int,input().split()))
ans=0
for bit in range(1<<n):
    for j in range(m):
        now=0
        for i in A[j]:
            if bit & 1<<i: now+=1
        if now%2!=P[j] : break
        if j==m-1: 
            
            ans+=1


print(ans)
                


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] counter = new int[27];
        int flag=0;
        while (sc.hasNext()) {
            String in = sc.nextLine();
           
            in=in.toLowerCase();
            for (int i = 0; i < in.length(); i++) {
          
                int value = in.charAt(i)-'a' ;
                if(value<0 || value>26){
                    continue;
                }
                if(value==-51){
                    flag=1;
                    break;
                }
           
               
                counter[value]++;
            }
            
            if(flag==1){
                break;
            }
        }
        for (int i = 0; i < 26; i++) {
            System.out.printf("%c : %d\n", i + 'a', counter[i]);
        }
        sc.close();
    }
}


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

#define      ll     long long int

const int N = 500;
int C[N];
int S[N];
int F[N];
int n;

int main()
{
    int i, j, k, l;
    cin >> n;
    for (i = 1; i < n; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for (i = 1; i <= n; i++) {
        ll s = S[i] + C[i];
        for (j = i + 1; j < n; j++) {
            if (S[j] <= s) {
                ll k = s / F[j];
                if (s % F[j] != 0) k++;
                s = k * F[j];
                s += C[j];
                continue;
            }
            s = S[j];
            s += C[j];
        }
        cout << s << '\n';
    }
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,x;
    cin>>n>>x;

    vector<int>v;

    for(int i=x-1;i>=x-n+1;i--)v.push_back(i);
    for(int i=x+1;i<=x+n-1;i++)v.push_back(i);
    v.push_back(x);

    sort(v.begin(),v.end());
    for(auto e:v)cout<<e<<" ";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long n = Long.parseLong(sc.next());
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        
        if((b-a) % 2 == 0){
            System.out.println((b-a) / 2);
        }else{
            System.out.println((Math.min(a-1, n-b)*2+1 + b-a) /2);
        }
    }
}

Measured memory_bytes: 25172
#include<stdio.h>

int main(void){

	int i=0;
	char letter;
	char string[10000];

	while(1){
		scanf("%c",&letter);
		if(letter=='\n'){
			string[i]='\0';
			break;
		}
		if(letter>='A'&&letter<='Z')
			letter+=32;
		else if(letter>='a'&&letter<='z')
			letter-=32;
		string[i]=letter;
		i++;
	}

	printf("%s\n",string);

	return 0;
}

Measured memory_bytes: 528
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int num[200010];
int head[200010];
int cnt = 0;
struct node{
    int to, next = 0;
}line[200010];
int a, b;

void add(int x, int y){
    line[++cnt].to = y;
    line[cnt].next = head[x];
    head[x] = cnt;
}

void dfs(int x, int sum){
    for(register int i = head[x]; i != 0; i = line[i].next){
        dfs(line[i].to, sum+num[line[i].to]);
        num[line[i].to] += sum;
    }
}

int main(){
    int i, j, k;
    cin >> n >> m;
    for(i = 1; i < n; ++i){
        scanf("%d%d",&a ,&b);
        add(a, b);
    }
    for(i = 1; i <= m; ++i){
        scanf("%d%d",&a ,&b);
        num[a] += b;
    }
    dfs(1, num[1]);
    for(i = 1; i <= n; ++i){
        printf("%d ",num[i]);
    }
    return 0;
}

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

char T[200005];

int main(){
    scanf(" %s", T);
    int len = strlen(T);
    for(int i = 0; i < len; i ++){
        if(T[i] == 'P'){
            putchar('P');
        }else{
            putchar('D');
        }
    }
    return 0;
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S >> T;

	int NS = S.length();
	int NT = T.length();

	int ans = inf;
	rep(s, 0, NS - NT + 1) {
		int cnt = 0;
		rep(t, 0, NT) if (S[s + t] != T[t]) cnt++;
		chmin(ans, cnt);
	}
	cout << ans << endl;
}







Measured memory_bytes: 3640
#include<iostream>
#include<string>//文字列
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<vector>
#include<iomanip>//小数点以下桁指定

using namespace std;


int main(){
	
	int a[3]={};
	cin>>a[0]>>a[1]>>a[2];
	int min=0;
	
	for(int i=0;i<3;i++){
		for(int j=i+1;j<3;j++){
			if(a[i]<a[j]){
				min=a[i];
				a[i]=a[j];
				a[j]=min;
			}
		}
	}
	cout<<a[0]*10+a[1]+a[2]<<endl;;
	
	

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
string S;
cin>>S;
if (S=="SUN") {
  cout<<7<<endl;
}
else if(S=="MON"){
cout<<6<<endl;
}
else if(S=="TUE"){
cout<<5<<endl;
}
else if(S=="WED"){
cout<<4<<endl;
}
else if(S=="THU"){
cout<<3<<endl;
}
else if(S=="FRI"){
cout<<2<<endl;
}
else{
cout<<1<<endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <queue>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<int, int> P;

llint n, k;
string s;
llint Q;
llint D, DM, M;

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

  cin >> n >> s;
  cin >> Q;
  for(int q = 0; q < Q; q++){
    cin >> k;
    D = DM = M = 0;
    llint ans = 0;

    for(int i = 0; i < n; i++){
      if(i >= k){
        if(s[i-k] == 'D') DM -= M, D--;
        else if(s[i-k] == 'M') M--;
      }
      if(s[i] == 'D') D++;
      else if(s[i] == 'M') DM += D, M++;
      else if(s[i] == 'C') ans += DM;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1948
gridNumber = []
numbers = []
for i in range(3):
    gridNumber.append(list(map(int, input().split())))

a1=0
b1=gridNumber[0][0] - a1
b2=gridNumber[0][1] - a1
b3=gridNumber[0][2] - a1

a2=gridNumber[1][0] - b1
a3=gridNumber[2][0] - b1

numbers.append([a1+b1, a1+b2, a1+b3])
numbers.append([a2+b1, a2+b2, a2+b3])
numbers.append([a3+b1, a3+b2, a3+b3])

for i in range(3):
    for j in range(3):
        if not(numbers[i][j] == gridNumber[i][j]):
            print("No")
            quit()
        else:
            pass

print("Yes")

Measured memory_bytes: 3064
//package beg_164;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		String yvgubhij = s.nextLine();
		
		HashSet<String> set = new HashSet<String>();
		for (int i=0;i<a;i++) {
			String b = s.nextLine();
			set.add(b);
		}
		System.out.println(set.size());
	}

}


Measured memory_bytes: 82592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		int c = Integer.parseInt(line[2]);

		int ans[] = { Math.abs(a - b), Math.abs(b - c), Math.abs(c - a) };

		Arrays.sort(ans);

		System.out.println(ans[0] + ans[1]);

	}

}


Measured memory_bytes: 23124
N = int(input())
raw = []

for i in range(N):
    S, P = input().split()
    P = int(P)
    S = str(S)
    raw.append([i+1]+[P]+[S])
# print(raw)

guide = sorted(raw, key=lambda x:x[1],reverse=True)
guide = sorted(guide, key=lambda x:x[2])
# print(guide)


for i in range(N):
    print(guide[i][0])

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a * c <= b) cout << c << endl;
    else cout << b / a << endl;
}


Measured memory_bytes: 256
card = {"S" => Array.new(13){|i|i + 1}, "H" => Array.new(13){|i|i + 1}, "C" => Array.new(13){|i|i + 1}, "D" => Array.new(13){|i|i + 1}}
gets.to_i.times do
  sute, num = gets.split(" ")
  card[sute][num.to_i - 1] = false
end
card.to_a.map{|(key, value)|
  [key, value.select{|item|item}]
  }.reject{|(key,value)|
  value.size == 0}.each{|(key, value)|
  value.each{|item|
    puts key + " " + item.to_s
    }}

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

A = list(map(int,input().split()))

memo = []

for key,val in enumerate(A):
    memo.append(val-key-1)

memo.sort()

b = memo[len(memo)//2]

ans  = 0
for key,val in enumerate(A):
    ans += abs(val-(b+key+1))

print(ans)

Measured memory_bytes: 107656
#include<bits/stdc++.h>
#include<string>
#include<numeric>
using namespace std;
//max=({});

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	string ans;
	for (int i = 0;i < n;++i) {
		ans += s[i];
		ans += t[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 200000
int p[N+1];
void era(void){
    int i,j;
    for(i=2;i<N;i++)
        p[i]=1;
    for(i=2;i*i<N;i++){
        if(p[i]){
            for(j=2*i;j<=N;j=j+i)
                p[j]=0;
        }
    }
}
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}
int main(void){
	int n,m,i,j,c1,c2,c3,s[10000];
	era();
	while(1){
		scanf("%d %d",&n,&m);
		if(n==-1)
			break;
		c3=0;
		for(i=n+1,c1=0;c1<100;i++){
			if(p[i]){
				for(j=i,c2=0;c2<100;j++){
					if(p[j]){
						s[c3++]=i+j;
						c2++;
					}
				}
				c1++;
			}
		}
		qsort(s,c3,sizeof(int),cmp);
		printf("%d\n",s[m-1]);
	}
	return 0;
}

Measured memory_bytes: 1488
from scipy.special import comb
n, p, *A = map(int, open(0).read().split())
o = sum(a%2 for a in A)
e = n - o

s = 0
for i in range(p, o+1, 2):
  s += comb(o, i, exact=True)
s *= pow(2, e)
print(s)

Measured memory_bytes: 42360
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, L;
	cin >> N >> L;
	int mn = 1000000000;
	int mnt = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int t = L + i;
		sum += t;
		if (mn > abs(t)) {
			mn = abs(t);
			mnt = t;
		}
	}
	int res = sum - mnt;
	cout << res << endl;
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	long long count = 0;

	for (int i = 1; i < N; i++) {
		for (int j = 1; j < N; j++) {
			if (i * j < N) {
				count++;
			}
			else{
				break;
			}
		}
	}

	cout << count << "\n";

	return 0;
}

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

int main(){
  string s,t;

  cin >> s >> t;

  string result = "Yes";

  int scount[26] = {0};
  int tcount[26] = {0};

  for(int i = 0;i < s.size();i++){
    scount[s[i]-'a']++;
    tcount[t[i]-'a']++;
  }

  int smat[200000] = {0};
  int tmat[200000] = {0};
  for(int i = 0;i < 26;i++){
    smat[scount[i]]++;
    tmat[tcount[i]]++;
  }
  for(int i = 0 ; i < s.size();i++){
    if(smat[i] != tmat[i]){
      result = "No";
    }
  }

  cout << result << endl;

  return 0;
}
    

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

int main(){
  string h,com,rep,temp;
  int a,b,n,i,j;
  cin>>h;
  cin>>n;
  for (i=0;i<n;i++){
    cin>>com>>a>>b;
    if (com== "print"){
      for (j=a;j<=b;j++){
        cout<<h[j];
      }
      cout<<endl;
    }else{
      temp="";
      for (j=0;j<a;j++)temp+=h[j];
      if (com=="replace"){
        cin>>rep;
        temp+=rep;
      }else{
        for (j=b;j>=a;j--)temp+=h[j];
      }
      if (b<h.size()-1){
        for (j=b+1;j<h.size();j++)temp+=h[j];
      }
      h=temp;
    }
  }
}



Measured memory_bytes: 3192
//package atcoder.beginner144;

import java.io.*;
import java.util.*;

public class Main {
    private static List<Integer>[] paths;
    private static double[] dp;
    private static int N, M;
    private static double ans;

    public static void main(String[] args) {
//        try {
//            FastScanner in = new FastScanner(new FileInputStream("src/input.in"));
//            PrintWriter out = new PrintWriter(new FileOutputStream("src/output.out"));
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

            solve(in, out);

//        }
//        catch (IOException e) {
//            e.printStackTrace();
//        }
    }

    private static void input(FastScanner in, PrintWriter out) {
        N = in.nextInt();
        M = in.nextInt();
        paths = new List[N + 1];
        dp = new double[N + 1];

        for(int i = 1; i <= N; i++) {
            paths[i] = new ArrayList<>();
        }
        for(int i = 0; i < M; i++) {
            int s = in.nextInt(), t = in.nextInt();
            paths[s].add(t);
        }
    }

    private static void f(int block) {
        dp[N] = 0;
        for(int i = N - 1; i >= 1; i--) {
            double sum = 0.0;
            double maxAdj = 0.0;
            int num = paths[i].size();
            for(int j : paths[i]) {
                sum += dp[j];
                maxAdj = Math.max(maxAdj, dp[j]);
            }
            if(i == block && num > 1) {
                num--;
                sum -= maxAdj;
            }
            dp[i] = sum / num + 1;
        }
        ans = Math.min(ans, dp[1]);
    }

    private static void solve(FastScanner in, PrintWriter out) {
        input(in, out);
        ans = Double.MAX_VALUE;
        for(int i = 1; i < N; i++) {
            f(i);
        }
        out.println(ans);
        out.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}




Measured memory_bytes: 49520
N = int(input())
#A = [list(map(int,input().split())) for i in range(N)]
#print (A)
def bubble_sort(arr1,arr2,n):
    for i in range(n):
        for j in range(0,n-i-1):
            if arr1[j] > arr1[j+1]:
                arr1[j],arr1[j+1] = arr1[j+1],arr1[j]
                arr2[j],arr2[j+1] = arr2[j+1],arr2[j]





A = []
B = []
max_key = 0
max_value = 0
for i in range(N):
    tmp1,tmp2 = map(int,input().split())
    A.append(tmp1)
    B.append(tmp2)
    if tmp1 > max_key:
        max_key = tmp1
        max_value = tmp2
print(max_value+max_key)
#bubble_sort(A,B,N)
#base = A[-1]
#addition = B[-1]


#print(base + addition)


Measured memory_bytes: 11072
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

char ma[100][100];
bool vis[100][100];
int vx[]={1,0,-1,0},vy[]={0,-1,0,1};
int H,W;
void umel(int x,int y,char c){
    vis[x][y]=true;
    for(int i=0;i<4;i++){
        int nx=x+vx[i],ny=y+vy[i];
        if(0<=nx && nx<H && 0<=ny && ny<W && ma[nx][ny]==c && !vis[nx][ny]){
            umel(nx,ny,c);
        }
    }
}
int main(){
    for(;;){
        scanf("%d %d\n",&H,&W);
        if(H==0&&W==0) break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                scanf("%c",&ma[i][j]);
                vis[i][j]=false;
            }
            scanf("\n");
        }
        int ret=0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(!vis[i][j]){
                    ret++;
                    umel(i,j,ma[i][j]);
                }
            }
        }
        printf("%d\n",ret);
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i64 n, p;
  cin >> n >> p;
  i64 odd = 0;
  rep(i, n) {
    int a; cin >> a;
    if (a % 2 == 1) odd++;
  }
  if (odd > 0) {
    cout << bit(n - 1) << endl;
  } else {
    if (p == 0) cout << bit(n) << endl;
    else cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256