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

int main() {
    string S;
    cin >> S;
    int ans = 0;
    int count = 0;

    rep(i, S.size())
    {
        if(S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C')
        {
            count++;
        }
        else
        {
            ans = max(ans, count);
            count = 0;
        }
        
    }
    ans = max(ans, count);

    cout << ans << endl;

    return 0;  

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll gcd(ll a, ll b){
    if(a < b)  swap(a,b);
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (ll i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
int main(){
    cout << fixed << setprecision(10);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll minc, maxc, mind, maxd, mincd, maxcd;
    if(a%c == 0) minc = a;
    else minc = (a/c+1)*c;

    if(a%d == 0) mind = a;
    else mind = (a/d+1)*d;
    /*
    cout << mind << endl;
    cout << "?? " << a << " " << d << endl; */
    maxc = (b/c)*c;
    maxd = (b/d)*d;

    ll cd = lcm(max(c,d),min(c,d));

    if(a%cd == 0) mincd = a;
    else mincd = (a/cd+1)*cd;

    maxcd = (b/cd)*cd;

    ll cnt1 = 0, cnt2 = 0, cnt3 = 0;

    if(minc <= maxc) cnt1 = (maxc - minc) / c + 1;
    if(mind <= maxd) cnt2 = (maxd - mind) / d + 1;
    if(mincd <= maxcd)  cnt3 = (maxcd - mincd) / cd + 1;
    /*cout << minc << " " << maxc << endl;
    cout << mind << " " << maxd << endl;
    cout << mincd << " " << maxcd << endl;
    cout << cnt1 << " " << cnt2 << " " << cnt3 << " " << endl;*/ 
    cout << (b - a) + 1 - cnt1 - cnt2  + cnt3 << endl;

    return 0;
}

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int a[3]; for(int &i : a) cin >> i;
    sort(a, a+3);
    if((a[1] == a[0] && a[0] != a[2]) || (a[1] == a[2] && a[0] != a[2])) cout << "Yes";
    else cout << "No";    
}

Measured memory_bytes: 3588
object Main {
  def main(args: Array[String]): Unit = {
    val Seq(a, b, k) = io.StdIn.readLine().split(" ").map(_.toInt).toSeq

    val m = math.min(a, b)

    println {
      (m to 1 by -1).toStream
        .filter(x => a % x == 0 && b % x == 0)(k - 1)
    }
  }
}


Measured memory_bytes: 25420
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {

  static int n, m;
  static int[] a;

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    m = Integer.parseInt(in[1]);

    in = br.readLine().split(" ");
    a = Stream.of(in).mapToInt(Integer::parseInt).toArray();

    br.close();

    Arrays.sort(a);

    int sum = 0;
    for(int i = 0; i < n; i++){
      sum += a[i];
    }

    int lim = (sum-1) / (4 * m) + 1;

    boolean ok = true;
    for(int i = n - 1; i >= n - m; i--){
      if(a[i] < lim) ok = false;
    }

    System.out.println(ok ? "Yes" : "No");
  }
}

Measured memory_bytes: 26580
def solve():
  ans = 0
  N, T = map(int, input().split())
  A = [list(map(int, input().split())) for _ in range(N)]
  A.sort()
  dp = [[0]*(T+A[-1][0]) for _ in range(N+1)]
  for i in range(1,N+1):
    for t in range(1,T+A[-1][0]):
      if t<A[i-1][0] or t>=T+A[i-1][0]:
        dp[i][t] = max(dp[i-1][t],dp[i][t-1])
      else:
        dp[i][t] = max([dp[i-1][t],dp[i][t-1],dp[i-1][t-A[i-1][0]]+A[i-1][1]])
  ans = max(dp[-1])
  return ans
print(solve())

Measured memory_bytes: 216112
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

// [l, r)
inline ll calc(vll& sum, int l, int r){
    return sum[r] - sum[l];
}

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

    int n, K; cin >> n >> K;
    vll a(n); for(auto& e : a) cin >> e;

    vll sum(n + K + 10);
    vll sump(n + K + 10);
    rep(i, n){
        ll diff = a[i];
        sum [i + 1] = sum [i] + diff;
        sump[i + 1] = sump[i] + max(0LL, diff);
    }

    ll res = 0;
    rep(i, n - K + 1){
        ll cur = calc(sump, 0, i) + calc(sump, i + K, n);
        chmax(cur, cur + calc(sum, i, i + K));
        chmax(res, cur);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4096
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int k, string s) {
    // 0, 1 でグループ化して個数を記録する
    int[] g;
    // 先頭要素が 0 なら、先頭に 0 個の 1 があると見なす
    if (s.front == '0') g ~= 0;

    int lo = 0;
    while (lo < s.length) {
        int hi = lo;
        while (hi < s.length && s[lo] == s[hi]) hi++;
        g ~= hi - lo;
        lo = hi;
    }

    // 累積和
    auto sum = new int[g.length];
    sum[0] = g[0];
    for (int i = 1; i < g.length; i++) {
        sum[i] = g[i] + sum[i - 1];
    }

    int ans = 0;
    // 0, 1, 0, 1, ... のパターンで並んでいるので
    // 2 個単位で k 個まで取り出す(2 * k + 1 個とる)
    for (int i = 0; i < sum.length; i += 2) {
        int hi = min(i + 2 * k, cast(int)sum.length - 1);

        int a = sum[hi] - (i-1 >= 0 ? sum[i-1] : 0);
        ans = max(ans, a);
    }
    return ans;
}

void main() {
    auto nk = readints;
    int k = nk[1];
    string s = read!string;

    writeln(calc(k, s));
}


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


struct abset {
  int a_num , b_num;
  abset(int a_num, int b_num) {
    this -> a_num = a_num;
    this -> b_num = b_num;
  }
  abset() {
    a_num = 0;
    b_num = 0;
  };
};

int get_group(abset abset1) {
  int a = abset1.a_num;
  int b = abset1.b_num;
  a %= 3;
  b %= 3;
  if(a == 1 && b == 0) return 1;
  if(a == 0 && b == 2) return 1;
  if(a == 2 && b == 1) return 1;
  if(a == 0 && b == 1) return 2;
  if(a == 2 && b == 0) return 2;
  if(a == 1 && b == 2) return 2;
  if(a == 1 && b == 1) return 3;
  if(a == 2 && b == 2) return 3;
  if(a == 0 && b == 0) return 3;
}

abset operator-(abset abset1, abset abset2) {
  return abset(abset1.a_num - abset2.a_num, abset1.b_num - abset2.b_num);
}

int main() {
  string S, T;
  cin >> S >> T;

  int Q;
  cin >> Q;



  vector<abset> vs(S.length());
  vector<abset> vt(T.length());

  {
    int a_num = 0, b_num = 0;

    for(int i = 0; i < S.length(); i++) {
      if(S[i] == 'A') a_num += 1;
      else b_num += 1;
      vs[i] = abset(a_num, b_num);
    }
  }

  {
    int a_num = 0, b_num = 0;
    for(int i = 0; i < T.length(); i++) {
      if(T[i] == 'A') a_num += 1;
      else b_num += 1;
      vt[i] = abset(a_num, b_num);
    }
  }

  for(int q = 0; q < Q; q++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(get_group(vs[b-1] - (a >= 2 ? vs[a - 2]: abset(0, 0))) == get_group(vt[d-1] - (c >= 2 ? vt[c-2]: abset(0, 0)))) cout << "YES" << endl;
    else cout << "NO" << endl;

  }


}


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

int main() {
  string str;
  while(cin >> str, str != "-") {
    int len = str.size(), is = 0, nh;
    cin >> nh;
    for(int ih = 0; ih < nh; ++ih) {
      int h;
      cin >> h;
      is += h;
    }
    is %= len;
    cout << str.substr(is) << str.substr(0, is) << endl;
  }
  return 0;
}

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

int main(){
    size_t N;
    unsigned long L, A;
    cin >> N >> L >> A;
    auto f = [&N](auto idx){
        puts("Possible");
        for(unsigned long i = N - 1; i > idx; --i)cout << i << endl;
        for(unsigned long i = 1; i <= idx; ++i)cout << i << endl;
        return 0;
    };
    for(unsigned long i = 1, B; i < N; ++i){
        cin >> B;
        if(A + B >= L)return f(i);
        swap(A, B);
    }
    puts("Impossible");
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    int n, m;   cin >> n >> m;  map<int, int> mp;
    for(int i=0;m>i;i++){
        int a, b;   cin >> a >> b;
        mp[a]++; mp[b]++;
    }
    for(auto it=mp.begin();it!=mp.end();++it){
        if((it->second)%2){
            cout << "NO";   return 0;
        }
    }
    cout << "YES";
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int a[301][301];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			scanf("%d", &a[i][j]);
		}
	}
	int n1=1, n2=n;
	while(n1!=n2){
		int nmid=(n1+n2)/2;
		set<int> st, st1;
		for(int i=1; i<=m; i++){
			st.insert(i);
		}
		deque<int> a1[301];
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				a1[i].push_back(a[i][j]);
			}
		}
		while(!st.empty()){
			int count[301]={};
			for(int i=0; i<n; i++){
				count[a1[i].front()]++;
			}
			int e=0;
			for(int i=0; i<n; i++){
				if(count[a1[i].front()]>nmid){
                    e=1;
					st.erase(a1[i].front());
					st1.insert(a1[i].front());
                    a1[i].pop_front();
				}
			}
			if(e==0){
				n2=nmid;
				break;
			}else{
              for(int i=0; i<n; i++){
                while(1){
					if(!a1[i].empty() && st1.find(a1[i].front())!=st1.end()){
                      a1[i].pop_front();
                    }else{
                      break;
                    }
				}
              }
            }
		}
		if(st.empty()){
			n1=nmid+1;
		}
	}
	printf("%d\n", n1);
	return 0;
}


Measured memory_bytes: 1168
#include <iostream>
#include <string>
#include<vector>
using namespace std;
int main() {
	int N;
	unsigned long long m, l=0;
	cin >> N;
	for (int n = 1; n < N; n++) {
		if (N % n == 0) {
			m = N / n - 1;
		}
		else {
			m = N / n;

		}
		
		l += m;
	}
	cout << l;
	return 0;

}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
    int x,y;
    
    while(1){
    scanf("%d %d",&x,&y);
    if(x==0&&y==0){
        break;
    }else if(x<y){
        printf("%d %d\n",x,y);
    }else{
        printf("%d %d\n",y,x);
    }
    }
    return(0);
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	void main()
	{
		write(a[qread()-1]);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> H;
    int tmp;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        H.push_back(tmp);
    }
    sort(H.begin(), H.end());
    int ans = INF;
    for (int i = 0; i <= N - K; i++)
        ans = min(ans, H[i + K - 1] - H[i]);
    cout << ans << endl;
    return 0;
}

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

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define LL long long
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;

template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}

LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}

template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) {
	return max(a, Smax(args...));
}
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) {
	return min(a, Smin(args...));
}

template <typename T>
#define errorl(args...) {  \
	string _s = #args;   \
	replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    errl(_it, args);  \
}
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}
#define error(args...) {  \
    string _s = #args;  \
    replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    err(_it, args);  \
    cerr<<endl; \
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}

int a[N];

void Solve() {
	int n;
	cin >> n;

	n *= 2;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	sort(a + 1, a + 1 + n);

	LL ans = 0;
	for (int i = 1; i <= n; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}


Measured memory_bytes: 3592
unittest
{
	assert( [ "3 2", "5 1 4", "2 3", "1 5" ].parse.expand.solve == 14 );
	assert( [ "10 3", "1 8 5 7 100 4 52 33 13 5", "3 10", "4 30", "1 4" ].parse.expand.solve == 338 );
	assert( [ "3 2", "100 100 100", "3 99", "3 99" ].parse.expand.solve == 300 );
	assert( [ "11 3", "1 1 1 1 1 1 1 1 1 1 1", "3 1000000000", "4 1000000000", "3 1000000000" ].parse.expand.solve == 10000000001 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	auto bcs = new long[][]( nm[ 1 ], 2 );
	foreach( ref bc; bcs )
	{
		input.popFront;
		bc = input.front.split.to!( long[] );
	}
	return tuple( as, bcs );
}

auto solve( long[] as, long[][] bcs )
{
	as.sort();
	bcs.sort!( ( x, y ) => y[ 1 ] < x[ 1 ] )();
	
	// 一番小さいカードから順番に大きい整数に書き換えた結果を集計
	auto ans = 0L;
	foreach( a; as )
	{
		if( !bcs.empty && a < bcs.front[ 1 ] )
		{
			a = bcs.front[ 1 ];
			bcs.front[ 0 ]--;
			if( bcs.front[ 0 ] == 0 ) bcs.popFront();
		}
		ans += a;
	}
	return ans;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	const int MXZ = 1<<17;
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll ans=0;
	cin >>n;
	vector<pii> p(n);
	rep(i, n){
		cin >>p[i].first; p[i].second=i+1;
	}
	sort(p.rbegin(), p.rend());
	bitset<MXZ> bs1, bs2;
	
	bs1[0] =bs2[0] =1;
	bs1[n+1] =bs2[n+1] =1;
	rep(i, n){
		int cid = p[i].second;
		bs1[cid] = bs2[n-cid] = 1;
		int l1=0, l2=0;
		int r1=n+1, r2=n+1;
		
		auto it = bs1._Find_next(cid);
		if(it <= n){
			r1 = it;
			it =  bs1._Find_next(r1);
			if(it <= n) r2 = it; 
		}
		it = bs2._Find_next(n-cid);
		if(it <= n){
			l2 = it;
			it =  bs2._Find_next(l2);
			if(it <= n) l1 = n-it; 
			l2=n-l2;
		}

		ll a=cid-l2, b=l2-l1;
		ll c=r1-cid, d=r2-r1;
		ans += (a*d + b*c) * p[i].first;
		//dbg(i, p[i].first, l1,l2,r1,r2, a*d+b*c, ans);
		
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	int n,x;
	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0) break;
		int ans = 0;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				for(int k=j+1;k<=n;k++){
					if(i+j+k == x) ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

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

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, M;
    cin >> N >> M;

    int l = 1, r = N - 1;
    if(N % 2 == 1) {
        while(l < r && M > 0) {
            cout << l << " " << r << endl;
            ++l; --r;
            --M;

        }
    } else {
        bool f = false;
        while(l < r && M > 0) {
            if(!f && r - l <= N / 2) {
                r--;
                f = true;

            }
            cout << l << " " << r << endl;
            ++l, --r;
            --M;

        }
    }

    return 0;
}



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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    void inputVecParallel(int index){return;}
    template<typename First,typename... Rest> void inputVecParallel(int ____i,vector<First> &first,Rest&... rest){
        cin >> first[____i];
        inputVecParallel(____i,rest...);
        return;
    }

    template<typename First,typename... Rest> void inputVecParallel(vector<First> &first,Rest&... rest)
    {
        int ____size = first.size();
        for(int ____i = 0;____i < ____size;++____i)
        {
            cin >> first[____i];
            inputVecParallel(____i,rest...);
        }
        return;
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}


void calculate(){
    long long a,b,c,k;
    Input::input(a,b,c,k);
    long long ans = 0;
    if(k <= a) ans = k;
    else if(k <= a + b) ans = a;
    else
    {
        ans = a;
        int n = k - a - b;
        ans -= n;
    }
    cout << ans << '\n';
}

int main(int,char**){
    calculate();    
}





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

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

  vector<int> k(m);
  vector<int> p(m);
  vector<vector<int>> s(m,vector<int>(n));
  int i,j;
  for(i=0;i<m;i++){
    cin>>k.at(i);
    for(j=0;j<k.at(i);j++){
      cin>>s.at(i).at(j);
    }
  }
  for(i=0;i<m;i++)
  cin>>p.at(i);

  int cnt=0;
  for(int bit=0;bit<(1<<n);bit++){
    bool syori=0;
    // cout<<"bit "<<bit<<endl;
    for(i=0;i<m;i++){
      int c=0;
      // cout<<"k.at("<<i<<")"<<endl;
      for(j=0;j<k.at(i);j++){
        if(bit&(1<<s.at(i).at(j)-1))
        c++;
      }
      // cout<<"c "<<c<<endl;
      if(c%2!=p.at(i)){
        syori=0;
        break;
      }
      else{
        syori=1;
      }
    }
    if(syori){
      cnt++;
    }
  }
  cout<<cnt<<endl;

}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
    if a >= b:
        b *= 2
    else:
        c *= 2

if a < b and b < c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=[0]*N
    x=[[] for _ in range(N)]
    y=[[] for _ in range(N)]
    for i in range(N):
        A[i]=int(input())
        x[i]=[0]*A[i]
        y[i]=[0]*A[i]
        for j in range(A[i]):
            X,Y=map(int,input().split())
            x[i][j],y[i][j]=X-1,Y
    ans=0
    for i in range(2**N):
        l=[-1]*N
        f=True
        for j in range(N):
            if (i >> j) & 0b1 == 1:
                if l[j] != 0:
                    l[j]=1
                    for k in range(A[j]):
                        if l[x[j][k]] == -1:
                            if y[j][k] == 1 and (i >> x[j][k]) & 0b1 == 1:
                                l[x[j][k]] = y[j][k]
                            elif y[j][k] == 0:
                                l[x[j][k]] = y[j][k]
                            else:
                                f=False
                                break
                        else:
                            if l[x[j][k]] != y[j][k]:
                                f=False
                                break
                    if f==False:
                        break
                else:
                    f=False
                    break
        if f==True:
            c=0
            for i in l:
                c+=1 if i==1 else 0
            ans=max(ans,c)
    print(ans)
                

if __name__ == '__main__':
    main()


Measured memory_bytes: 48112
from itertools import *
n=int(input())
s=input()
w=[0]*(n+1)
b=[0]*(n+1)
for i,j in enumerate(s):
  if j=='.':w[i]=1
  else:b[i+1]=1
for i in range(n):
  w[n-i-1]+=w[n-i]
  b[i+1]+=b[i]
ans=10**18
for i,j in zip(w,b):
  ans=min(ans,i+j)
print(ans)

Measured memory_bytes: 77076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll n;
    ll push=0;
    cin >> n;
    vector<ll> A(n);
    vector<ll> B(n);
    rep(i,n){
        cin >> A[i];
        cin >> B[i];
    }
    for(ll i=n-1; i>=0; i--){
        A[i] += push;
        if((A[i] % B[i]) > 0){
            push += B[i] - (A[i]%B[i]);
        }
    }
    cout << push << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n,i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

sum_a = sum(a)
sort_a = sorted(a, reverse = True)
mmm = sort_a[m-1]
base = sum(a)/ (4 * m)

if mmm < base:
    print("No")
else:
    print("Yes")
    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>


using namespace std;


static const int MAX = 10000;


vector<int> graph[MAX];
vector<int> sorted;
vector<int> in_edges(MAX, 0);
vector<bool> discovered(MAX, false);
queue<int> visiting;
int V, E;


void bfs(int start)
{
    visiting.push(start);
    discovered[start] = true;

    while (!visiting.empty()) {
        int now = visiting.front();
        visiting.pop();

        sorted.push_back(now);

        for (vector<int>::iterator it = graph[now].begin(); it != graph[now].end(); ++it) {
            in_edges[*it]--;
            if (!discovered[*it] && in_edges[*it] == 0) {
                visiting.push(*it);
                discovered[*it] = true;
            }
        }
    }
}


int main()
{
    cin >> V >> E;

    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        graph[s].push_back(t);
        in_edges[t]++;
    }

    for (int i = 0; i < V; i++)
        if (!discovered[i] && in_edges[i] == 0)
            bfs(i);

    for (vector<int>::iterator it = sorted.begin(); it != sorted.end(); ++it) {
        cout << *it << endl;
    }

    return 0;
}



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

int main() {
    int32_t n;
    cin >> n;
    int32_t h[n];

    int32_t h_max = 0;
    for (int32_t i = 0; i < n; i++) {
        int32_t h;
        cin >> h;
        if (h >= h_max) {
            h_max = h;
        }
        if (h_max - h >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main(){
    ll N, A, B;
    cin >> N >> A >> B;

    if((B - A) % 2 == 0){
        cout << (B - A) / 2 << endl;
    }else{
        cout << min(A, (N - B + 1)) +  (B - A - 1) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x) for(int i=0; i<x; i++)
typedef long long ll;
using ull = unsigned long long;
using namespace std;

int main(){
  int N;
  cin>>N;

  ull A[N];
  rep(i,N) cin>>A[i];
  rep(i,N){
    if(A[i] == 0){

     cout << 0<< endl;
     return 0;
   }
  }

  ull ans = 1;

  rep(i,N){
    if( A[i] <= 1000000000000000000ULL/ans){
      ans *= A[i];
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4376
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
ll mul(ll a, ll b, ll md){
	return a*b % md;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s1, s2; cin>>s1>>s2;
	s2.pop_back();
	s1 == s2 ? cout<<"Yes" : cout<<"No";
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define de cout << "debug" << endl;
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 N,K;
  cin >> N >> K;
  ll h[1000010];
  ll dp[1000010];
  REP(i,N) cin >> h[i];
  REP(i,1000010) dp[i] = INFF;
  dp[0] = 0;
  REPP(i,1,N){
    REPP(j,0,K+1){
      if(i-j < 0) continue;
      chmin(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
    }
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 11776
// UNNECESSARY
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
// #include <fstream>//ifstream/ofstream

// DATA STRUCTURES
#include <array>
#include <bitset>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>

// MISCELLANEOUS
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <cassert>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <new>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <utility>//pair

#ifndef REP
#define REP(i,n) for (int i = 0; i < n; ++i)
#endif

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

#ifndef READ
#define READ(x) std::cin >> x
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> plli;
typedef std::pair<ull, int> puli;
typedef std::pair<double, int> pdi;
typedef std::pair<ll, ll> pllll;
typedef std::pair<ull, ull> pulul;
typedef std::pair<double, double> pdd;
typedef std::tuple<int, int, int> ti3;
typedef std::tuple<int, int, int, int> ti4;

const bool debug = false;

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

using namespace std;

int main(void)
{
    size_t n;
    cin >> n;
    std::array<std::vector<int>, 2> grid;
    REP(i,2) {
        int x;
        REP(j,n) {
            cin >> x;
            grid[i].push_back(x);
        }
    }
    int max_sum = 0;
    REP(i,n) {
        int sum = 0;
        REP(j,i+1) {
            sum += grid[0][j];
        }
        for (size_t j = i; j < n; ++j) {
            sum += grid[1][j];
        }
        if (max_sum < sum) {
            max_sum = sum;
        }
    }
    cout << max_sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
void func(int);
int flg[8],n,x[8],y[8],cnt,zyu[8];
double sum,avg;
int main(void)
{
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&x[i],&y[i]);
		flg[i]=0;
	}
	sum=0.0;
	cnt=0;
	func(0);
	avg=sum/cnt;
	printf("%lf\n",avg);
	return 0;
}
void func(int nn)
{
	int i,x1,y1,x2,y2;
	double a;
	if(nn==n){
		a=0.0;
		for(i=0;i<n-1;i++){
			x1=zyu[i];
			y1=zyu[i];
			x2=zyu[i+1];
			y2=zyu[i+1];
			a+=sqrt((double)(x[x2]-x[x1])*(x[x2]-x[x1])+(y[y2]-y[y1])*(y[y2]-y[y1]));
		}
		sum+=a;
		cnt++;
	}
	else{
		for(i=0;i<n;i++){
			if(flg[i]==0){
				flg[i]=1;
				zyu[nn]=i;
				func(nn+1);
				flg[i]=0;
			}
		}
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main(){
  int n,m;
  vector<string> v;
  string str;
  int flag1 = 0;
  int flag2;
  cin >> n;
  for(int i = 0; i < n;i++){
    cin >> str;
    v.push_back(str);
  }

  cin >> m;

  for(int i = 0;i < m;i++){
    cin >> str;
    flag2 = 0;
    for(int j = 0; j < v.size();j++){
      if(str == v[j]){
        if(flag1 == 0){
          cout << "Opened by "<<str << endl;
          flag2 = 1;
          flag1 = 1;
        }else if(flag1 == 1){
          cout << "Closed by "<< str << endl;
          flag2 = 1;
          flag1 = 0;
        }
      }
    }
    if(flag2 == 0){
      cout << "Unknown " << str << endl;
    }
  }
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int N;
vector<int> t[20];
int dp[16][1<<16];

int dfs(int pos, int S) {
    if(S == (1<<N)-1) return 0;
    if(dp[pos][S] != -1) return dp[pos][S];
    int ret = 1000000000;

    //i番目をj番目の装備で攻略
    rep(i,N) {
        if(i == pos) continue;
        if((S>>i)&1) continue;
        rep(j,N) {
            if(i==j) continue;
            if(!((S>>j)&1)) continue;

            ret = min(ret, dfs(i,S|(1<<i)) + t[i][j+1]);
        }
        ret = min(ret, dfs(i, S|(1<<i)) + t[i][0]);
    }
    return dp[pos][S]=ret;

}

void solve() {
    rep(i,16) rep(j,1<<16) dp[i][j]=-1;
    rep(i,N) {
        t[i].resize(N+1);
        rep(j,N+1) {
            int a;
            cin>>a;
            t[i][j]=a;
        }
    }
    int ans = 1000000000;
    rep(i,N) {
        ans = min(ans,dfs(i, 1<<i)+t[i][0]);
    }
    cout<<ans<<endl;

    rep(i,N) t[i].clear();

}
int main() {

    while(cin>>N) {
        if(!N) return 0;
        solve();
    }

    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B, C;
    cin >> A >> B >> C;

    if (A*C <= B) {
        cout << C << endl;
    } else {
        cout << B/A << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]

check = [0] * M

for _ in range(N):
    K, *A = [int(i) for i in input().split()]
    for ai in A:
        check[ai - 1] += 1

count = 0
for ci in check:
    if ci == N:
        count += 1

print(count)

Measured memory_bytes: 3060
//
//  main.cpp
//  22.C++
//
//  Created by 襍オ豈?on 8/9/13.
//  Copyright (c) 2013 襍オ豈? All rights reserved.
//

#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;

struct Edge{
    int use;
    int a,b;
    long long int d2;
}edge[100000];

struct Point{
    struct Point *parent;
    int x,y;
}point[100000];

long long int dsts(int a,int b){
    long long int d1,d2;
    d1=point[a].x-point[b].x;
    d2=point[a].y-point[b].y;
    return d1*d1+d2*d2;
}

bool cmp(struct Edge a,struct Edge b){
    return a.d2>b.d2;
}

struct Point *fant(struct Point *a){
    if(a->parent){
        a->parent=fant(a->parent);
        return a->parent;
    }else{
        return a;
    }
}

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d%d",&point[i].x,&point[i].y);
    }
    for(int i=0;i<m;i++){
        scanf("%d%d",&edge[i].a,&edge[i].b);
        edge[i].a--;edge[i].b--;
        edge[i].d2=dsts(edge[i].a,edge[i].b);
    }
    sort(edge,edge+m,cmp);
    
    for(int i=0;i<m;i++){
        if(fant(point+edge[i].a)!=fant(point+edge[i].b)){
            (fant(point+edge[i].a))->parent=fant(point+edge[i].b);
            edge[i].use=1;
        }
    }
    
    
    double totle=0;
    for(int i=0;i<m;i++){
        if(edge[i].use==0){
            totle+=sqrt(edge[i].d2);
        }
    }
    printf("%.3lf\n",totle);
    return 0;
}

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

int fibo[50];
int rec(int i){
    if(i == 0 || i == 1) return 1;
    if(fibo[i] != -1) return fibo[i];
    
    int ret = 0;
    ret = rec(i-1) + rec(i-2);
    return fibo[i] = ret;
}

int main(void){
    // Your code here!
    int N;
    cin >> N;
    for(int i = 0; i < 50; i++) fibo[i] = -1;
    cout << rec(N) << endl;
}



Measured memory_bytes: 3108
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int INF=1e9;
const int maxn=1e5+10;
const double eps=1e-9;
int a[maxn];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
inline int gcd(int x,int y){
	if(y==0)return x;
	else return gcd(y,x%y);
}
int main(){
	int i,j,k,m,n;
	n=read();k=read();
	int flag=0;
	for(i=1;i<=n;i++){
		a[i]=read();
		if(a[i]>k)flag=1;
		if(a[i]==k)flag=2;
	}
	if(flag==2){
		printf("POSSIBLE\n");
		return 0;
	}
	else if(flag==0){
		printf("IMPOSSIBLE\n");
		return 0;
	}
	int x=a[1];
	for(i=2;i<=n;i++)
		x=gcd(x,a[i]);
	if(k%x==0 || x==1)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

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

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

int n, m, q;
vector<int> a, b, c, d;
ll ans = 0;


void dfs(string s) {
	if((int)s.size() == n) {
		ll sum = 0;
		for(int i = 0; i < q; i++) {

			if(s[b[i]] - s[a[i]] == c[i])sum += d[i];

		}
		ans = max(sum, ans);
		return;
	}

	for(int i = (s.empty() ? 1 : s.back()); i <= m; i++) {
		string t = s;
		t.push_back(i);
		dfs(t);
	}
}	

int main()
{
	cin >> n >> m >> q;
	a.resize(q), b.resize(q), c.resize(q), d.resize(q); 
	for(int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	string k = "";
	dfs("");
	cout << ans << endl;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<end
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  string s,t;
  cin>>s>>t;
  sortAl(s);
  sortAlr(t);
  ll x=std::min(s.size(),t.size());
  string res="Yes";
  int a=0;
  FOR(i,0,x){
    if(s[i]>t[i]){
      res="No";
      break;
    }
    if(s[i]<t[i]) break;
    a=i;
  }
  if(a==x-1 && s.size()>=t.size()){
    res="No";
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main() {
	int x1,y1,x2,y2,ans=0,tmp=0;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	vector<int>Cl(y2-y1+2),Cr(y2-y1+2),Cu(x2-x1+2),Cd(x2-x1+2),inv(max(x2,y2)+1,1);
	for(int i=1;i<=max(x2,y2);i++) {
		int p=i,pp=mod-2;
		while(pp) {
			if(pp&1) inv[i]=1ll*inv[i]*p%mod;
			p=1ll*p*p%mod;
			pp>>=1;
		}
	}
	Cl[0]=1;
	for(int i=x1+y1-2;i>=x1;i--) Cl[0]=1ll*Cl[0]*i%mod;
	for(int i=y1-1;i>0;i--) Cl[0]=1ll*Cl[0]*inv[i]%mod;
	for(int i=y1;i<=y2;i++) Cl[i-y1+1]=1ll*Cl[i-y1]*(i+x1-1)%mod*inv[i]%mod;
	Cd[0]=Cl[0];
	for(int i=x1;i<=x2;i++) Cd[i-x1+1]=1ll*Cd[i-x1]*(i+y1-1)%mod*inv[i]%mod;
	Cu[0]=Cl[y2-y1+1];
	for(int i=x1;i<=x2;i++) Cu[i-x1+1]=1ll*Cu[i-x1]*(i+y2)%mod*inv[i]%mod;
	Cr[0]=Cd[x2-x1+1];
	for(int i=y1;i<=y2;i++) Cr[i-y1+1]=1ll*Cr[i-y1]*(i+x2)%mod*inv[i]%mod;
	if(x2-x1>y2-y1) {
		for(int i=x1+y1;i<=x1+y2;i++) {
			tmp=(1ll*tmp*2+1ll*Cl[i-1-x1-y1+2]+1ll*Cd[i-1-x1-y1+2])%mod;
			ans=(ans+tmp)%mod;
		}
		for(int i=x1+y2+1;i<=x2+y1;i++) {
			tmp=(1ll*tmp*2+1ll*Cd[i-1-x1-y1+2]-1ll*Cu[i-1-x1-y2+1]+1ll*mod)%mod;
			ans=(ans+tmp)%mod;
		}
		for(int i=x2+y1+1;i<=x2+y2;i++) {
			tmp=(1ll*tmp*2-1ll*Cu[i-1-x1-y2+1]-1ll*Cr[i-1-x2-y1+1]+1ll*mod*2)%mod;
			ans=(ans+tmp)%mod;
		}
	}
	else {
		for(int i=x1+y1;i<=x2+y1;i++) {
			tmp=(1ll*tmp*2+1ll*Cl[i-1-x1-y1+2]+1ll*Cd[i-1-x1-y1+2])%mod;
			ans=(ans+tmp)%mod;
		}
		for(int i=x2+y1+1;i<=x1+y2;i++) {
			tmp=(1ll*tmp*2+1ll*Cl[i-1-x1-y1+2]-1ll*Cr[i-1-x2-y1+1]+1ll*mod)%mod;
			ans=(ans+tmp)%mod;
		}
		for(int i=x1+y2+1;i<=x2+y2;i++) {
			tmp=(1ll*tmp*2-1ll*Cu[i-1-x1-y2+1]-1ll*Cr[i-1-x2-y1+1]+1ll*mod*2)%mod;
			ans=(ans+tmp)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 19840
# まず、取れる分だけ取り出す
# 戻す（捨てる）操作は最後で良い。ソートして価値が低いものを捨てる
# 取り出す操作　＋　捨てる操作　＝ Kになる
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = 0

for L in range(N+1):
  for R in range(N+1):
    if L+R > K:
      break
    if L+R > N:
      break
    get = V[:L]
    if R > 0:
      get += V[-R:]
    get.sort()
        
    rest = K - (L+R) # 残り操作回数
    # 価値が0以下を捨てる個数
    minus = sum((1 if x < 0 else 0 for x in get))
    if rest < minus:
      value = sum(get[rest:])
    else:
      value = sum((x for x in get if x > 0))
      
    if max_value < value:
      max_value = value
print(max_value)      

Measured memory_bytes: 3064
import sys
X = int(input())

lim = int(X**(1/2))

listx =[]

if X == 1 or X == 2 or X ==3:
    print(1)
    sys.exit()

if X >= 4 and X <= 8:
    print(4)
    sys.exit()

for i in range(lim+1):
    if i == 0 or i ==1:
        continue
    a = i
    p = 0
    while a <= X:
        a = i ** p
        p += 1
    listx.append(i**(p-2))

print(max(listx))

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;

int main(){
	int n;
	int a[1000];
	cin>>n;
	memset(a,0,sizeof(a));
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		a[x]++;
	}
	int ans=0;
	for (int i=0;i<=500;i++){
		if (a[i]>0) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256