akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// vector 型
template<class T>
std::ostream& operator<<(std::ostream& os, const vector<T>& v){
  // ここでストリームに obj を書き込みます。
  for(const T& t:v) cout << t << " ";
  return os;
}

li gcd(li a,li b){
  return (b==0)?a:gcd(b,a%b);
}

void next(int& a){
  do{
    a++;
  }while(gcd(6,a)==1);
}


int main(){
  int n; cin >>n;
  int a=1;li s=0;
  vector<int> v;
  if(n==3){
    print(2,3,25);
    return 0;
  }
  rep(i,n-2){
    next(a);
    s+=a;
    v.push_back(a);
  }
  next(a);
  while(gcd(6,s+a)==1) next(a);
  v.push_back(a);
  s+=a;
  next(a);
  while((s+a)%6) next(a);
  v.push_back(a);
  print(v);
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  cout << a+b+c - max(a,max(b,c)) << endl;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]
inf = float("inf")
dp = [[inf]*(100000+1) for _ in range(n+1)]
dp[0][0] = 0
ans = 0
for i in range(n):
    for v in range(100001):
        if v - ls[i][1] >= 0:
            dp[i+1][v] = min(dp[i][v],dp[i][v-ls[i][1]]+ls[i][0])
        else:
            dp[i+1][v] = dp[i][v]
for j in range(100001):
    if dp[n][j] <= w:
        ans = j
print(ans)

Measured memory_bytes: 249132
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
const LL MOD = (LL)1e9 + 7;
LL fac[MAXN], inv[MAXN];
int visit[MAXN];

void init() {
     inv[0] = fac[1] = inv[1] = 1;
     for (int i = 2; i < MAXN; i++) inv[i] = MOD - ((MOD / i) * inv[MOD % i]) % MOD;
     for (int i = 2; i < MAXN; i++) inv[i] = (inv[i - 1] * inv[i]) % MOD;
     for (int i = 2; i < MAXN; i++) fac[i] = (fac[i - 1] * i) % MOD;
}

LL C(int n, int m) {
   if (!m || !n) return 1;
   LL ans = fac[n];
   ans = (fac[n] * inv[n - m]) % MOD;
   return (ans * inv[m]) % MOD;
}

int main() {
    int N;
    init();
    scanf("%d", &N);
    int tg, fs;
    for (int i = 1; i <= N + 1; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (visit[tmp]) {
           fs = visit[tmp];
           tg = i;
        } else visit[tmp] = i;
    }
    LL cnt = (fs - 1) + (N + 1 - tg);
    for (int i = 1; i <= N + 1; i++) {
        LL ans = C(N + 1, i);
        if (i - 1 <= cnt) {
           LL tmp = C(cnt, i - 1);
           ans -= tmp;
        }
        ans = (ans + MOD) % MOD;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3584
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

struct Edge{ int dst, cost; };
typedef vector<Edge> Node;
typedef vector<Node> Graph;
const int INF = 1000000000;
void add_edge(Graph& G, int a, int b) {
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
}
vector<int> SPFA(const Graph& G, int s) {
    int n = G.size();
    vector<int> dist(n, INF);
    vector<bool> inque(n);
    queue<int> que;

    dist[s] = 0;
    que.push(s);
    inque[s] = true;
    while(!que.empty()){
        int v = que.front();
        que.pop();
        inque[v] = false;
        for(Edge e : G[v]) {
            if(dist[e.dst] > dist[v] + e.cost) {
                dist[e.dst] = dist[v] + e.cost;
                if(!inque[e.dst]) {
                    que.push(e.dst);
                    inque[e.dst] = true;
                }
            }
        }
    }
    return dist;
}
int main(){
    iostream_init();
    int N, M, s, t;
    while(cin >> N >> M >> s >> t) {
        s--; t--;
        Graph G(N);
        REP(i, M) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            add_edge(G, a, b);
        }

        vector<int> ds = SPFA(G, s);
        vector<int> dt = SPFA(G, t);
        map<int, int> cnt;
        for(int x : dt) cnt[x]++;
        int D = ds[t];
        long long ans = 0;
        REP(i, N) {
            // ds[i] + 1 + E == D-1
            int E = D - ds[i] - 2;
            ans += cnt[E];
        }
        cout << ans << endl;

    }

    return 0;
}

/* vim:set foldmethod=marker: */

Measured memory_bytes: 9148
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const C = arg[0];
    const alphabets = "abcdefghijklmnopqrstuvwxyz".split("");
    
    const temp = alphabets.indexOf(C);
    
    console.log(alphabets[temp + 1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21956
/*g++ main.cpp -o main.out*/
/*./main.out*/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

map<int,int> m,t;
int main()
{
    int n,mm;
    cin>>n>>mm;
    int a=0,w=0;
    while(mm--)
    {
        int x;
        string s;
        cin>>x>>s;
        if(s=="AC")
        {
            if(m[x]==0)
            {
                a++;
                m[x]=1;
                w+=t[x];
            }
            else if(m[x]==1)
            {
                continue;
            }
        }
        else if(s=="WA")
        {
            if(m[x]==0)
            {
                t[x]++;
            }
            else if(m[x]==1)
            {
                continue;
            }
        }
    }
    cout<<a<<' '<<w<<endl;
    return 0;
}

















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

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

// ABC131-C

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
 
ll lcm(ll a, ll b) {
    if (a < b) swap(a, b);
    return a * b / gcd(a, b);
}


int main() {

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

    A--;

    ll ac = A / C;
    ll ad = A / D;
    ll acd = A / lcm(C,D);
    ll a = A - (ac + ad - acd);

    ll bc = B / C;
    ll bd = B / D;
    ll bcd = B / lcm(C,D);
    ll b = B - (bc + bd - bcd);

    cout << b-a << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long x;
	long glad = 0;
	scanf("%ld", &x);
	if(x/500>0) {
	glad += x / 500 * 1000;
	x = x - glad / 2;
	}
	if(x/5>0) {
	glad += x / 5 * 5;
	
	}
printf("%ld\n", glad);
	return 0;
}

Measured memory_bytes: 128
// ------------------------------------
// Date:2018/ 2/27
// Problem:ABC 079 GoodInteger a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main()
{
  char lastNum;
  int cnt = 0;
  string inputStr;
  cin >> inputStr;
  
  REP(i, inputStr.size()) {
    if (i == 0) {
      lastNum = inputStr[0];
    } else {
      if (lastNum != inputStr[i]) {
        if (i == 1) {
          lastNum = inputStr[1];
        } else {
          cout << "No" << endl;
          return 0;
        }
      } else {
        ++cnt;
        if (cnt >= 2) {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 256
s = int(input())
MAX = 10**6
def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n + 1

l = []
l.append(s)
for i in range(2,MAX+1):
    temp = f(s)
    if temp in l:
        print(i)
        exit()
    l.append(temp)
    s = temp


Measured memory_bytes: 2940
<?php
    $a = fgets(STDIN);
    const INT = 753;
    $min = 753;

    for($i=0; $i<strlen($a);$i++) {
        $tmp = (int)substr($a, $i, 3);
        if(strlen($tmp)!=3)continue;

        $diff = abs(INT - $tmp);
        if($diff < $min) {
            $min = $diff;
        }
    }

    echo $min;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    string a;
    int ans = 0;
    cin >> a ;
    //*/

    if(a.at(0) == '+'){
        ans++;
    } else {
        ans--;
    }

    if(a.at(1) == '+'){
        ans++;
    } else {
        ans--;
    }

    if(a.at(2) == '+'){
        ans++;
    } else {
        ans--;
    }

    if(a.at(3) == '+'){
        ans++;
    } else {
        ans--;
    }

    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if( a <= 8 && b <= 8 ){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    */
    
    cout << ans << endl;

    return 0; 
}


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

ll f(ll n){
    if(n%4==0) return n;
    if(n%4==1) return 1;
    if(n%4==2) return n^1;
    if(n%4==3) return 0;
}

int main(){
    ll a, b;
    cin >> a >> b;
    if(a==0){
        cout << f(b) << endl;
    }else{
        cout << (f(b)^f(a-1)) << endl;
    }
    return 0;
    // ll a, b;
    // cin >> a >> b;
    // ll num = b-a+1;

    // if(a==b){
    //     cout << a << endl;
    //     return 0;
    // }

    // ll out = 0;
    // rep(i, 41){
    //     // cout << out << endl;
    //     ll tmp1 = num / pow(2, i+1);
    //     ll rem = num - tmp1 * pow(2, i+1);
    //     // cout << rem << endl;
    //     if(rem!=0){
    //         ll tmp2 = a / pow(2, i+1);
    //         ll rem2 = a - tmp2 * pow(2, i+1);
    //         int tmp=0;
    //         if(rem2 >= pow(2, i)){
    //             if(rem2+rem-1 <= pow(2, i+1)-1){
    //                 tmp = rem;
    //             }else{
    //                 tmp = (pow(2, i+1)-rem2);
    //             }
    //         }else{
    //             if(rem2+rem-1-pow(2, i)>0){
    //                 tmp = rem2+rem-pow(2, i);
    //             }
    //         }
    //         cout << tmp << endl;
    //         tmp = tmp%2;
    //         out += pow(2, i)*tmp;
    //     }    
    // } 
    // cout << out << endl;
    // return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int OR3(int num);
int main(void) {
    int m,n;
    while (scanf("%d",&n)!=EOF&&n!=0) {
        scanf("%d",&m);
        printf("%d\n",OR3(m)-OR3(n-1));
    }
    return 0;
}

int OR3(int num) {
    if (num<=0) return 0;
    int i,j,k,count=0;
    for (i=0; pow(2,i)<=num; i++) {
        for (j=0; pow(2,i)*pow(3,j)<=num; j++) {
            for (k=0; pow(2,i)*pow(3,j)*pow(5,k)<=num; k++) {
                count++;
            }
        }
    }
    return count;
}

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

typedef long long ll;
const int maxn=2e5+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n;
vector<int> G[maxn],v,v1,v2;
int odd,even;

int depth[maxn];
int ans[maxn];

void dfs(int now,int p)
{
    if (depth[now]&1) odd++,v1.pb(now);
    else even++,v2.pb(now);
    for (int i:G[now])
        if (i!=p)
    {
        depth[i]=depth[now]+1;
        dfs(i,now);
    }
}

int32_t main()
{
    IOS
    cin>>n;
    for (int i=1;i<=n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
    dfs(1,-1);

    for (int i:v1) v.pb(i);
    for (int i:v2) v.pb(i);
    if (odd<(n+2)/3)
    {
        int id=0;
        for (int i=3;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=1;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=2;i<=n;i+=3) ans[v[id++]]=i;
    }
    else if (even<(n+2)/3)
    {
        int id=0;
        for (int i=2;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=1;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=3;i<=n;i+=3) ans[v[id++]]=i;
    }
    else if (odd<even)
    {
        int id=0;
        for (int i=1;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=3;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=2;i<=n;i+=3) ans[v[id++]]=i;
    }
    else
    {
        int id=0;
        for (int i=2;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=3;i<=n;i+=3) ans[v[id++]]=i;
        for (int i=1;i<=n;i+=3) ans[v[id++]]=i;
    }
    for (int i=1;i<=n;i++) cout<<ans[i]<<" \n"[i==n];
}



Measured memory_bytes: 20336
#include <stdio.h>

int main(){
    int x[5];
    int i;

    for(i=0; i<5; i++) scanf("%d", &x[i]);

    for(i=0; i<5; i++){
        if(x[i] == 0) break;
    }

    printf("%d\n", i+1);
    return 0;
}

Measured memory_bytes: 1680
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_H = 400, MAX_W = 400;
int H, W;
int field[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W];

ll dfs(int x, int y, ll& count) {
    visited[x][y] = true;

    ll res = 0;
    for (int k = 0; k < 4; ++k) {
        int nx = x + dx[k], ny = y + dy[k];
        if (0 <= nx && nx < H && 0 <= ny && ny < W && !visited[nx][ny] && field[nx][ny] != field[x][y]) {
            res += dfs(nx, ny, count);
        }
    }

    if (field[x][y] == 0) ++res;
    if (field[x][y] == 1) ++count;

    return res;
}

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

  cin >> H >> W;
  rep(i, H) {
      string str;
      cin >> str;
      rep(j, W) {
          if (str[j] == '#') field[i][j] = 1;
          else field[i][j] = 0;
      }
  }

  ll ans = 0;
  for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
          if (field[i][j] == 1 && !visited[i][j]) {
              ll count = 0;
              ll t = dfs(i, j, count);
              ans += t*count;
          }
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);


    int n,k;
    cin >> n >> k;
    int ary[n];
    rep(i,n) cin >> ary[i];

    sort(ary, ary+n);
    int ans = 0;
    rep(i,k) ans += ary[i];
    cout << ans << endl;
}


Measured memory_bytes: 3664
#include <iostream>

using namespace std;
const int mod=1e9+7 ;
char a[1100][1100] ;
int b[1100][1100] ;
int main()
{
int r,c;
cin >> r >> c ;
for (int i=1;i<=r;i++)
for (int j=1;j<=c;j++)
cin >> a[i][j] ;
b[1][1]=1 ;
for (int i=1;i<=r;i++){
for (int j=1;j<=c;j++){
if (a[i][j]=='#')
continue ;
if (a[i-1][j]!='#')
b[i][j]+=b[i-1][j] ;
if (a[i][j-1]!='#')
b[i][j]+=b[i][j-1] ;
b[i][j]%=mod ;
}
}
cout << b[r][c] ;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  
  rep(i,n) cin >> x[i];
  
  int ans = 0;
  rep(i,n){
    ans += min(x[i] * 2, (k - x[i]) *2);
  }
  
  cout << ans;
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define rep(i, V) for (int i = 0; i < V; i++)
#define repr(i, V) for (int i = V-1; i >= 0; i--)
#define repval(i, a, V) for (int i = a; i < V ; i++)
#define all(x) x.begin(), x.end()
#define ld long double
#define eps 0.0000000001
#define mod 1000000007
#define inf 1e16
#define vec vector
#define each(i, mp) for(auto& i:mp)

int nmax = 1e5;
using edge = struct{int to; ll cost;};
vector<vector<edge>> tree(nmax);
vector<ll> depth(nmax, 0);

void dfs(int v, int p, ll d){
    depth[v] = d;
    for (auto e: tree[v]){
        if (e.to == p) continue;
        dfs(e.to, v, d + e.cost);
    }
}

int main(){
    int n;
    cin >> n;
    int a,b;
    ll c;
    rep(i, n-1){
        cin >> a >> b >> c;
        a--, b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }

    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1, 0);
    
    int x, y;
    rep(i, q){
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }
}

Measured memory_bytes: 15580
while True:
    N, X = [int(i) for i in input().split()]
    if(N==0 and X==0):
        break

    cnt = 0
    for i in range(1, N):
        for j in range(i+1, N):
            if(j<X-i-j<=N):
                cnt += 1
    print(cnt)



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

int main(){
    int N,K,x,ans;
    ans = 0;
    scanf("%d%d",&N,&K);
    for (int i=0;i<N;i++){
        scanf("%d",&x);
        if (x-K>0){
            ans += x-K;
        }else if (2*x-K<=0){
        ans += x;
        }else{
        ans += K-x;
        }
    }
    printf("%d\n",2*ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    bool nega = A < 0,negb = B < 0;
    int ans;
    if(abs(A) == abs(B)){
        ans = nega ^ negb;
    }else{
        int dif = nega + negb;
        if(abs(A) > abs(B))dif = 2 - dif;
        ans = abs(abs(A) - abs(B)) + dif;
    }
//    if(B > A)ans = min(ans,B-A);
    if(B == 0)ans--;
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long fact[110000];
long long finv[110000];
long long inv[110000];
long long dp[3100][6100];
long long C(int a,int b){
	if(b<0||a<b)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
int main(){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<110000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<110000;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	int a,b;scanf("%d%d",&a,&b);
	dp[0][0]=1;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(!dp[i][j])continue;
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
			dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
			dp[i+1][j+2]=(dp[i+1][j+2]+dp[i][j])%mod;
		}
	}
	long long ret=0;
	for(int i=0;i<b;i++)ret=(ret+dp[a][i])%mod;
	for(int i=1;i<=a;i++){
		long long ks=C(a,i);
		for(int j=1;j*2<=a;j++){
			if(i+1>b||i*2-j*2+1<=b)continue;
		//	printf("%d %d: %lld\n",i,j,C(i-j*2,b-i-1));
			ret=(ret+C(i-j*2,b-i-1)*ks)%mod;
		}
		if(i*2>b&&b%2==1){
			ret=(ret+ks)%mod;
		}
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 144512
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define ll long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,t;
 
bool vis[maxn];
char s[5];

int a[maxn];
 
int main()
{
    int ans = 0,res = 0;
    cin>>n>>m;
    for(int i = 0,x; i < m; i++) 
    {
        cin>>x>>s;
        if(s[0] == 'A' && !vis[x])
        {
            ans++;vis[x] = 1;
        }
        if(s[0] == 'W' && !vis[x])
        {
            a[x]++;
        }
    }
    for(int i = 1; i <= n; i++) 
    {
        if(vis[i]) res += a[i];
    }
    cout<<ans<<' '<<res<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e5+10, mod= 998244353;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int suff=1;
	for(int i=k-1;i>0 && a[i]>a[i-1] ;i--) suff++;
	
	set<int> s;
	for(int i=0;i<k;i++)s.insert(a[i]);
	
	int res=0,sorted=0;
	if(suff!=k) res++;
	else sorted=1;
	
	for(int i=0;i<n-k;i++){
		suff=min(suff,k-1);
		if( a[i+k] > a[i+k-1] ) suff++;
		else suff=1;
		if(suff==k) sorted=1;
		
		int mn=*s.begin(), mx=*(--s.end());
		s.erase(s.find(a[i])); s.insert(a[i+k]);
		
		if( mn==a[i] && mx < a[i+k] ){
		
			continue;
		}
		
		if(suff!=k) res++;
	}
	cout<<res+sorted;
}


Measured memory_bytes: 10368
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (20)
#define MOD (998244353)

int a[MAXN];
int b[MAXN];
int c[MAXN];

int main(void)
{
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++) scanf("%d",&(a[i]));
    for(int i=0;i<n;i++) scanf("%d",&(b[i]));
    for(int i=0;i<n-1;i++) scanf("%d",&(c[i]));

    int ans = 0;
    for(int i=0;i<n;i++)
    {
        ans += b[a[i]-1];
        if(i>=1 && a[i]==(a[i-1]+1))
        {
            ans += c[a[i-1]-1];
        }
    }

    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n;
    std::cin >> n;

    std::vector<std::unordered_map<std::string, long long>> dp(n + 1);

    auto is_ok = [](std::string last_four) {
        for (int i = 0; i < 4; i++) {
            std::string t = last_four;
            if (i < 3) {
                std::swap(t[i], t[i + 1]);
            }

            if (t.find("AGC") != std::string::npos) {
                return false;
            }
        }

        return true;
    };

    auto dfs = [&](auto f, int idx, std::string last_three) -> long long {
        if (idx == n) {
            return 1;
        }

        if (dp[idx].count(last_three)) {
            return dp[idx][last_three];
        }

        long long val = 0;
        for (auto c : { 'A', 'G', 'C', 'T' }) {
            if (is_ok(last_three + c)) {
                val += f(f, idx + 1, last_three.substr(1, 2) + c) % mod;
                val %= mod;
            }
        }

        dp[idx][last_three] = val;
        return val;
    };

    std::cout << dfs(dfs, 0, "TTT") << std::endl;
}


Measured memory_bytes: 896
N,M=map(int,input().split())
A=0
PE=0
PRO=[[] for i in range(N)]
for i in range(M):
  P,S=input().split()
  P=int(P)-1
  PRO[P].append(S)
#print(PRO)
for i in range(N):
  tmp=0
  for j in range(len(PRO[i])):
    flag=False
    if PRO[i][j]=='AC':
      A+=1
      flag=True
    if PRO[i][j]=='WA':
      tmp+=1
    if flag:
      PE+=tmp
      break
print(A,PE)

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

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

int a[100005];

int main() {
	int n, k;
	cin >> n >> k;
	bool flag = 0;
	for (int i = 0; i<n; i++) {
		cin >> a[i];
		if (a[i] >= k) { flag = 1; }
	}
	if (!flag) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	for (int i = 1; i<n; i++) {
		a[i] = lcd(a[i], a[i - 1]);
	}
	if (k % a[n - 1] == 0) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int n,r,i,minp,maxp;

  scanf("%d",&n);
  scanf("%d",&r);

  minp=r;
  maxp=0-r;
  for(i=1;i<n;i++){
    scanf("%d",&r);
    if(maxp<r-minp)maxp=r-minp;
    if(minp>r)minp=r;
  }

  printf("%d\n",maxp);

  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define pii pair<int,int>
#define INF 1000000000
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int a,b,t;

int main(){
    fastio;
    cin>>a>>b>>t;
    int d = a;
    int sum = 0;
    while(a <= t){
        sum += b;
        a += d;
    }
    cout<<sum<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
const ll MOD=1e9+7;
ll mod(ll x)
{
   return (x%MOD+MOD)%MOD;
   // works for neg and pos values of x.
}
ll mul(ll a,ll b)
{
    return mod(mod(a)*mod(b));
}
bool comp(ll a, ll b)
{
    return a>b;
}
void solve()
{
       ll n,k;
       cin>>n>>k;
       vector <ll> pos,neg;
       fo(i,0,n)
       {
            ll x;
            cin>>x;
            if(x>0)
            {
                pos.pb(x);
            } 
            else
            {
                neg.pb(x);
            }
       }
       ll ans=1;
       if(pos.size()!=0)
       {
            if(k%2!=0)
            {
                sort(pos.begin(),pos.end());
                ans=mul(ans,pos.back());
                pos.pop_back();
                k-=1;
            }
            vector <ll> ok;
            sort(pos.begin(),pos.end(),comp);
            sort(neg.begin(),neg.end());
            for(ll i=0;(i+1)<pos.size();i+=2)
            {
                ok.pb(pos[i]*pos[i+1]);
            }
            for(ll i=0;(i+1)<neg.size();i+=2)
            {
                ok.pb(neg[i]*neg[i+1]);
            }
            if(pos.size()%2!=0 and neg.size()%2!=0)
            {
                ok.pb(pos.back()*neg.back());
            }
            sort(ok.begin(),ok.end(),comp);
            //deb(ok.size());
            fo(i,0,k/2)
            {
                ans=mul(ans,ok[i]);
            }
            cout<<ans<<endl;

       }
       else
       {
            sort(neg.begin(),neg.end());
            if(k%2!=0)
            {
                reverse(neg.begin(),neg.end());
            }
            fo(i,0,k)
            {
                ans=mul(ans,neg[i]);
            }
            cout<<ans<<endl;
       }
}
int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 6552
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> h(n);
  for_each(h.begin(), h.end(),[](auto&e){
    cin>>e;
  });
  vector<int> dp(n,0);
  dp[1]=abs(h[1]-h[0]);
  for (int i = 2; i < n; ++i)
  {
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),
      dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<dp.back()<<endl;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
ll ans[1004][1004];

int main() {
    FAST

    ll n,m,la,lb;
    cin>>n>>m;
    string st[n];
    for(la=0;la<n;la++)
        cin>>st[la];

    memset(ans, 0, sizeof(ans));

    ans[1][1]=1;
    for(la=1;la<=n;la++){
        for(lb=1;lb<=m;lb++){
            if(la==1 && lb==1)
                continue;
            if(st[la-1][lb-1]=='#')
                ans[la][lb]=0;
            else
                ans[la][lb]=(ans[la-1][lb]+ans[la][lb-1])%MOD;
        }
    }

    // for(la=1;la<=n;la++){
    //     for(lb=1;lb<=m;lb++)
    //         cout<<ans[la][lb]<<' ';
    //     cout<<endl;
    // }

    cout<<ans[n][m]<<endl;

    return 0;
}

Measured memory_bytes: 12580
#include <iostream>
#include <algorithm>
using namespace std;
long long n;
long long  a,b,c;

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

int main() {
	cin >> n;
	cin >> a;
	for (int i = 0; i < n-1; i++) {
		cin >> b;
		a = a/ gcd(max(a, b), min(a, b))*b;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let ans = if S.len() == 2 {
        S.iter().map(|&c| c).collect::<String>()
    } else {
        S.iter().rev().map(|&c| c).collect::<String>()
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

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

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

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

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

const int MAX = 3 * 1000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

int dp[MAX][MAX][2];

void ADD(int& key, int val)
{
	key += val;
	if (key >= MOD) key -= MOD;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	dp[0][0][1] = 1;
	FOR(j, 1, n + 1)
	{
		dp[0][j][0] = 1;
	}

	FOR(i, 0, m)
	{
		FOR(j, 0, n + 1)
		{
			FOR(t, 0, 2)
			{
				if (j > 0)
				{
					int newT = j == 1 ? 1 : t;
					ADD(dp[i + 1][j - 1][newT], dp[i][j][t]);
				}

				if (j < n)
				{
					ADD(dp[i + 1][j + 1][t], dp[i][j][t]);
				}

				if (j < n)
				{
					ADD(dp[i + 1][j][t], dp[i][j][t]);
				}

				if (j)
				{
					int newT = j == 1 ? 1 : t;
					ADD(dp[i + 1][j][newT], dp[i][j][t]);
				}
			}
		}
	}

	//FOR(i, 0, m + 1)
	//{
	//	FOR(j, 0, n + 1)
	//	{
	//		FOR(t, 0, 2)
	//		{
	//			cout << i << " " << j << " " << t << ": " << dp[i][j][t] << endl;
	//		}
	//	}
	//}

	int ans = 0;
	FOR(i, 0, n + 1)
	{
		ADD(ans, dp[m][i][1]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 71936
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+99;
int n,ans,s1[N],s2[N];
char ch[N];
int main()
{
	cin>>n;
	scanf("%s",ch+1);
	for(int i=1;i<=n;i++)s1[i]=s1[i-1]+(ch[i]=='E');
	for(int i=n;i>=1;i--)s2[i]=s2[i+1]+(ch[i]=='W');
	for(int i=1;i<=n;i++)ans=max(ans,s1[i-1]+s2[i+1]);
	cout<<n-1-ans<<endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	ll A, B, C, ans;	cin >> A >> B >> C;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)ans = 0;
	else ans = min(min(A*B, B*C), C*A);
	cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    int n, m;
    n = (s[0] - '0') * 10 + (s[1] - '0');
    m = (s[2] - '0') * 10 + (s[3] - '0');

    if (1 <= n && n <= 12 && !(1 <= m && m <= 12))
        cout << "MMYY" << endl;
    else if (!(1 <= n && n <= 12) && 1 <= m && m <= 12)
        cout << "YYMM" << endl;
    else if (1 <= n && n <= 12 && 1 <= m && m <= 12)
        cout << "AMBIGUOUS" << endl;
    else
        cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 256
//                             ¯\_(ツ)_/¯   
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mma,ava,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define ll long long
 
 
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
 
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

	int x;

	cin>>x;

	if(x>=400 && x<=599)cout<<"8";
	else if(x>=600 && x<=799)cout<<"7";
	else if(x>=800 && x<=999)cout<<"6";
	else if(x>=1000 && x<=1199)cout<<"5";
	else if(x>=1200 && x<=1399)cout<<"4";
	else if(x>=1400 && x<=1599)cout<<"3";
	else if(x>=1600 && x<=1799)cout<<"2";
	else cout<<"1";
	
	
}

Measured memory_bytes: 3648
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

using namespace std;

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}
template <class Con>
string concat(const Con &c, const string &spr){
	stringstream ss;
	typename Con::const_iterator it = c.begin(), en = c.end();
	bool fst = true;
	for(; it != en; ++it){
		if(!fst){ ss << spr; }
		fst = false;
		ss << *it;
	}
	return ss.str();
}

template <class Con, class Fun>
vector<typename Con::value_type> cfilter(const Con &c, Fun f) {
	vector<typename Con::value_type> ret;
	typename Con::const_iterator it = c.begin(), en = c.end();
	for(; it != en; ++it){
		if(f(*it)){
			ret.emplace_back(*it);
		}
	}
	return ret;
}
#if __cplusplus >= 201103L
template <class Con, class Fun>
auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> {
	vector<decltype(f(*c.begin()))> ret;
	ret.reserve(c.size());
	for(const auto &x: c){
		ret.emplace_back(f(x));
	}
	return ret;
}
#endif


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define tget(t,i) get<i>(t)

#define MOD 998244353LL
#define EPS 1e-8

void add(LL &x, LL y){
	x = (x + y + MOD) % MOD;
}

void mainmain(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector<int> ls(m), rs(m);
	for(int i = 0; i < m; ++i){
		scanf("%d%d", &ls[i], &rs[i]);
	}
	vector<LL> dp(n + 9);
	dp[1] = 1;
	dp[2] = -1;
	for(int i = 1; i <= n; ++i){
		add(dp[i], dp[i - 1]);
		for(int j = 0; j < m; ++j){
			add(dp[min(i + ls[j], n + 8)], dp[i]);
			add(dp[min(i + rs[j] + 1, n + 8)], -dp[i]);
		}
	}
	printf("%lld\n", dp[n]);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(const exception &e){
	cerr << "exception: " << e.what() << endl;
	abort();
}
catch(...){
	cerr << "exception" << endl;
	abort();
}


Measured memory_bytes: 4872
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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


int N, cnt;
VI A;

void dfs(int rest, bool even){
    if(!rest){
        if(even) ++cnt;
        return;
    }
    FORS(i, -1, 1){
        dfs(rest-1, (even || !((A[N - rest] + i) % 2)));
    }
}

int main(){
    cin >> N;
    A.resize(N);
    REP(i, N) cin >> A[i];
    dfs(N, false);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x)
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

class Solver {
public:
	int N;
	vector<int> a;
	
	void solve() {
		cin >> N;
		a.resize(N);
		rep(i, N) cin >> a[i];

		cout << sum(all(a)) - N << endl;
	}
};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}

// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;

// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;

// #define cin mycin
// #define cout mycout
// #define endl '\n'

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]).sort();

    int m = a[$-1];
    int r = -1;
    int dif = 10^^9 * 2 + 1;

    foreach (i ; 0 .. n-1) {
        if (abs(2*a[i] - m) < dif) {
            dif = abs(2*a[i] - m);
            r = a[i];
        }
    }

    writefln("%d %d", m, r);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 4344
#include<iostream>
#include<algorithm>
using namespace std;
long long n, a;
int main() {
	cin >> n >> a;
	long long maxn = n;
	for (int i = 2; i <= 40; i++) {
		long long D = 1, E = 1, F = i;
		while (true) {
			if (F == 0) { E++; F = i; }
			D /= E; D *= (E + 1); F--;
			if (D >= n) { maxn = min(maxn, 1LL * (i - 1)*a + E*F + (E + 1)*(i - F)); break; }
		}
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    long k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        if (i >= s.size()) {
            cerr << "Err\n";
            return 1;
        }
        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << "1\n";
    return 0;
}

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

int main() {
    int N;

    cin >> N;
    while (N > 0) {
        int dig = N%10;
        if (dig == 7) {
            cout << "Yes\n";
            return 0;
        }

        N/=10;
    }

    cout << "No\n";
}


Measured memory_bytes: 3624