akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *pa,*le,*ri;
};

struct Node *ro,*NIL;

void insert(int);
void pre(struct Node *);
void ino(struct Node *);
struct Node * find(struct Node *,int);
struct Node * minimum(struct Node *);
struct Node * successor(struct Node *);
void delete(struct Node *);

int main(){
  int num,buf;
  int i;
  char word[10];
  struct Node * buff;
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    scanf("%s",word);
    scanf("%d",&buf);
    if(word[0]=='i'){
      insert(buf);
    }else if(word[0]=='p'){
      ino(ro);
      printf("\n");
      pre(ro);
      printf("\n");
    }else if(word[0]=='f'){
      if((buff=find(ro,buf))!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(word[0]=='d'){
      delete((buff=find(ro,buf)));
    }
  }
  return 0;
}

void insert(int buf){
  struct Node *x,*y,*z;
  y=NIL;
  x=ro;

  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=buf;
  z->le=NIL;
  z->ri=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->le;
    else x=x->ri;
  }
  z->pa=y;
  if(y==NIL) ro=z;
  else if(z->key < y->key)y->le=z;
  else y->ri=z;
}

void pre(struct Node *ro){
  if(ro==NIL) return;
  printf(" %d",ro->key);
  pre(ro->le);
  pre(ro->ri);
}

void ino(struct Node *ro){
  if(ro==NIL) return;
  ino(ro->le);
  printf(" %d",ro->key);
  ino(ro->ri);
}

struct Node * find(struct Node *x,int buf){
  while(x!=NIL&&buf!=x->key){
    if(buf < x->key) x=x->le;
    else x=x->ri;
  }
  return x;
}

struct Node * successor(struct Node *buf){
  struct Node * temp;
  if(buf->ri != NIL){
    return minimum(buf->ri);
  }
  temp = buf->pa;
  while((temp!= NIL) && (buf == temp->ri)){
    buf=temp;
    temp=temp->pa;
  }
  return temp;
}

struct Node * minimum(struct Node * buf){
  while(buf->le!=NIL){
    buf=buf->le;
  }
  return buf;
}

void delete(struct Node *z){
  struct Node *y,*x;
  if(z->le==NIL||z->ri==NIL) y=z;
  else y=successor(z);
  
  if(y->le!=NIL) x=y->le;
  else x=y->ri;

  if(x!=NIL) x->pa=y->pa;

  if(y->pa==NIL) ro=x;
  else if(y==y->pa->le) y->pa->le=x;
  else y->pa->ri=x;

  if(y != z) z->key=y->key;
}




Measured memory_bytes: 20496
#include <iostream>

long long ext_gcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = ext_gcd(b, a%b, x, y);
  long long old_x = x;
  long long old_y = y;
  x = old_y;
  y = old_x - a/b * old_y;
  return d;
}

int main() {
  int n; std::cin >> n;
  long long mod = 1e9+7;
  // std::cout << mod << std::endl;
  long long x, y;
  long long gcd = ext_gcd(2, mod, x, y);
  int inv2 = x;
  // std::cout << "inv2: " << inv2 << std::endl;

  long long sum = 0;
  long long squ_sum = 0;

  while (n--) {
    long long a; std::cin >> a; 
    sum += a;
    sum %= mod;

    squ_sum += a*a; 
    squ_sum %= mod;
  }

  long long ans = (sum*sum - squ_sum) % mod;
  ans *= inv2;
  ans %= mod;
  if (ans < 0) ans += mod;
  std::cout << ans << std::endl;

  return 0;

}


Measured memory_bytes: 3636
PROGRAM-ID.                      ABC_046_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(9).
    01 N       PIC 9(4).
    01 K       PIC 9(4).
    01 total   PIC 9(10).
    01 ans     PIC X(10).

    01 ZS      PIC Z(11).
    01 DUMMY   PIC X(1).

PROCEDURE                        DIVISION.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO N K.

    MOVE 1 TO total.

    COMPUTE total = K * (K - 1) ** (N - 1)

    MOVE total TO ZS
    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

int main(){
    int n;
    double num;
    cin >> n;
    rep(i, n){
        if ((i + 1) % 2 == 1){
            num++;
        }
    }
    cout << fixed << setprecision(10) <<num / n <<endl;
    return 0;
}

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

signed main(){
  string S;
  cin >> S;
  vector<char> right;
  vector<char> left;
  bool hanten = false;

  int Q;
  cin >> Q;

  rep(i,Q){
    int query;
    cin >> query;
    if(query == 1)hanten = !hanten;
    if(query == 2){
      int f;char c;
      cin >> f >> c;
      if(f == 1)if(hanten)right.push_back(c);else left.push_back(c);
      else if(hanten)left.push_back(c);else right.push_back(c);
    }
  }
  string ans;
  if(hanten){
    for(int i = right.size()-1;i >= 0;i--){
      ans += right[i];
    }
    for(int i = S.length()-1;i >= 0;i--){
      ans += S[i];
    }
    for(int i = 0;i < left.size();i++){
      ans += left[i];
    }
  }
  else{
    for(int i = left.size()-1;i >= 0;i--){
      ans += left[i];
    }
    for(int i = 0;i < S.length();i++){
      ans += S[i];
    }
    for(int i = 0;i < right.size();i++){
      ans += right[i];
    }
  }
  cout << ans;
}



Measured memory_bytes: 4332
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    X_sorted = sorted(X)

    cand1 = X_sorted[N // 2 - 1]
    cand2 = X_sorted[N // 2]

    for target in X:
        if cand1 >= target:
            print(cand2)
        else:
            print(cand1)



Measured memory_bytes: 26772
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f,g,h;
int main()
{
	cin>>a;
	for(b=1;b<=9;b++)
	if(a%b==0&&a/b<=9&&a/b>=1)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

bool fn_is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

bool isOK(int index, int key, vector<ll>& a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key, vector<ll>& a) {
    int ng = -1;
    int ok = a.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key, a)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());

    cout << a[n-1] - a[0] << endl;
}


Measured memory_bytes: 3552
#include <iostream>
using namespace std;
 
int main()
{
	int h, w, ww;

	cin >> h >> w;
 
	while((h != 0) && (w != 0)) {
		while(h--) {
			ww = w;
			while(ww--)
				cout << '#';
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;
	}
	return 0;
}

Measured memory_bytes: 3040
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>

using namespace std;

int h,w,sx,sy,gx,gy;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};

char ma[21][21];
int co[21][21];
bool visited[21][21];

int main(){
    while(cin>>h>>w,h){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                co[i][j]=INT_MAX;
                cin>>ma[i][j];
                if(ma[i][j]=='A'){
                    sx=j,sy=i;
                } else if(ma[i][j]=='B'){
                    gx=j,gy=i;
                }
            }
        }
        queue<pair<pair<int,int>,int> >q;
        q.push(make_pair(make_pair(sx, sy), 0));
        while(q.size()){
           // cout<<q.size()<<endl;
            pair<pair<int,int>,int> p = q.front();
            q.pop();
            if(co[p.first.second][p.first.first]!=INT_MAX){
                continue;
            }
           // cout<<p.first.second<<" "<<p.first.first<<endl;
            co[p.first.second][p.first.first]=p.second;
            for(int i=0;i<4;i++){
                int nx=p.first.first+dx[i];
                int ny=p.first.second+dy[i];
                if(nx>=0&&nx<w&&ny>=0&ny<h&&ma[ny][nx]!='#'&&co[ny][nx]==INT_MAX){
                    q.push(make_pair(make_pair(nx, ny), p.second+1));
                }
            }
           // cout<<q.size()<<endl;
        }
        string pat;
        cin>>pat;
        int go=0;
        for(int j=0;;j++){
            int i=j%pat.length();
         //   cout<<gy<<" "<<gx<<" "<<co[gy][gx]<<" "<<INT_MAX<<endl;
            if(co[gy][gx]<=go){
                cout<<go<<" "<<gy<<" "<<gx<<endl;
                break;
            }
            if(go>100000){
                cout<<"impossible"<<endl;
                break;
            }
            if(pat[i]=='5'){
                
            } else if(pat[i]=='8'){
                gy--;
            } else if(pat[i]=='6'){
                gx++;
            } else if(pat[i]=='4'){
                gx--;
            } else if(pat[i]=='2'){
                gy++;
            }
            gy=max(0,gy);
            gy=min(h-1,gy);
            gx=max(0,gx);
            gx=min(w-1,gx);
            go++;
        }
    }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  string S;
  cin>>S;
  int n=0,w=0,s=0,e=0;
  for(auto&ch : S) {
    if(ch=='N')n++;
    if(ch=='W')w++;
    if(ch=='S')s++;
    if(ch=='E')e++;
  }
  if((n==0&&s>0)||(s==0&&n>0)||(w==0&&e>0)||(e==0&&w>0)) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

int main(){
  int a;
  int b;
  int ans=0;
  cin >> a >> b;
  if(a>9 || b>9){
    ans=-1;
  }
  else{
    ans = a*b;
  }
  cout << ans << endl;
  return 0;
}


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

bool prime[10000005] = {0};

void sprime() {
  int i;
  prime[0] = prime[1] = 1;
  for(i = 2; i < sqrt(10000000); ++i)
    if(!prime[i])
      for(int j = 2; i * j <= 10000000; ++j)
        prime[i * j] = 1;
}

int n;
long long cnt = 0;

int main() {
  int i;
  sprime();
  cin >> n;
  for(i = 2; i <= n; ++i)
    if((!prime[i]) && (!prime[2 + i])) cnt += 2;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 12864
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int n,m,d;
map<int,int>mp;
int main(){
    read(n);
    for (int i=1;i<=n;i++){
        read(d);
        mp[d]++;
    }
    read(m);
    bool flag=true;
    for (int i=1;i<=m;i++){
        read(d);
        if (!mp[d]) flag=false;
        else mp[d]--;
    }
    if (flag) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
int main(void){
 int A,B,C,D;
 scanf("%d",&A);
 scanf("%d",&B);
 scanf("%d",&C);
 scanf("%d",&D);
 if((A+B)>(C+D)) printf("Left\n");
 if((A+B)==(C+D)) printf("Balanced\n");
 if((A+B)<(C+D)) printf("Right\n");
 return 0;
 }

Measured memory_bytes: 128
#include <stdio.h>
main()
{
  int n;
  scanf("%d", &n);
  int a[n];
  for(int i=0; i<n; i++)
    scanf("%d", &a[i]);
  
  int f=0;
  for(int i=0; i<n; i++){
    if((a[i]%2==0 && a[i]%3!=0) && (a[i]%2==0 && a[i]%5!=0)) f=1;
  }
  
  if(f==0) printf("APPROVED");
  else printf("DENIED");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    ll N, M;
    cin >> N >> M;
    cout << (1900 * M + (N-M) * 100) * pow(2, M) << endl;
}

Measured memory_bytes: 4120
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

Measured memory_bytes: 256
local s = io.read()
local n = #s
local cycle_end_pos = {}
local box = {}
for i = 1, 26 do
  box[i] = false
end
local t = {}
for i = 1, n do
  t[i] = s:sub(i, i):byte() - 96
end
local boxcnt = 0
for i = 1, n do
  local v = t[i]
  if not box[v] then
    box[v] = true
    boxcnt = boxcnt + 1
    if boxcnt == 26 then
      table.insert(cycle_end_pos, i)
      boxcnt = 0
      for j = 1, 26 do box[j] = false end
    end
  end
end
-- node = (#cycles + 1) * 26
local edge = {}
local invedge = {}
local canuse = {}

for i = 1, (#cycle_end_pos + 1) * 26 do
  edge[i] = {}
  invedge[i] = {}
  canuse[i] = false
end

local first_pos = {}
local last_pos = {}
for ic = 1, #cycle_end_pos do
  local spos = ic == 1 and 1 or cycle_end_pos[ic - 1] + 1
  local epos = cycle_end_pos[ic]
  for i = 1, 26 do
    box[i] = false
    first_pos[i] = 0
    last_pos[i] = 0
  end
  boxcnt = 0
  for i = spos, epos do
    local v = t[i]
    if first_pos[v] == 0 then
      first_pos[v] = i
    end
    last_pos[v] = i
  end
  for i = 1, 26 do
    local src = (ic - 1) * 26 + i
    for j = 1, 26 do
      if last_pos[j] <= first_pos[i] then
        local dst = ic * 26 + j
        table.insert(edge[src], dst)
        table.insert(invedge[dst], src)
      end
    end
  end
end
for i = 1, 26 do
  local idx = #cycle_end_pos * 26 + i
  canuse[idx] = true
end
if #cycle_end_pos == 0 then
  for i = 1, n do
    local v = t[i]
    local idx = #cycle_end_pos * 26 + v
    canuse[idx] = false
  end
else
  for i = cycle_end_pos[#cycle_end_pos] + 1, n do
    local v = t[i]
    local idx = #cycle_end_pos * 26 + v
    canuse[idx] = false
  end
end
local tasks = {}
for i = 1, 26 do
  local idx = #cycle_end_pos * 26 + i
  if canuse[idx] then
    table.insert(tasks, idx)
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local invsrc = tasks[done]
  for i = 1, #invedge[invsrc] do
    local invdst = invedge[invsrc][i]
    if not canuse[invdst] then
      canuse[invdst] = true
      table.insert(tasks, invdst)
    end
  end
end
local ret = {}
local curpos = 0
for i = 1, 26 do
  if canuse[i] then
    curpos = i
    table.insert(ret, string.char(96 + i))
    break
  end
end
for ic = 1, #cycle_end_pos do
  for i = 1, #edge[curpos] do
    local dst = edge[curpos][i]
    if canuse[dst] then
      curpos = dst
      table.insert(ret, string.char(96 + dst - 26 * ic))
      break
    end
  end
end
print(table.concat(ret))


Measured memory_bytes: 171060
n=int(input())
l = [list(map(int,input().split())) for i in range(n)]
ans='No'
    
for i in range(n-2):

    if l[i][0]==l[i][1] and l[i+1][0]==l[i+1][1] and l[i+2][0]==l[i+2][1]:
        ans='Yes'
        break
    
print(ans)

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

const long long int MOD = 998244353;
long long int dp[3001][3001];
vector <int> A;
int n,s,t;

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

	cin >> n >> s;
	for(int i=0;i<n;i++)
	{
		cin >> t;
		A.push_back(t);
	}

	dp[0][0] = 1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=s;j++)
		{
			dp[i+1][j] = ((dp[i+1][j]%MOD) + ((2*dp[i][j])%MOD));
			dp[i+1][j]%=MOD;
			if(j + A[i] <= s)
			{
				dp[i+1][j+A[i]] = ((dp[i+1][j+A[i]]%MOD) + (dp[i][j]%MOD)%MOD);
				dp[i+1][j+A[i]]%=MOD;
			}
		}
	}

	cout << dp[n][s] << '\n';
	
    return 0;
}


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

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());
	cout << a[n - 1] - a[0] << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
const long long mod=1e9+7;
long long t,n,i,j;
struct mat{
	long long a[32][32];
	void init(){
		long long i,j;
		for(i=0;i<32;i++){
			for(j=0;j<32;j++){
				a[i][j]=0;
			} 
		}
		for(i=0;i<=15;i++){
			a[i+16][i]=1;
			if(i<11){
				a[i+16][i+16]=1;
			}
			else{
				a[i][i+16]=1;
			}
		}
		for(i=0;i<=15;i++){
			for(j=i+1;j<=15;j++){
				if(j<11){
					a[i+16][j+16]=1;
				}
				else{
					a[i][j+16]=1;
				}
			}
		}
	}
}a;
mat operator *(mat x,mat y){
	mat z;long long i,j,k;
	for(i=0;i<32;i++)for(j=0;j<32;j++){
		z.a[i][j]=0;
		for(k=0;k<32;k++) z.a[i][j]=(z.a[i][j]+1ll*x.a[i][k]*y.a[k][j])%mod;
	}
	return z;
}
mat pw(mat x,long long k){
	mat res;long long i,j;
	for(i=0;i<32;i++)for(j=0;j<32;j++)res.a[i][j]=(i==j);
	while(k){
		if(k&1) res=res*x;
		x=x*x;k>>=1;
	}
	return res;
}
signed main(){
	cin>>t;
	while(t--){
		cin>>n;n-=5;
		if(n<0){
			cout<<0<<endl;
			continue;
		}
		if(n==0){
			cout<<1<<endl;
			continue;
		}
		a.init();
		a=pw(a,n);
		long long s=0;
		for(i=0;i<=15;i++){
			s=(s+a.a[16][i+16])%mod;
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 3668
using Yorukatsu028.Questions;
using Yorukatsu028.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu028.Questions
{
    /// <summary>
    /// ABC101 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();

            yield return s.Count(c => c == '+') - s.Count(c => c == '-');
        }
    }
}


namespace Yorukatsu028
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu028.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu028.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
n = int(input())
s = input()
alpha = [0 for _ in range(ord("z") - ord("a") + 1)]

for i in range(len(s)):
    alpha[ord(s[i]) - ord("a")] += 1
# print(alpha)
_sum = alpha[0] + 1
for i in range(1, len(alpha)):
    _sum *= alpha[i] + 1
print((_sum - 1) % (10 ** 9 + 7))


Measured memory_bytes: 3316
#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;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i = 2; i < n; i++) {
    int a = dp[i - 2] + abs(h[i] - h[i - 2]);
    int b = dp[i - 1] + abs(h[i] - h[i - 1]);
    dp[i] = min(a, b);
  }

  cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys 
MOD = 10 ** 9 + 7
INF = 10**11
from heapq import heapify,heappush,heappop

def main():
    k,n = map(int,input().split())
    a = list(map(int,input().split()))
    dif = k - a[-1] + a[0]
    for i in range(1,n):
        tmp = a[i] - a[i - 1]
        if tmp > dif:
            dif = tmp
    ans = k - dif
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 26164
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int N;
vector<vector<vector<double>>> dp(330, vector<vector<double>>(330, vector<double>(330, -1)));

double func(double one, double two, double three){
  if(dp.at(one).at(two).at(three) >= 0) return dp.at(one).at(two).at(three);

  double res = (double)N;
  if(one > 0) res += one * func(one-1, two, three);
  if(two > 0) res += two * func(one+1, two-1, three);
  if(three > 0) res += three * func(one, two+1, three-1);
  res /= (one + two + three);
        

  return dp.at(one).at(two).at(three) = res;
}

int main(){
  cin >> N;
  double one = 0, two = 0, three = 0;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    if(a == 1) one++;
    else if(a == 2) two++;
    else three++;
  }
  
  dp.at(0).at(0).at(0) = 0.0;
  
  cout << fixed << setprecision(10);
  cout << func(one, two, three) << endl;
}

Measured memory_bytes: 286208
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto nt = readln.chomp.split.to!(int[]);
  auto res = int.max;
  foreach(_; 0..nt[0]) {
    auto tmp = readln.chomp.split.to!(int[]);
    if (tmp[1] > nt[1]) {
      continue;
    } else if (res > tmp[0]) {
      res = tmp[0];
    }
  }

  if (res != int.max) {
    writeln(res);
  } else {
    writeln("TLE");
  }
}


Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[300005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


/*
struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};



string ss, sss;


int main() {


	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		C[A[i]]++;
		C[B[i]]++;
	}

	S = "YES";

	for (int i = 1; i <=N; i++) {
		if (C[i] % 2 == 1) {
			S = "NO";
		}

	}

	
	cout << S << endl;
	return 0;

}


Measured memory_bytes: 8448
A = [0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(3):
    A[3*i], A[3*i+1], A[3*i+2] = map(int, input().split())
A_bingo = [0, 0, 0, 0, 0, 0, 0, 0, 0]

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        A_bingo[A.index(b)] = 1

# check
for i in range(3):
    if (A_bingo[3*i] == 1 and A_bingo[3*i+1] == 1 and A_bingo[3*i+2] == 1):
        print("Yes")
        exit()
    elif (A_bingo[i] == 1 and A_bingo[i+3] == 1 and A_bingo[i+6] == 1):
        print("Yes")
        exit()
if (A_bingo[0] == 1 and A_bingo[4] == 1 and A_bingo[8] == 1) or (A_bingo[2] == 1 and A_bingo[4] == 1 and A_bingo[6] == 1):
    print("Yes")
    exit()

print("No")


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

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

	int N, M;
	int A[100];
	int totalVotes = 0;
	
	cin >> N >> M;

	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		totalVotes += A[i];
	}

	double low = (1.0/(4*M))* totalVotes;
	int count = 0;

	for (int i = 0; i < N && (count < M); ++i)
	{
		if (A[i] >= low)
			++count;
	}

	if (count == M)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}



Measured memory_bytes: 256
/* 次に足すものをtemp に入れておく。
'+' が入るならtemp を加え、入らないならtemp を更新する。
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    string s;
    cin >> s;
    int n = s.size();
 
    ll ans = 0;
    for (int bit = 0; bit < 1<<(n - 1); bit++){
        ll temp = 0;
        for (int i = 0; i < n; i++){
            temp *= 10;
            temp += (s[i] - '0');
            if (bit & (1<<i) || i == n - 1){
                ans += temp;
                temp = 0;
            }
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
# coding=utf-8

if __name__ == '__main__':

    N = int(input())
    h = list(map(int, input().split()))

    dp = [0] * 100100

    #print(dp)

    for i in range(N):
        if i == 0:
            continue
        if i == 1:
            dp[i] = abs(h[i-1] -h[i])
            continue
        
        if dp[i -2] + abs(h[i - 2] - h[i]) <= dp[i - 1] + abs(h[i - 1] - h[i]):
            dp[i] = dp[i -2] + abs(h[i - 2] - h[i])
            #print('a')

        else:
            dp[i] = dp[i - 1] + abs(h[i - 1] - h[i])
            #print('b')

    print(dp[N - 1])
    #print(dp)

Measured memory_bytes: 20416
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{
	int n,i,j,k,l;
	cin>>n;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}
	int dp[n+1]={0};
	dp[0]=0;
	loop(i,1,n){
		if(i==1)
			dp[i]=dp[i-1]+abs(v[i-1]-v[i]);
		else
			dp[i]=min((dp[i-1]+abs(v[i-1]-v[i])),(dp[i-2]+abs(v[i-2]-v[i])));
	}
	cout<<dp[n-1]<<endl;
}
int  main() 
{
	fast_io;
	/*#ifndef ONLINE_JUDGE
	freopen("/home/sid/Documents/output.txt","w",stdout);
    freopen("/home/sid/Documents/input.txt","r",stdin);
 	#endif*/
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
	return 0; 
}

Measured memory_bytes: 4000
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make(map[int]int)
	ans := 0
	for i := 0; i < N; i++ {
		v := getInt()
		if a[v] == 0 {
			ans++
			a[v]++
		} else {
			a[v]--
			ans--
		}
	}
	out(ans)
}


Measured memory_bytes: 7424
#include <stdio.h>
int i;

int main(void)
{
    int a,b,hig=0;
    scanf("%d",&a);
    scanf("%d",&b);
    for(i=0;i<=b-a;i++)
    {
        hig+=i;
    }
    printf("%d",hig-b);
    
    
    return 0;
    
}

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

int main()
{
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,abs(n%k-k))<<endl;;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll a,b; cin >> a >> b;
  
  if(a+b == 15) cout << '+' << endl;
  else if(a*b == 15) cout << '*' << endl;
  else cout << "x" << endl;
  
  
}

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

using namespace std;

int main(void){
  int N;
  cin >> N;
  int ans = 30;
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    int b = 0;
    while(A % 2 == 0){
      A >>= 1;
      b++;
    }
    ans = min(ans, b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
h3110_fr13nd,
 
AUTHOR : @sam_jn
*/
 
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less_equal<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define NN 1000002
#define in(a, n) for(int i = 0; i < n; i++) cin >> a[i];
#define ot(a, n) for(int i = 0; i < n; i++) cout << a[i] << " ";
#define ot2(a, n) for(int i = 0; i < n; i++) cout << a[i] << "\n";
ll pwr(ll a, ll b);
ll pwr(ll a, ll b, ll m);
int baap[200002];
int prime[NN];
int find(int i);  
bool Union(int x, int y);
ll inv(ll x) {return pwr(x, MOD - 2, MOD);}
void init();
ll max(ll x, ll y, ll z) {return max(x, max(y, z));}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
//----------------------------------SOLUTION-BELOW-------------------------------------------// 

void solve(){
    int l, r, d, cnt = 0;
    cin >> l >> r >> d;
    for(int i = l; i <= r; i++){
        if(i % d == 0) cnt++;
    }
    cout << cnt;
}
int main(){


                                                            #ifndef ONLINE_JUDGE    
                                                            freopen("/home/samyak/Desktop/CP/input.txt", "r", stdin);
                                                            freopen("/home/samyak/Desktop/CP/output2.txt", "w", stdout);
                                                            #else
                                                            // online submission
                                                            #endif
// 

    boost
    int _ = 1;
    // cout << 0 << endl;
    // cin >> _;
    while(_--){
        solve();
        cout << endl;
    }
}
 
 
//--------------------------------------DEFININTIONS---------------------------------------
ll pwr(ll a, ll b){
    if(b == 0)
        return 1 ;
    ll c = pwr(a, b/2) ;
    c = c * c;
    if(b % 2)
        return c*a;
    return c ;
}
ll pwr(ll a, ll b, ll m){
    if(b == 0)
        return 1;
    ll c = pwr(a, b/2, m) % m ;
    c = (c * c) % m;    
    if(b % 2)
        return (c * a%m) % m;
    return c ;
}
int find(int i)  
{  
    if (baap[i] != i)  
        baap[i] = find(baap[i]);  
  
    return baap[i];  
}
 
bool Union(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y) return false;
    baap[x] = y;
    return true;
}
void init(){
  for(ll i = 2; i < NN; i++){
      if(prime[i]) continue;
      for(ll j = 2*i; j < NN; j += i)
          prime[j] = i;
  }
}

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

int main() {

	string s; cin >> s;	
	string a = "dream";
	string b = "dreamer";
	string c = "erase";
	string d = "eraser";
	reverse(s.begin(), s.end());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	reverse(c.begin(), c.end());
	reverse(d.begin(), d.end());
	int na = a.size(); // 5
	int nb = b.size(); // 7
	int nc = na;       // 5
	int nd = d.size(); // 6
	string tmp_s = s;
	bool can = true;
	while (na <= tmp_s.size()) {
		if (nb <= tmp_s.size()) {
			if (tmp_s.substr(0, na) == a || tmp_s.substr(0, nc) == c) {
				tmp_s = tmp_s.substr(na);
			}
			else if (tmp_s.substr(0, nb) == b) {
				tmp_s = tmp_s.substr(nb);
			}
			else if (tmp_s.substr(0, nd) == d) {
				tmp_s = tmp_s.substr(nd);
			}
			else {
				can = false;
				break;
			}
		}
		else if (tmp_s.size() == nd) {
			if (!(tmp_s == d)) {
				can = false;
			}
			break;
		}
		else if (tmp_s.size() == na) {
			if (!(tmp_s == a || tmp_s == c)) {
				can = false;
			}
			break;
		}
		else {
			can = false;
			break;
		}
	}
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N-1);
  rep(i,N-1)
  {
    cin >> A[i];
    A[i] --;
  }
  vector<int> ans(N,0);
  rep(i,N-1)
  {
    ans[A[i]] ++;
  }
  rep(i,N)
  {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_;i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define INF 10000000

int main(){
    int n,m,l[100000],r[100000];
    cin >> n >> m;
    REP(i,m){
        cin >> l[i] >> r[i];
    }
    int left=0, right=n+1;
    REP(i, m)
    {
        left = max(left, l[i]);
        right = min(right, r[i]);
    }
    if (right - left + 1 > 0)
    {
        cout << right - left + 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while ( cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while(1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for(i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if ( com[0] == 'i') { insert(key); np++; size++; }
        else if (com[0] == 'd') {
            if (strlen(com) > 6 ) {
                if (com[6] == 'F') deleteFirst();
                else if ( com[6] == 'L') deleteLast();
            } else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    
    printList();
    
    return 0;
}


Measured memory_bytes: 33868
#include <stdio.h>
int main(){
	char yeet[10];
	scanf("%s",&yeet);
	if (yeet[2] == yeet[3] && yeet[4] == yeet[5]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
		
return 0;	
}


Measured memory_bytes: 1660
#include <stdio.h>
#include <string.h>
#include <queue>

using namespace std;

int dist[100005];

int main()
{
	int n;
	queue<int> q;

	scanf("%d", &n);

	q.push(0);
	while (!q.empty() && !dist[0])
	{
		int num = q.front();
		q.pop();

		int next = (num + 1) % n;

		while (!dist[next])
		{
			q.push(next);
			dist[next] = dist[num] + 1;
			next = (next * 10) % n;
		}
	}

	printf("%d\n", dist[0]);

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void){
    int N, K, d, A;
    int cnt, L[100] = {0};
    cnt = 0;

    scanf("%d%d", &N, &K);
    for(int i = 0; i < K; i++){
        scanf("%d", &d);
        for(int j = 0; j < d; j++){
            scanf("%d", &A);
            L[A-1] = 1;
        }
    }
    for(int i = 0; i < N; i++){
        if(L[i] == 0)
            cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <math.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<pair<int,int>> x(n);
	vector<vector<int>> matrix(201);
	for (int i = 0; i < 201; i++)
	{
		matrix[i].resize(201);
	}
	for (int i = 0; i < n; i++)
	{
		cin >> x[i].first >> x[i].second;
		matrix[x[i].first][x[i].second] = 1;
	}
	vector<pair<int, int>> x2(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x2[i].first >> x2[i].second;
	}
	sort(x2.begin(), x2.end());
	int res = 0;
	for (int i = 0; i < n; i++)
	{
		int jj = x2[i].second;
		bool is = false;
		while (!is && jj >= 0)
		{
			int ii = x2[i].first;
			while (!is && ii >= 0)
			{
				if (matrix[ii][jj] == 1)
				{
					is = true;
					matrix[ii][jj] = 0;
				}
				ii--;
			}
			jj--;
		}
		res += is;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 384
function Main(input){
    input = input.split(" ")
    var array = new Array()
    for(var i = 0;i < 3;i++){
        array.push(parseInt(input[i],10))
    }

    console.log(array[0] + array[1] + array[2] + 9 * Math.max(...array))
}

Main(require("fs").readFileSync("/dev/stdin","utf8"))


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

int main(int argc, char const *argv[]) {
    while (true) {
        int h,w;cin>>h>>w;
        if (!h&&!w) break;
    
        rep(i,h) {
            rep(j,w) {
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>

using namespace std;
#define MAX 500000

template<typename T>
class MaxHeap
{
public:
	MaxHeap(int maxSize = MAX)
	{
		m_maxSize = maxSize;
		m_currentSize = 0;
		m_pArray = new T[m_maxSize];
	}

	virtual ~MaxHeap()
	{
		if (m_pArray) delete[] m_pArray;
		m_pArray = 0;
	}

	void Push(const T& data)
	{
		if (m_currentSize >= m_maxSize) throw("MaxHeap is full!");

		m_pArray[m_currentSize++] = data;
	}

	void Print()
	{
		for (int i = 0; i < m_currentSize; ++i)
			cout << " " <<m_pArray[i];
		cout << endl;
	}

	void Sort()
	{
		for (int i = m_currentSize - 1; i >= 0; --i)
			TrickleDown(i);
	}

private:
	/**
	 * 向下渗透
	 */
	void TrickleDown(int index)
	{
		if (index >= m_currentSize) return;

		int maxChild = -1;
		int leftChild = (index << 1) + 1;
		int rightChild = leftChild + 1;
		if (rightChild < m_currentSize)//双子节点
		{
			if (m_pArray[leftChild] > m_pArray[rightChild])
				maxChild = leftChild;
			else
				maxChild = rightChild;
		}
		else if (leftChild < m_currentSize)//只有左子节点
			maxChild = leftChild;
		else//无子节点
			return;

		if (m_pArray[index] >= m_pArray[maxChild]) return;
		//当前节点值小于子节点，与子节点交换
		T temp = m_pArray[maxChild];
		m_pArray[maxChild] = m_pArray[index];
		m_pArray[index] = temp;
		TrickleDown(maxChild);
	}

private:
	T* m_pArray;
	int m_maxSize;
	int m_currentSize;
};

int main()
{
	int n; cin >> n;
	int v;
	MaxHeap<int> heap;
	for (int i = 0; i < n; ++i)
	{
		cin >> v;
		heap.Push(v);
	}
	heap.Sort();
	heap.Print();

	return 0;
}


Measured memory_bytes: 4568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans=0;
    ans+=1000*(n/500);
    n%=500;
    ans+=(n/5)*5;
    cout<<ans;
	return 0;
}


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

int main(void){
	string text;
	getline(cin, text);
	for (int i=0; i<text.size(); i++){
		text[i]=toupper(text[i]);
	}
	cout<<text<<endl;
	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mod 1000000007
int main() 
{
    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll sum=0;
    for(ll i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
        cout<<"-1";
    else
    {
        ll ans = n-sum;
        cout<<ans;
    }
}


Measured memory_bytes: 3676