akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}

int main() {
	string str;
	cin >> s >> str;
	int cnt = 0;
	rep(i, 3) {
		if (s[i] == str[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    cout << n*n << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
int main(){
	int y,m,d;
	scanf("%d/%d/%d",&y,&m,&d);
	if(m<=4) puts("Heisei");
	else puts("TBD");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define op_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i=a; i <b; i++)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<int,int> mpii;
typedef map<ll,ll> mpll;
typedef map<int,ll> mpil;
typedef map<ll,int> mpli;

int main(){
  op_io;
  int n;
  cin>>n;
  int m = n%10;
  if(m==0 || m==1||m==6||m==8){
    cout<<"pon"<<endl;
  }
  if(m==2 || m==4||m==5||m==7||m==9){
    cout<<"hon"<<endl;
  }
  if(m==3){
    cout<<"bon"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cstdlib>

#include <algorithm>
#include <iostream>
#include <numeric>
#include <limits>
#include <functional>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

int main() {
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
#endif

  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  int ans = min(a, c);
  a -= ans;
  c -= ans;
  if (a == 0)
    ans += b + min(b + 1, c);
  else
    ans += b;
  printf("%d\n", ans);

  return 0;
}



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

public class Main{
	public static void main(String[] args)throws Exception{
	
		ArrayList<String> list = new ArrayList<String>();
	
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

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

		for(int i=0; i<n; i++){
			list.add(br.readLine());
		}
		
		for(int i=1; i<=13; i++){
			if(list.contains("S " +i) == false){
				sb.append("S "+ i +"\n");
			}
		}
		
		for(int i=1; i<=13; i++){
			if(list.contains("H " +i) == false){
				sb.append("H "+ i +"\n");
			}
		}
		
		for(int i=1; i<=13; i++){
			if(list.contains("C " +i) == false){
				sb.append("C "+ i +"\n");
			}
		}
		
		for(int i=1; i<=13; i++){
			if(list.contains("D " +i) == false){
				sb.append("D "+ i +"\n");
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 24252
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		while(N-->0)
		{
			double xp1=in.nextDouble(),yp1=in.nextDouble();
			double xp2=in.nextDouble(),yp2=in.nextDouble();
			double xp3=in.nextDouble(),yp3=in.nextDouble();
			double xk=in.nextDouble(),yk=in.nextDouble();//enemy
			double xs=in.nextDouble(),ys=in.nextDouble();//me
			int kabe=0;
			if(!(judge(xp1,yp1,xp2,yp2,xk,yk,xs,ys)>0||judge(xk,yk,xs,ys,xp1,yp1,xp2,yp2)>0))//壁と交差する
				kabe++;
			if(!(judge(xp2,yp2,xp3,yp3,xk,yk,xs,ys)>0||judge(xk,yk,xs,ys,xp2,yp2,xp3,yp3)>0))
				kabe++;
			if(!(judge(xp3,yp3,xp1,yp1,xk,yk,xs,ys)>0||judge(xk,yk,xs,ys,xp3,yp3,xp1,yp1)>0))
				kabe++;
			System.out.println(kabe==1 ? "OK":"NG");
		}
	}
	
	static double judge(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
	{
		double tc=(x1-x2)*(y3-y1)+(y1-y2)*(x1-x3);
		double td=(x1-x2)*(y4-y1)+(y1-y2)*(x1-x4);
		return tc*td;
	}
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e15 + 5;
double PI = 3.14159265358979323846;

void solve() {

    int n, w;
    cin >> n >> w;
    vl wt(n), val(n);
    ll V = 0;
    for (int i = 0; i < n; i++) {
        cin >> wt[i] >> val[i];
        V += val[i];
    }

    vvl dp(n + 1, vl(V + 1, inf));

    // dp[i][j] = mininmum capacity(w) of knapsack required to make value of j 
    // and with frst i elements

    dp[0][0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= V; j++) {
            if(j == 0){
                dp[i][j] = 0;
                continue;
            }

            if (val[i - 1] <= j) {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wt[i - 1]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    ll ans = 0;

    for (int value = V; value >= 0; value--) {
        if (dp[n][value] <= w and dp[n][value] != inf) {
            ans = value;
            break;
        }
    }

    cout << ans << endl;

}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 83028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int top(int n) {
    while (n > 9)
        n /= 10;
    return n;
}

int bottom(int n) {
    return n % 10;
}

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

    int N, cnt[9][9] = {0};
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        int t = top(i) - 1, b = bottom(i) - 1;
        if (b < 0)
            continue;
        cnt[t][b]++;
    }
    ll ans = 0;
    for (int i = 0; i < 9; ++i)
        for (int j = 0; j < 9; ++j)
            ans += (ll)cnt[i][j] * cnt[j][i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

int main()
{
    int a[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> a[i][j];
        }
    }

    int n;
    cin >> n;
    rep(ni, n){
        int x;
        cin >> x;
        rep(i, 3){
            rep(j, 3){
                if(a[i][j] == x){
                    a[i][j] = -1;
                }
            }
        }
    }

    bool ans = false;
    rep(i, 3){
        int cnt = 0;
        rep(j, 3){
            if(a[i][j] == -1){
                cnt++;
            }
        }
        if(cnt == 3){
            ans = true;
        }
    }
    rep(i, 3){
        int cnt = 0;
        rep(j, 3){
            if(a[j][i] == -1){
                cnt++;
            }
        }
        if(cnt == 3){
            ans = true;
        }
    }
    if(a[1][1] == -1){
        if(a[0][0] == -1 && a[2][2] == -1){
            ans = true;
        }
        if(a[0][2] == -1 && a[2][0] == -1){
            ans = true;
        }
    }
    puts(ans?"Yes":"No");
    
    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define debug(args...){string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> ii;
typedef pair <ii, int> iii;

void err(istream_iterator<string> it){}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
  int n;
  cin >> n;
  cout << !n << endl;
  return 0;
}

Measured memory_bytes: 3628
n,x,m=map(int,input().split())
a=[x]
su=x
s={x}
for i in range(n-1):
  x=(x**2)%m
  if x in s:
    n-=i+1
    a=a[a.index(x):]
    l=len(a)
    su+=sum(a)*(n//l)
    n-=(n//l)*l
    su+=sum(a[:n])
    print(su)
    exit()
  a.append(x)
  su+=x
  s.add(x)
print(su)

Measured memory_bytes: 77084
#![allow(non_snake_case)]

use proconio::input;

fn main() {
    input! {
        mut N: usize,
    }

    let offset = 'a' as u8;
    let mut ans = "".to_string();

    loop {
        if N == 0 {
            break;
        }

        let r = N % 26;
        let c = ((r as u8 + 25) % 26 + offset) as char;

        ans = c.to_string() + &ans;
        if N % 26 == 0 {
            N = N / 26 - 1;
        } else {
            N /= 26;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int K = int.Parse(Console.ReadLine());

            for (int i = 0; i < N; i++)
            {
                if (S[i] == S[K-1])
                    ;
                else
                {
                   S = S.Replace(S[i], '*');
                }
            }

            Console.WriteLine(S);

            Console.ReadLine();

        }
    }
}


Measured memory_bytes: 13140
import sys
sys.setrecursionlimit(1000000000)
from fractions import gcd
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    A,B,K = mis()
    if A >= K:
        print(A-K, B)
    else:
        K -= A
        print(0, max(0, B-K))


main()


Measured memory_bytes: 5428
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class Main
{
    static int power(long x, int y) 
    { 
        // Initialize result 
        long res = 1L;      
         
        // Update x if it is more   
        // than or equal to p 
        x = x % 1000000007;  
  
       if (x == 0) return 0; // In case x is divisible by p;    
  
        while (y > 0) 
        { 
            // If y is odd, multiply x 
            // with result 
            if((y & 1)==1) 
                res = (res * x) % 1000000007; 
      
            // y must be even now 
            // y = y / 2 
            y = y >> 1;  
            x = (x * x) % 1000000007;  
        } 
        res %= 1000000007;
        return (int)res; 
    } 
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int tmp1=power(10,n);
        int tmp2=power(9,n);
        int tmp3=power(8,n);
        int tmp=tmp1-2*tmp2+tmp3;
        while(tmp<0)
            tmp+=1000000007;
        tmp%=1000000007;
        System.out.println(tmp);
        
    }
}

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

int main()
{
    int a,b,c,x,ans = 0;
    cin >> a >> b >> c >> x;

    for(int i = 0; i <= a; i++)
        for(int j = 0; j <= b; j++)
            for(int k = 0; k <= c; k++)
                if(500 * i + 100 * j + 50 * k == x) ans++;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  map<string, int> m;
  int max = 1;
  rep(i, N) {
    string s; cin >> s;
    auto it = m.find(s);
    if(it != m.end()) {
      ++(it->second);
      if(it->second > max) {
        max = it->second;
      }
    } else {
      m.insert(make_pair(s,1));
    }
  }
  for(auto it=m.begin(); it != m.end(); ++it) {
    if(it->second == max) {
      cout << it->first << endl;
    }
  }
}

Measured memory_bytes: 23808
from math import ceil
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]

def attack(n):
    s = 0
    for h in H:
        h -= B*n
        if h > 0:
            s += ceil(h/(A-B))
    return s <= n

l = 0
r = 0
for h in H:
    r = max(ceil(h/B),r)

while l != r-1:
    mid = (l+r)//2
    if attack(mid):
        r = mid
    else:
        l = mid

print(r)

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

int main()
{
  string str;
  cin >> str;
  
  if(str[0] == str[1] ||
     str[0] == str[2] ||
     str[1] == str[2])
  {
    cout << "No" << endl;
  }
  else cout << "Yes" << endl;
  return 0;
}


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

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;

static const int INF = 1LL << 60;
static const int MOD = 1000000007;
//static const int MAX_N = 100005;

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

    int n, a[105];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int ans = INF;
    for (int i = -100; i <= 100; ++i) {
        int temp = 0;
        for (int j = 0; j < n; ++j) {
            int t = a[j] - i;
            temp += t * t;
        }
        ans = min(ans, temp);
    }

    cout << ans << endl;
}

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

int main() {
    vector<P> v(24);
    for(int i=0; i<24; ++i) {
        cin >> v[i].second >> v[i].first;
    }
    sort(v.begin(), v.begin()+8);
    sort(v.begin()+8, v.begin()+16);
    sort(v.begin()+16, v.end());
    cout << fixed << setprecision(2);
    for(int i=0; i<3; ++i) {
        for(int j=0; j<2; ++j) {
            cout << v[i*8+j].second << ' ' << v[i*8+j].first << endl;
        }
    }
    for(int i=0; i<3; ++i) {
        for(int j=0; j<2; ++j) {
            v[i*2+j] = v[i*8+j+2];
        }
    }
    sort(v.begin(), v.begin()+6);
    cout << v[0].second << ' ' << v[0].first << endl;
    cout << v[1].second << ' ' << v[1].first << endl;
}


Measured memory_bytes: 3212
#include <iostream>

using ll = long long int;

ll gcd(ll x, ll y)
{

    return (x % y) ? gcd(y, x % y) : y;
} //x>=y

ll pow(ll x, int n)
{

    return (n == 1) ? x : x * pow(x, n - 1);
}

int main()
{

    ll n;

    std::cin >> n;

    ll cnt = 0;

    //xが正の整数のとき
    for (ll i = 2; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            int x = 1;
            while (n % pow(i, x + 1) == 0)
                ++x;
            if ((n / pow(i, x)) % i == 1)
                ++cnt;
        }
    }

    ++cnt; //K=Nのとき

    //xが0のとき
    for (ll i = 2; i * i <= n - 1; ++i)
    {
        if ((n - 1) % i == 0)
            cnt += (i * i == n - 1) ? 1 : 2;
    }

    if (n > 2)
        ++cnt;

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) { string r = "["; for (int i = 0; i < (int)v.size() - 1; i++) r += to_string(v[i]) + ", ";
	if (!v.empty()) r += to_string(v.back()); return r + "]"; }

const int N = 10;
int n, m, ans;
vector<vi> adj;

void solve(int u, int V) {
	if (V == (1 << n) - 1) { ans++; return; }
	for (int i = 0; i < (int)adj[u].size(); i++) {
		int v = adj[u][i];
		if (V & (1 << v)) continue;
		solve(v, V | (1 << v));
	}
}

int main () { 
#ifdef XVENOM
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	
	int x, y;
	scanf("%d%d", &n, &m);
	adj.assign(n, vi(0));
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		x--; y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	ans = 0;
	solve(0, 1 << 0);
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char ch;
    
    while (1) {
        scanf("%c", &ch);
        //変換
        if (ch>=65 && ch<=90) {
            ch += 32;
        }else if(ch>=97 && ch <=122){
            ch -= 32;
        }
        printf("%c", ch);
        if (ch == '\n') break;
    }
    return 0;
}


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

int main(){
    int n, q;
    cin >> n >> q;
    ll a[n], x;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < q; i++){
        cin >> x;
        ll res = 0, sum = 0;
        int right = 0;
        for(int left = 0; left < n; left++){
            while(right < n && sum + a[right] <= x) sum += a[right++];
            res += (right - left);
            if(left == right) right++;
            else sum -= a[left];
        }
        cout << res << endl;
    }
    return 0;
}



Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main(){
    fast;
    ll H, sum = 0, count = 1;
    cin >> H;
    //if(H == 1)
      //  cout << 1;
    while(H >= 0)
    {
        if(H == 1)
        {
            sum = sum + 1;
            break;
        }

        sum = sum + 2*count;
        H = H/2;
        count = count * 2;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
n, p = map(int, input().split())
s = [int(x) for x in input()]

if p == 2:
    ans = 0
    for i in range(n):
        if s[i] % 2 == 0:
            ans += i+1
    print(ans)
    exit()

if p == 5:
    ans = 0
    for i in range(n):
        if s[i] == 0 or s[i] == 5:
            ans += i+1
    print(ans)
    exit()


po10 = [1]
for i in range(n-1):
    po10.append((po10[-1]*10) % p)

for i in range(n):
    s[i] *= po10[n-1-i]
    s[i] %= p

ss = [0]

for i in range(n):
    ss.append(ss[-1]+s[i])
    ss[-1] %= p


ss = sorted(ss)

ll = len(ss)

ans = 0
tmp = [0,0]
for i in range(ll):
    if ss[i] != tmp[0]:
        ans += (i-tmp[1])*(i-tmp[1]-1) //2
        tmp[0] = ss[i]
        tmp[1] = i

ans += (ll-tmp[1])*(ll-tmp[1]-1)//2

print(ans)


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

const int64_t MOD=1e9+7;

//MODべき乗
int64_t modpow(int64_t a,int64_t n){
  int64_t res=1;
  if(n==0) return res;
  while(n>0){
    if(n&1) res=(res*a)%MOD;
    a=(a*a)%MOD;
    n >>= 1;
  }
  return res;
}

int main(){
  int N;
  cin>>N;
  //lcmの素因数分解のmapを作る
  map<int64_t,int> prime;
  vector<int64_t> A(N);

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

    int64_t n=A[i];
    //nの素因数分解のmapを作る
    map<int64_t,int> sub_prime;
    for(int64_t j=2;j*j<=n;++j){
      while(n%j==0){
        ++sub_prime[j];
        n=n/j;
      }
    }
    if(n!=1){
      ++sub_prime[n];
    }

    //primeを更新する
    for(auto p:sub_prime){
    if(!prime.count(p.first)) prime[p.first]=p.second;
    else prime[p.first]=max(prime[p.first],p.second);
  }
  }
  
  int64_t sub_sum=1;
  for(auto p:prime){
    for(int i=0;i<p.second;++i){
    sub_sum=sub_sum*p.first;
    sub_sum %= MOD;
    }
  }

   int64_t sum=0;
   for(int i=0;i<N;++i){
     sum += sub_sum*modpow(A[i],MOD-2);
     sum %= MOD;
   }

   cout<<sum<<endl;
}

Measured memory_bytes: 896
#include <stdio.h>
 
void insertionSort(int [], int, int);
void shellSort(int [], int);
 
int cnt = 0;
int a[1000000];
 
void insertionSort(int a[], int n, int g){
  int i, j, key;
 
  for(i = g;i < n;i++){
    key = a[i];
    j = i - g;
    while(j >= 0 && a[j] > key){
      a[j+g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j+g] = key;
  }
}
 
void shellSort(int a[], int n){
  int m = 13; 
  int g[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 165720, 797161};
  int i;
 
  cnt = 0;
  while(g[m-1] > n){
    m--;
  }
  printf("%d\n", m);
  for(i = m-1;i >= 1;i--){
    printf("%d ", g[i]);
  }
  printf("%d\n", g[0]);
  for(i = m-1;i >= 0;i--){
    insertionSort(a, n, g[i]);
  }
}

main(){
  int n, i;
 
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
  }
  shellSort(a, n);
  printf("%d\n", cnt);
  for(i = 0;i < n;i++){
    printf("%d\n", a[i]);
  }
  return 0 ;
}
 



Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int p = 0;
  int m = 0;
  int i;
  for(i=0;i<4;i++){
    if(s[i]=='+') p++;
    else m++;
  }
  cout << p-m << "\n";
  return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>
#include<math.h>
#include <iostream>
using namespace std;
#define  LL long long


int main()
{

	LL a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	LL ans= 123123123123123;
	for(int i=0;i<=1900000;i++){
		LL aa=a*(x-i/2);
		if(aa<0) aa=0;
		LL bb=b*(y-i/2);
		if(bb<0) bb=0;
		ans=min(ans,c*i+aa+bb);
		//if(i/2>=max(a,b)) break;
	}
	printf("%lld\n",ans);


}


Measured memory_bytes: 256
def selection_sort(A: list, N:int) -> list:
    """
    :A[N]: サイズがNの整数型配列。
    :i: 未ソートの部分の先頭を指すループ変数で、配列の先頭から末尾に向かって移動する。
    :minj: 各ループの処理でi 番目からN-1 番目までの要素で最小のものの位置。j 未ソートの部分から最小値の位置（minj）を探すためのループ変数。
    """
    count = 0

    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        # alter position
        if(i != minj):
            a, b = A[i], A[minj]
            A[i], A[minj] = b, a
            count += 1

    return A, count
    
N = int(input())
A = list(map(int, input().split()))

A, count = selection_sort(A, N)
print(*A)
print(count)


Measured memory_bytes: 5620
'''
ITP-1_7-A
 ??????
????????????????????????????????????????????°????????????????????????????????°??????????????????????????¨??§??????
????????°??????????????°?????????????????????????????°????????????????????????
?????????????????°????????????????¨?????????° m?????????????¨?????????° f??????????¨?????????° r ??§?§?????????????????????????
??????????¨???¨??????????¨???? 50 ????????????m, f ??? 50?????????????¨???? 100 ????????? ???r ??? 100?????§??????
????¨????????????????????????´???????????°??? -1 ??¨????????????
??\??????????????§??????????????????????????????
?????????????¨??????????????¨????????????????????¬????????????´???????????? F???
?????????????¨???¨??????????¨????????¨??????°??? 80 ??\???????????°????????? A ???
?????????????¨???¨??????????¨????????¨??????°??? 65 ??\??? 80 ??????????????°????????? B???
?????????????¨???¨??????????¨????????¨??????°??? 50 ??\??? 65 ??????????????°????????? C???
?????????????¨???¨??????????¨????????¨??????°??? 30 ??\??? 50 ??????????????°????????? D???
??????????????????????¨?????????°??? 50 ??\???????????°????????? C???
?????????????¨???¨??????????¨????????¨??????°??? 30 ??????????????°????????? F???
???Input
?????°??????????????????????????\?????¨??????????????????????????????????????????????????§??????????????§??????????????? m???f???r ??? 1 ???????????????????????????
m???f???r ???????????? -1 ?????¨?????\?????????????????¨????????????
???Output
?????????????????????????????????????????????A???B???C???D???????????? F???????????????????????????????????????
'''
while True:
    # ??????????¨?????????° m?????????????¨?????????° f??????????¨?????????° r
    m, f, r = map(int, input().split())
    mf = m + f

    # EndCheck
    if m == f == r == -1:
        break

    # ?????????????¨??????????????¨????????????????????¬????????????´???????????? F???
    if -1 == m or -1 == f:
        print('F')
        continue
    # ?????????????¨???¨??????????¨????????¨??????°??? 80 ??\???????????°????????? A ???
    elif 80 <= mf:
        print('A')
    # ?????????????¨???¨??????????¨????????¨??????°??? 65 ??\??? 80 ??????????????°????????? B???
    elif 65 <= mf < 80:
        print('B')
    # ?????????????¨???¨??????????¨????????¨??????°??? 50 ??\??? 65 ??????????????°????????? C???
    elif 50 <= mf < 65:
        print('C')
    # ?????????????¨???¨??????????¨????????¨??????°??? 30 ??\??? 50 ??????????????°????????? D???
    elif 30 <= mf < 50:
        # ???????????????????¨?????????°??? 50 ??\???????????°????????? C???
        if 50 <= r:
            print('C')
        else:
            print('D')
    # ?????????????¨???¨??????????¨????????¨??????°??? 30 ??????????????°????????? F???
    elif 30 > mf:
        print('F')

Measured memory_bytes: 7700
N = int(input())

prev_t, prev_x, prev_y = 0, 0, 0
flag = 'Yes'

for i in range(N):
  next_t, next_x, next_y = map(int, input().split())

  t = next_t - prev_t
  x = next_x - prev_x
  y = next_y - prev_y
  
  if x+y > t or (t-(x+y))%2 != 0:
    flag = 'No'
    break
  prev_t, prev_x, prev_y = next_t, next_x, next_y

print(flag)


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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
ll n;
ll a, b;
//check T
void solve()
{
	cin >> n >> a >> b;
	cout << n/(a+b) * a + min(a, n%(a+b))<< endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 256
M,K=gets.split.map(&:to_i)
if M==0
    puts K==0 ? "0 0" : -1
elsif M==1
    puts K==0 ? "1 0 0 1" : -1
else
    if 2**M<=K
        puts -1
        exit
    end
    ans=[]
    (2**(M)).times do |i|
        ans << i if i!=K
    end
    rev=ans.reverse
    ans << K
    ans+=rev+[K]
    puts ans.join(" ")
end


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    int64_t m0 = a[0] + a[1], m1 = -a[0] - a[1];
    for (auto i : irange(2L, n)) {
        tie(m0, m1) =
                make_pair(max(m0, m1) + a[i],
                          max(m0 - 2 * a[i - 1], m1 + 2 * a[i - 1]) - a[i]);
    }

    cout << max(m0, m1) << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{	
	int t[4]={0},n[4]={0};
	for(int i=0;i<4;i++)
	{
		scanf("%d %d",&t[i],&n[i]);
	}
	for(int i=0;i<4;i++)
	{
		switch (t[i])
		{
			case 1:printf("%d\n",n[i]*6000);break;
			case 2:printf("%d\n",n[i]*4000);break;
			case 3:printf("%d\n",n[i]*3000);break;
			case 4:printf("%d\n",n[i]*2000);break;
		}
	}
	return 0;
}


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

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  int a, b, c;
  a = P + Q;
  b = Q + R;
  c = R + P;
  cout << min(min(a, b), c) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <set>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef pair<int,int> pii;

/// pair<int,int> hasher
namespace std{
	template<typename I>
	class hash<pair<I,I>>{
		public:
		size_t operator()(const pair<I,I> &p) const {return hash<long long>() (((long long)(p.first))<<32|p.second);}
	};
}

double solve(const vector<pii> &a){
	set<int>ys;
	for(auto &e:a)ys.insert(e.second);
	int n=a.size();
	vector<double>mx,my;
	for(int i=0;i<n;i++){
		mx.push_back(a[i].first);
		my.push_back(a[i].second);
		if(i==n-1)continue;
		if(a[i].second<a[i+1].second){ //??????i????°???§??????
			for(auto it=ys.begin();it!=ys.end();++it){
				if(a[i].second<*it && *it<a[i+1].second){
					double dy=a[i+1].second-a[i].second;
					double dx=(a[i+1].first-a[i].first)/dy*(*it-a[i].second);
					mx.push_back(a[i].first+dx);
					my.push_back(*it);
				}
			}
		}else{ //??????i????±±??§??????
			for(auto it=ys.end();it--!=ys.begin();){
				if(a[i+1].second<*it && *it<a[i].second){
					double dy=a[i+1].second-a[i].second;
					double dx=(a[i+1].first-a[i].first)/dy*(*it-a[i].second);
					mx.push_back(a[i].first+dx);
					my.push_back(*it);
				}
			}
		}
	}
	int m=mx.size();
	priority_queue<pair<double,pii>>q;
	unordered_set<pii>se;
	q.push({0,{0,m-1}});
	for(;!q.empty();){
		double c=q.top().first;
		int l=q.top().second.first;
		int r=q.top().second.second;
		q.pop();
		if(se.find({l,r})!=se.end())continue;
		se.insert({l,r});
		if(l==r)return -c;
		for(int i=-1;i<2;i++)for(int j=-1;j<2;j++)
			if(0<=l+i&&l+i<m && 0<=r+j&&r+j<m && fabs(my[l+i]-my[r+j])<1e-9)
				q.push({c-hypot(mx[l]-mx[l+i],my[l]-my[l+i])-hypot(mx[r]-mx[r+j],my[r]-my[r+j]),{l+i,r+j}});
	}
	abort();
}

int main(){
	int N,x,y;
	for(;scanf("%d",&N),N;){
		vector<pii>a(N);
		for(int i=0;i<N;i++)scanf("%d%d",&a[i].first,&a[i].second);
		printf("%f\n",solve(a));
	}
}

Measured memory_bytes: 4492
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=100005;
int n,k;
class Perm{
public:
	int to[maxn];
	void init(){
		REP(i,n){
			int x;scanf("%d",&x);
			to[x]=i;
		}
	}
	Perm inv(){
		Perm res;
		REP(i,n)res.to[to[i]]=i;
		return res;
	}
	Perm operator * (const Perm &o)const{
		Perm res;
		REP(i,n)res.to[i]=o.to[to[i]];
		return res;
	}
}id,p,q,cur,a[6],b[6];
Perm quickpow(Perm x,int pow){
	Perm res=id;
	for(;pow;pow>>=1){
		if(pow&1)res=res*x;
		x=x*x;
	}
	return res;
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&k);
	k--;
	p.init();
	q.init();
	REP(i,n)id.to[i]=i;
	a[0]=a[1]=a[2]=id;
	a[3]=b[1]=q;
	a[4]=a[5]=b[2]=q*p.inv();	
	b[0]=p;
	b[3]=p.inv();
    b[4]=q.inv();
    b[5]=q.inv()*p;
	cur=q*p.inv()*q.inv()*p;
	cur=quickpow(cur,k/6)*a[k%6];
	cur=(cur*b[k%6]*cur.inv()).inv();
	REP(i,n)printf("%d ",cur.to[i]);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 12160
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
  {
    char c;
    scanf("%c", &c);
    if (c == 'Y')
    {
      puts("Four");
      return 0;
    }
  }
  puts("Three");
  return 0;
}

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

using namespace std;

int main(void){
	int n;
	cin >> n;

	vector<int> a(n);

	int max = -1000000;
	int min = 1000000;
	long long int sum = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;

		sum += a;
		if (max < a){
			max = a;
		}
		if (min > a){
			min = a;
		}
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
 
using namespace std;
 
int main()
{   
    int i;
    char str[19];
    cin >> str;
    str[5]=' ';
    str[13]=' ';
   
  for(i=0;i<19;i++){
    cout << str[i] ;
  }
    
  
       return 0;
}

Measured memory_bytes: 256
import sys
amount = int(input())

lst1 = [3,4,5]
if amount in lst1:
    print(1)
    sys.exit()
elif amount < 6:
    print(0)
    sys.exit()

coins = [x for x in range(3,amount+1)]

lst = [amount+1 for x in range(amount+1)]

lst[0] = 1
lst[1] = 0
lst[2] = 0
lst[3] = 1
lst[4] = 1
lst[5] = 1


for i in range(6,amount+1):
    counter = 0
    for coin in coins:
        change = i - coin

        if change >= 0:
            counter += lst[change]
    lst[i] = counter

print(lst[-1] % (10**9 + 7))




Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const in maxn = 25;
const in inf = 1e9;

in grid[maxn][maxn],dist[maxn][maxn],cur,at,xx[]={1,-1,0,0},yy[]={0,0,1,-1};

void bfs(in x,in y)
{
    in jafoi[maxn][maxn];
    rep(i,0,maxn)
    {
        rep(j,0,maxn) jafoi[i][j] = 0;
    }
    jafoi[x][y] = 1;
    queue<ii> q;
    q.push(ii(x,y));
    while(!q.empty())
    {
        ii agr = q.front();
        q.pop();
        rep(i,0,4)
        {
            in u = agr.F+xx[i];
            in v = agr.S+yy[i];
            if(grid[u][v] == 1 and jafoi[u][v] == 0)
            {
                q.push(ii(u,v));
                dist[u][v] = dist[agr.F][agr.S]+1;
                jafoi[agr.F+xx[i]][agr.S+yy[i]] = 1;
            }
        }
    }
}

int main()
{
    IOS;
    in n,m,ans = -1;
    cin >> n >> m;
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            char c;
            cin >> c;
            if(c == '.') grid[i+1][j+1] = 1;  
        }
    }
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            rep(k,0,maxn)
            {
                rep(l,0,maxn) dist[k][l] = 0;
            }
            if(grid[i+1][j+1] == 1)
            {
                bfs(i+1,j+1);
                in cur = -1;
                rep(k,0,maxn)
                {
                    rep(l,0,maxn) cur = max(cur,dist[k][l]);
                }
                ans = max(ans,cur);
            } 
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split('\n');
  var limit = input[5];
  var max = input[4];
  var min = input[0];
  var maxDistance = max - min;
  if(maxDistance > limit) {
    console.log(':(');
  } else {
    console.log('Yay!');
  }
}

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


Measured memory_bytes: 7372
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

nx = n * max(max(x), a)
y = [xi - a for xi in x]
dp = [[0 for j in range(2 * nx + 1)] for i in range(n + 1)]
dp[0][nx] = 1

for i in range(n):
    for j in range(2 * nx + 1):
        if j - y[i] > 2 * nx:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = dp[i][j] + dp[i][j - y[i]]

print(dp[n][nx] - 1)


Measured memory_bytes: 5744
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N + 1, 0);
    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        A[l]++;
        A[r + 1]--;
    }
    for (int i = 0; i < N; i++) A[i+1] += A[i];

    int ret = 0;
    for (int i = 0; i < N; i++) if (A[i] == M) ret++;
    cout << ret << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<vector<int>> mat(n,vector<int>(3));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>mat[i][j];
        }
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int max = INT_MIN;
            for(int k=0;k<3;k++){
                if(j!=k && max<mat[i-1][k]){
                    max = mat[i-1][k];
                }
            }
            mat[i][j]+=max;
        }
    }
    int max = INT_MIN;
    for(int i=0;i<3;i++){
        if(max<mat[n-1][i])
            max = mat[n-1][i];
    }
    cout<<max<<endl;
    return 0;
}

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

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int M[N+1][N+1];  // 隣接行列

void bfs(int n, int d[], int color[]) {
  int vertex;
  queue<int> Q;
  
  // 初期状態
  for (int i = 1; i <= n; i++) {
    d[i] = -1;
    color[i] = WHITE;
  }
  vertex = 1;  // 始点
  d[vertex] = 0;
  Q.push(vertex);
  //bfs
  while (!Q.empty()) {
    vertex = Q.front();
    Q.pop();
    color[vertex] = GRAY;
    // 見訪問の隣接する頂点を探してキューに入れる
    for (int i = 1; i <= n; i++) {
      if (M[vertex][i] && color[i] == WHITE) {
        color[i] = GRAY;
        Q.push(i);
        d[i] = d[vertex] + 1;  // 距離
      }
    }
    color[vertex] = BLACK;  // 処理終了
  }
}

int main() {
  int i, j, n, u, k, v, d[N+1], color[N+1];

  cin >> n;
  // 与えられた隣接リストを隣接行列表現に直す
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    for (j = 0; j < k; j++) {
      cin >> v;
      M[u][v] = 1;
    }
  }
      
  // bfs
  bfs(n, d, color);

  // 出力
  for (i = 1; i <= n; i++) cout << i << " " << d[i] << endl;

  return 0;
}



Measured memory_bytes: 3128
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    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 Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




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

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



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=0;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  sort(ALL(v));
  rep(i,n-1){
    for(ll j=i+1;j<n;j++){
      ll k=lower_bound(ALL(v),v[i]+v[j])-v.begin();
      ans+=k-(j+1);
    }
  }
  cout<<ans<<endl;
}

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

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

int ans;
vector<string> f;

void solve(int x, int y)
{
  if (x < 0 || x >= f[0].size())
    return;
  if (y < 0 || y >= f.size())
    return;
  if (f[y][x] == '#')
    return;
  
  ++ans;
  f[y][x] = '#';

  for (int i = 0; i < 4; ++i)
    solve(x+dx[i], y+dy[i]);
}

int main()
{
  int W, H, x, y;
  for ( ; ; ) {
    cin >> W >> H;
    if (W == 0 && H == 0)
      break;

    f.clear();
    for (int i = 0; i < H; ++i) {
      string tmp;
      cin >> tmp;
      int a = tmp.find_first_of("@", 0);
      if (a != string::npos) {
	x = a;
	y = i;
      }
      f.push_back(tmp);
    }
    ans = 0;
    solve(x, y);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int max=0;
            int min=10000;
            int j=0;
            int k=0;
            int ave;
            int sum=0;
            int[] s = new int[n];
            for(int i=0;i<n;i++){
                s[i] = sc.nextInt();
                if(s[i]>=max){
                    max=s[i];
                    j=i;
                }
                if(s[i]<=min){
                    min=s[i];
                    k=i;
                }
            }
            for(int i=0;i<n;i++){
                if(i==j||i==k) sum-=s[i];
                sum += s[i];
            }
            ave = (int)(sum/(n-2));
            System.out.println(ave);
        }
    }
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	string s;cin>>s;
	rep(i,s.size()){
		if(i%2==0){
			if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
				
			}
			else{
				puts("No");return 0;
			}
		}
		else{
			if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
			}
			else{
				puts("No");return 0;
			}
		}
	}
	puts("Yes");
}

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

int main() {
  int n;
  cin>>n;
  deque<int> a;
  rep(i,n){
    int x;
    cin>>x;
    if(i%2==1){
      a.push_back(x);
    }
    else{
      a.push_front(x);
    }
  }
  if(n%2==1){
    rep(i,n) {
      cout<<a.at(i);
      if(i!=n-1){
        cout<<" ";
      }
    }
  }
  else{
    rep(i,n) {
      cout<<a.at(n-i-1);
      if(i!=n-1){
        cout<<" ";
      }
    }
  }
  cout<<endl; 
}

Measured memory_bytes: 2944