akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  bool flag=false;
  for(int i=0;i<=x;i++)
  {
    int x1=i;
    int x2=x-x1;
    if((2*x1+4*x2)==y)
    {
      cout<<"Yes\n";
      flag=true;
      break;
    }
  }
  if(!flag)
    cout<<"No\n";
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
long long n,i,a[200001],max1,max2,num1,num2;
int main(){
	cin>>n;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<=n;i++){
		if(a[i]>max1){
			max2=max1;
			num2=num1;
			max1=a[i];
			num1=i;
		}
		else if(a[i]>max2){
			max2=a[i];
			num2=i;
		}
	}
	for(i=1;i<=n;i++){
		if(i!=num1) cout<<max1<<endl;
		else cout<<max2<<endl;
	}
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
typedef long long ll;
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  printf("%d",(N * 800) - ((N / 15) * 200)); 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int a,b,c,ans=0,coin=0;
    in(a,b,c);
    while(coin<c){
        ans++;
        coin+=a;
        if(ans%7==0)coin+=b;
        if(coin>=c){
            out(ans);
            return 0;
        }
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

int main (){
       char c;
       cin >> c;
       char b =c +1;
       cout << b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	ll d = c - a - b;
	if (d > 0 && 4 * a * b < d * d)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int h1,h2,m1,m2,s1,s2,sum1=0,sum2=0;

cin>>h1>>m1>>s1>>h2>>m2>>s2;
sum1=3600*h1+60*m1+s1;
sum2=3600*h2+60*m2+s2;
sum2-=sum1;
h2=sum2/3600;m2=(sum2%3600)/60;s2=(sum2%3600)%60;
cout<<h2<<" "<<m2<<" "<<s2<<endl;
sum1=0,sum2=0;

cin>>h1>>m1>>s1>>h2>>m2>>s2;
sum1=3600*h1+60*m1+s1;
sum2=3600*h2+60*m2+s2;
sum2-=sum1;
h2=sum2/3600;m2=(sum2%3600)/60;s2=(sum2%3600)%60;
cout<<h2<<" "<<m2<<" "<<s2<<endl;
sum1=0,sum2=0;

cin>>h1>>m1>>s1>>h2>>m2>>s2;
sum1=3600*h1+60*m1+s1;
sum2=3600*h2+60*m2+s2;
sum2-=sum1;
h2=sum2/3600;m2=(sum2%3600)/60;s2=(sum2%3600)%60;
cout<<h2<<" "<<m2<<" "<<s2<<endl;
sum1=0,sum2=0;
return 0;
}

Measured memory_bytes: 1164
#include "vector"
#include "set"
#include "map"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define MOD 1000000007

typedef vector<int> vi;
typedef pair<int, int> pii;

struct v {
    int x;
    int i;
    int closed;
};

bool comp(const v& x, const v& y) {
    return (x.x < y.x) || (x.x == y.x && x.closed < y.closed);
};

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

ll pw(ll x, int n) {
    if (n == 1) {
        return x;
    }
    if (n%2 == 0) {
        return pw((x*x) % MOD, n/2);
    }
    return (pw(x, n-1) * x) % MOD;
}

int get_min(map<int, set<int> >& m) {
    return m.begin()->first;
}

int get_min(set<int>& m) {
    return *m.begin();
}

int get_max(map<int, set<int> >& m) {
    auto it = m.end();
    it--;
    return it->first;
}

int get_max(set<int>& m) {
    auto it = m.end();
    it--;
    return *it;
}

void solve() {
    int k, n;
    cin >> k >> n;

    vector<ll> a(n);
    cin >> a;

    ll s = 0;
    ll ma = 0;
    for (int i=1; i<n; i++) {
        s += a[i] - a[i-1];
        ma = max(ma, a[i]-a[i-1]);
    }
    s += a[0] + k - a[n-1];
    ma = max(ma, a[0] + k - a[n-1]);

    cout << s - ma;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    if (0) {
        int tests;
        cin >> tests;
        while (tests--) {
            solve();
            cout << endl;
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{

	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		int b[]=new int[n];
		for(int i=0;i<n;i++){
			b[i]=sc.nextInt();
		}
		int c[]=new int[n-1];
		for(int i=0;i<n-1;i++){
			c[i]=sc.nextInt();
		}
		int total=0;
		for(int i=0;i<n;i++){
			total+=b[i];
		}


		for(int i=1;i<n;i++){
			if(a[i]-a[i-1]==1){
				total+=c[a[i-1]-1];
			}
		}

		System.out.println(total);


	}
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    string N;
    cin>>N;
    
    cout<<(N[0]==N[2]?"Yes":"No");
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main(){ 
  int n;
  string s;
  cin >> n >> s;
  int mod = 0;
  for (int i = 0; i < n; i++) if (s[i] == '1') mod++;
  int mod1 = mod + 1, mod2 = mod - 1;
  ll x1 = 0, x2 = 0;
  vector<ll> cur1(n, 1), cur2(n, 1);
  
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (mod1 > 0) (x1 += cur1[i]) %= mod1;
      if (mod2 > 0) (x2 += cur2[i]) %= mod2;
    }
    if (i != 0) {
      if (mod1 > 0) cur1[i - 1] = (cur1[i] * 2) % mod1;
      if (mod2 > 0) cur2[i - 1] = (cur2[i] * 2) % mod2;
    }
  }

  vector<int> cnt(200001, 0);
  auto calc = [&](int x){
    int ret = 0;
    while (x != 0) {
      int tmp = __builtin_popcount(x);
      x = x % tmp;
      ret++;
    }
    return ret;
  };
  for (int i = 0; i <= 200000; i++) {
    cnt[i] = calc(i);
  }

  
  for (int i = 0; i < n; i++) {
    ll res = -1;
    ll cur = 0;
    int c = 0;
    if (s[i] == '1') {
      if (mod2 > 0) {
        res = x2;
        cur = cur2[i];
        (res = res - cur + mod2) %= mod2;
        c = 1;
      }
    } else {
      if (mod1 > 0) {
        res = x1;
        cur = cur1[i];
        (res += cur) %= mod1;
        c = 1;
      }
    }
    int ans = 0;
    if (res != -1) ans += cnt[res];
    cout << ans + c << endl;
  }
  return 0;
} 

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


void solve(long long N, long long K, std::vector<long long> h){
    vector<ll> dp(N+1,1000000000);
    dp[0] = 0;
    dp[1] = 0;
    for(int i=1;i<N;i++){
        // cerr << dp[i+1] << endl;
        for(int j=1;j<=K;j++){
            if(i+j>N){
                break;
            }
            dp[i+j] =min(dp[i+j],dp[i] + abs(h[i-1]-h[i-1+j]));
            
            // cerr << "i=" << i << "j=" <<j << "val =" << dp[i+j] << endl;
        }
        // cerr << dp[i+1] << endl;
    }
    cout << dp[N] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = nextLongList()
    val ans = A.reduce { a, b -> gcd(a, b) }
    println(ans)
}

tailrec fun gcd(a: Long, b: Long): Long {
    if (a < b) return gcd(b, a)
    if (b == 0L) return a
    if (a <= 0L) throw IllegalArgumentException()
    return gcd(b, a % b)
}

Measured memory_bytes: 57576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<16,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M,Q;cin>>N>>M>>Q;
        if(N+M+Q==0) break;
        vector<vector<int>> A(M,vector<int>(N));
        vector<int> state(N,0);
        
        for(int k=0;k<Q;k++){
            string S,T;cin>>S>>T;
            for(int i=0;i<N;i++){
                state[i]^=int(S[i]-'0');
            }
            
            for(int i=0;i<N;i++){
                for(int j=0;j<M;j++){
                    if(state[i]^int(T[j]-'0')) A[j][i]=0;
                    else A[j][i]++;
                }
            }
        }
        
        for(int i=0;i<M;i++){
            vector<int> can;
            for(int j=0;j<N;j++){
                if(A[i][j]==Q) can.push_back(j);
            }
            
            if(can.size()==1){
                if(can[0]<=9) cout<<can[0];
                else cout<<char('A'+can[0]-10);
            }else cout<<'?';
            //cout<<can.size()<<" ";
        }
        
        cout<<endl;
    }
}





Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define fo(i, k, n) for (int i = k; i <= n; ++ i)
#define fod(i, k, n) for (int i = k; i >= n; -- i)
template <typename T, typename U>
static inline void maxx (T &x, U y) {
  if (x < y) {
    x = y;
  }
}
template <typename T, typename U>
static inline void minn (T &x, U y) {
  if (x > y) {
    x = y;
  }
}
template<typename T>
void read (T &x) {
  x = 0;
  T neg = 1;
  register T c = getchar ();
  if (c == '-') {
    neg = -1;
  }
  while (c < 48 || c > 57) {
    c = getchar ();
  }
  for (; c < 48 || c > 57; c = getchar ());
  for (; c <= 57 && c >= 48; c = getchar ()) {
    x = (x << 3) + (x << 1) + (c & 15);
  }
  x *= neg;
}
template<typename T>
void write (T x) {
  bool neg = 0;
  if (x < 0) {
    x *= -1;
    neg = 1;
  }
  char snum[65];
  int i = 0;
  do {
    snum[++ i] = x % 10 + '0';
    x /= 10;
  }
  while (x);
  //-- i;
  if (neg) {
    putchar ('-');
  }
  while (i > 0) {
    putchar (snum[i --]);
  }
}
///declare
long long n, k, a[100001], q, cnt[100001];
int main () {
  if (fopen ("test.inp", "r")) {
    freopen ("test.inp", "r", stdin);
  }
//  else {
//    freopen(".inp", "r", stdin);
//    freopen(".out", "w", stdout);
//  }
  ios_base :: sync_with_stdio (0);
  cin.tie (nullptr);
  cout.tie (nullptr);
  read (n);
  read (k);
  read (q);
  fo (i, 1, q) {
    read (a[i]);
    ++ cnt[a[i]];
  }
  fo (i, 1, n) {
    if (q - cnt[i] >= k) {
      cout << "No";
    }
    else {
      cout << "Yes";
    }
    cout << "\n";
  }
}


Measured memory_bytes: 2176
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];
/*
int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
	 while(z[++Z]=x%10+48,x/=10);
	 while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}*/
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
const int N=100005;
ll C,x[N],w[N],sum,maxx,maxx1[N],maxx2[N];
int main()
{
	int n,pos1,pos2;
	read(n);read(C);
	for (int i=1;i<=n;i++) read(x[i]),read(w[i]);
	for (int i=1;i<=n;i++)
		sum+=w[i],maxx1[i]=max(maxx1[i-1],sum-x[i]);
	sum=0;
	for (int i=n;i>=1;i--)
		sum+=w[i],maxx2[i]=max(maxx2[i+1],sum-(C-x[i]));
	maxx=max(maxx1[n],maxx2[1]);
	sum=0;
	for (int i=1;i<=n;i++) sum+=w[i],maxx=max(maxx,maxx2[i+1]+sum-x[i]*2);
	sum=0;
	for (int i=n;i>=1;i--) sum+=w[i],maxx=max(maxx,maxx1[i-1]+sum-(C-x[i])*2);
	cout<<maxx;
	return 0;
}








Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int graph[N][N];
    rep(i,0,N)rep(j,0,N)graph[i][j] = 1;
    rep(i,0,N)graph[i][i] = 0;
    if(N % 2){
        rep(i,0,N-1){
            graph[i][N-i-2] = graph[N-i-2][i] = 0;
        }
    }else{
        rep(i,0,N){
            graph[i][N-i-1] = graph[i][N-i-1] = 0;
        }
    }
    vector<P> ans;
    rep(i,0,N)rep(j,i+1,N){
        if(graph[i][j])ans.emplace_back(i+1,j+1);
    }
    cout << ans.size() << endl;
    for(auto p:ans){
        cout << p.first << " " << p.second << endl;
    }
}

Measured memory_bytes: 384
count = 0
n,m = map(int, input().split())
sw = {}
lt = {}
for i in range(1, m+1):
    s = map(int, input().split())
    s = list(s)
    k = s[0]
    s = s[1:]
    lt[i] = s
    for j in range(k):
        t = sw.get(s[j], [])
        t.append(i)
        sw[s[j]] = t
p = map(int, input().split())
p = list(p)

for i in range(pow(2, n)):
    sw_sta = [False] * (n + 1)
    for j in range(n):
        if (i & pow(2,j)) != 0:
            sw_sta[j + 1] = True
    allon = True
    for j in range(m):
        c = 0
        for k in lt[j + 1]:
            if sw_sta[k]:
                c += 1
        if c % 2 != p[j]:
            allon = False
            break
    if allon:
        count += 1
print(count)

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

using ll = long long;
#define MAXH 1010
#define MAXW 1010
const int MOD = 1e9+7;

int H, W;
char g[MAXH][MAXW];

int dx[] = {1, 0};
int dy[] = {0, 1};
int dp[MAXH][MAXW];

void debug() {
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            cout << dp[i][j];
        }
        cout << endl;
    }
}
int main() {
    cin >> H >> W;
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            cin >> g[i][j];
        }
    }

    memset(dp, 0, sizeof(dp));
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            if(i==1&&j==1){
                dp[i][j] = 1;
                continue;
            }
            if(g[i][j] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
        }
    }
    cout << dp[H][W] << endl;
//    debug();
    return 0;
}


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

int main() {
    stack<int> s1;
    stack<pair<int, int>> s2;
    char ch;
    int sum = 0;

    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\')
            s1.push(i);
        else if (ch == '/' && s1.size() > 0) {
            int j = s1.top();
            s1.pop();
            int a = i - j;
            sum += a;
            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while (s2.size() > 0) {
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    rep(i, ans.size()) { cout << ' ' << ans[i]; }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3164
# ----------------------------
N,M,X = map(int, input().split())
A = [list(map(int, input().split(" "))) for i in range(N)]

MOD = 10**9+7
a = [0]*M
value = [0]
ans = MOD

for i in range(2**N):
    for j in range(N+1):
        if(i >> j) & 1:
            for k in range(M):
                a[k] += A[j][k+1]
            value.append(A[j][0])

    if min(a) >= X :
        ans = min(ans,sum(value))
    a = [0]*M
    value = []

print(-1 if ans == MOD else ans)


Measured memory_bytes: 9220
#include <stdio.h>

int main(){
    int y,m,d;
    char a,b;
    scanf("%d%c%d%c%d",&y,&a,&m,&b,&d);
    if(m<=4){
        printf("Heisei\n");
    }
    else
    {
        printf("TBD\n");
    }
    
}


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



int main(){
	long long int a;
	long long int b;
	cin >> a >> b;
	if (a == 0 || b == 0){
		puts("Zero");
		return 0;
	}
	if (a < 0 && b>0){
		puts("Zero");
		return 0;
	}
	if (a >= 0 && b >= 0){
		puts("Positive");
		return 0;
	}
	if (a < 0 && b < 0){
		long long int ab = abs(a - b);
		ab++;
		if (ab % 2LL){
			puts("Negative");
		}
		else{
			puts("Positive");
		}
		return 0;
	}
	long long int ab = abs(a);
	if (ab % 2LL){
		puts("Negative");
	}
	else{
		puts("Positive");
	}
	return 0;
}

Measured memory_bytes: 256
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort
b = []
c = []
bc = []
m.times do |i|
  b[i],c[i] = gets.chomp.split(" ").map(&:to_i)
  bc.push([b[i],c[i]])
end
bc.push([0,0])
bc.sort_by!{|x| -x[1]}
i = 0
j = 0
loop = true
while a[i] < bc[j][1] && j < m
  bc[j][0].times do
    if a[i] < bc[j][1] && loop
      a[i] = bc[j][1]
      i += 1 if loop
      if i >= n
        i = n-1
        loop = false
      end
    end
  end
  j += 1
end
puts a.inject(:+)

Measured memory_bytes: 28824
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;


int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<ll>> dp(55, vector<ll>(2));
  for(ll i = 50; i >= 0; --i) {
    int cnt = 0;
    rep(j, n) {
      if(a[j]>>i&1) cnt++;
    }
    ll num = 1LL<<i;
    if(dp[i + 1][1] != 0) dp[i][1] = max(cnt * num, (n - cnt) * num) + dp[i + 1][1];
    if(k>>i&1) {
      dp[i][0] = (n - cnt) * num + dp[i + 1][0];
      dp[i][1] = max(dp[i][1], dp[i + 1][0] + cnt * num);
    } else {
      dp[i][0] = cnt * num + dp[i + 1][0];
    }
  }
  ll ans = max(dp[0][0], dp[0][1]);
  cout << ans << endl;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r: f64 = read();

    println!(
        "{} {}",
        ((r) * (r) * std::f64::consts::PI),
        2.0 * r * std::f64::consts::PI
    );
}


Measured memory_bytes: 5072
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main(){
      long n , k;
      cin >> n >> k;
     
      vector<long> x(n);
     
        for(int i = 0 ;i < n ; i++) cin >> x[i];
                         
      long h = 1000000000;
      
       for(int i = 0 ; i <= n - k ; i++){
        h = min (h , abs(x[i]) + abs(x[i + k - 1] - x[i]));
       }
       for(int i = 0 ; i <= n - k;i++){
        h = min(h , abs(x[i + k - 1]) + abs(x[i + k - 1] - x[i]));
       }
      
      
      cout << h << endl;
    }


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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a);

        a = (a * a); 
        b >>= 1;
    }
    return res;
}

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

#define N 200010
#define MOD 1000000007


int f[1000010];
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int k, n;
    cin >> k >> n;

    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }

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

    ma = max(ma, k - a[n - 1] + a[0]);
    cout << k - ma;
    return 0;
}

Measured memory_bytes: 1792
package main

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

func main() {
	scan_init()
	k := scanInt()
	n := scanInt()
	// a := make([]int,n)
	circle := make(map[int]int)
	houses := []int{}
	for i:=0; i<n; i++ {
		number := scanInt() % k
		if number == 0 {
			number = k
		}
		if _,ok := circle[number]; !ok {
			circle[number] = number
			houses = append(houses,number)
		}
	}
	mergin := 0
	sort.Ints(houses)
	newN := len(houses)
	for i:=1; i<newN; i++ {
		length := houses[i] - houses[i-1]
		if length<0 {
			length = -length
		}
		if length > mergin {
			mergin = length
		}
	}
	length := (k-houses[newN-1])+houses[0]
	if length < 0 {
		length = -length
	}
	if mergin < length {
		mergin = length
	}
	fmt.Println(k-mergin)
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//  sc.Scan()
//	return sc.Text()
//}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int l, r;
    cin >> l >> r;
    
    r = min(r, l + 3000);
    int ans = 2019;

    for(int i = l; i <= r; i++) {
        for(int j = i+1; j <= r; j++) {
            int mul = ((ll)i * j) % 2019;
            chmin(ans, mul);
        }
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/


Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 200001

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main() {
  int N, A[MAX_N];
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    A[i] -= i;
  }

  sort(A, A+N);
  int b = A[N/2];

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += max((A[i] - b), -(A[i] - b));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd);
#endif
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << '\n';
    return 0;
}


Measured memory_bytes: 256
//
// Created by Bhagirathi Nayak on 16/07/20.
//

//#include </usr/local/include/bits/stdc++.h>
//#include <bits/stdc++.h>


using namespace std;

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>

string num;
int k,l;
int dp[1000000][4][2];

int count(int idx,int cnt_k,int already_smaller){

    //cout<<idx<<" "<<cnt_k<<" "<<already_smaller<<"\n";

    if(cnt_k>k)
        return 0;

    if(idx==l)
        return cnt_k==k;

    if(dp[idx][cnt_k][already_smaller]!=-1)
        return dp[idx][cnt_k][already_smaller];

    int curr_digit = num[idx]-'0';

    int lim = already_smaller == 1 ? 9 : curr_digit;

    int sum = 0;
    for (int digit = 0; digit <= lim; ++digit) {
        sum += count(idx+1,
                digit!=0 ? cnt_k+1:cnt_k,
                digit<curr_digit || already_smaller);
    }

    dp[idx][cnt_k][already_smaller] = sum;
    return sum;
}

int main(){
    cin>>num;
    cin>>k;

    l=num.length();

    for (int i = 0 ; i < 1000000 ; ++i) {
        for (int j = 0; j < 4; ++j) {
            for (int m = 0; m < 2; ++m) {
                dp[i][j][m] = -1;
            }
        }
    }

    cout<<count(0,0,0)<<endl;
    //cout<<count(0,0,1)<<endl;

    return 0;
}



Measured memory_bytes: 34444
#include<iostream>
#include<stdio.h>
#include<cctype>

using namespace std;

int main(){
    char x, y;
    while(1){
        scanf("%c", &x);
        if(islower(x)){
            y = toupper(x);
        }else{
            y = tolower(x);
        }
        cout << y;
        if(x == '\n')break;
    }return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	string s;
	cin>>s;
	rp(i,0,s.size()-1)cout<<'x';
	return 0;
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

int main()
{
  int n,sum=0;
  cin>>n;
  vector<int> x(n);
  REP(i,n){
    cin>>x[i];
    sum+=x[i];
  }

  ll v=INF;
  REP2(i,1,101){
    ll temp=0;
    REP(j,n){
      temp+=pow(x[j]-i,2);
    }
    if(v>temp) v=temp;
    else break;
  }
  cout<<v<<endl;
  
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> X(n);//配列
  rep(i, n) cin >> X[i].second >> X[i].first;
  sort(X.begin(), X.end());
  int ch = 0;
  int gh = 0;
  rep(i, n){
    ch += X[i].second;
    if(ch>X[i].first) {
      cout << "No" << endl;
      gh = 1;
      break;
    }
  }
  if(gh==0) cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    optimize();
    int n,i,c=0,a;
    cin>>n;
    map<long long,int>m;
    for(i=0; i<n; i++)
    {
        cin>>a;
        m[a]++;
    }
    for(auto u:m)
    {
        if(u.first<=u.second)
            c+=(u.second-u.first);
        else
            c+=u.second;
    }
    cout<<c<<"\n";
    return 0;

}


Measured memory_bytes: 9636
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    string st;
    st=s+t;
    rep(i,n){
        st[i*2]=s[i];
    }
    rep(i,n){
        st[i*2+1]=t[i];
    }
    cout<<st<<endl;
}


        


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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    string S;

    cin >> S;

    cout << (S[0] != S[1] && S[1] != S[2] && S[2] != S[0] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
L,R=map(int,input().split())
if R>=L+2018:
 print(0)
else:
 Llst=[0]*2019
 Rlst=[0]*2019
 for i in range(L,R):
  Llst[i%2019]+=1
 for i in range(L+1,R+1):
  Rlst[i%2019]+=1
 ans=2019
 for i in range(2019):
  for j in range(2019):
   if i!=j and Llst[i]==1 and Rlst[j]:
    ans=min(ans,(i*j)%2019)
 print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, m, l, r;
	cin>>n>>m;
	int lb=1, ub=n;
	REP(i, m){
		cin>>l>>r;
		CHMAX(lb, l);
		CHMIN(ub, r);
	}
	cout<<max(0, ub-lb+1)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int a[300010];
int main(){
	int n;
	LL ans=0;
	cin>>n;	
	for(int i=0;i<3*n;i++)cin>>a[i];
	sort(a,a+3*n);
	for(int i=0;i<n;i++){
	    ans+=a[3*n-1-2*i-1];
	}
	cout<<ans<<endl;
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

const int MAX = 100'000 + 5;
ll fac[MAX], finv[MAX], inv[MAX];

struct mint {
  ll x;
  mint(ll x=0) : x(x%mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res*=a;
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  string s; std::cin >> s;
  vi cnt(26);
  for (auto &c : s) cnt[c-'a']++;
  mint ans = 1;
  rep(i, 26) if (cnt[i] > 0) {
    ans *= cnt[i] + 1;
  }
  ans -= 1;
  std::cout << ans.x << "\n";
}


Measured memory_bytes: 512
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

N = input()

m = {}

for loop in range(N):
    s, p1, p2 = raw_input().split()
    m[s] = (int(p1), int(p2))

N = input()
lst = raw_input().replace('/', '//').split()
sta = []

for s in lst:
    hoge = [0 for i in range(256)]
    if s in m:
        p = m[s]
        for i in range(p[0], p[1] + 1):
            hoge[i] = 1
        sta.append(hoge)
    elif s in ['+', '-', '*', '//']:
        n2 = sta.pop()
        n1 = sta.pop()
        #print s,n1, n2
        for i in xrange(256):
            for j in xrange(256):
                if n1[i] and n2[j]:
                    try:
                        index = eval(str(i) + s + str(j))
                        hoge[index % 256] = 1
                    except:
                        print "error"
                        exit()
        #print hoge
        sta.append(hoge)
    else:
        hoge[int(s)] = 1
        sta.append(hoge)

print "correct"
    



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b)
{
    if (a > b)
        a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b)
{
    if (a < b)
        a = b;
}

int main()
{
    ll n;
    cin >> n;
    ll ans;
    for (ll p = (ll)sqrt(n); p > 0; p--)
    {
        if (n % p == 0)
        {
            ll q = n / p;
            ans = p + q - 2;
            break;
        }
    }
    cout << ans << endl;
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H,W,n,x,y;
	string s,t;
	cin>>H>>W>>n>>x>>y>>s>>t;
	for(int i=0;i<4;i++){
		char fi = "LRUD"[i];
		char se = "RLDU"[i];
		int z;
		if(i==0)	z=y;
		else if(i==1)	z=W-y+1;
		else if(i==2)	z=x;
		else z=H-x+1;
		int b;
		if(i<2)	b=W;
		else	b=H;
		for(int j=0;j<s.size();j++){
			if(s[j]==fi)	z--;
			if(z==0){
				cout<<"NO"<<endl;
				return 0;
			}
			if(t[j]==se&&z!=b)	z++;
		}
	}
	cout<<"YES"<<endl;
}



Measured memory_bytes: 920
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    V< V<int> > dp(2, V<int>(n + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[0][i + 1] = min(dp[0][i], dp[1][i]) + s[i] - '0';
        dp[1][i + 1] = min(dp[0][i] + 1 + 10 - (s[i] - '0'), dp[1][i] + 10 - (s[i] - '0') - 1);
    }
    cout << min(dp[0][n], dp[1][n]) << '\n';
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repback(i, n, k) for (int i=int(n); i >= (int)(k); --i)

typedef long long ll;

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> h(n);
    rep(i, n){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll ans = 1000000000000;//適当にでかい数
    for(int i = 0;i < n - k + 1; i++){
      ans = min(ans,h[i+k-1]-h[i]);
    }
    cout << ans << endl;
    return 0;	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};
vector<vector<int>> dp(1001, vector<int>(1001));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    string S, T;
    cin >> Q;
    rep(q, Q) {
        cin >> S >> T;
        dp.assign(S.size() + 1, vector<int>(T.size() + 1, 0));
        rep(i, 0, S.size()) {
            rep(j, 0, T.size()) {
                if(S.at(i) == T.at(j)) {
                    dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
                } else {
                    dp.at(i + 1).at(j + 1) =
                        max(dp.at(i + 1).at(j), dp.at(i).at(j + 1));
                }
            }
        }
        cout << dp.at(S.size()).at(T.size()) << endl;
    }
}


Measured memory_bytes: 7160