akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    int pt = 0, px = 0, py = 0;
    rep(i, n) {
        int t, x, y;
        cin >> t >> x >> y;
        if (!((t - pt) >= abs(x - px) + abs(y - py) &&
              ((t - pt) - abs(x - px) - abs(y - py)) % 2 == 0)) {
            cout << "No" << endl;
            return 0;
        }
        pt = t;
        px = x;
        py = y;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10
#define MP make_pair

int map[124][124];
bool map_flg[124][124];
int x_move[] = { 0,0,1,-1 };
int y_move[] = { -1,1,0,0 };

int main() {
	int w, h;

	while (cin >> w >> h && w != 0 && h != 0) {
		memset(map, 0, sizeof(map));
		memset(map_flg, true, sizeof(map_flg));
		int xs, ys;
		int xg, yg;
		int n;

		cin >> xs >> ys >> xg >> yg >> n;

		for (int i = 1; i <= n; ++i) {
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			int x_, y_;
			if (d == 0) {
				x_ = 4;
				y_ = 2;
			}
			else {
				x_ = 2;
				y_ = 4;
			}
			for (int j = y; j < y + y_; ++j) {
				for (int j2 = x; j2 < x + x_; ++j2) {
					map[j][j2] = c;
				}
			}
		}

		if (map[ys][xs] != map[yg][xg]) {
			cout << "NG" << endl;
			continue;
		}

		stack<pair<int, int> > st;
		st.push(MP(xs, ys));
		int m_c = map[ys][xs];
		bool flg = false;
		while (!st.empty()) {
			int x = st.top().first, y = st.top().second;
			st.pop();
			map_flg[y][x] = false;
			for (int i = 0; i < 4; ++i) {
				int x_ = x + x_move[i], y_ = y + y_move[i];
				if (map[y_][x_] == m_c && map_flg[y_][x_]) {
					if (y_ == yg && x_ == xg) {
						flg = true;
						break;
					}
					st.push(MP(x_, y_));
				}
			}
			if (flg) { break; }
		}

		if (flg) { cout << "OK" << endl; }
		else { cout << "NG" << endl; }
	}

	return 0;
}

Measured memory_bytes: 3148
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int n = Integer.parseInt(strAry[0]);
		int m = Integer.parseInt(strAry[1]);
		int[][] matrix = new int[n][m];
		int[] vector = new int[m];
		for (int i = 0; i < n; i++) {
			String[] strMat = br.readLine().split(" ");
			for (int j = 0; j < m; j++) {
				matrix[i][j] = Integer.parseInt(strMat[j]);
			}
		}
		for (int i = 0; i < m; i++) {
			vector[i] = Integer.parseInt(br.readLine());
		}
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				c[i] += matrix[i][j] * vector[j];
				}
			System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 27628
n, k = [int(i) for i in input().split()]
mod = 10**9+7
ans = 0
a = [0]
for i in range(1, k + 1):
    a.append(pow(k // i, n, mod))

ans = 0
b = [0]*(k+1)
for i in reversed(range(1, k + 1)):
    c = a[i]
    for j in range(i + i, k + 1, i):
        c -= b[j]
    c %= mod
    b[i] = c
    ans += c * i
    ans %= mod
print(ans)


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

int main()
{
    int R, C; cin >> R >> C;

    auto grid = vector<string>(R);
    for (auto& row : grid) cin >> row;

    auto trace = vector<string>(R);
    for (auto& row : trace) row = string(C, '.');

    auto r = 0, c = 0;
    while (true)
    {
        trace[r][c] = '#';
        if (r == R-1 && c == C-1) break;
        else if (r != R-1 && grid[r+1][c] == '#') r++;
        else if (c != C-1 && grid[r][c+1] == '#') c++;
        else break;
    }

    cout << (grid == trace ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 384
import Control.Applicative
import Control.Monad
main = do
--     ss <- (map read . words) <$> getLine
--     putStrLn $ show (head ss)
--     s <- (read $ (head ss))::Int
--     s <- head ss
    ss <- string2int <$> getLine
    if ss == 0
      then return()
      else do
           (putStrLn $ show ((length $ collats ss)-1))
           main


collats 1 = [1]
collats n
    | even n = n : collats (n `div` 2)
    | odd n = n : collats (n * 3 +1)

-- rInt.hs
rInt :: String -> Int
rInt str = read str :: Int  -- rInt ?????? read Int ?????\?
string2int str = read str :: Int -- string2int ??? string to int ?????\

Measured memory_bytes: 4044
//此题23333333333
#include<iostream>
using namespace std;
int n,m,i,j,t[101],x,ans,p;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>t[i];
		ans+=t[i];
	}
	cin>>m;
	for(i=1;i<=m;i++)
	{
		cin>>p>>x;
		cout<<ans-t[p]+x<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector <int> a;
vector <int> all;
int n,m;


int main() {

  while(1) {
    cin >> n >> m;
    if(n == 0 && m ==0) break;
    a.resize(n);
    for(int i=0;i<n;i++) cin >>a[i];

    a.push_back(0);
    all.clear();
    for(int i=0;i<a.size();i++) 
      for(int j=i;j<a.size();j++)
	all.push_back(a[i]+a[j]);

    sort(all.begin(),all.end());

    int ans = 0;
    int allsize = all.size();
    int b = 0;

    for(int i=allsize-1;i>= 0;i--) {
      for(int j=b;j<allsize;j++) {
	int sum = all[i] + all[j];
	if(sum > m) break;
	b++;
	ans = max(ans,sum);
      }
      if(ans == m) break;
    }


    cout << ans <<endl;
  }
  return 0;
  
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;

int main() {
    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        cout << x * r - d << '\n';
        x = x * r - d;
        
    }
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int keta(long long S) {
    int ans = 1;
    while (true) {
        if (S < 10) {
            break;
        }
        ans++;
        S = floor(S / 10);
    }
    return ans;
}

int sub(int a, int b) {
    int ans;
    if (a < b) {
        ans = b - a;
        return ans;
    }
    ans = a - b;
    return ans;
}

int main() {
    long long S;
    cin >> S;
    vector<long long> data(keta(S));
    long long num;
    int N = keta(S);
    for (int i = N - 1; 0 <= i; i--) {
        num = S % 10;
        data.at(i) = num;
        S = floor(S / 10);
    }
    int sum, ansa;
    int ans = sub(data.at(0) * 100 + data.at(1) * 10 + data.at(2), 753);
    for (int i = 1; i < N - 2; i++) {
        sum = sub(data.at(i) * 100 + data.at(i + 1) * 10 + data.at(i + 2), 753);
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int 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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s = "ABC";
    string t;
    cin >> t;
    if(s == t )cout << "ARC" << endl;
    else cout << s << endl;
}

Measured memory_bytes: 3612
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 3010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,m,i,j,k,x,y,z,Ans;
LL a[N][N],f[N][N][4];

IL int Abs(LL x){return (x<0)?-x:x;}
IL void Swap(LL &a,LL &b){a^=b^=a^=b;}
IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	m=read();	k=read();
	for (i=1;i<=k;i++){
		x=read();	y=read();	z=read();
		a[x][y]+=z;
	}
	memset(f,-1,sizeof(f));
	f[1][1][0]=0;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++){
			for (k=3;k>=0;k--){
				if (f[i][j][k]==-1)	continue;
				if (a[i][j] && k<3)
					f[i][j][k+1]=Max(f[i][j][k+1],f[i][j][k]+a[i][j]);
				}
			for (k=0;k<=3;k++){
				if (f[i][j][k]==-1)	continue;
				if (j<m)
					f[i][j+1][k]=Max(f[i][j][k],f[i][j+1][k]);
				if (i<n)
					f[i+1][j][0]=Max(f[i][j][k],f[i+1][j][0]);
			}
		}
	Ans=Max(f[n][m][0],f[n][m][1]);
	Ans=Max(Ans,Max(f[n][m][2],f[n][m][3]));
	printf("%lld\n",Ans);
	return 0;
}

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

ans = [0] * (N + 5)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if tmp <= N:
                ans[tmp] += 1

for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 74596
#include <algorithm>
#include <cstdio>
#include <climits>
#include <queue>
#include <utility>

const int N = 500000;

int n, m, a[N], result[N];
std::pair<int, int> ma[N << 1];
std::priority_queue<int> queue;

int get_id(int l, int r)
{
    return l + r | l != r;
}

void build(int l, int r)
{
    int id = get_id(l, r);
    if (l == r) {
        ma[id] = {a[l], l};
    } else {
        int m = l + r >> 1;
        build(l, m);
        build(m + 1, r);
        ma[id] = std::max(ma[get_id(l, m)], ma[get_id(m + 1, r)]);
    }
}

std::pair<int, int> query(int l, int r, int a, int b)
{
    if (b < l || r < a) {
        return {INT_MIN, -1};
    }
    if (a <= l && r <= b) {
        return ma[get_id(l, r)];
    }
    int m = l + r >> 1;
    return std::max(query(l, m, a, b), query(m + 1, r, a, b));
}

void remove(int l, int r, int k)
{
    if (k < l || r < k) {
        return;
    }
    int id = get_id(l, r);
    if (l == r) {
        ma[id] = {INT_MIN, -1};
    } else {
        int m = l + r >> 1;
        remove(l, m, k);
        remove(m + 1, r, k);
        ma[id] = std::max(ma[get_id(l, m)], ma[get_id(m + 1, r)]);
    }
}

void check(int i)
{
    auto ret = query(0, n - 1, i * m, (i + 1) * m - 1);
    if (ret.first != INT_MIN && query(0, n - 1, ret.second - m + 1, ret.second + m - 1).first == ret.first) {
        queue.emplace(ret.second);
    }
}

int main()
{
//#ifdef LOCAL_JUDGE
//    freopen("F.in", "r", stdin);
//#endif
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
        a[i] --;
    }
    build(0, n - 1);
    for (int i = 0; i * m < n; ++ i) {
        check(i);
    }
    int cnt = n;
    while (!queue.empty()) {
        int idx = queue.top();
        queue.pop();
        if (result[idx]) {
            continue;
        }
        result[idx] = cnt --;
        remove(0, n - 1, idx);
        idx /= m;
        check(idx);
        check(idx - 1);
        check(idx + 1);
    }
    for (int i = 0; i < n; ++ i) {
        printf("%d\n", result[i]);
    }
}


Measured memory_bytes: 17392
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,L,T;
int X[100010];
int W[100010];
int ans[100010];

int main(){
	scanf("%d%d%d" , &N , &L , &T);
	repp(i,0,N){
		scanf("%d%d" , X+i , W+i);
		if(W[i] == 1){
			ans[i] = (T + X[i]) % L;
		} else {
			ans[i] = ((X[i] - T) % L + L) % L;
		}
	}
	LL p = 0;
	repp(i,1,N){
		if(W[i] != W[0]){
			int s = W[0] == 1 ? (X[i]-X[0]+L)%L : (X[0]-X[i]+L)%L;
			if(T*2>=s && s > 0) ++p;
			p += (T*2-s) / L;
		}
	}
	int y = ans[0];
	sort(ans,ans+N);
	p %= N;
	if(W[0] == 2) p = (N - p) % N;
	int z = 0;
	while(ans[z] != y) ++z;
	if(W[0] == 1 && ans[z] == ans[(z+1)%N]) ++z;
	repp(i,0,N){
		printf("%d\n" , ans[(z+N-p+i)%N]);
	}
	return 0;
}


Measured memory_bytes: 2304
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i,j,k in zip(a,b,c):
  if i == j and j == k:
    continue
  elif i == j or j == k or k == i:
    ans += 1
  else:
    ans += 2
print(ans)    

Measured memory_bytes: 3060
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    match a.cmp(&b) {
        std::cmp::Ordering::Less => println!("a < b"),
        std::cmp::Ordering::Equal => println!("a == b"),
        std::cmp::Ordering::Greater => println!("a > b"),
    }
}



Measured memory_bytes: 5028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main(){
int n;cin>>n;
string a,b;cin>>a>>b;
vector <char> v(2*n);
for(int i=0;i<n;i++){
    v[i*2]=a[i];
}
for(int i=1;i<n+1;i++){
    v[i*2-1]=b[i-1];
}
for(int i=0;i<2*n;i++)cout<<v[i];


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	int a,n;
	cin>>n>>a;
	if(n%500<=a)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}

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

int main()
{
  string s;
  cin >> s;
  bool N(false), W(false), S(false), E(false);
  for (const auto& c : s) {
    switch (c) {
    case 'N': N = true; break;
    case 'W': W = true; break;
    case 'S': S = true; break;
    case 'E': E = true; break;
    }
  }
  cout << ((N xor S) or (E xor W) ? "No" : "Yes") << endl;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n,m;
int main(){
	cin >> n >> m;
	set<int>ac;
	vector<int>wa(n+1);
	for(int i = 0; i < m; i++){
		int p;
		string s;
		cin >> p >> s;
		if(s == "AC")ac.insert(p);
		if(s == "WA" and ac.find(p) == ac.end())wa[p]++;
	}
	int wa_count = 0;
	for(int i = 1; i < n+1;i++){
		if(ac.find(i) != ac.end()){
			wa_count += wa[i];
		}
	}
	cout << ac.size() << " " << wa_count << endl;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long l, r;
	cin>>l>>r;
	long long n1 = l/2019;
	long long n2 = r/2019;
	if(n1==n2)
	{
		if(l%2019==0 || r%2019==0)
			cout<<0<<endl;
		else
		{
			long long m = INT_MAX;
			for(int i = l;i<r;i++)
			{
				for(int j = i+1;j<=r;j++)
				{
					long long p = ((i%2019)*(j%2019))%2019;
					if(p<m)
					{
						m = p;
					}
				}
			}
			cout<<m<<endl;
		}
	}
	else
	{
		cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
H,W,D=map(int,input().split())
a=[list(map(int,input().split())) for i in range(H)]
Q=int(input())

y=[[-1,-1] for i in range(H*W+1)]

for i in range(H):
    for j in range(W):
        y[a[i][j]]=[i,j]

x=[ [0] for i in range(D)]

for i in range(D):
    j=H*W-i-D
    while j>0:
        tmp1,tmp2=abs(y[j][0]-y[j+D][0]),abs(y[j][1]-y[j+D][1])
        x[i].append(x[i][-1]+tmp1+tmp2)
        j-=D

for q in range(Q):
    L,R=map(int,input().split())
    i=(H*W-R)%D
    l=(H*W-i-R)//D
    r=(H*W-i-L)//D
    print(x[i][r]-x[i][l])

Measured memory_bytes: 25716
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define el cout<<endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n; cin >> n;
    int x; cin >> x;
    vector<int> m(n);
    repeat (i, n) cin >> m[i];
    
    int ans = n;
    repeat (i, n) x -= m[i];
    
    sort(m.begin(), m.end());
    while (x >= m[0]) {
        x -= m[0];
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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


  cin >> n >> m;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    ma = max(ma, a);
    mi = min(mi, b);
  }
  cout << max(0LL, mi - ma + 1) << endl;





  return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

static large solve(vector<int> x, int k) {
    int n = x.size();
    x.resize(2 * n);
    for (auto i = 0; i < n; ++i) {
        x[n + i] = x[i];
    }
    auto sum = vector<large>(2 * n + 1);
    sum[0] = 0;
    for (auto i = 0; i < 2 * n; ++i) {
        sum[i + 1] = sum[i] + x[i];
    }

    auto best = LLONG_MIN;
    auto wholesum = sum[n] - sum[0];

    for (int start = 0; start < n; ++start) {
        for (int size = 1; size <= min(n, k); ++size) {
            auto L = start;
            auto R = start + size;
            auto sumLR = sum[R] - sum[L];
            auto loops = (k - size) / n;
            best = max({best, sumLR, sumLR + wholesum * loops});
        }
    }
    return best;
}

int main()
{
    int n, k;
    cin >> n >> k; // 5000, 10^9
    auto p = vector<int>(n);
    auto c = vector<int>(n);
    for (auto& p_i : p) {
        cin >> p_i;
        p_i--;
    }
    for (auto& c_i : c) {
        cin >> c_i;
    }

    auto visited = vector<char>(n);
    auto x = vector<vector<int>>(n);
    
    for (int start = 0; start < n; ++start) {
        if (visited[start]) continue;
        auto&& xx = x[start];
        auto i = start;
        do {
            xx.push_back(c[i]);
            visited[i] = true;
            i = p[i];
        } while (i != start);
    }

    auto best = LLONG_MIN;
    for (int start = 0; start < n; ++start) {
        if (x[start].empty()) continue;
        best = max(best, solve(move(x[start]), k));
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 3880
def intmod2(n):
    return int(n) % 2

def rankmod2(A):
    global N, M
    ret = 0
    i = 0
    j = 0
    while i < N and j < M:
        if A[i][j]:
            ret += 1
        else:
            for ii in range(i+1, N):
                if A[ii][j]:
                    A[i], A[ii] = A[ii], A[i]
                    ret += 1
                    break
            else:
                j += 1
                continue
                
        for ii in range(i+1, N):
            if A[ii][j]:
                for jj in range(j, M):
                    A[ii][jj] = (A[ii][jj] + A[i][jj]) % 2
        i += 1
        j += 1
        
    return ret
                        
P = 998244353
N, M = map(int, input().split())
A = [list(map(intmod2, input().split())) for _ in range(N)]
r = rankmod2(A)
print((pow(2, N+M-1, P)-pow(2, N+M-r-1, P)) % P)

Measured memory_bytes: 3956
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> ii;
/////////////////////////////////////////////////////////////////////
# define M_PI 3.14159265358979323846 
int main()
{
  int r;
  cin >> r;
  r *= 2;
  double circ = M_PI * r;
  cout << circ << endl;
  return 0;
}


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

int main() {

	ll n; cin >> n;
	const ll p = 5;
	vector<ll> num(p, 0);
	for (ll i = 0; i < n; i++) {
		string s; cin >> s;
		if (s[0] == 'M') num[0]++;
		else if (s[0] == 'A') num[1]++;
		else if (s[0] == 'R') num[2]++;
		else if (s[0] == 'C') num[3]++;
		else if (s[0] == 'H') num[4]++;
	}
	ll ans = 0;	
	ans += num[0] * num[1] * num[2];
	ans += num[0] * num[1] * num[3];
	ans += num[0] * num[1] * num[4];	
	ans += num[0] * num[2] * num[3];
	ans += num[0] * num[2] * num[4];		
	ans += num[0] * num[3] * num[4];
	ans += num[1] * num[2] * num[3];
	ans += num[1] * num[2] * num[4];
	ans += num[1] * num[3] * num[4];
	ans += num[2] * num[3] * num[4];
	cout << ans << endl;
	return 0;	
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
	
	int a ,b ; cin>>a>>b;
	if(a>2*b) cout<<a-(2*b);
	else cout<<0;
    
    

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


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

string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  if (s.front() != s.back()) {
    cout << (s.size() % 2 == 1 ? "First" : "Second") << endl;
  } else {
    cout << (s.size() % 2 == 0 ? "First" : "Second") << endl;
  }

  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  char c = ' ';
  int redisue = 0;
  for (int i = 0; i < n; i ++)
  {
    char tmp;
    cin >> tmp;
    if (c != tmp)
    {
      c = tmp;
      redisue ++;
    }
  }
  
  cout << redisue;
  return 0;
}


Measured memory_bytes: 256
# 素因数分解してくれる関数
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

A, B = map(int, input().split())

A_soinsu = set(factorize(A))
B_soinsu = set(factorize(B))

ans = A_soinsu & B_soinsu

print(len(ans) + 1)


Measured memory_bytes: 3060
def cin; gets.split.map(&:to_i) end
def cout(*x); puts x.join(" ") end

exit if $0 != __FILE__

D = 10**9+7
n = gets.to_i
str = gets.chop
hs = {}
str.chars do |c|
  hs[c] = 0 if !hs[c]
  hs[c] += 1
end

r = hs.values.inject(1) {|cnt, x| (cnt * (x+1)) % D}

puts r-1

Measured memory_bytes: 1916
import sys
N = int(input())
S = [input() for _ in range(N)]

SM = dict()
for s in S:
    if not s in SM:
        SM[s] = 0
    SM[s] += 1
ansM = sorted(SM.items(), key=lambda x: x[1], reverse=True)

count = ansM[0][1]
ans = list()
for a in ansM:
    if a[1] == count:
        ans.append(a[0])
    else:
        break

for a in list(sorted(ans)):
    print(a)

Measured memory_bytes: 49868
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;

int n, q;
int A[32];

bool search(int key, int i, int sum) {
	if (sum == key) return true;
	if (i == n) return false;
	if (search(key, i + 1, sum + A[i])) return true;
	else return search(key, i + 1, sum);
}

int main(int argc, char **argv)
{
	int i, x;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &x);
		if (search(x, 0, 0)) puts("yes");
		else puts("no");
	}
	return 0;
}

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

#define f first
#define s second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define px pair<db, db>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define input(a) for (auto& el : a) cin >> el;
#define output(a) cout << '!'; for (auto& el : a) cout << el << ' '; cout << '\n'; cout.flush();
#define sz(el) int(el.size())
#define sq(a) ((a) * (a))
#define xll bitset<128>
#define xmin(a,b) a = min(a, b)
#define xmax(a,b) a = max(a, b)
#define sun(a) sort(all(a)); a.resize(unique(all(a)) - a.begin());
/**/  /// extra
//#define forn(i,n) for (int i = 0; i < n; ++i)
//#define rforn(i,n) for (int i = n - 1; i >= 0; --i)
#define bn '\n'
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
//#define G vector<vector<pii>>
#define GVE vector<vector<edge>>
#define usi unordered_set<int>
#define usp set<pii>
/**/

using namespace std;

const int INF = 1'000'000'017;
const ll LLINF = 1'000'000'000'000'000'017LL;
const ld inf = 1.0 / 0.0;
const ld eps = 1e-9;
const int MOD = 998244353;

//mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

//uniform_int_distribution<int> uid(l, r); [l, r]
//int x = uid(rng);

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

    int n, m;
    cin >> n >> m;
    multiset<int> z;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        z.emplace(x);
    }
    while (m--) {
        int el = *(--z.end());
        z.erase(--z.end());
        z.emplace(el / 2);
    }
    ll s = 0;
    for (auto& el : z) {
        s += el;
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Wire
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int x, y;
		x = parseInt(line.substring(0, line.indexOf(' ')));
		y = parseInt(line.substring(line.indexOf(' ') + 1));

		int g = gcd(x, y);

		int ans = 0;

		ans += g + 1;
		ans += (x / g - 1) * g;
		ans += (y / g - 1) * g;

		System.out.println(ans);
	}

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

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

int main(){
  int X,Y; //X匹、Y本
  cin >> X >> Y;
  rep(i,X+1){
    if(2*i+4*(X-i)==Y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3620
from operator import itemgetter

def main(N, A, B, C):
    a, b = 0, 0
    aindex = list(i[-1] for i in sorted(zip(C, A, B, range(N)), key=itemgetter(0, 1, 2), reverse=True))
    bindex = list(i[-1] for i in sorted(zip(C, B, A, range(N)), key=itemgetter(0, 1, 2), reverse=True))
    t = 0
    i = 0
    ai = 0
    bi = 0
    c = set()
    while i < N:
        if t == 0:
            while aindex[ai] in c:
                ai += 1
            a += A[aindex[ai]]
            c.add(aindex[ai])
        else:
            while bindex[bi] in c:
                bi += 1
            b += B[bindex[bi]]
            c.add(bindex[bi])
        i += 1
        t += 1
        t %= 2
    print(a - b)


if __name__ == "__main__":
    N = int(input())
    A, B = [], []
    C = []
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(a+b)
    main(N, A, B, C)

Measured memory_bytes: 45692
n = int(input())
i = 2
ans = 0
while True:
  if i * i > n:
    break
  if n % i == 0:
    cnt = 0
    while n % i == 0:
      n /= i
      cnt += 1
    k = 1
    while cnt >= k:
      cnt -= k
      k += 1
    ans += k - 1
  i += 1
if n > 1:
  ans += 1
print(ans)

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

t_0 = 0
x_0 = 0
y_0 = 0
flag = True

for _ in range(N):
    t,x,y = map(int,input().split())

    if not (abs(x-x_0) + abs(y-y_0) <= abs(t-t_0) and (abs(x-x_0)+abs(y-y_0))%2 == abs(t-t_0)%2):
        flag = False
    x_0 = x
    y_0 = y
    t_0 = t

print("Yes" if flag else "No")

Measured memory_bytes: 9204
N, Q = map(int, input().split())
S = input()
count = [0]*N
for i in range(1, N): #i番目までに何個の'AC'があったかをリスト格納
    count[i] += count[i-1]
    if S[i-1:i+1] == 'AC':
        count[i] += 1
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r-1]-count[l-1])

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double hh=h*30 + 0.5*m, mm=m*6;
  double kakudo = max(hh,mm) - min(hh,mm);
  chmin(kakudo, 360-kakudo);
  kakudo = kakudo*M_PI/180.0;

  double ans = a*a+b*b-2*a*b*cos(kakudo);

  printf("%.9f", sqrt(ans));
  return 0;
}


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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 N;
int A[200005];
int B[200005];

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        cin>>A[i];
        B[A[i]]++;
    }
    int sum=0;
    for(int i=0;i<=N;++i)if(B[i]>0)sum+=B[i]*(B[i]-1);
    for(int i=0;i<N;++i){
        int res=sum-B[A[i]]*(B[A[i]]-1);
        res+=max((B[A[i]]-1)*(B[A[i]]-2),0ll);
        cout<<res/2<<endl;
    }
}

Measured memory_bytes: 6736
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
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 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;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vec<ll> right(n+1,0),left(n+1,0);
    rep(i,n){
        left[i+1]=gcd(left[i],a[i]);
    }
    for(ll i=n-1;i>=0;i--) {
        
        right[i]=gcd(right[i+1],a[i]);
    }
    
    ll res=0;
    rep(i,n) res=max(res,gcd(left[i],right[i+1]));
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, L;
    cin >> N >> L;
    int S = 0;
    for(int i = 0; i < N; i++) {
        S += L + i;
    }
    int A = 1e6;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(A > abs(L + i)) {
            ans = S - (L + i);
            A = abs(L + i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
int N, sum = 0;
vector<int> S(101, 0);
bitset<100001> bit;

int main(void){
	
	scanf("%d", &N);
	for(int i = 0; i < N; ++i) scanf("%d", &S[i]), sum += S[i];
	
	bit[0] = true;
	for(int i = 0; i < N; ++i){
	    for(int p = sum; p >= S[i]; --p){
	        if(bit[p - S[i]]) bit[p] = true;
	    }
	}
	
	int ans = 0;
	for(int i = 0; i <= sum; ++i) if(bit[i] && i % 10 != 0) ans = max(ans, i);
	printf("%d", ans);
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <vector>
#define rep(i,n) for(int i=0; i< int(n); i++)
using namespace std;


int main(){
	int n,k;
	int a[60];
	cin >> n >> k ;
	rep(i,n) cin >> a[i];
	sort(a, a+n, greater<int>());
	int ans = 0;
	rep(i,k) ans += a[i];
	cout << ans << endl;

} 



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

int main() {
	int N, K;
    cin >> N >> K;
    int ans = 0;
    for (int i=0; i<N; i++){
    	int x, a, b;
    	cin >> x;
        a=x;
      	b=K-x;
		if (a<0) a = -a;
        if (b<0) b = -b;
        if (a<=b) ans += 2*a;
        if (a>b) ans += 2*b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdint>
#include <string>

int main() {
  std::string s;
  std::cin >> s;
  std::int_fast64_t k;
  std::cin >> k;

  std::int_fast64_t trailing_one_count = 0;
  char first_not_one = '\0';
  for (const char& c : s) {
    if (c == '1') {
      ++trailing_one_count;
    } else {
      first_not_one = c;
      break;
    }
  }

  std::cout << (k <= trailing_one_count ? '1' : first_not_one) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using Int = long long;

int main() {

	Int N;
	std::cin >> N;

	std::vector<Int> A(N);
	for (int i = 0; i < N; i++)std::cin >> A[i];

	std::sort(A.begin(), A.end());

	Int ans = 0;
	Int count = 0;


	while (count < N) {
		Int temp = A[count];
		Int res = 0;

		while (count < N && temp == A[count]) {
			count++;
			res++;
		}
		ans += res % 2;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <unordered_map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e6+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };


unordered_map<ll,ll> Map;
ll a[maxn];

int main()
{
    ll n = read();
    rep(i,1,n) a[i] = read(), Map[a[i]]++;
    sort(a+1,a+1+n);
    ll ans = 0;
    per(i,n,1)
    {
        for(ll j=0; (1LL<<j)<=1e10; j++)
        {
            if((1<<j) < a[i]) continue;
            if(Map[(1<<j)-a[i]]>=1&&((1<<j)-a[i]==a[i]?Map[a[i]]>=2:Map[a[i]]>=1 )) {Map[a[i]]--, Map[(1<<j)-a[i]]--, ans ++; break;}
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 39612
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn solve() {
    let big_prime: u64 = 1_000_000_000 + 7;
    input!(n: u64);

    let mut ow = 8;
    let mut with0 = 1;
    let mut with9 = 1;
    let mut with09 = 0;
    for _ in 2..=n {
        with09 = (with09 * 10 + with0 + with9) % big_prime;
        with0 = (with0 * 9 + ow) % big_prime;
        with9 = (with9 * 9 + ow) % big_prime;
        ow = (ow * 8) % big_prime;
    }

    println!("{}", with09);
}
fn main() {
    std::thread::Builder::new()
        .name("solve".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2268
#include <iostream>
#include <string>

using namespace std;

int main(){
    string S; cin >> S;
    bool f=true;
    int c=0;
    if(S[0] != 'A'){
        cerr << "111 ";
        f=false;
    }
    for(int i=1;i<S.length();i++){
        cerr << S[i] << " ";
        
        if(S[i] == 'C'){
             c++;
             if(i==1 || i==S.length()-1) f=false;
        //}else if(S[i]<'a' || S[i]>'z'){
        }else if(isupper(S[i])){
            cerr << "aaa " ;
            f=false;
        }
    }
    cerr << c << " " << f << endl;
    if(f){
        if(c==1){
            cout << "AC" << endl;
        }else{
            cout << "WA" << endl;
        }
    }else{
        cout << "WA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
using namespace std;
typedef long long ll;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9 + 7;

const int MAX_N = 100000;
int N;
ll x[MAX_N];
ll fac[MAX_N];
ll finv[MAX_N];
ll inv[MAX_N];
ll p[MAX_N];

int main() {
    cin >> N;
    rep(i,N) cin >> x[i];
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    repi(i,2,MAX_N) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
    rep(i,N-1) (p[i+1] = p[i] + inv[i+1]) %= MOD;
    ll ans = 0;
    rep(i,N-1) {
        (ans += (x[i+1]-x[i]) * p[i+1]) %= MOD;
    }
    repi(i,1,N) (ans *= i) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4096