akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #define fi first
    #define se second
    #define For(i, a, b) for (int i = (a); i <= (b); ++i)
    #define Ford(i, a, b) for(int i = (a); i >=(b); --i)
    #define endl '\n'
    #define debug(a) cout << a << endl
    using namespace std;
    
    typedef long long ll;
    typedef pair <ll, ll> pll;
    typedef vector <ll> vll;
    
    const ll maxN = 1e18;
    const ll minN = -1e18;
    const ll MOD = 1e9 + 7;
    
    const ll limit = 2e5 + 5;
    const ll limit1 = 1e6 + 5;
    const ll limit2 = 1e3 + 5;

    ll n, m, R;
    ll a[limit1];
    ll res = 0, sum = 0, ans = 0, kd, hkd;


    void FastIn(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }

    void ReadIn(){
        cin >> R;

         cout << R * 2 * 3.14;
    }
    int main(){
        FastIn();
        ReadIn();
    }
        

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

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> sum(n+1);
    for(int i = 1;i < n;i++){
        sum[i+1] = sum[i];
        if(s[i-1] == 'A' && s[i] == 'C')sum[i+1]++;
    }
    rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
}


Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vi h(n);
    rep(i, 0, n) cin >> h[i];

    int cnt = 0, m = 0;
    rep(i, 0, n)
    {
        if (h[i] >= m)
        {
            cnt++;
        }
        m = max(m, h[i]);
    }
    cout << cnt << endl;
}


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

using namespace std;
#define BUF (2005)

int n,z,w;
int a[BUF];

int main(void){
	cin >> n >> z >> w;
	for(int i=1;i<=n;i++)cin >> a[i];

	if(n==1){
		cout << abs(a[1]-w) << endl;
		return 0;
	}

	int ans =0;
	for(int i=1;i<n;i++){
		ans = max( ans , min(abs(a[i]-a[n]) , abs(a[n]-a[n-1])) );
	}
	ans = max( ans , abs(a[n]-w) );
	ans = max( ans , abs(a[n]-a[n-1]) );

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int maxn=1e5+5;
const int MOD=1e9+7;
int a[maxn];
ll f[maxn];
int first[maxn];
ll ans1[maxn];
int cmp(int a,int b)
{
    return a>b;
}
string s;
map<ll,int> mp;
vector<int> v;
int main()
{
    int n;
    int ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]) {
                    //cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;

}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int s, w; cin >> s >> w;
	if (s <= w) puts("unsafe");
	else puts("safe");
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cmath>

int main(){
  float a, b;
  std::cin >> a >> b;
  std::vector<int> percent8;
  std::vector<int> percent10;
  
  for (int i = std::ceil(a * 12.5); i < (a + 1) * 12.5; i++){
    percent8.push_back(i);
  }
  
  for (int i = std::ceil(b * 10); i < (b + 1) * 10 ; i++){
    percent10.push_back(i);
  }
  
  for (int i = 0; i < percent8.size(); i++){
    if (std::find(percent10.begin(), percent10.end(), percent8[i]) != percent10.end()){
      std::cout << percent8[i];
      return 0;
    }
  }
  
  std::cout << -1;
  return 0;
}

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

int main(){
   long long N, K;
   cin >> N >> K;

   long long n = 0;
   if (N < K){
      if (N > K-N){
         cout << K-N << endl;
      } else{
         cout << N << endl;
      }
   }else {
      if (N%K > K-N%K){
         cout << K-N%K << endl;
      } else{
         cout << N%K << endl;
      }
   }
}



Measured memory_bytes: 3616
s = input()
slen = len(s)
left = s[0: int((slen-1)/2)]
right = s[int((slen+1)/2): slen]
if s != s[::-1]:
    print('No')
elif left != left[::-1]:
    print('No')
elif right != right[::-1]:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
	int a,b,x=0;
	scanf("%d %d",&a,&b);
	int c[]={1,3,5,7,8,10,12};
	int d[]={4,6,9,11};
	if (a!=2||b!=2)
	{
		for (int i = 0; i < 7; ++i)
		{
			if (a==c[i])
			{
				for (int j = 0; j < 7 ; ++j)
				{
					if (b==c[j])
					{
						x=1;
					}
				}
			}
		}
		for (int k = 0; k < 4; ++k)
		{
			if (a==d[k])
			{
				for (int l = 0; l < 4; ++l)
				{
					if (b==d[l])
					{
						x=1;
					}
				}
			}
		}
	}
	if (x==1)
	{
		printf("Yes\n");
	}else 
	{
		printf("No\n");
	}
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int main() {
	string a,b,c;
	cin >> a >> b >> c;
	
	cout << "A" << b[0] << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
int a,b;
cin>>a>>b;
if(a>8 || b>8)
 cout<<":(";
else
 cout<<"Yay!";
system("pause");
return 0;
}

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

char ch[200010];
int p[30];
long long ans;

int main()
{
	scanf("%s",ch+1);
	for(int i=1;i<=strlen(ch+1);i++){
		p[ch[i]-'a']++;
		ans+=i-p[ch[i]-'a'];
	}
	printf("%lld\n",ans+1);
	return 0;
}

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

int main() {
  int N, A, B;
  int x;
  cin >> N >> A >> B;
  x = N * A;
  if(x < B || x == B){
    cout << x << endl;
  }
  else if(x > B){
    cout << B << endl;
  }
  return 0;
}

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

int main() {
	long long N, ANS = 0, Now = 0;
	priority_queue<long long> PQ;
	static long long V[300000], M[300000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> M[i];
		for (int j = 0; j < M[i]; j++) {
			cin >> V[Now];
			Now++;
		}
	}
	Now--;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = 0; j < M[i]; j++) {
			PQ.push(V[Now]);
			Now--;
		}
		ANS += PQ.top();
		PQ.pop();
	}
	cout << ANS << endl;
}


Measured memory_bytes: 9280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
typedef long long ll;
const int N = 2e5+10 , OO = 0x3f3f3f3f , mod = 1e9 + 7;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
 

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
  int n;
  scanf("%d", &n);
  map < int , string > mp;
  mp[2] = mp[4] = mp[5] = mp[7] = mp[9] = "hon";
  mp[0] = mp[1] = mp[6] = mp[8] = "pon";
  mp[3] = "bon";

  printf("%s\n", mp[n % 10].c_str());


  return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int n,var[4],chs[100100],bck[100100][4];
string str[100100];
void bao(int id){
	if(id==n+1){
		cout<<"Yes"<<endl;
		for(int i=1;i<=n;i++) cout<<(char)(chs[i]+'A'-1)<<endl;
		exit(0);
	}
	int x=str[id][0]-'A'+1;
	int y=str[id][1]-'A'+1;
	if(var[x]>=bck[id][x]){
		var[x]--;
		var[y]++;
		chs[id]=y;
		bao(id+1);
		var[y]--;
		var[x]++;
		return;
	}
	if(var[y]>=bck[id][y]){
		var[y]--;
		var[x]++;
		chs[id]=x;
		bao(id+1);
		var[x]--;
		var[y]++;
		return;
	}
	if(var[x]){
		var[x]--;
		var[y]++;
		chs[id]=y;
		bao(id+1);
		var[y]--;
		var[x]++;
	}
	if(var[y]){
		var[y]--;
		var[x]++;
		chs[id]=x;
		bao(id+1);
		var[x]--;
		var[y]++;
	}
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>var[1]>>var[2]>>var[3];
	for(int i=1;i<=n;i++){
		cin>>str[i];
	}
	int xx,yy;
	for(int i=n;i>=1;i--){
		xx=str[i][0]-'A'+1;
		yy=str[i][1]-'A'+1;
		bck[i][1]=bck[i+1][1];
		bck[i][2]=bck[i+1][2];
		bck[i][3]=bck[i+1][3];
		bck[i][xx]++;
		bck[i][yy]++;
	}
	bao(1);
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 16408
#include <stdio.h>

int main( void ) {
    int N, K;
    int h[100000];
    int i, ans;

    scanf("%d %d", &N, &K);
    for (i=0;i<N;++i) {
        scanf("%d", &h[i]);
    }

    ans = 0;
    for (i=0;i<N;++i) {
        if ( h[i] >= K ) {
            ans++;
        }
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 512
// NOT MY CODE
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define len(x) (int) x.length()
#define all(x) x.begin(),x.end()
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-4;
const int MAX=1e5+10;
const ll mod=1e9+7;
/****************************************  head  ****************************************/
int n,flag;
string s;
ll ans;
map<pair<string,string>,int> mp;
void dfs(int p,string a,string b)
{
	if(p==n)
	{
		if(flag) ans+=mp[MP(a,b)];
		else mp[MP(a,b)]++;
		return;
	}
	dfs(p+1,a+s[p],b);
	dfs(p+1,a,b+s[p]);
}
int main()
{
	while(~scanf("%d",&n))
	{
		cin>>s;
		mp.clear();
		flag=0;
		dfs(0,"","");
		flag=1;
		reverse(all(s));
		ans=0;
		dfs(0,"","");
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 87808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool jadgec=0,jadgef=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='C'){
            jadgec=1;
        }
        if(jadgec==1 && s[i]=='F'){
            jadgef=1;
        }

        if(jadgec==1 && jadgef==1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n[3], max, i, sum, maxi;

  scanf("%d %d %d", &n[0], &n[1], &n[2]);
  sum = 0;
  max = n[0];
  maxi = 0;
  for (i = 0; i <= 2; i++) {
    if (max < n[i]) {
      max = n[i];
      maxi = i;
    }
  }
  for (i = 0; i <= 2; i++) {
    if (maxi == i) {
      sum += 10 * n[i];
    }
    else {
      sum += n[i];
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
	int x, cnt = 1;
	
	while (1)
	{
		cin >> x;
		if (x == 0) return 0;
		cout << "Case " << cnt << ": " << x << "\n";
		cnt++;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>

using namespace std;

#define MAXN 100005

int N,M;
bool mark[MAXN];

vector<pair<int,int>> v[MAXN];
int len[MAXN];

bool DFS(int t)
{
	vector<pair<int,int>>::iterator it;
	for(it = v[t].begin() ; it!=v[t].end() ; it++)
	{
		int p = (*it).first;
		int val = (*it).second;
		if(!mark[p])
		{
			mark[p] = true;
			len[p] = len[t]+val;
			if(!DFS(p))return false;
		}
		else if(len[p] != len[t]+val)return false;
	}
	return true;
}

int main()
{
	cin>>N>>M;
	int L,R,D;
	while(M--)
	{
		scanf("%d %d %d",&L,&R,&D);
		v[L].push_back(make_pair(R,D));
		v[R].push_back(make_pair(L,-D));
	}
	for(int i=1 ; i<=N ; i++)
	{
		if(!mark[i])
		{
			mark[i] = true;
			if(!DFS(i))
			{
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n,k;
    cin2(n,k);
    lli v[n];
    ncin1(n,v);

    lli max_c = min(n,k);
    lli ans = 0;
    // 左右合わせて c 回取る
    REPE(c,0,max_c) {
        // left 個左から取り、right個右から取る。
        REPE(left,0,c) {
            lli right = c - left;

            lli cur = 0;
            //cur = sum_from_left[left] + sum_from_right[right];
            REP(i,0,left) {
                cur += v[i];
            }
            REP(i,0,right) {
                cur += v[n-i-1];
            }

            priority_queue<lli, vector<lli>, greater<lli>> que;
            REP(i,0,left) {
                if (v[i] < 0)
                    que.push(v[i]);
            }
            REP(i,0,right) {
                if (v[n-i-1] < 0)
                    que.push(v[n-i-1]);
            }
            // 負のやつの合計
            lli x = 0;
            REP(i,0,max<lli>(0, k-c)) {
                if (que.empty())
                    break;
                x += que.top();
                que.pop();
            }
            cur -= x;
            //cout3(left, right, cur);
            ans = max(cur, ans);
        }

    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    Cell[][] A = new Cell[3][3];
    A[0][0] = new Cell(sc.nextInt());
    A[0][1] = new Cell(sc.nextInt());
    A[0][2] = new Cell(sc.nextInt());
    A[1][0] = new Cell(sc.nextInt());
    A[1][1] = new Cell(sc.nextInt());
    A[1][2] = new Cell(sc.nextInt());
    A[2][0] = new Cell(sc.nextInt());
    A[2][1] = new Cell(sc.nextInt());
    A[2][2] = new Cell(sc.nextInt());
    int N = sc.nextInt();
    int[] called = new int[10];
    for(int i = 0; i < N; i++ ){
      called[i] = sc.nextInt();
      for (int j = 0; j < 3; j++) {
          for (int k = 0; k < 3; k++) {
              A[j][k].setCalled(called[i]);
          }
      }
    }
    sc.close();

    if ( (A[0][0].isCalled() && A[0][1].isCalled() && A[0][2].isCalled()) ||
         (A[1][0].isCalled() && A[1][1].isCalled() && A[1][2].isCalled()) ||
         (A[2][0].isCalled() && A[2][1].isCalled() && A[2][2].isCalled()) ||
         (A[0][0].isCalled() && A[1][0].isCalled() && A[2][0].isCalled()) ||
         (A[0][1].isCalled() && A[1][1].isCalled() && A[2][1].isCalled()) ||
         (A[0][2].isCalled() && A[1][2].isCalled() && A[2][2].isCalled()) ||
         (A[0][0].isCalled() && A[1][1].isCalled() && A[2][2].isCalled()) ||
         (A[0][2].isCalled() && A[1][1].isCalled() && A[2][0].isCalled()) ) {
        System.out.println("Yes");
    } else {
        System.out.println("No");
    }
    return;
  }
}

class Cell {
    private int num = 0;
    private boolean called;

    public Cell(int my_num) {
        num = my_num;
        called = false;
    }
    public void setCalled(int called_num) {
        if (num == called_num) {
            called = true;
        }
    }
    public boolean isCalled() {
        return called;
    }
}


Measured memory_bytes: 22612
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}
		br.close();

		Arrays.parallelSort(a);
		int mid = (a.length - 1) / 2;
		int l = 0;
		int r = a.length - 1;
		long ans = a[r] - a[mid];
		boolean rflg = true;
		while (l < mid && mid < r) {
			ans += a[r] - a[l];
			if (rflg) {
				r--;
			} else {
				l++;
			}
			rflg = !rflg;
		}
		if (a.length % 2 == 1) {
			mid = a.length / 2;
			l = 0;
			r = a.length - 1;
			long ans2 = a[mid] - a[l];
			rflg = false;
			while (l < mid && mid < r) {
				ans2 += a[r] - a[l];
				if (rflg) {
					r--;
				} else {
					l++;
				}
				rflg = !rflg;
			}
			ans = Math.max(ans, ans2);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 31016
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n, k;
	cin >> n >> k;
	vi h(n);
	rep(i, n) cin >> h[i];

	vi dp(n, INF);
	dp[0] = 0;
	rep(i, n) rep1(j, k) if(i + j < n) chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            var list = new List<Work>();
            int[] b;
            for(int i = 0; i < input; i++){
                b = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                list.Add(new Work(b[0], b[1]));
            }
            list.Sort();

            long currentTime = 0;

            foreach(var a in list){
                currentTime += a.Cost;
                if(currentTime > a.DeadLine){
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");


        }


            public class Work : IComparable<Work>{
                public int Cost{get;set;}
                public int DeadLine{get;set;}

                public Work(int i, int x){
                    Cost = i;
                    DeadLine = x;
                }

                public int CompareTo(Work x){

                    return this.DeadLine - x.DeadLine;
                }
            }
    }
}

Measured memory_bytes: 25248
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  ll ans=0;
  ll ab=0,b=0,a=0;
  ll cnt=0;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    for(int j=0;j<s.size()-1;j++)
      if(SUBS(s,j+1,j+2)=="AB")cnt++;
    if(s.front()=='B'&&s.back()=='A')
      ab++;
    else if(s.front()=='B')
      b++;
    else if(s.back()=='A')
      a++;
  }
  //cout<<ab<<" "<<a<<" "<<b<<endl;
  for(int i=0;i<min({ab,a,b});i++)ans+=2;
  ll num=min({ab,a,b});
  ab-=num;
  a-=num;
  b-=num;
  if(ab==0)ans+=min(a,b);
  else{
    if(ans==0&&a==0&&b==0)ans+=ab-1;
    else{
      ans+=ab;
    }
  }
  //  cout<<ans<<" "<<cnt<<endl;
  cout<<ans+cnt<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, x;
	cin >> n >> x;
	
	if (x == 1 or x == 2 * n - 1) {
		cout << "No" << endl;
	} else {
		int ans[2 * n - 1];
		memset(ans, -1, sizeof(ans));
		ans[n - 2] = x - 1;
		ans[n - 1] = x;
		ans[n] = x + 1;
		int now = 1;
		rep(i, 2 * n - 1) {
			if (ans[i] == -1) {
				while (abs(now - x) <= 1) now++;
				ans[i] = now++;
			}
		}
		cout << "Yes" << endl;
		rep(i, 2 * n - 1) cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2304
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    bool card[4][13] = {};
    for(int i = 0;i < n;i++)
    {
        char ch;
        int a;
        cin >> ch >> a;
        if(ch == 'S')
        {
            card[0][a - 1] = true;
        }
        else if(ch == 'H')
        {
            card[1][a - 1] = true;
        }
        else if(ch == 'C')
        {
            card[2][a - 1] = true;
        }
        else
        {
            card[3][a - 1] = true;
        }
    }
    for(int i = 0;i < 4;i++)
    {
        for(int j = 0;j < 13;j++)
        {
            if(!card[i][j])
            {
                if(i == 0)
                {
                    cout << "S ";
                }
                else if(i == 1)
                {
                    cout << "H ";
                }
                else if(i == 2)
                {
                    cout << "C ";
                }
                else
                {
                    cout << "D ";
                }
                cout << j + 1 << "\n";
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
const double PI=3.14159265358979323846;
 
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	long n, k;
	cin >> n >> k;

	long a = n / k;
	long ans = min( abs(n - a*k), abs(n - (a+1)*k) );

	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<iomanip>
#include<queue>

int main(){
	int n, m;
	std::vector<int> aList;
	std::vector<int> bList;

	std::cin>>n>>m;

	aList.resize(m);
	bList.resize(m);

	for(int i=0; i< m; i++){
		int tmpA, tmpB;
		std::cin>>tmpA>>tmpB;

		aList[i]= tmpA-1;
		bList[i]= tmpB-1;
	}

	std::vector<std::vector<int>> graph(n);

	for(int i=0; i<m; i++){
		graph[aList[i]].push_back(bList[i]);
		graph[bList[i]].push_back(aList[i]);
	}

	std::vector<int> node(n, -1);
	node[0]=0;

	std::queue<int> q;
	q.push(0);

	while(!q.empty()){
		int src= q.front();
		q.pop();

		for(int i=0; i< graph[src].size(); i++){
			int dst= graph[src][i];
			if(node[dst]< 0){
				q.push(dst);
				node[dst]= src;
			}
		}
	}


	bool isPossible= true;

	for(int i=0; i<node.size(); i++)
		if(node[i]<0)
			isPossible=false;

	if(isPossible){
		std::cout<<"Yes"<<std::endl;
		for(int i=1; i< node.size(); i++)
			std::cout<<node[i]+1<<std::endl;
	}
	else{
		std::cout<<"No"<<std::endl;

	}

	return 0;	

}

Measured memory_bytes: 11732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, K;
  cin >> N >> K;
  if (K > (N-1) * (N-2) / 2) {
    cout << -1 << '\n';
    return 0;
  }
  vector<P> edges;
  for (int i = 2; i <= N; i++) {
    edges.emplace_back(1, i);
  }
  int M = N - 1 + (N-1) * (N-2) / 2 - K;
  for (int i = 2; i <= N; i++) {
    for (int j = i+1; j <= N; j++) {
      edges.emplace_back(i, j);
    }
  }
  cout << M << '\n';
  rep(i, M) {
    printf("%d %d\n", edges[i].first, edges[i].second);
  }
  return 0;
}

Measured memory_bytes: 3812
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    double t,x;
    cin >> t >> x;
    if(t>=1 && t<=100 && x>=1 && x<=100)
    {
        double result= t/x;
        printf("%.10lf\n",result);
    }
    return 0;
}


Measured memory_bytes: 3720
import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, k = list(map(int,ipti().split()))
    s = input()

    lg = [0] * (n+3)

    s_first = s[0]
    s_last =s[-1]

    idx = 0

    if s_first == "0":
        lg[0] = 0
        idx = 1

    s_groupby = itertools.groupby(s)

    for _, group in s_groupby:
        lg[idx] = len(list(group))
        idx += 1

    if s_last == "0":
        idx += 1

    rn = 2*k + 1

    if rn >= idx:
        print(n)
        sys.exit()

    temp = sum(lg[0:rn])
    ans = temp

    for i in range(2, idx-rn+1, 2):
        temp -= (lg[i-2] + lg[i-1])
        temp += (lg[i-2+rn] + lg[i-1+rn])
        ans = max(ans, temp)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 45936
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using pint = pair<int,int>;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int 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;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int H, W, N;
vector<pint> wall;
long long dp[3100][2] = {0};

int main() {
    COMinit();
    cin >> H >> W >> N;
    wall.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> wall[i].first >> wall[i].second;
        --wall[i].first, --wall[i].second;
    }
    wall.push_back(pint(0, 0));
    sort(wall.begin(), wall.end());
    N = (int)wall.size();
    dp[0][0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int num = 0; num < 2; ++num) {
            for (int j = i + 1; j < N; ++j) {
                if (wall[j].first < wall[i].first || wall[j].second < wall[j].second) continue;
                int dx = wall[j].first - wall[i].first;
                int dy = wall[j].second - wall[i].second;
                long long factor = COM(dx + dy, dx);
                dp[j][1 - num] += dp[i][num] * factor % MOD;
                dp[j][1 - num] %= MOD;
            }
        }
    }
    
    long long res = COM(H+W-2, H-1);
    for (int i = 1; i < N; ++i) {
        for (int num = 0; num < 2; ++num) {
            int dx = H-1-wall[i].first;
            int dy = W-1-wall[i].second;
            long long tmp = dp[i][num] * COM(dx + dy, dx) % MOD;
            
            //cout << i << ", " << num << ": " << dp[i][num] << ", " << tmp << endl;
            
            if (num & 1) res = (res - tmp + MOD) % MOD;
            else res = (res + tmp) % MOD;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 5248
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

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

struct Monoid {
  int64_t val, len;
  Monoid() {}
  Monoid(int64_t v, int64_t l) : val(v), len(l) {}
  static Monoid ident() { return Monoid(0, 0); }
  static Monoid multiply(Monoid l, Monoid r) {
    return Monoid(l.val + r.val, l.len + r.len);
  }
  bool operator==(const Monoid &rhs) const {
    return val == rhs.val and len == rhs.len;
  }
};

struct Lonoid {
  int64_t x;
  Lonoid() {}
  Lonoid(int64_t x) : x(x) {}
  static Lonoid ident() { return Lonoid(numeric_limits<int>::min()); }
  static Lonoid multiply(Lonoid f, Lonoid g) { // f \circ g
    if (f == Lonoid::ident()) return g;
    return f;
  }
  static Monoid apply(Lonoid f, Monoid m) { // f(m)
    if (f == Lonoid::ident()) return m;
    return Monoid(f.x * m.len, m.len);
  }
  bool operator==(const Lonoid &rhs) const { return x == rhs.x; }
};

template <typename M, typename L>
struct SegmentTree {
  int n;
  M em;
  L el;
  vector<M> dat;
  vector<L> laz;
  SegmentTree(int N, vector<M> a) {
    assert(N == (int)a.size());
    n = 1;
    em = M::ident();
    el = L::ident();
    while (n < N) {
      n *= 2;
    }
    dat.resize(n * 2 - 1, em);
    rep(i, N) dat[i + n - 1] = a[i];
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = M::multiply(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
    laz.resize(n * 2 - 1, el);
  }
  void _update(int i, L f) {
    dat[i] = L::apply(f, dat[i]);
    laz[i] = L::multiply(f, laz[i]);
  }
  void update(int ql, int qr, L f) { update(ql, qr, f, 0, 0, n); }
  void update(int ql, int qr, L f, int i, int il, int ir) {
    if (qr <= il or ir <= ql) return;
    if (ql <= il and ir <= qr) {
      _update(i, f);
    } else {
      auto m = (il + ir) / 2, lch = i * 2 + 1, rch = i * 2 + 2;
      _update(lch, laz[i]);
      _update(rch, laz[i]);
      laz[i] = el;
      update(ql, qr, f, lch, il, m);
      update(ql, qr, f, rch, m, ir);
      dat[i] = M::multiply(dat[lch], dat[rch]);
    }
  }
  M query(int ql, int qr) { return query(ql, qr, 0, 0, n); }
  M query(int ql, int qr, int i, int il, int ir) {
    if (ql <= il and ir <= qr) {
      return dat[i];
    } else if (qr <= il or ir <= ql) {
      return em;
    } else {
      auto m = (il + ir) / 2;
      return L::apply(laz[i], M::multiply(query(ql, qr, i * 2 + 1, il, m),
                                          query(ql, qr, i * 2 + 2, m, ir)));
    }
  }
};

int main() {

  int n, q;
  cin >> n >> q;
  SegmentTree<Monoid, Lonoid> seg(n, vector<Monoid>(n, Monoid(0, 1)));
  while (q--) {
    int t;
    cin >> t;
    if (t == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      seg.update(s, t + 1, Lonoid(x));
    } else {
      int s, t;
      cin >> s >> t;
      cout << seg.query(s, t + 1).val << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 10508
#include <stdio.h>
#include <string.h>
 
int xmove[4001];
int ymove[4001];
int xmove_len=0, ymove_len=0;
 
char S[8001];
int goalx,goaly;
 
char dp[4001][8001];
 
int abs(int a){ return (a < 0)? -a : a;}
char possible(int goal, int * move, int move_len){
    if(move_len == 0){
        if(goal == 0) return 1;
        else          return 0;
    }
    
    int sum = 0;
    for(int i = 0; i < move_len ; i++) sum += move[i];
      
    if(sum < goal || (sum-goal) % 2 == 1) return 0;
 
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    dp[0][move[0]]=1;
    for(int i = 1; i < move_len; i++){
        for(int j = 0; j <= (sum-goal)/2 ; j++){
            dp[i][j] |= dp[i-1][j];
            if(j-move[i] >= 0) dp[i][j] |= dp[i-1][j-move[i]];    
        }
    }
    return dp[move_len-1][(sum-goal)/2];
}
 
int main(void){
    scanf("%s",S);
    scanf("%d %d",&goalx,&goaly);
 
    int xmove_ind = 0, ymove_ind = 0;
    char dir_x = 1;
    int count = 0;
    for(int i = 0; i <= strlen(S); i++){
        if(i == strlen(S) || S[i] == 'T' ){
            if(dir_x) xmove[xmove_ind++] = count;
            else      ymove[ymove_ind++] = count;
            
            dir_x = !dir_x;
            count = 0;
        }else{
            count++;
        }
    }
    xmove_len = xmove_ind;
    ymove_len = ymove_ind;

    if(possible(abs(goaly),ymove,ymove_len)){
        if(xmove_len==1){
            if(goalx == xmove[0]) puts("Yes");
            else                  puts("No");
        }else{
            if(possible(abs(goalx-xmove[0]), &(xmove[1]), xmove_len-1)) puts("Yes");
            else                                                        puts("No");
        }
    }else{
        puts("No");
    }
    
    return 0;
}

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

const int N = 2e5 + 10;

int dp[N];
int n, c;
char ss[N];
long long pw[N], sum, ans[N];

void solve (int c, int t) {
	if (c == 0) return;
	
	sum = 0; pw[0] = 1;
	for (int i = 1; i <= n; i ++) {
		pw[i] = (pw[i - 1] * 2) % c;
		sum = (sum * 2 + (ss[i] - '0')) % c;
	}
	if (t == 1) {
		for (int i = 1; i <= n; i ++) if (ss[i] == '0') {
			long long x = (sum + pw[n - i]) % c;
			ans[i] = dp[x] + 1;
		}
	} else {
		for (int i = 1; i <= n; i ++) if (ss[i] == '1') {
			long long x = (sum - pw[n - i] + c) % c;
			ans[i] = dp[x] + 1;
		}
	}
}

int main (void) {
	for (int i = 1; i < N; i ++) 
		dp[i] = dp[i % __builtin_popcount(i)] + 1;

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

	if (c == 0) {
		for (int i = 1; i <= n; i ++)
			puts("1");
	} else {
		solve(c + 1, 1);
		solve(c - 1, 0);
		for (int i = 1; i <= n; i ++)
			printf("%lld\n", ans[i]);
	}

}

Measured memory_bytes: 7832
#include<stdio.h>
int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  int K;
  scanf("%d",&K);
  long long int ans=0;
  for(int i=1;i<K+1;i++)
	  for(int j=1;j<K+1;j++){
        int x=gcd(i,j);
		  for(int k=1;k<K+1;k++)ans+=gcd(x,k);
      }
  printf("%d",ans);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int MOD = 2019;

int main(){
    string s;
    cin >>s;
    int n = s.size();

    ll ans = 0;
    vector<int> ct(MOD);
    for(const char &c:s){
        int v = c-'0';

        vector<int> nx(MOD);
        rep(i,MOD) nx[(i*10+v)%MOD] += ct[i];
        ++nx[v];

        swap(ct,nx);
        ans += ct[0];
    }

    cout << ans << "\n";
    return 0;
}


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

int main()
{
  char c;
  cin >> c;
  
  if((c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'))
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<long long, long long> pll;
typedef pair<int, int> pi;
typedef long double ld;
typedef pair<long double, long double> pld;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j, k;
    ll N, K;
    cin >> N >> K;
    vll P, C(N);
    for(i = 0; i < N; i++) {
        ll p;
        cin >> p;
        p--;
        P.push_back(p);
    }
    for(auto &e : C)
        cin >> e;
    ll ans = -INF;
    for(i = 0; i < N; i++) {
        ll s = 0;
        vll visited(N, 0);
        visited[i] = 1;
        ll cnt = 0;
        ll p = i;
        while(cnt < K) {
            p = P[p];
            s += C[p];
            ans = max(ans, s);
            cnt++;
            if(visited[p] == 1) {
                if(s <= 0)
                    break;
                else {
                    ll nl = cnt;
                    s *= (K / nl) - 1;
                    ans = max(ans, s);
                    cnt = nl * ((K / nl) - 1);
                    while(cnt < K) {
                        p = P[p];
                        s += C[p];
                        ans = max(ans, s);
                        cnt++;
                    }
                }
            }
            visited[p] = 1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n, m;
   cin >> n >> m;
   int L, R;
   L = -1, R = 1e6;
   rep(i, 0, m) {
      int l, r;
      cin >> l >> r;
      L = max(L, l);
      R = min(R, r);
   }
   if (R < L) {
      cout << 0 << endl;
   } else {
      cout << R - L + 1 << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<queue> 
using namespace std;
int x;
int main(){
//	freopen("x.txt","r",stdin);
	scanf("%d",&x);
	x=x%1000;
	cout<<(1000-x)%1000<<endl;;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

const pair<ld, ld> Fail(-1, -1);

int w, h;
vs fld;
vector<vi> ind;

pair<ld, ld> solve(int v) // weight, x
{
	vector<ld> x;
	set<int> on;
	REP(i, h)REP(j, w)
	{
		if (ind[i][j] != v) continue;
		x.push_back(j);
		if (i > 0 && ind[i - 1][j] != -1 && ind[i - 1][j] != v) on.insert(ind[i - 1][j]);
	}
	for (auto u : on)
	{
		auto tmp = solve(u);
		if (tmp.first == -1) return Fail;
		int l = w, r = 0;
		FOR(i, 1, h)REP(j, w)
		{
			if (ind[i][j] == v && ind[i - 1][j] == u)
			{
				chmin(l, j);
				chmax(r, j);
			}
		}
		if (tmp.second + 0.5 <= l || tmp.second +0.5 >= r + 1) return Fail;
		REP(i, tmp.first) x.push_back(tmp.second);
	}
	ld sum = 0;
	for (auto i : x) sum += i;
	return make_pair(x.size(), sum / x.size());
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	while (cin >> w >> h, w)
	{
		fld.clear(); ind.clear();
		fld.resize(h); cin >> fld;
		ind.resize(h, vi(w, -2));
		int tmp = 0;
		REP(i, h)REP(j, w)
		{
			if (fld[i][j] == '.') ind[i][j] = -1;
			if (ind[i][j] >= -1) continue;
			queue<pii> que;
			que.emplace(i, j);
			char c = fld[i][j];
			ind[i][j] = tmp;
			while (!que.empty())
			{
				int x = que.front().first, y = que.front().second;
				que.pop();
				REP(i, 4)
				{
					int nx = x + dx[i], ny = y + dy[i];
					if (!valid(nx, ny, h, w) || ind[nx][ny] >= -1 || fld[nx][ny] != c) continue;
					ind[nx][ny] = tmp;
					que.emplace(nx, ny);
				}
			}
			tmp++;
		}
		int root, l = w, r = 0;
		REP(j, w)
		{
			if (ind[h - 1][j] != -1)
			{
				root = ind[h - 1][j];
				chmin(l, j);
				chmax(r, j);
			}
		}
		auto res = solve(root);
		if (res.first >= 0 && (res.second + 0.5 > l || res.second + 0.5 < r + 1)) cout << "STABLE" << endl;
		else cout << "UNSTABLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#define llint long long
#define inf 1e18
#define mod 1000000007

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

llint n, k;
llint a[100005];

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	for(int i = 1; i <= n; i++) a[i] = (a[i]%mod+mod) % mod;
	
	make_fact();
	
	llint ans = 0;
	for(int i = k; i <= n; i++){
		ans += a[i] * comb(i-1, k-1) % mod, ans %= mod;
	}
	for(int i = 1; i <= n-k+1; i++){
		ans += mod - a[i] * comb(n-i, k-1) % mod, ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll dp[3010][3010];
int N;
vector<int> a;
bool flag[3010][3010];

ll solve(int L,int R){
	if(flag[L][R]) return dp[L][R];
	flag[L][R] = 1;
	if(L == R) return dp[L][R] = a[L];
	ll res = max(a[L]-solve(L+1,R),a[R]-solve(L,R-1));
	return dp[L][R] = res;
}
 
int main(){
	cin >> N;
	a.resize(N);
	rep(i,N) cin >> a[i];
	ll ans = solve(0,N-1);
	cout << ans << endl;
}


Measured memory_bytes: 78592
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <ctype.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;

typedef long long ll;
typedef pair<ll, int> pp;
#define mp(a, b) make_pair(a, b)

struct edge {
	int v, w;
	int next;
	edge() {}
	edge(int v_, int w_, int n_) : v(v_), w(w_), next(n_) {}
};

int n, cnt;
int head[10001];
edge e[600000];
bool vis[10001];
ll dis[10001];

void init()
{
	cnt = 0;
	memset(head, -1, sizeof head);
}
void addedge(int u, int v, int w)
{
	e[++cnt] = edge(v, w, head[u]); head[u] = cnt;
}
void dijkstra(int s)
{
	for (int i = 0; i < n; i++)
		vis[i] = 0, dis[i] = ll(1e18);
	dis[s] = 0; vis[s] = 1;
	for (int i = head[s]; i != -1; i = e[i].next)
		dis[e[i].v] = e[i].w;
	while(1)
	{
		int idx = -1;
		ll dist = 1e18;
		for (int j = 0; j < n; j++)
			if (!vis[j] && dist > dis[j])
			{
				idx = j;
				dist = dis[j];
			}
		if (idx == -1)
			break;
		vis[idx] = 1;
		for (int j = head[idx]; j != -1; j = e[j].next)
		{
			int v = e[j].v;
			ll w = e[j].w;
			if (dis[v] > dis[idx] + w)
				dis[v] = dis[idx] + w, vis[v] = 0;
		}
	}
}

int id[10001];

int main()
{
	int s;
	while (scanf("%d", &n) == 1)
	{
		init();
		for (int i = 0; i < n; i++)
		{
			int u, k;
			scanf("%d%d", &u, &k);
			id[i] = u;
			if (u == 0)
				s = i;
			while (k--)
			{
				int v, w;
				scanf("%d%d", &v, &w);
				addedge(u, v, w);
			}
		}
		dijkstra(s);
		for (int i = 0; i < n; i++)
			printf("%d %lld\n", id[i], dis[i]);
	}
	return 0;
}


Measured memory_bytes: 9092
#include <iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int k;
    cin >> k;
    int g;
    int res = 0;
    for(int a = 1 ; a <= k ; a++){
        for(int b = 1 ; b <= k ; b++){
            g = __gcd(a,b);
            for(int c = 1 ; c <= k ; c++){
                res += __gcd(g,c);
            }
        }
    }
    cout<<res;
}

Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            var H = HW[0];

            var array = new List<string>();

            for (var i=0;i<H;i++)
            {
                array.Add(Console.ReadLine());
            }

            foreach(var item in array)
            {
                Console.WriteLine(item);
                Console.WriteLine(item);
            }

        }
    }

Measured memory_bytes: 13268