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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
//const int mod = 1000000007;
const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  mint dp[n+1][s+5];
  rep(i, n+1) rep(j, s+1) dp[i][j] = 0;
  dp[0][0] = 1;


  rep(i, n) {
    for(int j = 0; j <= s; ++j) {
      if(j-a[i] >= 0) dp[i+1][j] += dp[i][j-a[i]];
      dp[i+1][j] += (dp[i][j]*2);
    }
  }
  cout << dp[n][s].x << endl;
}


Measured memory_bytes: 74044
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, a, b) for(int i=(a); i<(int)(b); i++)

typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node { int from, to, cost; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}

int main(void){
	string s; cin >> s;
	vector<int> right(s.size());
	vector<int> left(s.size());
	
	int count = 0;
	rep(i, s.size()){
		if(s[i] == 'R') count++;
		else{
			if(count == 0) continue;
			if(count % 2 == 0){
				right[i-1] = count/2;
				right[i] = count/2;
			} else{
				right[i-1] = count/2 + 1;
				right[i] = count/2;
			}
			count = 0;
		}
	}
	for(int i = s.size()-1; 0 <= i; i--){
		if(s[i] == 'L') count++;
		else{
			if(count == 0) continue;
			if(count % 2 == 0){
				left[i+1] = count/2;
				left[i] = count/2;
			} else{
				left[i+1] = count/2 + 1;
				left[i] = count/2;
			}
			count = 0;
		}
	}

	rep(i, s.size()){
		cout << right[i]+left[i];
		if(i != s.size()-1) cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

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

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        long sumA = 0; // a[i] - b[i] が正の時、それを集計(必要な操作の回数)
        long sumB = 0; // a[i] - b[i] が負の時、a[i] + 1 = b[i] または a[i] = b[i] となるために必要な偶数を集計
        for (int i = 0; i < n; i++) {
            int bi = sc.nextInt();
            int diff = a[i] - bi;

            if (diff >= 0) {
                sumA += diff;
            } else {
                diff = -diff;
                sumB += diff - (diff % 2);
            }
        }

        System.out.println((sumA * 2 <= sumB) ? "Yes" : "No");
    }
}

Measured memory_bytes: 42612
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL =LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};


int main() {
    string s;cin>>s;
    
    if(s.size()%2==1){
        int piv = (int)s.size()/2;
        int c = 0;
        while(s[piv-c] == s[piv] && s[piv+c] ==s[piv] && piv-c >=0) c++;
        c--;
        cout<<s.size()-(s.size()-2*c)/2<<endl;
    }else{
        
        int pivl = (int)s.size()/2 -1;
        int pivr = (int)s.size()/2;
        int c = 0;
        while(s[pivl] == s[pivr] && s[pivl-c] == s[pivl] && s[pivr+c] ==s[pivr] && pivl-c >=0) c++;
        cout<<s.size()-(s.size()-2*c)/2<<endl;
        
    }
    
    return 0;
}










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

int main(){

  long K,N;
  long dis;
  long s;
  cin >> K >> N;
  vector<long> house(N);

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

  if(house.at(N-1) - house.at(0) <= house.at(0) + (K - house.at(1))){
    dis = house.at(N-1) - house.at(0);
  }else{
    dis = house.at(0) + (K - house.at(1));
  }


  for(int i = 1;i<N-1;++i){
    if((K - house.at(i)) + house.at(i-1) <= house.at(i) + (K - house.at(i+1))){
      s = (K - house.at(i)) + house.at(i-1);
    }else{
      s = house.at(i) + (K - house.at(i+1));
    }

    if(s < dis){
      dis = s;
    }
  }

  cout << dis << endl;

}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

bool isOK(string a, string b)
{
	FOR (i, 0, SZ(a))
	{
		if (a[i] == '-' || b[i] == '-') continue;
		if (a[i] != b[i]) return false;
	}
	return true;
}

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	string a;
	string b;

	cin>>n>>a>>b;

	FOR (i, 0, n+4)
	{
		if (isOK(a, b))
		{
			cout<<n + i<<endl;
			return 0;
		}

		a += '-';
		b = '-' + b;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  string s,t; cin >> s >> t;
  if(t.substr(0,s.size())==s) cout << yes;
  else cout << no;
  return 0;
}

Measured memory_bytes: 3600
K = gets.to_i

def digitsum(num)
    ret = 0
    while num > 0
        ret += num % 10
        num /= 10
    end
    ret
end

last = 1
ans = [1]
diff = 1
while ans.length < K
    num1 = last + diff
    num2 = last + diff * 10
    val1 = num1.to_f / digitsum(num1)
    val2 = num2.to_f / digitsum(num2)
    if val1 <= val2
        nextnum = num1
    else
        nextnum = num2
        diff *= 10
    end
    ans.push(nextnum)
    last = nextnum
end
puts ans

Measured memory_bytes: 1788
module Main (main) where
import Control.Monad.State

strToInt str = (read str :: Integer)
getLineInt = fmap strToInt getLine

getLineIntN n = do
  i <- getLineInt
  if (n > 1) then getLineIntN (n-1) >>= (\xs -> return $ i : xs)
  else return $ i : []

calcProfit = do
  (xs, maxProf, minPrice) <- get
  case xs of
    [] -> return maxProf
    first:rest -> do
      if first < minPrice then put (rest, maxProf, first)
      else if (first - minPrice) > maxProf then put (rest, first - minPrice, minPrice)
      else put (rest, maxProf, minPrice)
      calcProfit

main = do
  rowNum <- getLineInt
  ls <- getLineIntN rowNum
  -- putStrLn $ show ls
  let first:second:xs = ls
  putStrLn $ show $ evalState calcProfit (xs, second - first, min first second)



Measured memory_bytes: 121128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define show(x, y); cout << x << " " << y << endl;
using namespace std;

int n, m;
vector<int> g[100001];
bool vis[100001];
int path[100001];
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
int inDegree[100001];

void dfs(int u){
    vis[u] = true;
    for(auto v : g[u]){
        path[v] = max(path[v], path[u] + 1);
        inDegree[v]--;
        pq.push({inDegree[v], v});
        if(inDegree[v] == 0){
            dfs(v);
        }
    }
}

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        inDegree[y]++;
    }
    for(int i = 1; i <= n; i++){
        pq.push({inDegree[i], i});
    }
    while(!pq.empty()){
        while(!pq.empty() && vis[pq.top().second] == true){
            pq.pop();
        }
         pair<int, int> p = pq.top();
        int x = p.first, y = p.second;
        if(vis[y] == false){
            dfs(y);
        }
    }
    int ans = 1;
    for(int i = 1 ; i <= n; i++){
        ans = max(ans, path[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 14576
#include <algorithm>
#include <bitset>
#include <boost/multi_array.hpp>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

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

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int H, W, K;
  cin >> H >> W >> K;

  vector<string> grid(H);
  int sx, sy;
  rep(i, H) {
    cin >> grid[i];
    rep(j, W) {
      if (grid[i][j] == 'S') {
        sx = i;
        sy = j;
      }
    }
  }

  boost::multi_array<int, 2> dist(boost::extents[H][W]);
  fill(dist.origin(), dist.origin() + H * W, H * W);

  using P = pair<int, int>;
  queue<P> q;

  int lx = H, rx = 0, ly = W, ry = 0;
  dist[sx][sy] = 0;
  q.push(P(sx, sy));
  while (!q.empty()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();

    chmin(lx, x);
    chmax(rx, x);
    chmin(ly, y);
    chmax(ry, y);

    if (dist[x][y] == K) {
      continue;
    }

    for (int dx = -1; dx <= 1; dx++)
      for (int dy = -1; dy <= 1; dy++) {
        if (abs(dx) + abs(dy) == 1) {
          int nx = x + dx, ny = y + dy;
          int nd = dist[x][y] + 1;
          if (nx >= 0 && nx < H && ny >= 0 && ny < W && grid[nx][ny] == '.' &&
              dist[nx][ny] > nd) {
            dist[nx][ny] = nd;
            q.push(P(nx, ny));
          }
        }
      }
  }

  const int result = 1 + (min({lx, H - 1 - rx, ly, W - 1 - ry}) + K - 1) / K;
  cout << result << endl;
  return 0;
}

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


int main (){
    int N;
    cin >> N ;
    int d[N];
    for(int i=0;i<N;i++) {
        cin >> d[i];
    }
    sort(d,d+N,greater<int>());
    int total=0;
    for(int i=0;i<N;i++){
        if(d[i] != d[i+1]){
            total++;
        }
    }
    cout << total <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int x;
  scanf("%d",&x);
  if(400<=x && x<=599) printf("8");
  else if(600<=x && x<=799) printf("7");
  else if(800<=x && x<=999) printf("6");
  else if(1000<=x && x<=1199) printf("5");
  else if(1200<=x && x<=1399) printf("4");
  else if(1400<=x && x<=1599) printf("3");
  else if(1600<=x && x<=1799) printf("2");
  else if(1800<=x && x<=1999) printf("1");
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define int LL
using namespace std;
typedef long long LL;
const int MAX_N=10005;
const int MAX_D=105;
const int Mod=1e9+7;
string k;
int D;
int dp[MAX_N][MAX_D];
int dfs(int pos,int sum,bool limit) {
	if (pos==k.size()) return (sum%D)?0:1;
	if (!limit && dp[pos][sum]!=-1) return dp[pos][sum];
	int u = limit?k[pos]-'0':9;
	int ret = 0;
	for (int i=0; i<=u; ++i) {
		ret += dfs(pos+1,(sum+i)%D,limit && i==k[pos]-'0');
		ret%=Mod;
	}
	if (!limit) dp[pos][sum] = ret;
	//  cout<<"dfs("<<pos<<","<<sum<<","<<limit<<")="<<ret<<endl;
	return ret;
}
signed main() {
	memset(dp,-1,sizeof(dp));
	cin>>k>>D;
	cout<<(dfs(0,0,true)-1+Mod)%Mod<<endl;
	return 0;
}


Measured memory_bytes: 9216
#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);

int ccnt[2];
vi used;
vector<vi> G;

bool check(int v, int c){
    used[v] = c;
    ccnt[c]++;

    bool ret = true;
    for(auto& nv : G[v]){
        int nc = c ^ 1;
        if(used[nv] == nc) continue;
        if(used[nv] == c) return false;
        ret &= check(nv, nc);
    }

    return ret;
}

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

    int n, m; cin >> n >> m;
    G = vector<vi>(n);
    rep(i, m){
        int a, b; cin >> a >> b; a--, b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    used = vi(n, -1);
    ll res = 0;
    if(check(0, 0)){
        res = 1LL * ccnt[0] * ccnt[1] - m;
    }
    else {
        res = 1LL * n * (n - 1) / 2 - m;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int n, k;
	cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> s(n+1);
    rep(i,n) {
        s[i+1] = (s[i]+a[i])%k;
    }
    map<int,int> mp;
    ll ans = 0;
    queue<int> q;
    rep(j,n+1) {
        ans += mp[s[j]];
        mp[s[j]]++;
        q.push(s[j]);
        if (q.size() == k) {
            mp[q.front()]--;
            q.pop();
        }
    }
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
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};

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

    int cnt = 0;
    ll ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'B') cnt++;
        else{
            ans += cnt;
        }
    }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  int s, t, x;
};
bool operator<(const ST& a, const ST& b){
  return a.x < b.x;
}

int main(){
  int N, Q;
  cin >> N >> Q;
  vector<ST> v;
  rep(i,N){
    int s, t, x;
    cin >> s >> t >> x;
    v.push_back((ST){s,t,x});
  }
  sort(ALLOF(v));

  set<int> s;
  map<int,int> m;
  vector<int> q;
  rep(i,Q){
    int a;
    cin >> a;
    q.push_back(a);
    s.insert(a);
  }

  rep(i,v.size()){
    int x = v[i].s - v[i].x;
    int y = v[i].t - v[i].x;
    auto it = s.lower_bound(x);

    while(it != s.end() && *it < y){
      m[*it] = v[i].x;
      it = s.erase(it);
    }
  }

  rep(i,Q){
    if(m.count(q[i]) == 0) cout << -1 << endl;
    else cout << m[q[i]] << endl;
  }
  
  return 0;
}


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

using namespace std;

typedef unsigned long long ll;

int main(){
    ll n; cin >> n;
    ll a = n / 11; ll b = n % 11; int c = 0;
    if(b > 6) c = 2;
    if(0 < b && b <= 6) c = 1;
    
    cout << a * 2 + c << endl;
}


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

using namespace std;

int v[100000][3], dist[100000][3];

int main()
{
    int n;
    cin>>n;
    for(int i = 0 ; i < n ; i++){
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    }
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < 3 ; j++){
            for(int k = 0 ; k < 3 ; k++){
                if(j != k ){
                    dist[i][j] = max(dist[i][j], dist[i-1][k] + v[i][j]);
                }
            }
        }
    }
    cout<<max(dist[n-1][0], max(dist[n-1][1], dist[n-1][2]));
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void){
        int a,b,c;
        int sum;

        scanf("%d %d %d",&a,&b,&c);

        sum = a + b + c;

        if (sum >= 22){
                printf("bust\n");
        }
        else{
                printf("win\n");
        }
        return 0;

}

Measured memory_bytes: 1644
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
		System.out.println(min(a,b,c)+" "+max(a,b,c));
		
	}
	public static int max(int... ar) {Arrays.sort(ar);return ar[ar.length-1];}
	public static int min(int... ar) {Arrays.sort(ar);return ar[0];}
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

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

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

bool isPrime[25001];
int ok[100001];
int ok_m[100001];

signed main(){
    vector<int> prime;
    fill( isPrime, isPrime + 25001, true );
    isPrime[0] = isPrime[1] = false;

    for( int i = 2; i < 25001; i++ ){
        if( isPrime[i] ){
            for( int j = i * i; j < 25001; j += i ){
                isPrime[j] = false;
            }
            prime.push_back( i );
        }
    }

    int yakusu, cnt = 0;
    for( int i = 12; i <= 100000; i++ ){
        if( ok[i] ) continue;
        int t = i;
        yakusu = 1;
        for( int j = 0; j < prime.size(); j++ ){
            cnt = 1;
            while( t != 0 && t % prime[j] == 0 ){
                cnt++;
                t /= prime[j];
                if( cnt == 5 ) break;
            }
            yakusu *= cnt;
            if( yakusu >= 5 ) break;
        }
        if( yakusu >= 5 ) {
            ok[i] = 1;
            for( int j = i + i; j <= 100000; j += i ){
                ok[j] = 1;

            }
        }else ok[i] = -1;
    }

    FOR( i, 12, 100001 ){
        if( ok[i] == -1 ) ok_m[i] = ok_m[i - 1];
        else ok_m[i] = ok_m[i - 1] + 1;
    }

    int Q; cin >> Q;
    REP( i, Q ){
        int N; cin >> N;
        cout << ok_m[N] << endl;
    }
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  ll maxa = *max_element(a.begin(), a.end());
  if (k <= maxa && k % g == 0) cout << "POSSIBLE\n";
  else cout << "IMPOSSIBLE\n";



  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100;
const int inf=0x3f3f3f3f;
const int m=2019;
typedef pair<int,int> P;

map<string,int>mp;
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    string s;
    while(n--){
        cin>>s;
        if(!mp[s])
            mp[s]++,ans++;
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 19324
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int x = scanner.nextInt();
		scanner.close();
		if (a > x) {
			System.out.println("NO");
			System.exit(0);
		}
		if (a + b >= x) {
			System.out.println("YES");
			System.exit(0);
		}
		System.out.println("NO");
		
	}
}


Measured memory_bytes: 21844
import bisect

N = int(input())
x = list(map(int, input().split()))
L = int(input())

dest = []
dest_1 = [0] * N
for i in range(N):
    dest_1[i] = bisect.bisect_left(x, x[i] + L + 0.5) - 1
dest.append(dest_1)
for i in range(1, len(bin(N - 1)) - 1):
    dest_prev = dest[i - 1]
    dest_i = [0] * N
    for j in range(N):
        dest_i[j] = dest_prev[dest_prev[j]]
    dest.append(dest_i)

Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    k = len(dest) - 1
    ans = 0
    while True:
        d = dest[k][a]
        if d >= b:
            if k > 0:
                k -= 1
            else:
                ans += 1
                break
        else:
            ans += 2 ** k
            a = d
    print(ans)


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

signed main () {
	int n;
	cin >> n;
	int64_t ans = 0;
	for (int a = 1; a <= n; ++a) {
		int res = n / a - int(n % a == 0);
		ans += res;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
#define Mohamed_Gad fast()
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(),v.end()
#define endl "\n"
#define sz(x) size(x)
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    //freopen("Output.txt", "w", stdout);
#endif

}
//long long frq[100009],prf[100009];

int main() {
    fast();
   string x;int t=0;
  int n;
  cin>>n;
  cout<<(n*(n+1))/2<<endl;


}


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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
typedef long long ll;


int main()
{
    int mod = 1e9 + 7;
    int h, w, K;
    cin >> h >> w >> K;
    vector<vector<int>> dp(h + 1, vector<int>(w, 0));
    dp[0][0] = 1;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int k = 0; k<1<<(w-1); k++)
            {
                bool ok = true;
                for (int l = 0; l < w-2; l++)
                {
                    if(((k>>l)&1) &&((k>>(l+1))&1)){
                        ok = false;
                    }
                }
                if(ok){
                

                if(j>=1 &&( (k>>(j-1))&1)){
                    dp[i + 1][j - 1] += dp[i][j];
                    dp[i + 1][j - 1] %= mod;
                }
                else if(j<w-1 && ((k>>j)&1)){
                    dp[i + 1][j + 1] += dp[i][j];
                    dp[i + 1][j + 1] %= mod;
                }
                else  {
                    dp[i + 1][j] += dp[i][j];
                    dp[i + 1][j] %= mod;
                }
                }
            }   
        }
    }
    cout << dp[h][K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<deque>
#define MAXN 200
using namespace std;
typedef long long LL;
LL N;
int len,digit[MAXN+5];
deque<int> que;
void Work(LL x)
{
	len=0;
	while(x)
	{
		digit[++len]=x%2;
		x/=2;
	}
}
int main()
{
	scanf("%lld",&N);
	N++;
	Work(N);
	int id=0;
	for(int i=len-1;i>=1;i--)
	{
		que.push_back(++id);
		if(digit[i]==1)
			que.push_front(++id);
	}
	printf("%d\n",id*2);
	for(int i=0;i<(int)que.size();i++)
		printf("%d ",que[i]);
	for(int i=1;i<=id;i++)
		if(i==1)
			printf("%d",i);
		else
			printf(" %d",i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

int card[100001];

int main() {
	int n, k;
	while (cin >> n >> k && n != 0 && k != 0) {

		memset(card, 0, sizeof(card));

		for (int i = 0; i < k; ++i) {
			int num;
			cin >> num;
			card[num] = 1;
		}

		int start = 1;
		int cnt = 0;
		int ans = 0;
		for (int i = 1; i <= n + 1; ++i) {
			if (card[i] == 0) {
				for (int i2 = start; i2 < i; ++i2) {
					card[i2] = cnt;
				}
				ans = max(ans, cnt);
				cnt = 0;
				start = i + 1;
			}
			else {
				cnt++;
			}
		}

		if (card[0] == 1) {
			for (int i = 1; i <= n; ++i) {
				if (card[i] == 0) {
					ans = max(ans, card[i - 1] + card[i + 1] + 1);
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int w[105];
  for (int i=0; i<n; i++) {
    cin>>w[i];
  }
  int ans=1e9;
  for (int i=0; i<n-1; i++) {
    int sum=0;
    for (int j=0; j<=i; j++) {
      sum+=w[j];
    }
    for (int j=i+1; j<n; j++) {
      sum-=w[j];
    }
    ans=min(ans,abs(sum));
  }
  
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int64_t h;
	cin >> h;
	//hは2^x
	int x = 0;
	while (true) {
		if (h >= 2) {
			h /= 2;
			x++;
		}
		else break;
	}
	//1+2+4を(x+1項)足したものが答え
	int64_t res = 0;
	for (int i = 0; i <= x; i++) {
		res += pow(2, i);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
weather_report = input()
weather_now = input()
match_result = 0
split_weather_report = []
split_weather_now = []

for i in weather_report:
    split_weather_report += i
for j in weather_now:
    split_weather_now += j

for i in range(3):
    if (split_weather_report[i] in split_weather_now[i]):
        match_result += 1

print(match_result)

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

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  int b[m];
  int cnt = 0;
  for(int i=0; i<m; i++){
  	cin >> b[i];
  }
  
  int a, sum;
  for(int i=0; i<n; i++){
	sum = 0;
    for(int j=0; j<m; j++){
      cin >> a;
      sum += a*b[j];
    }
  	sum += c;
    if(sum > 0) cnt++;
  }
  
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque

(N, M) = [int(x) for x in input().split()]

edges = [[int(x) - 1 for x in input().split()] for i in range(M)]  # 0 indexed


def bfs(source, getNbr):
    q = deque([source])
    dist = {source: 0}
    while q:
        node = q.popleft()
        d = dist[node]
        for nbr in getNbr(node):
            if nbr not in dist:
                q.append(nbr)
                dist[nbr] = d + 1
    return dist


graph = [[] for i in range(N)]
for u, v in edges:
    graph[u].append(v)
    graph[v].append(u)


def getNbr(u):
    return graph[u]


best = 0
seen = set()
for root in range(N):
    if root not in seen:
        comp = bfs(root, getNbr)
        best = max(best, len(comp))
        for k in comp:
            seen.add(k)
print(best)


Measured memory_bytes: 170696
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 NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] tmpArray = br.readLine().split(" ");

		long input[] = new long[n];

		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
		}

		Arrays.sort(input);

		boolean result = true;
//		for(int i = 0; i < n; i++){
//			if(input[(i + 1)%n] != (input[i%n]^input[(i + 2)%n])){
//				result = false;
//				break;
//			}
//			//System.out.println(input[(i + 1)%n]+ " = "+ (input[i%n]^input[(i + 2)%n]));
//		}

		long val = input[0];
		for(int i = 1; i < n; i++){
			val ^= input[i];
		}

//		if(result){
		if(val == 0){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 37596
using System;

namespace ABC056_A_HonestOrDishonest
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			string a = input[0];
			string b = input[1];

			if (a == "H")
			{
				if (b == "H")
				{
					Console.WriteLine("H");
					return;
				}
			}
			else
			{
				if (b == "D")
				{
					Console.WriteLine("H");
					return;
				}
			}
			
			Console.WriteLine("D");
		}
	}
}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int M=1e3+5;

int n,m,a[M],b[M],mem[M][M*8];

vector<int>c[M];

int dp(int pos,int mask)
{
    if (mask==0)
    {
        return 0;
    }
    if (pos==m)
    {
        return 1e9;
    }
    if (mem[pos][mask]!=-1)return mem[pos][mask];
    int ans=1e9;
    ans=min(ans,dp(pos+1,mask));
    int nmask=mask;
    for (int i=0;i<b[pos];i++)
    {
        if (nmask&(1<<c[pos][i]))
        {
            nmask-=(1<<c[pos][i]);
        }
    }
    ans=min(ans,a[pos]+dp(pos+1,nmask));
    return mem[pos][mask]=ans;
}

int main()
{
    memset(mem,-1,sizeof mem);
    cin >> n >> m;
    for (int i=0;i<m;i++)
    {
        cin >> a[i] >> b[i];
        for (int j=0;j<b[i];j++)
        {
            int tmp;
            cin >> tmp;
            tmp--;
            c[i].pb(tmp);
        }
    }
    int ans=dp(0,(1<<n)-1);
    if (ans==(1e9))cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 32000
#include <bits/stdc++.h>
using namespace std;
char a[10001]; 
bool c,f;
int main() {
    cin>>a;
    for(int i=0;i<strlen(a);i++){
        if(a[i]=='C')c=true;
        if(a[i]=='F'&&c==true)f=true; 
    }
    if(f==true) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
num = int(input())

num_range = range(1, 10)

flag = False

for n in reversed(num_range):
    if flag:
        break
    if num % n == 0:
        temp = num / n
        for m in num_range:
            if flag:
                break
            if temp == m:
                flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	int same=1,minb=1e9;
	lint ans=0;
	for(int i=nxi(); i; --i){
		int a=nxi(),b=nxi();
		same&=a==b;
		if(a>b) apn(minb,b);
		ans+=a;
	}
	printf("%lld\n",same?0ll:ans-minb);
	return 0;
}


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

ans = 0
for i in range(N-1):
    eat = 0
    if a[i] + a[i+1] > x:
        eat = a[i] + a[i+1] - x
        if eat <= a[i+1]:
            a[i+1] -= eat
        else:
            a[i+1] = 0
            a[i] -= (eat - a[i+1])
    ans += eat

print(ans)

Measured memory_bytes: 14132
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(n: int, a: "List[int]"):
    cum = 0
    mn = 10000000000
    counter1 = 0
    for i in range(n):
        if cum + a[i] == 0:
            counter1 += 1
            if i % 2 == 0:
                cum += a[i] + 1
            else:
                cum += a[i] - 1
        elif cum + a[i] > 0:
            if i % 2 == 0:
                cum += a[i]
            else:
                counter1 += abs(a[i] + abs(cum) + 1)
                cum -= abs(cum)+1
        else:
            if i % 2 == 0:
                counter1 += abs(a[i] - abs(cum) - 1)
                cum += abs(cum)+1
            else:
                cum += a[i]

    cum = 0
    counter2 = 0
    for i in range(n):
        if cum + a[i] == 0:
            counter2 += 1
            if i % 2 != 0:
                cum += a[i] + 1
            else:
                cum += a[i] - 1
        elif cum + a[i] > 0:
            if i % 2 != 0:
                cum += a[i]
            else:
                counter2 += abs(a[i] + abs(cum) + 1)
                cum -= abs(cum) + 1
        else:
            if i % 2 != 0:
                counter2 += abs(a[i] - abs(cum) - 1)
                cum += abs(cum) + 1
            else:
                cum += a[i]
    print(min(counter1, counter2))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 17620
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします！
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/

#include <bits/stdc++.h>


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


#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)

#define intt long long
#define P pair<int,int>

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

using namespace std;

//Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
            res %= m;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}

int mypow(int x, int y) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
        }
        x = x * x;
        y /= 2;
    }
    return res;
}
//is the number (x) a prime number?
bool prime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (!(x % i)) {
            return false;
        }
    }
    return true;
}


//saidai-kouyakusuu
inline int gcd(int x, int y) {
    if (!y) {
        return x;
    }
    return gcd(y, x % y);
}


//number of keta
int keta(int x) {
    int ans = 0;
    while (x) {
        x /= 10;
        ans++;
    }
    return ans;
}

//sum of keta
int ketasum(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

inline int lcm(int x, int y) {
    int ans = x / gcd(x, y) * y;
    return ans;
}
int twobeki(int x) {
    int ans = 0;
    while (1) {
        if (!(x & 1)) {
            ans++;
            x /= 2;
        }
        else {
            break;
        }
    }
    return ans;
}


template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
    if (lhs < rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
void YES(){
    cout<<"YES"<<endl;
}
void NO(){
    cout<<"NO"<<endl;
}


#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld",i)
#define fendl printf("\n")
//Library-End

int n,a,k,ans,b,x,m;
int cnt[34];
signed main() {
    cin>>n>>m;
    rep(i,n){
        fin(k);
        rep(j, k){
            fin(a);
            cnt[a]++;
        }
    }
    REP(i, m){
        if (cnt[i]==n) {
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	long long n, q;
	cin >> n >> q; 
	string s;
	cin >> s;
	vector<long long>t(n);
	long long l, r,count=0;
	for (long long i = 1; i < n; i++) {
		if (s[i - 1] == 'A'&&s[i] == 'C') {
			count++;
		}
		t[i] = count;
	}
	for (long long i = 0; i < q; i++) {
		cin >> l >> r;
		l--;
		r--;
		cout << t[r] - t[l] << endl;
	}
}

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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
  int n, w;
  cin >> n >> w;
  vector<ll>we(n);
  vector<ll>v(n);
  rep(i, 0, n){
      cin >> we[i] >> v[i];
  }
  vector<vector<ll>>dp(n+1, vector<ll>(100100,0));
  rep(i, 0, n){
    rep(j, 0, w+1){
      chmax(dp[i+1][j],dp[i][j]);
      if(j-we[i]<0)continue;
      chmax(dp[i+1][j],dp[i][j-we[i]]+v[i]);
    }
  }
  cout << dp[n][w] << endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int M = 1e5+10;
int dp[105][M];
int main(){
    int n,k,a;
    cin >> n >> k;
    fill(dp[0],dp[0]+M,1);
    for(int i = 1; i <= n; ++i){
        cin >> a;
        for(int j = 0; j <= k; ++j){
            int r = j;
            int l = max(j-a,0);
            dp[i][j] = dp[i-1][r] - (l ? dp[i-1][l-1] : 0);
            if(dp[i][j] < 0)dp[i][j] += mod;
        }
        if(i != n){
            for(int j = 1; j <= k; ++j){
                dp[i][j] += dp[i][j-1];
                if(dp[i][j] >= mod)dp[i][j]-=mod;
            }
        }
    }
    cout << dp[n][k];
    return 0;
}

Measured memory_bytes: 43016
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int n;
    cin>>n;
    vi dp(n+2,INF);
    dp[0]=0;
    vi h(n+2,0);
    rep(i,n) cin>>h[i];
    rep(i,n){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    out(dp[n-1]);
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int left = 0;
        int right = arr.length - 1;
        int count = 0;
        while (left <= right) {
            if (left == right) {
                if (arr[left] == '(' || arr[left] == ')') {
                    count++;
                }
                break;
            }
            if (arr[left] == '(') {
                if (arr[right] != ')') {
                    count++;
                }
            } else if (arr[left] == ')') {
                if (arr[right] != '(') {
                    count++;
                }
            } else {
                if (arr[left] != arr[right]) {
                    count++;
                }
            }
            left++;
            right--;
        }
        System.out.println(count);
    }
    
}


Measured memory_bytes: 26256
def main():
    S = list( map( int, list( input())))
    N =len(S)
    A = [0]*2019
    P = 2019
    num = [0] * P
    num[0] = 1
    now, ans = 0, 0
    _10 = 1
    for i in range(N-1, -1, -1):
        now = (now + int(S[i]) * _10) % P
        _10 *= 10
        _10 %= P
        ans += num[now]
        num[now] += 1
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 12076
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cnt = 0
for i in range(N):
    b = B[i]
    if A[i]>=b:
        cnt += b
        b = 0
    else:
        cnt += A[i]
        b -= A[i]
    if A[i+1]>=b:
        cnt += b
        A[i+1] -= b
    else:
        cnt += A[i+1]
        A[i+1]=0
print(cnt)

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

using lint = long long;

lint Pow(lint b, lint e) {
	lint result = 1;
	for (lint i = 1; i <= e; i *= 2, b = 1ll * b * b) 
		if (i & e) result *= 1ll* b;
	return result;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    lint h;
    cin >> h;
    lint power = log2(h);
    // cout << power << '\n';
    cout << Pow(2ll, power+1) - 1 << '\n';
}

Measured memory_bytes: 384
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int min = 1001001001;
            for(int i = 0; i <= s.Length- t.Length; i++)
            {
                int tmp = t.Length;
                for (int j = 0; j < t.Length; j++)
                {
                    if (s[i + j] == t[j]) tmp--;
                }
                min = (int)Math.Min(min, tmp);
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 25880