akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <chrono>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class xor_shift {
    uint32_t x, y, z, w;
public:
    xor_shift() : x(static_cast<uint32_t>((chrono::system_clock::now().time_since_epoch().count())&((1LL << 32)-1))),
    y(1068246329), z(321908594), w(1234567890) {};

    uint32_t urand(){
        uint32_t t;
        t = x ^ (x << 11);
        x = y; y = z; z = w;
        w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        return w;
    };

    int rand(int n){
        if(n < 0) return -rand(-n);
        uint32_t t = numeric_limits<uint32_t>::max()/(n+1)*(n+1);
        uint32_t e = urand();
        while(e >= t) e = urand();
        return static_cast<int>(e%(n+1));
    }

    int rand(int a, int b){
        if(a > b) swap(a, b);
        return a+rand(b-a);
    }
};


xor_shift rd;

template<int M>
class rolling_hash {

    static ll &B() {
        static ll B_ = rd.rand(2, M-1);
        return B_;
    }
    static vector<ll> &p() {
        static vector<ll> p_{1, B()};
        return p_;
    }
public:
    vector<ll> hash;
    explicit rolling_hash(const string &s) {
        if(p().size() <= s.size()){
            int l = p().size();
            p().resize(s.size()+1);
            for (int i = l; i < p().size(); ++i) {
                p()[i] = (p()[i-1]*p()[1])%M;
            }
        }
        hash.resize(s.size()+1, 0);
        for (int i = 0; i < s.size(); ++i) {
            hash[i+1] = (hash[i]*B() + s[i]) % M;
        }
    };

    ll get(int l, int r){
        ll res = hash[r]+M-hash[l]*p()[r-l]%M;
        return res >= M ? res-M : res;
    }
};

int main() {
    string s, t;
    cin >> s >> t;
    rolling_hash<MOD> hash1(s), hash2(t);
    for (int i = 0; i+t.size() <= s.size(); ++i) {
        if(hash2.hash.back() == hash1.get(i, i+t.size())) cout << i << "\n";
    }
    return 0;
}


Measured memory_bytes: 19820
#include <stdio.h>

int main(void) {
  int N, D, X;
  int A[110];
  int i;
  int sum = 0;
  
  scanf("%d %d %d", &N, &D, &X);
  for(int i = 0; i < N; i++) {
    int A;
    scanf("%d", &A);
    sum += (D-1)/A + 1;
  }
  printf("%d\n", X + sum);
  
  return 0;
}
    

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define accum(x) accumulate((x).begin(),(x).end(),0)

int main(){
	int n; cin>>n;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	int sum=accum(v);
	int cnt=0;
	while(sum!=0){
		bool flg=false;
		int zero=0;
		for(int i=0; i<n; i++){
			if(v[i]!=0) {v[i]--; flg=true;}
			else if(flg&&v[i]==0) {zero++; flg=false;}
		}
		if(flg) cnt++;
		cnt+=zero;
		sum=accum(v);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
  string X;
  cin >> X;
  stack<char> s;
  for (char c : X) {
    if (c == 'S') s.push(c);
    else if (s.empty() || s.top() == 'T') s.push(c);
    else if (s.top() == 'S') s.pop();
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 644
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
vector<vector<int> > field;

// 深さ優先探索
bool seen[60][60];
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1};
int w,h;

void dfs(int current_h, int current_w){
    seen[current_h][current_w] = true;

    for(int dir=0; dir < 8; dir++){
        int next_w = current_w + dx[dir];
        int next_h = current_h + dy[dir];

        if(next_w < 0) continue;
        if(next_h < 0) continue;
        if(next_w >= w) continue;
        if(next_h >= h) continue;
        
        if(field[next_h][next_w] == 1 && !seen[next_h][next_w]){
            dfs(next_h, next_w);
        }
    }
}

int main(){
    while(true) {
        cin >> w >> h;
        memset(seen, 0, sizeof(seen));
        if( w==0 && h==0 ){
            break;
        }

        field.assign(h, vector<int>(w, 0));
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cin >> field[i][j];
            }
        }

        int count = 0;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(field[i][j] ==1 && !seen[i][j] ){
                    dfs(i, j);
                    count ++;
                }
            }
        }

        cout << count << endl;
    }
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	while (1) {
		int h, w;
		cin >> h >> w;
		if (h == 0) {
			break;
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<P> A(N),B(N);
    rep(i,0,N)cin >> A[i].first >> A[i].second;
    rep(i,0,N)cin >> B[i].first >> B[i].second;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int cnt = 0;
    rep(i,0,N){
        int maxx = -1, maxj = -1;
        rep(j,0,N){
            if(A[j].first < B[i].first && A[j].second < B[i].second){
                if(maxx < A[j].second){
                    maxx = A[j].second;
                    maxj = j;
                }
            }
        }
        if(maxj == -1)continue;
        cnt++;
        A[maxj].second = INF;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N, l, r, f;
  
  scanf("%d", &N);
  
  for (int i = 0; i < N; i++){
    scanf("%d %d", &l, &r);
    f += r - l + 1;
  }
  
  printf("%d\n", f);
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>

using namespace std;
#define int long long

const int INF=(1LL<<31)-1;
struct SegmentTree{

   static const int N=1<<17;
   vector<int> seg, lazy;
   SegmentTree(){
      seg.resize(2*N-1, INF);
      lazy.resize(2*N-1, -1);
   }

   void refresh(int i, int l, int r){
      if(lazy[i]!=-1){
         seg[i]=lazy[i];
         if(r-l>1){
            lazy[2*i+1]=lazy[i];
            lazy[2*i+2]=lazy[i];
         }
         lazy[i]=-1;
      }
   }

   void update(int a, int b, int x, int i=0, int l=0, int r=N){
      refresh(i, l, r);
      if(b<=l or r<=a){
         return;
      }else if(a<=l and r<=b){
         lazy[i]=x;
         refresh(i, l, r);
      }else{
         int m=(r+l)/2;
         update(a, b, x, 2*i+1, l, m);
         update(a, b, x, 2*i+2, m, r);
         seg[i]=min(seg[2*i+1], seg[2*i+2]);
      }
   }

   int getmin(int a, int b, int i=0, int l=0, int r=N){
      refresh(i, l, r);
      if(b<=l or r<=a){
         return INF;
      }else if(a<=l and r<=b){
         return seg[i];
      }else{
         int m=(r+l)/2;
         int vl=getmin(a, b, 2*i+1, l, m);
         int vr=getmin(a, b, 2*i+2, m, r);
         return min(vl, vr);
      }
   }

};

signed main(){

   int N, Q;
   cin>> N>> Q;
   SegmentTree st;
   while(Q--){
      int q; cin>> q;
      if(q==0){
         int s, t, x;
         cin>> s>> t>> x;
         st.update(s, t+1, x);
      }else{
         int s, t;
         cin>> s>> t;
         cout<< st.getmin(s, t+1)<< endl;
      }
   }

   return 0;
}

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

int main(){
    string S,T;
    int ans = 0;
    cin >> S;
    cin >> T;
    for(int i=0; i <= 2; i++){
        if(S.substr(i,1) == T.substr(i,1)){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
line = gets.split(' ')

cnt = 0
flag = true
while flag do
    0.upto(n - 1) do |i|
        if (line[i].to_i.odd? || (line[i].to_i / 2 ** cnt).odd?)
            flag = false
            break
        end
    end
    cnt += 1 if flag
end

print(cnt)


Measured memory_bytes: 1788
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a,b;
    cin >> a >> b;
    int ans;
    if(a < 6)ans = 0;
    else if(a >=13) ans = b;
    else ans = b/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    int m, t, p, r;
    vector<string> x;
    while (1)
    {
        cin >> m >> t >> p >> r;
        if (m == 0)
        {
            break;
        }
        vector<pair<pair<int, int>, int> >team(t); // 得点：時間: チーム番号: <ペナルティ番号,ペナルティ数>
        vector<vector<int> > wrong(t,vector<int>(p,0)); // チーム番号：間違えた問題番号
        int m1, t1, p1, j1;
        //チーム番号を入れていく
        for (int i = 0; i < team.size(); i++)
        {
            team[i].second = i + 1;
        }

        for (int k = 0; k < r; k++)
        { // 提出回数だけ繰り返す
            cin >> m1 >> t1 >> p1 >> j1;
            if (j1 == 0)
            {
                team[t1 - 1].first.second = team[t1 - 1].first.second - m1 - wrong[t1-1][p1-1] * 20; // 時間を代入
                team[t1 - 1].first.first += 100;
            }
            else
            { //　不正解だった場合
                wrong[t1-1][p1-1]++;
            }
        }
        sort(team.begin(), team.end());
        string x_chi = "";
        char numStr[512];
        string formatStr;
        //debugよう
        for (int i = team.size() - 1; i > 0; i--)
        {
            if (team[i].first.first == team[i - 1].first.first)
            {
                if (team[i].first.second == team[i - 1].first.second)
                {
                    sprintf(numStr, "%d=", team[i].second);
                }
                else
                {
                    sprintf(numStr, "%d,", team[i].second);
                }
            }
            else
            {
                sprintf(numStr, "%d,", team[i].second);
            }
            formatStr += numStr;
            // cout << team[i].second << ": " << team[i].first.first << " " << team[i].first.second << endl; // 0に得点：i+1番のペナルティ
        }
        // 最後の一つを追加
        // cout << team[0].second << ": " << team[0].first.first << " " << team[0].first.second << endl; // 0に得点：i+1番のペナルティ
        sprintf(numStr, "%d", team[0].second);
        formatStr += numStr;
        x.push_back(formatStr);
    }
    for (int i = 0; i < x.size(); i++)
    {
        cout << x[i] << endl;
    }
}



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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>

const int N = 2e5 + 1;
const ll mod = 1e9 + 7;

int a[N];
ll prfx[N + 1];

void solve() {
    int n;
    cin >> n;
    prfx[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        prfx[i + 1] = prfx[i] + a[i];
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll a = prfx[i + 1] - prfx[i];
        ll b = prfx[n] - prfx[i + 1];
        ans += ((a % mod) * (b % mod)) % mod;
        ans %= mod;
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 5996
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        class Vector2
        {
            public Vector2(double x, double y)
            {
                X = x;
                Y = y;
            }
            public Vector2(Vector2 v)
            {
                X = v.X;
                Y = v.Y;
            }

            public double X;
            public double Y;

            public double Length()
            {
                return Math.Sqrt(X * X + Y * Y);
            }
        }


        static Vector2[] pos;

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            pos = new Vector2[N];

            for (int i = 0; i < N; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                pos[i] = new Vector2(double.Parse(s[0]), double.Parse(s[1]));
            }

            double ans = 0;

            for (int i = 0; i < N; i++)
            {
                bool[] done = new bool[N];
                ans += Length(i, 0, done);
            }

            for (int i = 0; i < N; i++)
            {
                ans /= (i + 1);
            }

            Console.WriteLine(ans);

            return;
        }

        static double Length(int p, double baseLen, bool[] done)
        {
            bool[] done2 = new bool[done.Length];
            for (int i = 0; i < done.Length; i++)
            {
                done2[i] = done[i];
            }
            done2[p] = true;

            bool all = true;
            for (int i = 0; i < done.Length; i++)
            {
                all &= done2[i];
            }
            if(all)
            {
                return baseLen;
            }

            Vector2 from = new Vector2(pos[p]);
            double ans = 0;

            for (int i = 0; i < done.Length; i++)
            {
                if(!done2[i])
                {
                    Vector2 to = new Vector2(pos[i]);
                    to.X -= from.X;
                    to.Y -= from.Y;
                    ans += Length(i, baseLen + to.Length(), done2);
                }
            }

            return ans;
        }
    }
}



Measured memory_bytes: 17356
#define rep(i,n)for(i=0;i<n;i++)
W,H,m,c[10][16];DP[51][16][16][16][16];CalcO(o,x,y){c[x][y]>0?o+=c[x][y]:0;return o>0?o>m?m:o:0;}CalcF(f,x,y){return c[x][y]<0?f+c[x][y]:f;}Walk(x,y,l,r,o,f){int*p=&DP[o][y][x][l][r];f>*p?*p=f:0;}Dig(x,y,l,r,o,f){Walk(x,y,l,r,CalcO(o-1,x,y),CalcF(f,x,y));}*p,x,y,g,d,v,f,o,l,r,f0;main(){for(;scanf("%d%d%d%d%d",&W,&H,&f0,&m,&o)*W;memset(DP,!printf(f?"%d\n":"NA\n",f0-f),sizeof(*DP)*2)){rep(y,H)rep(x,W)scanf("%d",&c[x][y]);f0++;if(o>1)rep(x,W)DP[CalcO(o-1,x,0)][0][x][x][x]=CalcF(f0,x,0);rep(y,H-1)rep(g,W)for(o=m;o>1;o--)rep(d,2)rep(l,W-g)rep(v,g+1)if(r=l+g,p=&DP[o][y][x=d?l+v:r-v][l][r],f=*p){*p=0;Dig(x,y+1,x,x,o,f);x?x>l?Walk(x-1,y,l,r,o-1,f):Dig(x-1,y,x-1,r,o,f):0;x<W-1?x<r?Walk(x+1,y,l,r,o-1,f):Dig(x+1,y,l,x+1,o,f):0;}f=0;rep(x,W)rep(o,m)p=&DP[o+1][H-1][x][x][x],*p>f?f=*p:0,*p=0;}}

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

using namespace std;

#define fto(i, s, e) for(int i = s; i <= e; ++i)
#define fto1(i, s, e) for(int i = s; i < e; ++i)
#define fdto(i, s, e) for(int i = s; i >= e; --i)
#define fit(var, it) for(__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define frit(var, it) for(__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it)

#define newl '\n'
#define debugt cerr << 0.001*clock() << newl
#define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl
#define debug(v, l, r) fto(_i, l, r) debug1(v, _i)
#define debug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl
#define debug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << newl

#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define glen(v) int((v).size())

template<typename T1, typename T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.ff << ", " << v.ss << ')';
}

#define eps 1e-15
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003

int n;
int a[maxn], b[maxn], c[maxn];
int f1[maxn], f2[maxn], f3[maxn];

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("main.inp", "r", stdin);
		//freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	fto (i, 1, n) scanf("%d%d%d", &a[i], &b[i], &c[i]);

	fto (i, 1, n) {
		f1[i] = max(f2[i-1], f3[i-1]) + a[i];
		f2[i] = max(f1[i-1], f3[i-1]) + b[i];
		f3[i] = max(f1[i-1], f2[i-1]) + c[i];
	}

	printf("%d\n", max({f1[n], f2[n], f3[n]}));

	return 0;
}


Measured memory_bytes: 2560
// G - Longest Path
// O(V)
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> pii;
 
const ll inf = 1e15L;
const int maxn = 3000;
double p[maxn];
double dp[maxn][maxn];
 
int main(){
    // freopen("input.txt", "r", stdin);
    // ios_base::sync_with_stdio(0);
    // cin.tie(0); 
    int n;
    scanf("%d", &n);
    memset(p, 0, sizeof(p));
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1.;
    for (int i = 1; i <= n; ++i)
    {
         scanf("%lf", &p[i]);
         dp[i][0] = dp[i-1][0] * (1-p[i]);
         // dp[i][i] = dp[i-1][i-1] * p[i];
    }
    
    //dp[i][j] - i is the number of current coins, j is the number fo heads
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= i; ++j){
            dp[i][j] = p[i] * dp[i-1][j-1] + (1 - p[i]) * dp[i-1][j];
        }
    }
    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j <= n; ++j)cout << dp[i][j] << " ";
    //         cout << endl;
    // }
    double res = 0.;
    for (int head = 1; head <= n; ++head)
    {
        int tail = n - head;
        if(head > tail)res = res + dp[n][head];
    }
    printf("%.10lf\n", res);
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

const int MOD = (int)1e9 + 7;
const int MAX_N = (int)2e5 + 777;

int a[MAX_N], n;

inline int add(int x, int y)
{
	int r = x + y;

	return (r >= MOD ? r - MOD : r);
}

inline int mult(int x, int y)
{
	return (x * 1LL * y) % MOD;		
}

void solve()
{
	cin >> n;
	n *= 2;

	for(int i = 0; i < n; ++i)
	{
		char ch;
		cin >> ch;

		a[i] = (ch == 'B');
		a[i] ^= (i & 1);
	}

#ifdef __LOCAL
	for(int i = 0; i < n; ++i)
		cout << a[i] << " ";

	cout << endl;
#endif

	int bal = 0;

	for(int i = 0; i < n; ++i)
	{
		bal += (a[i] ? +1 : -1);

		if(bal < 0)
		{
			cout << "0" << endl;
			return;
		}
	}

	if(bal > 0)
	{
		cout << "0" << endl;
		return;
	}

	int answ = 1;
	int cnt1 = 0;

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

		if(a[i] == 0)
		{
			answ = mult(answ, cnt1);
			--cnt1;
		}
	}

	for(int i = 1; i <= n / 2; ++i)
		answ = mult(answ, i);

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll>p(n),v(n);
    for(ll i=0;i<n;i++)cin>>p[i];
    for(ll i=0;i<n;i++)cin>>v[i];
    ll ans=INT_MIN;
    for(ll i=0;i<n;i++){
        ll csum=0;
        ll cnt=0,idx=i;
        do{
            if(cnt==k)break;
            idx=p[idx]-1;
            csum+=v[idx];
            ans=max(ans,csum);
            cnt++;
        }while(idx!=i);
        //cout<<cnt<<endl;
        if(csum>0 && cnt<k){
            ll cyc=k/cnt;
            ll rem=k%cnt;
            //cout<<rem<<endl;
            ll sum1=csum*cyc;
            ll sum2=csum*(cyc-1);
            do{
                idx=p[idx]-1;
                sum2+=v[idx];
                ans=max(ans,sum2);
            }while(idx!=i);
            do{
                if(rem==0)break;
                idx=p[idx]-1;
                sum1+=v[idx];
                ans=max(ans,sum1);
                rem--;
            }while(idx!=i);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3740
N = int(input())
segment = []

for _ in range(N):
    x, l = map(int, input().split())
    segment.append([max(0, x-l), x+l])

segment.sort(key=lambda seg: seg[1])

ans = 0
curr_time = -1

for i in range(N):
    if curr_time < segment[i][0]:
        curr_time = segment[i][1] - 1
        ans += 1

print(ans)

Measured memory_bytes: 21336
import java.util.*;
import java.math.*;

class Problem {
  int n;
  long[] a;
  
  public Problem(int n, long[] a) {
    this.n = n;
    this.a = a;
  }

  public void solve() {
    System.out.println(calc());
  }

  public long calc() {
    if (hasAnyZero()) return 0;
    long ans = 1;
    for (int i = 0; i < n; i++) {
      if (1000000000000000000L / ans < a[i]) return -1;
      ans *= a[i];
    }
    return ans;
  }

  public boolean hasAnyZero() {
    for (int i = 0; i < a.length; i++) if (a[i] == 0) return true;
    return false;
  }
}

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    Problem p = new Problem(n, a);
    p.solve();
  }
}



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


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

  ll ret = 0;
  ll last = S.size()-1;
  while(S[last]=='B' && last>0) last--;
  for(int i=S.size()-2; i>=0; i--){
    if(S[i]=='B' && S[i+1]=='W'){
      ret += last - i;
      last--;
      S[i] = 'W';
    }
  }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
using Grid = vector<vector<char>>;
#define vc vector<char>
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
void dfs(string s,ll &n,char c){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    for(char x='a';x<=c+1;x++){
        if(x>c){
            dfs(s+x,n,x);
        }else{
            dfs(s+x,n,c);
        }
    }
    return;
}

int main(){
    ll N;
    cin>>N;
    dfs("a",N,'a');
}

Measured memory_bytes: 1536
# -*- coding:utf-8 -*-

import sys

def func(x):
    return x**2

def rec(x,d):
    return d*func(x)

array = []
for i in sys.stdin:
    array.append(int(i))

for i in range(len(array)):
    d = array[i]
    k = int(600/d)
    result = 0
    for j in range(k):
        result += rec(j*d,d)

    print(result)

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

int main(){
    int n, rp, ans = 0;
    cin >> n;
    int d[n];
    rep(i,n) cin >> d[i];
    rp = (n*n-n)/2;
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll ans = 0;
vector<ll> v(51);
vector<ll> p(51);

void dfs(ll n, ll x){
    if(v[n] - 1 <= x){
        ans += p[n];
    }else if(v[n-1] + 2 < x){
        ans += p[n-1];
        ans += 1;
        dfs(n-1,x - v[n-1] - 2);
    }else if(v[n-1] + 2 == x){
        ans += p[n-1];
        ans += 1;
    }else if(1 < x){
        dfs(n-1,(x-1));
    }
}

int main()
{
    ll n,x;
    cin >> n >> x;
    v[0] = 1;
    p[0] = 1;
    for(int i = 1; i <= 50; i++){
        v[i] = v[i-1] * 2 + 3;
        p[i] = p[i-1] * 2 + 1;
    }
    dfs(n,x);
    cout << ans;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long x = (long)Math.abs(sc.nextLong());
		long k = sc.nextLong();
		long d = sc.nextLong();

		if ( x<=d ) {
			if ( k%2==0 ) System.out.println(x);
			else          System.out.println(d-x);
			System.exit(0);
		}

		long t = x/d ;
		if ( t>=k ) {
			System.out.println(x - d*k);
			System.exit(0);
		}

		long xt = x - d*t ;
		if ( (k-t)%2==0 ) System.out.println(xt);
		else              System.out.println(d-xt);
	}
}

Measured memory_bytes: 35736
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int h, w;

        Scanner s = new Scanner(System.in);
        do{
            h = s.nextInt();
            w = s.nextInt();
            if ((h==0) && (w==0)) break;
            for (int i=0; i<h; i++){
                for (int j=0; j<w; j++){
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }while(true);
    }
}


Measured memory_bytes: 34596
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

#define endl '\n'
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef pair<int, int> ii;
typedef long long LL;
typedef long double LD;

int a[100005];
void solve(){
    int n, res = 0;
    cin >> n;
    FOR(i, 1, n+1) cin >> a[i];
    FOR(i, 1, n+1) {
    	if(a[a[i]] == i) {
    		res += 1;
    	}
    }
    cout << res / 2 << endl;
}

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

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string.h>

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



void solve()
{
	int A[5];
	for (int i = 0; i < 5; ++i)
	{
		cin >> A[i];
	}
	int minIndex = 0;
	int minVal = 100;
	for (int i = 0; i < 5; ++i)
	{
		if (A[i] % 10 == 0)
		{
			continue;
		}
		if (A[i] % 10 < minVal)
		{
			minVal = A[i] % 10;
			minIndex = i;
		}
	}
	int sum = 0;
	for (int i = 0; i < 5; ++i)
	{
		if (i != minIndex)
		{
			sum += A[i];
			if (A[i] % 10 != 0)
			{
				sum += 10 - A[i] % 10;
			}
		}
	}
	sum += A[minIndex];
	cout << sum << endl;
}

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

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

int my_abs(int num){
    if (num > 0)
        return num;
    else
        return -num;
}

int main() {
    int n,s1,s2,min=100000,dis,ite=0,l;
    cin >> n;
    int w[n];

    while (std::cin >> l) {
        w[ite] = l;
        ite++;
        if (ite >= n) {
            break;
        }
    }



    for(int T = 0; T < n; T++) {

        s1=0;
        s2=0;

        for(int i = 0; i <= T; i++){
            s1+=w[i];
        }
        for(int i = T+1; i < n; i++){
            s2+=w[i];
        }

        dis = my_abs(s1-s2);

        if(dis < min)
            min = dis;

    }

    cout << min;

    return 0;
}

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

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);

    vector<int> Adiff(N);
    for (int i = 0; i < N-1; i ++) {
        Adiff.at(i) = A.at(i+1) - A.at(i);
    }
    Adiff.at(N-1) = A.at(0) + K - A.at(N-1);
    int maxindex = 0;
    for (int i = 0; i < N; i ++) {
        if (Adiff.at(i) >= Adiff.at(maxindex)) maxindex = i;
    }
    int ans = K;
    ans -= Adiff.at(maxindex);
    cout << ans << endl;
}

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

int main() {
    int N;
    cin>>N;
    vector<int>P(N);
    for(int i=0;i<N;i++){
        cin>>P[i];
    }
    int count=0;
    int x=P[0];
    for(int i=0;i<N;i++){
        x=min(P[i],x);
        if(P[i]<=x){count++;}
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

bool isallzero(int n[], int m, int num) {
	for (int i = 0; i < num; i++) {
		if (i == m) {
			continue;
		} else if (n[i] != 0) {
			return false;
		}
	}

	return true;
}

int main() {
	while (true) {
		int n, p;
		cin >> n >> p;
		if (n == 0) {
			break;
		}
		
		int bowl = p;
		int candidates[n];
		int current = 0;
		for (int i = 0; i < n; i++) {
			candidates[i] = 0;
		}

		while (true) {
			if (bowl > 0) {
				bowl--;
				candidates[current]++;
				if (bowl == 0 && isallzero(candidates, current, n)) {
					cout << current << endl;
					break;
				}
			} else {
				bowl = candidates[current];
				candidates[current] = 0;
			}
			current = (current + 1) % n;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
lia = list(map(int,input().split()))
count = 0

for i in range(n):
    if lia[i] < 0:
        lia[i] = -lia[i]
        count += 1

if count % 2 == 0:
    print(sum(lia))
else:
    print(sum(lia) - 2 * min(lia))


Measured memory_bytes: 14412
from sys import stdin
from itertools import combinations
N,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = 10**18
for i in combinations(range(1,N),K-1):
    tallest = A[0]
    tmp = 0
    for j in range(1,N):
        if j in i:
            if tallest >= A[j]:
                tmp += (tallest - A[j] + 1)
                tallest = (tallest + 1)
            else:
                tallest = max(tallest,A[j])
        else:
            tallest = max(tallest,A[j])
    ans = min(ans,tmp)
print(ans)

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

int main() {
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2 + y1 - y2;
    y3 = y2 - x1 + x2;
    x4 = x1 - y2 + y1;
    y4 = y1 + x2 - x1;
    
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 3664
import java.util.Scanner;
 
public class Main {
 
    Scanner scanner = new Scanner(System.in);
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        int N=scanner.nextInt();
        int ans=0;
        for(int i=0;i<N;i++){
            ans+=-(scanner.nextInt()-scanner.nextInt()-1);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25832
import sys
x = int(input())

item = int(x / 105) + 2

for a in range(item) :
    for b in range(item - a) :
        for c in range(item - a - b) :
            for d in range(item - a - b - c) :
                for e in range(item - a - b - c - d) :
                    for f in range(item - a - b - c - d -e) :
                        if 100*a + 101*b  + 102*c + 103*d + 104*e + 105*f == x :
                            print("1")
                            sys.exit()
print("0")

Measured memory_bytes: 3064
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        if (a[i] == a[j] || a[j] == a[k]) continue;
        if (a[i] + a[j] > a[k]) ++ret;
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3180
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

struct Point {
	int x;
	int y;
};

// 迷路探索
// 予め端は壁にしておく
const char wall = '#';	// 壁
const char space = '.'; // 通路
std::vector<std::vector<int>> bfs(const std::vector<std::vector<char>>& maze,
								  std::pair<int, int> s) {
	const int h = maze.size();
	const int w = maze[0].size();
	std::vector<std::vector<int>> distances(h, std::vector<int>(w, INF));
	distances[s.second][s.first] = 0;
	std::queue<std::pair<int, int>> q;
	q.push(s);
	while(!q.empty()) {
		std::pair<int, int> p = q.front();
		q.pop();
		int d = distances[p.second][p.first];
		for(size_t i = 0; i < 4; i++) {
			if((p.second + dy[i] < 0 || h <= p.second + dy[i]) ||
			   (p.first + dx[i] < 0 || w <= p.first + dx[i]) ||
			   (distances[p.second + dy[i]][p.first + dx[i]] < INF) ||
			   (maze[p.second + dy[i]][p.first + dx[i]] == wall)) {
				continue;
			}

			distances[p.second + dy[i]][p.first + dx[i]] = d + 1;
			q.push(make_pair(p.first + dx[i], p.second + dy[i]));
		}
	}
	return distances;
}

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	int wc = 0;
	REP(i, h) {
		string line;
		cin >> line;
		REP(j, w) {
			s[i][j] = line[j];
			wc += s[i][j] == wall ? 1 : 0;
		}
	}

	if(s[0][0] == '#') {
		cout << -1 << endl;
		return 0;
	}

	VI2D dists = bfs(s, make_pair(0, 0));
	cout << (dists[h - 1][w - 1] == INF
				 ? -1
				 : (h * w - (dists[h - 1][w - 1] + 1) - wc))
		 << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  long long H, W;

  //unused = scanf("%I64d %I64d", &H, &W);
  unused = scanf("%lld %lld", &H, &W);

  if(H==1 || W==1) printf("%lld", 1);
  else printf("%lld", (H*W+1)/2);

  return 0;
}

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

int main() {
    int N;
    cin >> N;
   
   
   if(N >= 10) {
     N = N%10;
   }

       if(N == 3){
         cout << "bon" << endl;
       }
       else if(N == 0 | N == 1 | N == 6 | N == 8){
         cout << "pon" << endl;
       }
       else{
         cout << "hon" << endl;
       }
    }


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

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
#define mod 1000000007
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}

int main()
{

    string s,t;
    cin>>s>>t;
    int a=0;
    rep(i,0,s.length())if(s[i]!=t[i])a++;
    cout<<a;
}


Measured memory_bytes: 3852
n , k = map(int, input().split())

li = [0]*(n+2)
lis = []
lr=[]
lis2 =[0]*(3*n)
lis2[1]=1
lis2[2]=-1

for i in range(k):
    l,r = map(int, input().split())
    lr.append((l,r))

for i in range(1,n+1):
    lis2[i]+=lis2[i-1]
    lis2[i]%=998244353

    for j,k in lr:
        lis2[i+j]+=lis2[i]
        lis2[i+k+1]-=lis2[i]

print(lis2[n]%998244353)


Measured memory_bytes: 27444
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}


int heap[1000], sz = 0;


void solve(void)
{
  string str;
  cin>>str;
  bool check = 1;
  for (int i = 1; i < str.size(); i++)
  {
    if(str[i] != '9') check = 0;
  }
  
  if(check == 1)
  {
    int A = str[0] - '0';
    cout<<A +9*((int)str.size()-1)<<endl;
    return;
  }
  else if(str.size() == 1)
  {
    cout<<str[0] - '0'<<endl;
  }
  else
  {
    int ANS = 0;
    int A = (int)(str[0] - '0');
    ANS += --A;
    ANS += 9*((int)str.size()-1);
    cout<<ANS<<endl;
  }
  
  
  return;
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()



const int MAX_N=100010;
vector<bool> sss(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  ll n;
  cin>>n;
  vector<bool> p=sss();
 
  while(!p[n]){
    n++;
  }
  cout<<n<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
//const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll k; cin >> k;
    ll seq = 0;
    rep(i, k) {
        seq = (seq * 10 + 7) % k;
        if(seq == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    cin >> a >> v;

    cin >> b >> w;
    cin >> t;

    d = abs(a - b);
    x = v - w;

    if(d <= x * t)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" <<endl;
    }
    

    //cout << 0 << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 3636
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)
    val as = Array.fill(n) {
      in.readLine().toCharArray
    }
    val bs = Array.fill(m) {
      in.readLine().toCharArray
    }

    for {
      ax <- 0 until n - m + 1
      ay <- 0 until n - m + 1
    } {
      @tailrec
      def fit(bx: Int, by: Int): Boolean = {
        by == m || as(ax + bx)(ay + by) == bs(bx)(by) && fit((bx + 1) % m, by + (bx + 1) / m)
      }
      if (fit(0, 0)) {
        out.println("Yes")
        out.flush()
        return
      }
    }

    out.println("No")
    out.flush()
  }
}


Measured memory_bytes: 25536