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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

int gcd(int a, int b){
    if (b == 0) {
        return a;
    }
    return gcd(b, a%b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}


void solve(){
    ll A, B, C;
    cin >> A >> B >> C;

    if ((A & 1) || (B & 1) || (C & 1)) {
        cout << 0 << endl;
        return;
    }

    if (A == B && B == C) {
        cout << -1 << endl;
        return;
    }


    ll ans = 0;
    while ( (A % 2 != 1) && 
            (B % 2 != 1) &&
            (C % 2 != 1)){
        ll tmpA, tmpB, tmpC;
        tmpA = (B + C) / 2;
        tmpB = (C + A) / 2;
        tmpC = (A + B) / 2;
        A = tmpA;
        B = tmpB;
        C = tmpC;
        ans++;
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;
int main() {
  ll N,K;
  cin >> N >> K;
  ll ans = -1;
  vector<P> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(a.begin(),a.end());
  for (int i = 0; i < N; i++) {
    K -= a[i].second;
    if (K <= 0) {
      ans = a[i].first;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using N = pair<int, int>;
using Data = vector<vector<N>>;

int main() {
  int n;
  cin>>n;
  Data data(n);
  for(int i=0; i<n; i++) {
    int a;
    cin>>a;
    for(int j=0; j<a; j++) {
      N claim;
      cin>>claim.first>>claim.second;
      data[i].push_back(claim);
    }
  }

  int ans = 0;
  for(int bit=0; bit<(1<<n); bit++) {
    bool ok = true;
    int num = __builtin_popcount(bit);
    for(int i=0; i<n; i++) {
      if(((bit>>i)&1)==1) {  //人i+1が正直者と仮定するなら、そいつの言い分は検証する必要がある

        for(N check : data[i]) {
          if(((bit>>(check.first-1))&1) != check.second) ok=false;
        }
      }
    }
    if(ok && num>ans) ans=num;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i < n; i++)
#define ALL(n) begin(n), end(n)

int main()
{
  int a, b, c, d;
  int a_num, c_num;

  cin >> a >> b >> c >> d;
  a_num = (c + b - 1) / b;
  c_num = (a + d - 1) / d;

  string ans;
  if(a_num <= c_num){
    ans = "Yes";
  } else {
    ans = "No";
  }

  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int X,Y;cin >> X >> Y;
    int ans = 0;
    if(X == 3) ans += 100000;
    if(X == 2) ans += 200000;
    if(X == 1) ans += 300000;
    if(Y == 3) ans += 100000;
    if(Y == 2) ans += 200000;
    if(Y == 1) ans += 300000;
    if(X == 1 && Y == 1) ans += 400000;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

class RMQ {
private:
    vector<ll> val;
    int N;
public:
    RMQ(int n, ll init);
    void update(int i, int x);
    ll find(int r, int l, int fn, int fr, int fl);
    ~RMQ();
};

RMQ::RMQ(int n, ll init) {
    N = n;
    val.resize(2*N-1, init);
}

void RMQ::update(int i, int x) {
    i += N-1;
    val[i] = x;
    while (i > 0) {
        i = (i-1)/2;
        val[i] = min(val[i*2+1], val[i*2+2]);
    }
}

ll RMQ::find(int a, int b, int k, int l, int r) {
    // [a, b)のクエリ
    // ノードk(区間[a, b)担当)が答える
    if (b <= l || r <= a) return LINF; // 区間がかぶらなければLINF
    if (a <= l && r <= b) return val[k]; // 区間が完全にかぶっていればval[k]
    else {
        // 一部だけかぶる場合は左右の子に委託する
        ll c1 = find(a, b, 2*k+1, l, (l+r)/2);
        ll c2 = find(a, b, 2*k+2, (l+r)/2, r);
        return min(c1, c2);
    }
}

RMQ::~RMQ() {
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    string s; cin>>s;
    int o = n+1;
    int N = 1;
    while (N < o) N*=2;
    RMQ seg(N,LINF);
    vector<ll> dp(o,LINF);
    dp[n] = 0;
    seg.update(n,0);
    for (int i = n-1; i >= 0; --i) {
        if (s[i]=='1') continue;
        ll x = seg.find(i,min(o,i+m+1),0,0,N);
        if (x==LINF) {
            cout << -1 << endl;
            return 0;
        }
        seg.update(i,x+1);
        dp[i] = x+1;
    }
    // sprint(dp);
    int cur = dp[0];
    if (cur==LINF) {
        cout << -1 << endl;
        return 0;
    }
    int l = 0; int r = 0;
    vector<int> ans;
    while (cur>0) {
        if (dp[r]==LINF) {
            r++;
            continue;
        }
        if (cur == dp[r]) {
            r++;
        }
        else {
            ans.push_back(r-l);
            l = r;
            cur = dp[r];
        }
    }

    print(ans);
    return 0;
}

Measured memory_bytes: 3960
from collections import deque

def parse():
  N, M = map(int, input().split(" "))

  rooms = [[] for n in range(N)]
  for m in range(M):
    a, b = map(int, input().split(" "))
    rooms[a - 1].append(b - 1)
    rooms[b - 1].append(a - 1)
  
  return N, M, rooms

def main():
  N, M, rooms = parse()
  # print(rooms)

  # 探索する部屋番号をqに入れる
  q = deque([])
  q.append(0)

  # 各部屋の道しるべを入れる変数
  guides = [None for n in range(N)]
  guides[0] = 0
  while len(q) > 0:
    room_num = q.popleft()
    # print("room_num:", room_num)

    # 次に探索する部屋は，今の部屋を道しるべに指す
    for next_room_num in rooms[room_num]:
      # print("guides[next_room_num]:", guides[next_room_num])
      if guides[next_room_num] == None:
        q.append(next_room_num)
        # print(next_room_num)
      
        guides[next_room_num] = room_num
        # if next_room_num != room_num:

      
    # print("q:", q)
    # print("guides:", guides)
    # input()
  
  for guide in guides[1:]:
    if guide == None:
      print("No")
      exit(0)
  print("Yes")
  for guide in guides[1:]:
    print(guide + 1)

if __name__ == "__main__":
  main()

Measured memory_bytes: 34932
#include <stdio.h>
int arr[250];
int main()
{
    int n,i;
    int sum=0;
    int flag=1;
    scanf("%d",&n);
  for(i=0;i<n;i++)
  {
      scanf("%d",&arr[i]);
  }
   do
   {
       for(i=0;i<n;i++)
  {
      if(arr[i]%2!=0)
      {
          flag=0;
          break;
      }
      arr[i]=arr[i]/2;
  }
  if(flag==0) break;
  sum++;
   }while(1);
   printf("%d\n",sum);
   return 0;
}


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

int n, m;
int a;
int r[32][101010];
int cnt[32];

int dp[1 << 20];

int dfs(int c = 0, int s = 0)
{
  int &ret = dp[c];

  if (ret != -1) return ret;

  ret = 0;

  for (int i = 0; i < m; i++){
    if ((c >> i) & 1) continue;
    ret = max(ret, dfs(c + (1 << i), s + cnt[i]) + (r[i][s + cnt[i]] - r[i][s]));
  }

  return ret;
}

int main()
{
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 1; i <= n; i++){
    cin >> a;
    a--;
    cnt[a]++;
    r[a][i]++;
  }

  for (int j = 0; j < m; j++){
    for (int i = 1; i <= n; i++){
      r[j][i] += r[j][i - 1];
    }
  }

  cout << n - dfs() << endl;
}

Measured memory_bytes: 15048
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
	int i = 0, max_num = 0, max_length_string_num = 0, tmp_num = 0;
	map< string, int > input_word;
	string tmp, max_length_string, max_num_string;

	while ( cin >> tmp )
	{
		input_word[tmp] = input_word[tmp] + 1;
		if ( tmp.length() > max_length_string_num )
		{
			max_length_string = tmp;
			max_length_string_num = tmp.length();
		}
	}

	map< string, int >::iterator it = input_word.begin();
	while ( it != input_word.end() )
	{
		tmp_num = (*it).second;
		if ( tmp_num > max_num )
		{
			max_num_string = (*it).first;
			max_num = tmp_num;
		}
		++it;
	}

	cout << max_num_string << " " << max_length_string << endl;

	return 0;
}

Measured memory_bytes: 2964
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l, ans=0;
    cin >> n >> l;
    if(l+n-1 < 0)
    {
        rep(i,1,n) ans += l+i-1;
    }
    else if(l>0)
    {
        rep(i,2,n+1) ans += l+i-1;
    }
    else
    {
        rep(i,1,n+1) ans += l+i-1;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int k[20], s[20], p[20];

int main(void)
{
    int n, m, s1;
    cin >> n >> m;
    REP(i, m) {
        s[i] = 0;
        cin >> k[i];
        REP(j, k[i]) {
            cin >> s1;
            s[i] |= (1 << (s1-1));
        }
//        cout << i << ": " << s[i] << endl;
    }
    REP(i, m) cin >> p[i];
    ll cnt = 0;
    for(int sw = 0; sw < (1<<n); sw++) {
//        cout << "sw:" << sw << endl;
        bool all=true;
        REP(i, m) {
            int on = 0;
            REP(j, n) {
                if(((sw & s[i]) & (1 << j))!=0) on ++;
            }
//            cout << "  on:" << on << " p:" << p[i] << endl;
            if(on % 2 != p[i]) all = false;
        }
        if(all) cnt ++; 
//        cout << "cnt:" << cnt << endl;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int face[6]={},n;
    for(int i=0;i<6;i++){
        cin>>face[i];
    }
    cin>>n;
    for(int i=0;i<n;i++){
        int num_up,num_front,dice[6][5]={{1,2,4,3,1},{0,3,5,2,0},{0,1,5,4,0},{0,4,5,1,0},{0,2,5,3,0},{1,3,4,2,1}};
        cin>>num_up>>num_front;
        int a=0;
        while(true){
            if(face[a]==num_up) break;
            a+=1;
        }
        int b=0;
        while(true){
            if(face[b]==num_front) break;
            b+=1;
        }
        int c=0;
        while(true){
            if(b==dice[a][c]) break;
            c+=1;
        }
        cout<<face[dice[a][c+1]]<<endl;
    }   
        
    return 0;
}



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

int N;
int A[200000];

int searchNext(int num, int index){
	int skipCount = 0;
	for (int i = index; i < N; i++)
	{
		if(A[i] == num){
			skipCount += searchNext(num+1, i+1);
			break;
		}
		skipCount++;
	}
	return skipCount;
}

int main()
{

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	
	bool noAns = true;
	int ans = -1;
	for (int i = 0; i < N; i++)
	{
		if(A[i] == 1){
			noAns = false;
		}
	}

	if(!noAns){
		ans = searchNext(1, 0);
	}
	
	cout << ans << endl;

	 return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string.h>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

int a, b;

int main()
{
	while (cin >> a >> b) {
		cout << a + b << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
 
int main()
{
 
  ll N, K;
  cin >> N >> K;
 
  ll ans = 0;
 
  if (K % 2 == 1)
  {
    ll num = floor(N / K);
    ans += pow(num, 3);
  }
  else if (K % 2 == 0)
  {
    ll num = floor(N / (K / 2));
    ll numK = floor(N / K);
    ans += pow(numK, 3);
    ans += pow(num - numK, 3);
  }
 
  cout << ans;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=100005;
const int mod=1e9+7;
int n,m,sz,ans;
int x[maxn],y[maxn],dp[maxn];
vector<pii>pts;
vector<int>all;

namespace Fenwick{
	int t[maxn];
	void add(int v,int val){
		for(v++;v<=sz;v+=(v&-v)){
			t[v]+=val;
			if(t[v]>=mod)t[v]-=mod;
		}
	}
	int sum(int v){
		int res=0;
		for(v++;v;v-=(v&-v)){
			res+=t[v];
			if(res>=mod)res-=mod;
		}
		return res;
	}
}

int main(){
	scanf("%d%d",&n,&m);
	rep(i,n)scanf("%d",&x[i]);
	rep(i,m)scanf("%d",&y[i]);
	rep(i,n){
		int pos=lower_bound(y,y+m,x[i])-y;
		if(pos==0||pos==m)continue;
		pts.pb(mp(x[i]-y[pos-1],y[pos]-x[i]));
		all.pb(y[pos]-x[i]);
	}
	sort(pts.begin(),pts.end());
	pts.resize(unique(pts.begin(),pts.end())-pts.begin());
	sort(all.begin(),all.end());
	all.resize(unique(all.begin(),all.end())-all.begin());
	sz=int(all.size());
	rep(i,int(pts.size())){
		int j=i;
		while(j<int(pts.size())&&pts[j].fst==pts[i].fst){
			int pos=lower_bound(all.begin(),all.end(),pts[j].snd)-all.begin();
			dp[j]=Fenwick::sum(pos-1);
			dp[j]++;
			if(dp[j]>=mod)dp[j]-=mod;
			j++; 
		}
		for(int k=i;k<j;k++){
			int pos=lower_bound(all.begin(),all.end(),pts[k].snd)-all.begin();
			Fenwick::add(pos,dp[k]);
		}
		i=j-1;
	}
	ans=1; 
	rep(i,int(pts.size())){
		ans+=dp[i];
		if(ans>=mod)ans-=mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3188
using System;

public class AtCoderB
{
    static void Main()
    {
        int r;
        int d;
        int x;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            r = int.Parse(words[0]);
            d = int.Parse(words[1]);
            x = int.Parse(words[2]);
        }

        long before = x;
        for (int i = 1; i <= 10; i++)
        {
            Console.WriteLine(r * before - d);
            before = r * before - d;
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=3e5+10;
const int mod=1e9+7;
int a[N],b[N];
ll maxs=-9999;
ll sum;
struct A
{
    int x,y;
};
map <pair<int,int >,int >mp;
int main()
{
    int h,w,m;
    int q[N],t[N];//记录最多障碍物的行和列。
    int cnt1,cnt2;//记录有多少条最多的行和列。
    cin>>h>>w>>m;
    int  sum1=0,sum2=0;//求最大的行和列。
    for(int i=0; i<m; i++)
    {
        int x,y;
        cin>>x>>y;
        mp[make_pair(x,y)]++;
        a[x]++;
        b[y]++;
    }
    for(int i=1; i<=h; i++)
    {
        if(sum1<a[i])
        {
            cnt1=0;
            memset(q,0,sizeof(q));
            sum1=max(sum1,a[i]);
            q[cnt1++]=i;
            while(sum1==a[i+1])
            {
                q[cnt1++]=i;
                i++;
            }
        }
        if(sum1==a[i])
        {
            q[cnt1++]=i;
            while(sum1==a[i+1])
            {
                q[cnt1++]=i;
                i++;
            }
        }
    }
    for(int i=1; i<=w; i++)
    {
        if(sum2<b[i])
        {
            cnt2=0;
            memset(t,0,sizeof(t));
            sum2=max(sum2,b[i]);
            t[cnt2++]=i;
            while(sum2==b[i+1])
            {
                t[cnt2++]=i;
                i++;
            }
        }
        if(sum2==b[i])
        {
            t[cnt2++]=i;
            while(sum2==b[i+1])
            {
                t[cnt2++]=i;
                i++;
            }
        }
    }
    sum=sum1+sum2;
    int xx=0;
    for(int i=0; i<cnt1; i++)
    {
        for(int j=0; j<cnt2; j++)
        {
            int x1,y1;
            x1=q[i];
            y1=t[j];
            if(mp[make_pair(x1,y1)]==0)//判断是否交点有障碍物
            {
                xx=1;
                break;
            }

        }
        if(xx==1)
        {
            break;
        }
    }
    if(xx==0)
    {
        sum--;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 27064
s = input()
s1, s2 = [], []

ans = 0
for i in range(len(s)):
    if s[i] == '\\':
        s1.append(i)
    if s[i] == '/' and s1:
        j = s1.pop()
        a = i - j
        ans += a
        while s2 and s2[-1][0] > j:
            a += s2.pop()[1]
        s2.append([j, a])
print(ans)
print(len(s2), *(a for j, a in s2))

Measured memory_bytes: 8324
const MOD: u64 = 1000000007;

fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: u32 = s.next().unwrap().parse().unwrap();
	let m: u32 = s.next().unwrap().parse().unwrap();
	let a = std::cmp::max(n, m);
	let b = std::cmp::min(n, m);
	if a - b >= 2 {
		println!("0");
	} else if a == b {
		println!("{}", 2 * factorial(a) * factorial(b)% MOD);
	} else {
		println!("{}", factorial(a) * factorial(b) % MOD);
	}
}

fn factorial(n: u32) -> u64 {
	(2..n + 1).fold(1, |r, i| r * (i as u64) % MOD)
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int main() {
  long long n;
  cin >> n;
  if (n % 2)
    cout << 0 << '\n';
  else {
    long long c(10), x(0);
    while (n / c) {
      x += n / c;
      c *= 5;
    }
    cout << x << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        month:usize,
        day:usize,
    };

    println!("{}", solve(month,day) );
}

fn solve(month:usize,day:usize) -> usize{
    return if day >= month { month } else {month -1}
}
macro_rules! tests {
    ($($test_name:ident:$name:ident($( $args:expr ),*) => $expected:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $test_name() {
                    assert_eq!($expected,super::$name($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:solve(11,3) => 10,
    test2:solve(10,10) => 10,
    test3:solve(1,1) => 1,
    test4:solve(5,5) => 5,
}


Measured memory_bytes: 4352
A = [0] * 5

for i in range(5):
    A[i] = int(input())
K = int(input())

flag = 0
for i, a in enumerate(A):
    for j, a2 in enumerate(A[i+1:]):
        if abs(a2 - a) > K:
            flag = 1

if flag == 1:
    print(":(")
else:
    print("Yay!")

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

int main(){
	int a,b;
	int n;
	cin >>n>>a>>b;
	int sum=0;
	int cnt=0;
	for(int i=1;i<n+1;i++){
		int num=i;
		int dig;
		while(num){
			dig=num%10;
			cnt +=dig;
			num/=10;
		}
		if(cnt <= b && a <= cnt){
			sum+=i;
		}
		cnt=0;
	}
	cout<<sum<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <set>
#include <iomanip>

using namespace std;

typedef unsigned long long ull;
typedef pair<int, int> P;

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

	int maxSum = 0, sum = 0;
	double ans = 0.0;

	vector<int> p(n);
	for (int i = 0; i < n; i++) 
	{
		cin >> p[i];
		sum += p[i];

		if (i < k - 1)
			continue;

		if (sum > maxSum)
			maxSum = sum;

		sum -= p[i - k + 1];
	}

	ans = 0.5 * (maxSum + k);

	cout << fixed << setprecision(12) << ans << endl;

}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int m, n;
  m = max({a, b, c});
  n = a + b + c - max({a, b, c});
  
  cout << 10 * m + n << endl;
}


Measured memory_bytes: 256
import fractions

d = [int(x) for x in input().split()]
lcm = int(d[2] * d[3] // fractions.gcd(d[2], d[3]))
b = d[1] - int(d[1] // d[2]) - int(d[1] // d[3]) + int(d[1] // lcm)
a_1 = d[0] - 1
a = a_1 - int(a_1 // d[2]) - int(a_1 // d[3]) + int(a_1 // lcm)
print(b - a)

Measured memory_bytes: 5044
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int D[10][10];

void solve() {
	cin >> N;
	rep(i, 1, N + 1) {
		vi vec;
		int n = i;
		while(n) {
			vec.pb(n % 10); n /= 10;
		}
		D[vec.front()][vec.back()]++;
	}
	int res = 0;
	rep(i, 1, 10) {
		rep(j, 1, 10) {
			res += D[i][j] * D[j][i];
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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



int main() {
int a;
cin>>a;
vector<int>v(a);
for(int i=0;i<a;i++)
cin>>v[i];
sort(v.begin(),v.end());
cout<<v[v.size()-1]-v[0];
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////

int a,b;
int l, r;
int i,j;
int main(){
    scanf("%d%d",&a,&b);
    l = 0;
    fornum (i,1,1000){
        l += i;
        if(l<=a)
            continue;
        if(a+i+1==b){
            printf("%d", l-a);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,t,p;
  int d,c,x,y;
  int ans=0;
  int a=0,b=0;
  int paper[70][70];
  while(1){
     for(int i=0;i<70;i++){
      for(int j=0;j<70;j++){
        paper[i][j]=0;
      }
    }
    cin>>n>>m>>t>>p;
    if(n==0 && m==0 && t==0 && p==0) break;
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
        paper[i][j]=1;
      }
    }
    /*for(int j=0;j<m;j++){
        for(int k=0;k<n;k++){
          cout<<paper[j][k]<<" ";
        }
        cout<<endl;
    }*/
    for(int i=0;i<t;i++){
      cin>>d>>c;
      a=1;
      if(d==1){
        for(int j=c;j<c+c;j++){
          for(int k=0;k<m;k++){
          paper[k][j]+=paper[k][j-a];
          paper[k][j-a]=0;
        }
         a+=2;
        }
        for(int j=(n-1);j>=0;j--){
          for(int k=0;k<m;k++){
            if(paper[k][j]==0){
              for(int a=j;a<n*2;a++){
                paper[k][a]=paper[k][a+1];
              }
            }
          }
        }
        }
      if(d==2){
        for(int j=c;j<c+c;j++){
          for(int k=0;k<n;k++){
            paper[j][k]+=paper[j-a][k];
            paper[j-a][k]=0;
          }
          a+=2;
        }
        for(int j=(m-1);j>=0;j--){
          for(int k=0;k<n;k++){
            if(paper[j][k]==0){
              for(int a=j;a<m*2;a++){
                paper[a][k]=paper[a+1][k];
              }
            }
          }
        }
      }
   /*for(int j=0;j<m;j++){
        for(int k=0;k<n;k++){
          cout<<paper[j][k]<<" ";
        }
        cout<<endl;
        }*/
      }
    for(int i=0;i<p;i++){
      cin>>x>>y;
      ans=paper[y][x];
      cout<<ans<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int d;
	cin >> d;
	if (d == 25) cout << "Christmas" << endl;
	else if (d == 24) cout << "Christmas Eve" << endl;
	else if (d == 23) cout << "Christmas Eve Eve" << endl;
	else cout << "Christmas Eve Eve Eve" << endl;
 	return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin >> N >> M;
  bool fl = true;
  if(N>=M)
    fl = false;
  if(fl){
  vector<int> vec(M);
  int a;
  for(int i=0;i<M;i++){
    cin >> a;
    vec.at(i)=a;
  }
  sort(vec.begin(),vec.end());
  int all=vec.at(M-1)-vec.at(0);
  int b=0;
  vector<int> sa(M-1);
  for(int i=1;i<M;i++){
    b = vec.at(i)-vec.at(i-1);
    sa.at(i-1)=b;
  }
  sort(sa.begin(),sa.end());
  b=0;
    for(int i=0;i<N-1;i++){
      all -= sa.at(M-2-i);
    }
    cout << all;
  }else
    cout << "0";
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (abs(c - a) <= d) {
    cout << "Yes" << endl;
    return 0;
  }
  
  if (abs(b - a) <= d && abs(c - b) <= d) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
xorsm = 0
res = 0
for x in a: xorsm ^= x
for i in range(N): a[i] &= ~xorsm
ln = max(a).bit_length()
k = 0
for i in range(ln - 1, -1, -1):
  for j in range(k, N):
    if a[j] & (1 << i):
      a[k], a[j] = a[j], a[k]
      break
  else: continue
  for j in range(N):
    if j == k: continue
    if a[j] & (1 << i): a[j] ^= a[k]
  k += 1
for i in range(k): res ^= a[i]
print(res * 2 + xorsm)

Measured memory_bytes: 71488
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long double a,b; cin >> a >> b;
    cout << (ll)(a*b) << endl;
}


Measured memory_bytes: 3776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	Vertex[] Vertexes;

	class Vertex {
		int Idx;
		ArrayList<Integer> Link;

		Vertex(int i) {
			Idx = i;
			Link = new ArrayList<Integer>();
		}

		void AddLink(int v) {
			Link.add(v);
		}
	}

	int N;
	int M;
	int cnt;

	public void init() {
		N = 0;
		M = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		M = Integer.parseInt(strArr[1]);
		// System.out.println(N);
		Vertexes = new Vertex[N + 1];
		for (int i = 1; i <= N; i++) {
			Vertexes[i] = new Vertex(i);
		}
	}

	public boolean hasNext() {
		return cnt < M;
	}

	public void readBody(String str) {
		String[] strArr = str.split(" ");
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		Vertexes[a].AddLink(b);
		Vertexes[b].AddLink(a);
		cnt++;
	}

	public void solve() {
		// for (int i = 1; i <= N; i++) {
		// System.out.println(Vertexes[i].Idx);
		// for (int l : Vertexes[i].Link)
		// System.out.print(" " + l);
		// System.out.println();
		// }
		int Head = 1;
		int Tail = 1;

		int min = Integer.MAX_VALUE;
		for (int i = 1; i <= N; i++) {
			if (Vertexes[i].Link.size() < min) {
				min = Vertexes[i].Link.size();
				Head = i;
			}
		}
		min = Integer.MAX_VALUE;
		for (int l : Vertexes[Head].Link) {
			if (Vertexes[l].Link.size() < min) {
				min = Vertexes[l].Link.size();
				Tail = l;
			}
		}

		ArrayList<Integer> path = new ArrayList<Integer>();
		HashSet<Integer> vset = new HashSet<Integer>();
		path.add(Head);
		path.add(Tail);
		vset.add(Head);
		vset.add(Tail);

		for (boolean criteria = true; criteria;) {
			criteria = false;
			for (int l : Vertexes[Head].Link) {
				if (!vset.contains(l)) {
					Head = l;
					path.add(0, l);
					vset.add(l);
					criteria = true;
					break;
				}
			}
			if (!criteria) {
				for (int l : Vertexes[Tail].Link) {
					if (!vset.contains(l)) {
						Tail = l;
						path.add(l);
						vset.add(l);
						criteria = true;
						break;
					}
				}
			}
		}

		System.out.println(path.size());
		String sep = "";
		for (int p : path) {
			System.out.print(sep + p);
			if ("".equals(sep))
				sep = " ";
		}
		System.out.println();
	}

}


Measured memory_bytes: 80568
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

class Int {
public:
	string s;
	Int(int i);
	Int operator++();
	bool operator<(Int i);
};
Int::Int(int i) {
	s = to_string(i);
}
Int Int::operator++() {
	for (int i = s.size() - 1; i >= 0; i--) {
		if ('0' <= s[i] && s[i] < '9') {
			s[i]++;
			break;
		}
		else s[i] = '0';
	}
	if (s[0] == '0')s = '1' + s;
	return *this;
}
bool Int::operator<(Int i) {
	if (s.size() != i.s.size())return s.size() < i.s.size();
	return s < i.s;
}
ostream&operator<<(ostream&os, Int i) {
	os << i.s;
	return os;
}
int main() {
	int n; scanf("%d", &n);
	string s;
	rep(i, n) {
		string d; cin >> d;
		s += d;
	}
	for (Int i = 0;; ++i) {
		if ((int)s.find(i.s) == -1) {
			cout << i << endl;
			break;
		}
	}
}

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

int main() {
  int n;
  while(cin >> n && n!=0) {
    int a[n][5];
    for(int i=0; i<n; i++) {
      for(int j=0; j<4; j++) cin >> a[i][j];
      a[i][4]=4*a[i][1]+9*a[i][2]+4*a[i][3];
    }
    int b[4];
    for(int i=0; i<4; i++) cin >> b[i];
    vector<int> ans;
    for(int i=0; i<n; i++) {
      int cnt=0;
      for(int j=1; j<5; j++) {
	if(a[i][j]<=b[j-1]) cnt++;
      }
      if(cnt==4) ans.push_back(a[i][0]);
    }
    if(ans.size()==0) cout << "NA" << endl;
    else {
      for(vector<int>::iterator it=ans.begin(); it!=ans.end(); it++)  cout << *it << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define N 100005
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
char s[N];
int n,ch[N];
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;++i)ch[i]=s[i]-'0';
	if(ch[n])return puts("-1"),0;
	if(!ch[1]||!ch[n-1])return puts("-1"),0;
	for(int i=1;i<n;++i)if(ch[i]!=ch[n-i])return puts("-1"),0;
	int pos=1;
	for(int i=2;i<=n;++i){
		printf("%d %d\n",pos,i);
		if(ch[i-1])pos=i;
	}
	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
int main(void)
{
	int h,w,i,j;
	do{
	scanf("%d %d",&h,&w);
	if(h<=300 && w<=300)
	{
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			if(i==0 || i==h-1 || j==0 || j==w-1)printf("#");
			if(i!=0 && i!=h-1 && j>0 && j<w-1)printf(".");
		}
		if(h!=0 && w!=0)printf("\n");
	}
	if(h!=0 && w!=0)printf("\n");
	}
	}while(h!=0 && w!=0);
return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;
  map<int, int> se;
  rep(i, n) se[a[i]]++;
  if (se.size() == 1) {
    bool f = false;
    each(s, se) if (s.first == 0) f = true;
    if (f) yes(); no();
  }
  if (se.size() >= 4) no();
  if (n % 3 != 0) no();

  if (se.size() == 3) {
    vi32 x;
    each(s, se) {
      x.push_back(s.first);
      if (s.second != n / 3) no();
    }
    if ((x[0] ^ x[1]) == x[2]) yes(); no();
  } else {
    int z = 0, c = 0;
    each(s, se) if (s.first == 0) {
      z = s.second;
    } else {
      c = s.second;
    }
    if (z == n / 3 && c == n / 3 * 2) yes();
    no();
  }
}


Measured memory_bytes: 4224
local mfl, mce, mmi = math.floor, math.ceil, math.min
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = self.stage[i + 1][j * 2 - 1] + self.stage[i + 1][j * 2]
    end
  end
end
SegTree.create = function(self, n)
  self.emptyvalue = 0
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = 0 end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage, mul = 1, 1
  while right - left + 1 < self.size[start_stage] do
    start_stage = start_stage + 1
  end
  local ret = self.emptyvalue
  local t1, t2, t3 = {start_stage}, {left}, {right}
  while 0 < #t1 do
    local stage, l, r = t1[#t1], t2[#t1], t3[#t1]
    table.remove(t1) table.remove(t2) table.remove(t3)

    local sz = self.size[stage]
    if (l - 1) % sz ~= 0 then
      local newr = mce((l - 1) / sz) * sz
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, mmi(r, newr))
      l = newr + 1
    end
    if sz <= r + 1 - l then
      ret = ret + self.stage[stage][mce(l / sz)]
      l = l + sz
    end
    if l <= r then
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, r)
    end
  end
  return ret
end
SegTree.decValue = function(self, idx)
  self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] - 1
  for i = self.stagenum - 1, 1, -1 do
    local dst = mce(idx / 2)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.stage[i + 1][idx] + self.stage[i + 1][rem]
    idx = dst
  end
end
SegTree.inc = function(self, idx)
  self.stage[self.stagenum][idx] = 1 + self.stage[self.stagenum][idx]
end
SegTree.new = function(n)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  -- obj.updateAll = SegTree.updateAll
  -- obj.create = SegTree.create
  -- obj.getRange = SegTree.getRange
  -- obj.inc = SegTree.inc
  -- obj.decValue = SegTree.decValue
  obj:create(n)
  return obj
end

local n, k = io.read("*n", "*n")
local sum, tmp, conv = {}, {}, {}
sum[1] = io.read("*n") - k
for i = 2, n do
  sum[i] = sum[i - 1] + io.read("*n") - k
end
sum[n + 1] = 0
for i = 1, n + 1 do tmp[i] = sum[i] end
table.sort(tmp)
local sumTypeCount = 1
local sumTypeList = {}
conv[tmp[1]] = 1
sumTypeList[1] = tmp[1]
for i = 2, n + 1 do
  if tmp[i] ~= sumTypeList[sumTypeCount] then
    sumTypeCount = sumTypeCount + 1
    conv[tmp[i]] = sumTypeCount
    sumTypeList[sumTypeCount] = tmp[i]
  end
end
local segtree = SegTree.new(sumTypeCount)
for i = 1, n do
  segtree:inc(conv[sum[i]])
end
segtree:updateAll()
local bias = 0
local cnt = 0
for i = 1, n do
  cnt = cnt + segtree:getRange(conv[bias], sumTypeCount)
  segtree:decValue(conv[sum[i]])
  bias = sum[i]
end
print(cnt)


Measured memory_bytes: 35624
#include <iostream>
#include <cstring>

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

const int INF = 1e9;

using namespace std;

int m, n;
int c[21];

int dp[21][100005];

int dfs(int i, int sum) {
    if (i == m) {
        if (n == sum)
            return 0;
        else
            return INF;
    }
    if (dp[i][sum] != -1) {
        return dp[i][sum];
    }
    int ret;
    ret = dfs(i + 1, sum);
    if (sum + c[i] <= n) {
        ret = min(ret, dfs(i, sum + c[i]) + 1);
    }

    return dp[i][sum] = ret;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    rep(i, m) cin >> c[i];
    cout << dfs(0, 0) << endl;
}

Measured memory_bytes: 13640
#include<iostream>
using namespace std;
int main(){
  long long a;
  cin>>a;
  int ok=0;
  long long i=2;
  while(ok==0){
    if(i==a){
      cout<<a<<endl;
      ok=1;
    }
    if(a%i==0){
      a++;
      i=2;
    }
    else{
      i++;
    }
  }
 return 0; 
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let _n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    //累積和 前処理 Eの数を集計
    let mut count = s.iter().filter(|x| **x == 'E').count();
    let mut ans = count;

    //左端1番目からリーダーをずらしながらチェック。
    for ch in s.iter(){
        if *ch == 'E'{
            count -= 1;
            ans = std::cmp::min(count,ans);
        }else{
            count += 1;
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 3800
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int field[50][50];
int W, H;

void dfs(int y, int x) {

	queue<P> que;
	que.push(mp(y,x));
	while(!que.empty()) {
		P here = que.front();
		que.pop();
		for(int dy = -1; dy <= 1; dy++) for(int dx = -1; dx <= 1; dx++) {
			int ny = here.first + dy;
			int nx = here.second + dx;
			if(0 <= ny && ny < H && 0 <= nx && nx < W && field[ny][nx] == 1) {
				field[ny][nx] = 0;
				que.push(mp(ny, nx));
			}
		}
	}
}

int main() {
	for(; cin >> W >> H, W || H;) {

		memset(field, 0, sizeof field);
		rep(i,H) rep(j,W) cin >> field[i][j];
		int ans = 0;
		rep(i,H) rep(j,W) if(field[i][j]) {
			dfs(i,j);
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0