akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

ll memo[30];
ll fact(int x) {
	//if (memo[x])return memo[x];
	ll ret = 1;
	for (int i = 1; i <= x; i++)ret *= i;
	//pe(x); print(ret);
	memo[x] = ret;
	return ret;
}
void solve() {
	int N; cin >> N;
	vector<int>A(N + 1), B(N);
	REP(i, N + 1)cin >> A[i];
	REP(i, N)cin >> B[i];
	ll ans = 0;
	REP(i, N) {
		if (B[i] >= A[i]) {
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;

		}
		else {
			ans += B[i];
			A[i] -= B[i];
			B[i] = 0;
		}

		if (B[i] >= A[i+1]) {
			ans += A[i + 1];
			A[i + 1] = 0;
			B[i] -= A[i+1];
		}
		else {
			ans += B[i];
			A[i+1] -= B[i];
			B[i] = 0;
		}
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll k;
    cin>>k;
    string  s;
    cin>>s;
    if(s.length()<=k)
      cout<<s;
    else
    {
      for(int i=0;i<k;i++)
      {
        cout<<s[i];
      }
      cout<<"..."<<endl;
    }
}
return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long long number;

    cin >> number;

    vector<long long> distances;

    // current best distance -> n * 1, so move in y n-1 times, OR move in x n-1 times
    long long dist = number - 1;

    // get factors
    for( long long i = 1; i * i <= number; ++i)
    {
        if(number % i == 0)
        {
            distances.push_back(i);
            //if (number / i != i)
                distances.push_back(number/i);

        }
    }

    for(auto i : distances)
    {
        dist = min(dist, i + number/i - 2);
    }

    cout << dist;





    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

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

int main(){
    fast_io
    
    ll n, k;
    cin>>n>>k;
    if(k==1 || n==k) {
        cout<<0<<endl;
        return 0;
    }
    else{
        ll am=n%k;
        cout<<min(am, abs(am-k))<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
N,K=map(int, input().split())
instr=input()
lft=0
rgt=1
voids=int(instr[0] == '0')
maxlen=0
while lft < rgt:
    maxlen = max(maxlen, rgt-lft)
    if rgt < N and (instr[rgt] == '1' or (instr[rgt-1] == '0' and instr[rgt] == '0')):
        rgt += 1
    elif rgt < N and voids < K:
        voids += 1
        rgt += 1
    else:
        voids -= lft+1 < N and instr[lft] == '0' and instr[lft+1] == '1'
        lft += 1
print(maxlen)


Measured memory_bytes: 42864
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
    char c;
    rep(i,4)
    {
        cin>>c;
        cout<<c;
    }
    cout<<" ";
    rep(i,8)
    {
        cin>>c;
        cout<<c;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

   int n = sc.nextInt();
 
   int[] nums = new int[n];
 
   for (int i = 0; i < n; ++i) {
    nums[i] = sc.nextInt();
   }

   for (int i = n-1; i > 0; --i) {
    System.out.print(nums[i] + " ");
   }

   System.out.println(nums[0]);
    sc.close();
   }
}


Measured memory_bytes: 26232
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    t = [list(map(int, input().split())) for _ in range(3)]
    for i in range(2):
        if not t[i][0] - t[i + 1][0] == t[i][1] - t[i + 1][1] == t[i][2] - t[i + 1][2]:
            print("No")
            exit()
    for j in range(2):
        if not t[0][j] - t[0][j + 1] == t[1][j] - t[1][j + 1] == t[2][j] - t[2][j + 1]:
            print("No")
            exit()
    print("Yes")

main()


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

int main(){
	int a, b, d, r;
	double f;
	
	cin >> a >> b;
	
	d = a / b;
	r = a % b;
	f = (double)a / b;
	
	cout << d << " ";
	cout << r << " ";
	printf("%.8f\n", f);	
		
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n; cin>>n;
  if(n==0) cout<<1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h> 
using namespace std;
int main()
{
    long long X,m,n;
    cin>>X;
    m=100;
    n=0;
    while(m<X)
    {
        n++;
        m=m+(m/100);
    }
    cout<<n;
    return 0;
}

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

int main(){
	int a,i,c[10]={0,0,0,0},flag=0;
  	for(i=0;i<6;i++){
	cin>>a;
		c[a-1]++;
      for(int j=0;j<4;j++){
    	  if(c[j]>2){
				flag=1;
           break;
          }
         }
    }

  	if(flag==0){
		cout<<"YES"<<endl;
    }else{
		cout<<"NO"<<endl;
    }
}


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

using namespace std;

int main(){
	int n, ww;
	cin >> n >> ww;

	int w[n],v[n];

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

	int dp[20000],go[20000];
	memset(dp,0,sizeof(dp));
	memset(go,-1,sizeof(go));

	for(int i = n-1;i >= 0;i--){
		for (int j = w[i];j <= ww;j++){
			dp[j] = max(dp[j],dp[j-w[i]] + v[i]);
		}
	}
	cout << dp[ww] << endl;
	// for(int i = 0;i <= ww;i++)printf("%3d ",i);
	// cout << endl;
	// for(int j = 0;j < n;j++){
	// 	for(int i = 0;i <= ww;i++){
	// 		printf("%3d ",dp[j][i]);
	// 	}
	// 	cout << endl;
	// }


	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int H, W;
  cin >> H >> W;
  string S[H];
  for(int i=0; i<H; i++) cin >> S[i];

  int h = H;
  int w = W;
  
  bool tf_1 = true;
  bool tf_2 = true;
  while(tf_1 || tf_2){
    // 行の比較
    string comp_1 = "";
    for(int i=0; i<w; i++) comp_1 += ".";  
    for(int i=0; i<h; i++){
      string now_row = "";
      for(int j=0; j<w; j++) now_row += S[i][j];    
      if(now_row == comp_1){
        for(int j=i; j < h -1; j++){
          swap(S[j], S[j+1]);
        }
        h--;
        tf_1 = true;
        break;
      }
      tf_1 = false;
    }
    // 列の比較
    string comp_2 = "";
    for(int i=0; i<h; i++) comp_2 += ".";  
    for(int i=0; i<w; i++){
      string now_col = "";
      for(int j=0; j<h; j++) now_col += S[j][i];
      if(now_col == comp_2){
        for(int l=0; l < h; l++) {
          for(int k=i; k < w -1; k++){
            swap(S[l][k], S[l][k+1]);
          }
        }
        w--;
        tf_2 = true;
        break;
      }
      tf_2 = false;
    }    
  }
  
  // 結果の表示
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cout << S[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/**
Make it happen now, not tomorrow.
Tomorrow is a loser's excuse.
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef map<int, int> mi;
typedef map<ll, ll> ml;
typedef unordered_map<int, int> umi;
typedef unordered_map<ll, ll> uml;

const int mod = 1e9 + 7; // 998244353;

ll power(ll x, ll y) {ll xx = x, ans = 1; while (y > 0) {if (y & 1)ans = (ans * xx); xx = (xx * xx); y = y >> 1;} return ans;}
ll nCr(ll n, ll r) {ll p = 1, k = 1; if (n - r < r) r = n - r;  if (r != 0) {while (r) {p *= n; k *= r; ll m = __gcd(p, k); p /= m; k /= m; n--; r--;}} else p = 1; return p;}
void printv(vl v) {cout << "Vector is \n"; for (auto x : v)cout << x << " "; cout << "\nVector End\n";}
void printa(int a[], int n) {cout << "Array is\n"; for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << "\nVector End\n";}
int day(int date, int month, int year) {if (month == 1) {month = 13; year--;} if (month == 2) {month = 14; year--;} int q = date, m = month, k = year % 100, j = year / 100; int day = q + (13 * (m + 1)) / 5 + k + (k / 4) + (j / 4) + 5 * j; day = day % 7; return day;}
ll ston(string s) {ll val = 0, bs = 1; ll sl = s.length(); sl--; while (sl >= 0) {val += ((s[sl] - 48) * bs); bs *= 10; sl--;} return val;}
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}

#define F first
#define S second
#define mp make_pair
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(),v.end()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int main() {
	string s;
	cin>>s;
	int ans=0;
	int c=0;
	for (int i=0;i<s.length();i++){
        if (s[i]=='R'){
            c++;
        }
        else c=0;
        ans=max(c,ans);
	}
	cout<<ans<<endl;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i, n + 1) cin >> a[i];

    ll sum = accumulate(a.begin(), a.end(), 0ll);
    sum -= a[0];
    ll branch = 1;
    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        if (branch < a[i] || sum < 0) {
            puts("-1");
            return 0;
        }

        ans += branch;
        sum -= a[i];
        branch -= a[i];
        branch = min(branch * 2, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
var sub_fn = (ary)=>{
  
}
reader.on('close', () => {
  lines.shift()
  var x = (lines.map((a)=>{return 1*a})).sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
});
 //console.log(x)
  var cnt = 1;
  for(var i in x){
    if(i >0 && x[i-1]<x[i]){
    ++cnt}
  }

  console.log(cnt)
});


Measured memory_bytes: 7756
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

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

typedef long long ll;

int main()
{
	/*int h, w, n;
	cin >> h >> w >> n;
	int m = max(h, w);
	int ans = (n + m - 1) / m;
	cout << ans;*/


	/*int n;
	cin >> n;
	vector<pair<int, int>>v(n);
	rep(i, n)cin >> v[i].first >> v[i].second;
	sort(all(v));*/
	


	int n, k, s;
	cin >> n >> k >> s;
	vector<int>a(n, s);
	rep(i, n-k) {
		if (s == 1e9)a[i] = 1;
		else a[i] = 1e9;
	}
	rep(i, n) {
		cout << a[i] << " ";
	}
	
	return 0;
}

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

int main(){
	
	long x = 0;
	long total = 0, m = 0,ans = 0;
	cin >> x;//値を受け取る

	total = x / 11;
	m = x % 11;
	ans = total * 2;

	
	if(m > 6)ans+=2;
	else if(m >0)ans += 1;

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

Measured memory_bytes: 256
def popcount(x):
    x -= (x >> 1) & 0x55555555
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x += x >> 8
    x += x >> 16
    return x & 0x3f

A = [0] * 200001
for i in range(1, 200001):
    A[i] = A[i % popcount(i)] + 1


N = int(input())
xx = input()
p = xx.count("1") - 1
q = xx.count("1") + 1

X = int(xx, 2)
xx = xx[::-1]

if p: a = X % p
b = X % q
s = 1
t = 1
ANS = []
for i, x in enumerate(xx):
    if x == "0":
        ANS.append(A[(b + t) % q] + 1)
    else:
        ANS.append(A[(a - s) % p] + 1 if p else 0)
    if p: s = s * 2 % p
    t = t * 2 % q

for ans in ANS[::-1]:
    print(ans)

Measured memory_bytes: 14492
import java.util.*;

class UnionFind {
	int[] roots;
	int[] sameSetCnt;
	
	public UnionFind(int N) {
		roots = new int[N];
		sameSetCnt = new int[N];
		for(int i = 0; i < N; ++i) {
			roots[i] = i;
			sameSetCnt[i] = 1;
		}
	}
	
	int getRoot(int x) {
		if(roots[x] == x) return x;
		else return roots[x] = getRoot(roots[x]);
	}
	
	boolean isSameSet(int x, int y) {
		return getRoot(x) == getRoot(y);
	}
	
	void unite(int x, int y) {
		int rx = getRoot(x);
		int ry = getRoot(y);
		if(rx == ry) return;
		
		if(sameSetCnt[rx] < sameSetCnt[ry]) {
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		sameSetCnt[rx] += sameSetCnt[ry];
		roots[ry] = rx;
	}
	
	int getSameSetNum(int i) {
		return sameSetCnt[getRoot(i)];
	}
}

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int h = 0;
	static int w = 0;
	static char[][] grids = null;
	static boolean[][] hasVisited = null;
	static UnionFind uf = null;
	static int[] dy = {-1, 1, 0, 0};
	static int[] dx = {0, 0, -1, 1};
	
	public static void main(String[] args) {
		h = sc.nextInt();
		w = sc.nextInt();
		grids = new char[h][w];
		hasVisited = new boolean[h][w];
		for(int i = 0; i < h; ++i) grids[i] = sc.next().toCharArray();
		
		uf = new UnionFind(h * w);
		// 黒と白が隣接する各箇所に辺を張る
		for(int y = 0; y < h; ++y) {
			for(int x = 0; x < w; ++x) {
				dfs(y, x);
			}
		}
		
		int[][] bnum = new int[h][w];
		// 各連結成分について黒の数を数える
		for(int y = 0; y < h; ++y) {
			for(int x = 0; x < w; ++x) {
				if(grids[y][x] == '#') {
					int ufRootIndex = uf.getRoot(w * y + x);
					++bnum[ufRootIndex / w][ufRootIndex - ufRootIndex / w * w];
				}
			}
		}
		
		// 各連結成分について選ぶ組み合わせの数を足していく
		long ans = 0;
		for(int i = 0; i < h * w; ++i) {
			if(uf.getRoot(i) == i) {
				int bn = bnum[i / w][i - i / w * w];
				int wn = uf.getSameSetNum(i) - bn;
				ans += 1L * bn * wn;
			}
		}
		System.out.println(ans);
	}
	
	static boolean isOutside(int y, int x) {
		return y < 0 || h <= y || x < 0 || w <= x;
	}
	
	static void dfs(int sy, int sx) {
		// 訪問済みなら何もせず終了
		if(hasVisited[sy][sx]) return;
		
		// 自身のマスに訪問済みの印をつける
		hasVisited[sy][sx] = true;
		
		// 自身のマスの色
		char self = grids[sy][sx];
		
		// 上下左右のマスを見る
		for(int i = 0; i < 4; ++i) {
			int oy = sy + dy[i];
			int ox = sx + dx[i];
			
			// 範囲外ならばスキップ
			if(isOutside(oy, ox)) continue;
			
			// 相手のマスの色
			char other = grids[oy][ox];
			if(self != other) {
				// 自身と相手の色が異なれば辺を張る
				int selfIndex = w * sy + sx;
				int otherIndex = w * oy + ox;
				uf.unite(selfIndex, otherIndex);
				
				// 相手のマスに関してDFS
				dfs(oy, ox);
			}
		}
	}
}

Measured memory_bytes: 44444
#include <stdio.h>

int main(){
	int N; //入力
	int i; //counter
	unsigned long long sum = 0; //出力

	scanf("%d", &N);
	for (i=1; i<=N; i++){
		if (i%3 != 0 && i%5 != 0){//3でも5でもないなら足す
			sum += i;
		}
	}
	printf("%lld\n", sum); 
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

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

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	vector<vector<int>> vec(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> vec[i][j];
		}
	}

	vector<int> a(3);
	vector<int> b(3);
	for (int x = 0; x <= 100; x++) {
		a[0] = x;
		b[0] = vec[0][0] - a[0];
		b[1] = vec[0][1] - a[0];
		b[2] = vec[0][2] - a[0];
		a[1] = vec[1][0] - b[0];
		a[2] = vec[2][0] - b[0];

		int count = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (vec[i][j] == a[i] + b[j]) count++;
				else break;
			}
		}
		if (count == 9) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin >> n;
 vector<int> vec(n);
 for(int i=0;i<n;++i){
  cin >> vec[i];
 }
 sort( vec.begin(), vec.end() );
 vec.erase( unique( vec.begin(), vec.end() ), vec.end() );
 cout << vec.size();



  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	int x;cin>>x;
  if(x<600)cout<<8<<endl;
  else if(x<800)cout<<7<<endl;
  else if(x<1000)cout<<6<<endl;
  else if(x<1200)cout<<5<<endl;
  else if(x<1400)cout<<4<<endl;
  else if(x<1600)cout<<3<<endl;
  else if(x<1800)cout<<2<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 3632
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  k = int(input())
  ls = set()
  for i in range(1, k+1):
    for j in range(len(s)-i+1):
      ls.add(s[j:j+i])
  ls = sorted(list(ls))
  print(ls[k-1])

if __name__=='__main__':
  main()



Measured memory_bytes: 4592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;


const int MAX_N = 1 << 20;
int n;
int dat[2 * MAX_N - 1];//セグ木を持つグローバル配列

//初期化
void init(int n_) {
	n = 1;
	//簡単のため、要素数を2のべき乗に
	while (n < n_)n *= 2;
	//gcdに影響を与えない値で初期化する
	for (int i = 0; i < 2 * n - 1; i++)dat[i] = 0;
}

//k番目の値(0-indexed)をaに更新
void update(int k, int a) {
	k += n - 1;//葉の節点
	dat[k] = a;
	//上りながら更新
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

//[a,b)のgcdを求める
//そとからは、(a,b,0,0,n)として呼ぶ
int query(int a, int b, int k, int l, int r) {
	//[a,b)と[l,r)が交差していなければ、gcdに影響を与えない値を返す
	//関数定義でgcdの単位元を0としている
	if (r <= a || b <= l)return 0;
	//[a,b)が[l,r)を完全に含んでいれば、この節点の値
	if (a <= l && r <= b)return dat[k];
	//そうでなければ、二つの子のgcd
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
}

int h[200020], a[200020];
int dp[200020];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	init(N+1);
	int hmax = 0;
	REP(i, N) {
		cin >> h[i];
		hmax = max(hmax, h[i]);
	}
	REP(i, N)cin >> a[i];
	REP(i, N) {
		int tmp = query(0, h[i], 0, 0, n);
		update(h[i], tmp + a[i]);
		int nowans = query(0, h[i]+1, 0, 0, n);
		//printf("%lld:%lld\n", h[i], nowans);
	}
	int ans = query(0, hmax+1,0,0,n);
	print(ans);
}


Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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 / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
cout<<lcm(2,n)<<endl;
}










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

int main(){
    int n;
    cin >> n;
    string s[n];
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    sort(s,s+n);
    long long m,a,r,c,h;
    m = lower_bound(s,s+n,"N") - lower_bound(s,s+n,"M");
    a = lower_bound(s,s+n,"B") - lower_bound(s,s+n,"A");
    r = lower_bound(s,s+n,"S") - lower_bound(s,s+n,"R");
    c = lower_bound(s,s+n,"D") - lower_bound(s,s+n,"C");
    h = lower_bound(s,s+n,"I") - lower_bound(s,s+n,"H");
    long long ans;
    ans = m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;
const int mod = 1000000007;

int add(int a, int b)
{
	int c = a + b;
	if (c >= mod)c -= mod;
	return c;
}

int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)c += mod;
	return c;
}

int mlt(int a, int b)
{
	long long c = a * 1LL * b;
	return c % mod;
}

int bp(int a, int b)
{
	if (b == 0)return 1;
	if (b % 2 == 0)
	{
		int val = bp(a, b / 2);
		return mlt(val, val);
	}
	if (b % 2 == 1)
	{
		int val = bp(a, b - 1);
		return mlt(val, a);
	}
}

int inv(int a)
{
	return bp(a, mod - 2);
}

int ibit(int mask, int i)
{
	return (mask >> i) % 2;
}

void outp(vector<vector<int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		for (int j = 0; j < v[i].size(); j++)cout << v[i][j] << ' ';
		cout << endl;
	}
	cout << endl;
}
void iter(vector<int>&v)
{
	int n=v.size();
	vector<int>sfadd(n);
	for(int i=0; i<n; i++)
	{
		int val=i-v[i];
		if(val>=0)
			sfadd[val]++;
		else sfadd[0]++;
		val=i+v[i];
		if(val+1<n)
			sfadd[val+1]--;
	}
	vector<int>cr(n);
	cr[0]=sfadd[0];
	for(int i=1; i<n; i++)
		cr[i]=cr[i-1]+sfadd[i];
	v=cr;
}
int main()
{
	string s;
	cin>>s;
	s.resize(3);
	cout<<s;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <iterator>
#include <math.h>
#include <cstdlib>
#include <cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
int main(){
  int N;
  cin >> N;
  char S[N];
  cin  >> S;
  int Enum = 0;
  FOR(i,1,N){
    if(S[i] == 'E')  Enum++;
  }
  int Wnum = 0;
  int ans = Enum;//Enum => 右変更すべき人数　Wnum 左変更すべき人数
  FOR(i,1,N){
    if(S[i-1] == 'W'){
      Wnum++;
    }else{
    //  Enum++;
    }
    if(S[i] == 'W'){
      //Wnum--;
    }else{
      Enum--;
    }
    ans = min(ans , Wnum+Enum);
  }
  cout << ans << endl;
  return 0;
 }

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    ll x,n;
    cin >> x >> n;
    set<ll>p;
    rep(i,n){
        ll t;
        cin >> t;
        p.insert(t);
    }
    rep(i,1000){
        ll now = x+i;
        if(p.count(now)==0){
            cout << now << endl;
            return 0;
        }
        ll nx = x-i-1;
        if(p.count(nx)==0){
            cout << nx << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n, T;
    read(n, T);
    
    int t;
    read(t);
    int last = 0;
    int ns = 0;
    
    FOR(n - 1) {
        read(t);
        if (t - last > T) ns += t - last - T;
        last = t;
    }
    print(t + T - ns);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
        
        solve();
        
    }
    
}



Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
void func1(int X,int Y){
  if(X>0){
    rep(i,X-Y,X) cout<<X-Y-1<<" "<<i<<endl;
    rep(i,X-Y,X) cout<<X<<" "<<i<<endl;
    func1(X-1,Y-2);
  }
}
signed main(){
  int N; cin>>N;
  if(N%2==0){
    cout<<(N-2)*(N-2)/2+N-2<<endl;
    func1(N,N-2);
  }
  else{
    cout<<N-1+(N-3)/2*(N-3)+N-3<<endl;
    rep(i,1,N) cout<<i<<" "<<N<<endl;
    func1(N-1,N-3);
  }
  }


Measured memory_bytes: 256
#coding: utf-8
import math

def yis(z):
    y = int(math.floor(math.sqrt(e - z * z * z)))
    return y

while True:
    e = int(raw_input())
    y = 0
    z = 0
    if e == 0:
        break
    for i in range(1000):
        if i * i * i > e:
            z = i - 1
            break
    n = z
    m = e
    for i in range(n + 1):
        y = yis(z)
        m = min(m,e - y * y - z * z * z + y + z)
        z = z - 1
    print m

    

Measured memory_bytes: 6412
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def D2(x1,y1,x2,y2):
        return (x1-x2)**2+(y1-y2)**2

    # 2円が交点を持つか
    def check(R1,R2,eps = 1e-6):
        x1,y1,r1 = R1
        x2,y2,r2 = R2
        d2 = D2(x1,y1,x2,y2)
        if (r1-r2)**2 <= d2 <= (r1+r2)**2:
            return 1
        else:
            return 0

    # 2円の交点を出力
    def point(R1,R2):
        if not check(R1,R2):
            return []
        else:
            x1,y1,r1 = R1
            x2,y2,r2 = R2
            x2 -= x1
            y2 -= y1
            r = x2**2+y2**2
            a = (r+r1**2-r2**2)/2
            d = (r*r1**2-a**2)**0.5
            X,Y = a*x2/r, a*y2/r
            k = d/r
            X1,Y1 = X+y2*k+x1, Y-x2*k+y1
            X2,Y2 = X-y2*k+x1, Y+x2*k+y1
            return [(X1,Y1),(X2,Y2)]

    r1 = LI()
    r2 = LI()
    p1,p2 = point(r1,r2)
    if p2 < p1:
        p1,p2 = p2,p1
    print(*p1,*p2)
    return

#Solve
if __name__ == "__main__":
    solve()



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

int main(){
  int N, strong = -1;
  srand((unsigned)time(NULL));
  cin >> N;
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    if(count(s.begin(), s.end(), 'x') == 0) strong = i + 1;
  }
  for(int i = 0; i < 1000; i++){
    cout << (~strong ? strong : rand() % N + 1) << endl;
  }
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int dp[500004][27] = {0};
string s;
int n;
int p[500004][19] = {0};

int dfs(int i, int j, int l) {
  if (dp[i][j] < n + 2) return dp[i][j];
  if (l > 26 || i == n) return dp[i][j] = n + 1;
  if (s[i] == 'a' + j) {
    return dp[i][j] = i + 1;
  } else if (s[i] < 'a' + j) {
    int next = dfs(i, j - 1, l + 1);
    if (next > n) {
      return dp[i][j] = next;
    } else {
      return dp[i][j] = dfs(next, j - 1, 0);
    }
  } else {
    int next = dfs(i, 26, l + 1);
    if (next > n) {
      return dp[i][j] = next;
    } else {
      return dp[i][j] = dfs(next, j, 0);
    }
  }
}

int get(int i, int j) {
  int ret = i;
  int k = 0;
  while (j && ret <= n) {
    if (j % 2) {
      ret = p[ret][k];
    }
    k++;
    j >>= 1;
  }
  return ret;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> s;
  n = s.size();
  s.push_back('a');
  for (int i = 0; i <= n + 2; i++) for (int j = 0; j < 27; j++) dp[i][j] = n + 2;
  for (int i = n; i >= 0; i--) {
    for (int j = 0; j < 27; j++) {
      dfs(i, (s[i] - 'a' + j) % 27, 0);
    }
    p[i][0] = dfs(i, 26, 0);
  }

  for (int k = 0; k < 18; k++) {
    for (int i = 0; i < n + 1; i++) {
      int to = p[i][k];
      if (to <= n)
        p[i][k + 1] = p[to][k];
      else
        p[i][k + 1] = to;
    }
  }

  int q;
  cin >> q;
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    l--;
    int x = l;
    int k = 18;
    while (x < r && k >= 0) {
      if (p[x][k] <= r) {
        x = p[x][k];
      } else {
        k--;
      }
    }
    if (x == r) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 91164
def calc():
    i_list = input().split()
    n = int(i_list[0])
    m = int(i_list[1])

    min_card = 1
    max_card = n

    for i in range(m):
        i_list = input().split()
        l = int(i_list[0])
        r = int(i_list[1])
        if l > min_card:
            min_card = l
        if r < max_card:
            max_card = r

    ok_num = max_card - min_card + 1
    if ok_num > 0:
        print(ok_num)
    else:
        print(0)

if __name__ == '__main__':
    calc()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> E;
const LL MOD = 1000000007LL;
LL a[2001];
LL memo[2001][2];
int N, Z, W;
LL solve(int n, int t) {
	if (memo[n][t] != -1) return memo[n][t];
	LL ret;
	if (t) {
		ret = 0;
		for (int i = n + 1; i < N; i++) {
			ret = max(ret, solve(i, 0));
		}
		if(n>0) ret = max(ret, abs(a[N] - a[n]));
		else ret = max(ret, abs(a[N] - W));
	}
	else {
		ret = 1LL << 60;
		for (int i = n + 1; i < N; i++) {
			ret = min(ret, solve(i, 1));
		}
		if (n>0) ret = min(ret, abs(a[N] - a[n]));
		else ret = min(ret, abs(a[N] - Z));
	}
	return memo[n][t]=ret;
}
int main() {
	cin >> N >> Z >> W;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	memset(memo, -1, sizeof(memo));
	cout << solve(0, 1) << endl;
}

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

template <typename N> class seg {
    vector<N> t;
    void upd(int a, N n, int p, int l, int r) {
        if(a < l || r <= a)
            return;
        t[p] = op(t[p], n);
        if(r - l < 2)
            return;
        int m = l + r >> 1;
        upd(a, n, p + 1, l, m), upd(a, n, p + (r - l & -2), m, r);
    }
    N get(int a, int b, int p, int l, int r) const {
        if(b <= l || r <= a)
            return e();
        if(a <= l && r <= b)
            return t[p];
        int m = l + r >> 1;
        return op(get(a, b, p + 1, l, m), get(a, b, p + (r - l & -2), m, r));
    }

  public:
    const int s;
    seg(int s) : s(s), t(s + s, e()) {}
    void upd(int a, N n) { upd(a, n, 0, 0, s); }
    N get(int a, int b) const { return get(a, b, 0, 0, s); }

    static N e() { return -1e9; }
    static N op(N x, N y) { return max(x, y); }
};

pair<int, int> x[222222];
int d[222222];
int main() {
    int n, p = 998244353;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        x[i] = {a, b};
    }
    sort(x, x + n);
    seg<int> t(n);
    d[n] = 1;
    for(int i = n; i--;) {
        int k = lower_bound(x + i, x + n,
                            make_pair(x[i].first + x[i].second, (int)-1e9)) -
                x;
        k = max(k, t.get(i + 1, k));
        d[i] = (d[i + 1] + d[k]) % p;
        t.upd(i, k);
    }
    cout << d[0] << endl;
    return 0;
}


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

const Long N = 1e5 + 10;

set<Long> ini[N];
set<Long> fin[N];

Long tree1[N];
Long tree2[N];

Long query1(Long i){
	Long sum=0;
	while(i>0){
		sum+=tree1[i];
		i-=(i&-i);
	}
	return sum;
}
Long query2(Long i){
	Long sum=0;
	while(i>0){
		sum+=tree2[i];
		i-=(i&-i);
	}
	return sum;
}

void update1(Long i, Long val){
	while(i<N){
		tree1[i]+=val;
		i+=(i&-i);
	}
	return;
}
void update2(Long i, Long val){
	while(i<N){
		tree2[i]+=val;
		i+=(i&-i);
	}
	return;
}

Long query(Long x){
	return query1(x)*x-query2(x);
}

void update(Long i, Long j, Long v){
	update1(i,v);
	update1(j+1,-v);
	update2(i,v*(i-1));
	update2(j+1,-j*v);
	return;
}

pair<Long,Long> cambia(Long l, Long r, Long n){
	pair<Long, Long> a,b;
	a = {l,r};
	b = {n-r-1,n-l-1};
	a = min(a,b);
	if(a.second >= n/2){
		Long aux = min(n/2 - 1,n-a.second-2);
		a = {a.first,aux};
	}
	return a;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;
	
	Long m, l, r, n;
	string cad;
	cin >> cad >> m;
	n = cad.size();
	for(Long i = 0; i < m; i++){
		cin >> l >> r;
		l--;
		r--;
		if(l+r == n-1) continue;
		pair<Long,Long> nuevo = cambia(l,r,n);
		ini[nuevo.first].insert(nuevo.second);
	}
	
	for(Long i = 0; i < n/2; i++){
		Long sz = ini[i].size();
		auto it = ini[i].begin();
		if(sz == 1){
			fin[*it].insert(i);
		}else if(sz > 1){
			Long ant = i;
			while(it != ini[i].end()){
				if(ant != i){
					ini[ant].insert(*it);
				}
				fin[*it].insert(ant);
				ant = *it + 1;
				it++;
			}
		}
	}
	
	vector< pair<Long,Long> > rangos;
	
	for(Long i = 0; i < n/2; i++){
		Long sz = fin[i].size();
		auto it = fin[i].begin();
		if(sz == 1){
			rangos.push_back({*it,i});
		}else if(sz > 1){
			Long ant = *it;
			while(it != fin[i].end()){
				it++;
				if(it == fin[i].end()){
					rangos.push_back({ant,i});
				}else{
					rangos.push_back({ant,*it-1});
					ant = *it;
				}
			}
		}
	}
	
	sort(rangos.begin(),rangos.end());
	
	for(Long i = 0; i < rangos.size(); i++){
		l = rangos[i].first + 1;
		r = rangos[i].second + 1;
		Long auxi = (cad[n-l] - 'a') - (query(l) - query(l-1) + (cad[l-1] - 'a'));
		auxi %= 26;
		auxi += 26;
		auxi %= 26;
		update(l,r,auxi);
	}
	
	for(Long i = 0; i < n/2; i++){
		Long aux = query(i+1) - query(i);
		if(((cad[i] - 'a') + aux)%26 != (cad[n-i-1] - 'a')){
			cout << "NO\n";
			return 0;
		}
	}

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

Measured memory_bytes: 69184
#include <cstdio>
const int MAXC = 15;
char	S[MAXC]{ };
bool yes=true;
int A, B;

int main()
{
	scanf("%d%d %s", &A, &B, S);
	for(int i = A+B; i >= 0; --i)
		if(i != A)
			yes &= ('0' <= S[i]) && (S[i] <= '9');
		else
			yes &= (S[i] == '-');
	puts(yes ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<n1<<"\n"
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
int comp(const void* a, const void* b)  
{ return *(int*)a > *(int*)b ; }  
  
// Function to count all possible triangles with arr[]  
// elements  
int findNumberOfTriangles(int arr[], int n)  
{  
    // Sort the array elements in non-decreasing order  
    qsort(arr, n, sizeof( arr[0] ), comp);  
  
    // Initialize count of triangles  
    int count = 0;  
  
    // Fix the first element. We need to run till n-3  
    // as the other two elements are selected from  
    // arr[i+1...n-1]  
    for (int i = 0; i < n - 2; ++i)  
    {  
        // Initialize index of the rightmost third  
        // element  
        int k = i + 2;  
  
        // Fix the second element  
        for (int j = i + 1; j < n; ++j)  
        {  
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
    return count;  
}  
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    int arr[n];
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    cout<<findNumberOfTriangles( arr, n )<<"\n";  

}


Measured memory_bytes: 256