akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if ( (a * b) % 2 == 1){
            System.out.println("Odd");
        }else{
            System.out.println("Even");
        }
        scanner.close();
    }
}

Measured memory_bytes: 21844
import math

N, K = list(map(int, input().split()))
mod = 10**9+7


def combination(a, b):
    ans = (math.factorial(a) // math.factorial(a-b)) // math.factorial(b)
    return ans


for i in range(1, K+1):
    if (N-K+1-i) >= 0:
        ans1 = combination(N-K+1, i)
        ans2 = combination(K-1, i-1)
        print(ans1 % mod*ans2 % mod)
    else:
        print(0)


Measured memory_bytes: 66392
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// ここにコードを挿入
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		if(c<(a-b)) {
			System.out.println(0);
		}else {
			System.out.println(c-(a-b));
		}
	}

}


Measured memory_bytes: 23764
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

a,b,c = inm()
print('Yes' if a==b and b==c  else 'No')


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

int main() {
	int n, k, r, s, p, cnt = 0;
	string t;
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;
	vector <int> A(t.length(), 0);

	for (int i = 0; i < n; i++) {
		if (i < k || !A[i-k] || t.substr(i, 1) != t.substr(i - k, 1)) {
			if (t.substr(i, 1) == "r") cnt += p;
			else if (t.substr(i, 1) == "s") cnt += r;
			else cnt += s;
			A[i] = 1;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 896
# -*- coding: utf-8 -*-

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

a_koho = int(A/0.08)
b_koho = int(A/0.1)

# print(a_koho,b_koho)

if a_koho == b_koho:
    # print(a_koho)
    exit()

start = min(a_koho,b_koho)
end = max(a_koho,b_koho)

for i in range(start-100,end+1+100):
    if i < 1:
        continue

    a = int(i*0.08)
    b = int(i*0.1)

    # print(a,b)

    if a == A and B == b:
        print(i)
        exit()

print("-1")

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

using namespace std;

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pairll;

#define sll(x) scanf("%lld",&x);
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)

#define ff first
#define ss second

inline ll readInt()
{
    ll in; scanf("%lld",&in); return in;
}

inline ll ADD(ll a, ll b, ll mod)
{
    return (a + b + mod + mod)%mod;
}

inline ll SUBS(ll a, ll b, ll mod)
{
    return (a-b+mod + mod) %mod;
}

inline ll MUL(ll a, ll b, ll mod)
{
    return (a*b + mod)%mod;
}

ll bigMod(ll base, ll power, ll mod)
{
    if(!power) return 1;
    if(!base) return 0;

    ll temp = bigMod(base, power/2, mod);

    if(power%2 == 0)
    {
        return (temp*temp)%mod;
    }
    else return (((temp*temp)%mod)*base)%mod;
}

inline ll modInverse(ll a, ll modp)
{
    return bigMod(a, modp -2, modp);
}

inline ll modInverseExtended(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  

void autoinput()
{
    #ifndef ONLINE_JUDGE
    READ; 
    //WRITE;

    #endif
}

int main()
{
    autoinput();
    char s[200069];

    scanf("%s",s);

    for(ll i = 0; s[i]; i++)
    {
        if(s[i] == '?') printf("D");
        else printf("%c",s[i]);
    }
    puts("");
}



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

namespace ABC047A___キャンディーと2人の子供
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] candyPacks = input.Split(' ');

            List<int> candyPackList = ParseInValueToInteger(candyPacks).ToList();

            int maxValue = candyPackList.Max();
            int maxValueIndex = candyPackList.IndexOf(maxValue);

            candyPackList.Remove(maxValue);
            bool canEqual = (maxValue == candyPackList.Sum());

            string output = "No";
            if (canEqual)
            {
                output = "Yes";
            }

            Console.WriteLine(output);
        }

        private static IEnumerable<int> ParseInValueToInteger<T>(IEnumerable<T> enumerable)
        {
            IList<int> list = new List<int>();

            foreach (var value in enumerable)
            {
                list.Add(int.Parse(value.ToString()));
            }

            return list;
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <string>
class Point;
class Sentinel;
class Point {
	long double x, y;
public:
	Point(const double &a = { 0 }, const double &b = { 0 }) :x(a), y(b) {};
	bool operator<(const Point &other) const {
		return (x < other.x) || ((x == other.x) && (y < other.y));
	}
	bool operator>(const Point &other) const {
		return other < *this;
	}
	long double operator*(const Point &other) const {
		return x * other.y - y * other.x;
	}
	void inspect() const {
		std::cout << x << "-" << y << std::endl;
	}
	Point operator-(const Point &other) const {
		return Point(x - other.x, y - other.y);
	}
};
class Sentinel : public Point {
public:
	Sentinel() :Point(10000,10000) {};
};
std::list<Point> sort(std::vector<Point> &vec, const int &left, const int &right) {
	if (left == right) {
		return std::list<Point>{vec.at(left), Sentinel()};
	}
	else {
		std::list<Point> l = sort(vec, left, left + (right - left) / 2);
		std::list<Point> r = sort(vec, left + 1 + (right - left) / 2, right);
		std::list<Point> res;
		for (const auto &a : l) {
			while (r.front() < a) {
				res.push_back(r.front());
				r.pop_front();
			}
			res.push_back(a);
		}
		return res;
	}
}
double sub(const Point &a, const Point &b, const Point &c) {
	return (a - b) * (b - c);
}
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		std::vector<Point> vec(n);
		for (auto &v : vec) {
			double x, y;
			std::scanf("%lf,%lf", &x, &y);
			v = Point(x, y);
		}
		auto list = sort(vec, 0, n - 1);
		list.pop_back();
		std::vector<Point> a(n + 2), b(n + 2);
		a.at(0) = list.front(), a.at(1) = list.front(), b.at(0) = list.front(), b.at(1) = list.front();
		auto i = 1, j = 1;
		for (const auto &p : list) {
			while (sub(a.at(i - 1), a.at(i), p) > 0) {
				--i;
				//std::cout << i << "-";
			}
			a.at(++i) = p;
			//std::cout << i << std::endl;
			while (sub(b.at(j - 1), b.at(j), p) < 0) {
				--j;
				//std::cout << j << "=";
			}
			b.at(++j) = p;
			//std::cout << j <<  std::endl;
		}
		std::cout << n - i - j + 4 << std::endl;
		std::cin >> n;
	}
	return 0;
}

Measured memory_bytes: 3212
n,k=map(int,input().split())
d=list(map(int,input().split()))
ans=0
for l in range(min(n,k)+1):
    for r in range(min(n-l,k-l)+1):
        tl=d[:l]+d[-r:] if r>0 else d[:l]
        tk=k-l-r
        s=0
        for t in sorted(tl):
            if t<0 and tk>0:
                s+=-t
                tk-=1
            ans=max(ans,sum(tl)+s)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

ll C[22],A[22][22];

int main(){
  int N,M,X; cin>>N>>M>>X;
  rep(i,N){
    cin>>C[i];
    rep(j,M) cin>>A[i][j];
  }

  ll ans=1e15;
  rep(bit,(1<<N)){
    ll sum[22]={},tmp=0;
    rep(i,N){
      if(((1<<i)&bit)==0) continue;
      tmp+=C[i];
      rep(j,M) sum[j]+=A[i][j];
    }
    bool flag=1;
    rep(i,M){
      if(sum[i]<X) flag=0;
    }
    if(flag) ans=min(ans,tmp);
  }
  if(ans==1e15) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>

int main(){
  int n,N=0,v,i,j;

  scanf("%d",&N);

  int A[N];

  if(N>100||N<1) exit(1);
  
  for(n=0; n<N; n++){
    scanf("%d",&A[n]);
    if(A[n]<0||A[n]>1000) exit(2);
  }

  for(n=0; n<N; n++){
    if(n!=0) printf(" %d",A[n]);
    else printf("%d",A[n]);
  }

  printf("\n");

  for(i=1; i<N; i++){
    v = A[i];
    j = i - 1;
    
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }

    for(n=0; n<N; n++){
      if(n!=0) printf(" %d",A[n]);
      else printf("%d",A[n]);
    }
    printf("\n");
  }
  
  return 0;
}



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

int main()
{
	int K;
	cin >> K;
	int count = 0;

	for (int i = 1; i <= K; i++) {
		for (int k = i; k <= K; k++) {
			if (i % 2 == 0 && k%2==1) {
				count++;
			}
			if (i % 2 == 1 && k % 2 == 0) {
				count++;
			}
		}
	}
	cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
a = int(input())
N = list(map(int,input().split()))

ans = 1

if 0 in N:
    ans = 0
else:
    for i in range(len(N)):
        ans *= N[i]
        if ans > 10**18:
            break

if ans > 10**18:
    print('-1')
else:
    print(ans)

Measured memory_bytes: 21660
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

from math import sqrt
a, b, c = mi()    

if 4 * a * b < (c-(a+b))*  (c-(a+b)) and (c-(a+b)) >= 0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3060
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>





int main(void){
int n,k;
long long int s;
scanf("%d%d%lld",&n,&k,&s);
long long int ans[n];
int i;
/*for(i=0;i<n;i=i+2){
  if(k>0){
    if(s>i){
    ans[i]=i;
    ans[i+1]=s-i;
  }
  else{
    ans[i]=i;
    ans[i+1]=i-s;
  }
  }
  else{
    ans[i]=1000000000;
    ans[i+1]=1000000000;
  }
  k--;
}*/
for(i=0;i<n;i++){
  if(k>0){
    ans[i]=s;
    k--;
  }
  else{
    ans[i]=1000000000-1;
  }
}
for(i=0;i<n;i++){
  printf("%lld ",ans[i]);
}


  return 0;
}


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

int main() {
  long long  h, n;
  cin >> h >> n;
  
  pair<long long, long long> t[n];
  for (int i = 0; i < n; i++) {
    long long _a, _b;
    cin >> _a >> _b;
    t[i] = make_pair(_a, _b);
  }
  
  vector<long long> dp_mp(10010, 1e9+7);
  dp_mp[0] = 0;
  
  for (long long  i = 1; i <= h; i++) {
    for (long long j = 0; j < n; j++) {
      long long mp;
      if (i - t[j].first <= 0) {
        mp = min(dp_mp[i], t[j].second);
      } else {
        long long rest_hp = i - t[j].first;
        mp = t[j].second + dp_mp[rest_hp];
      }
      //cerr << i << ' ' << j << ' ' << mp << endl;
      dp_mp[i] = min(dp_mp[i], mp);
    }
  }
  
  cout << dp_mp[h] << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n; cin >> n;
    int a[4]; a[0] = a[1] = a[2] = a[3] = 0;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        if(s == "AC") a[0]++;
        if(s == "WA") a[1]++;
        if(s == "TLE") a[2]++;
        if(s == "RE") a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
    return 0;
}

Measured memory_bytes: 3628
A,B = map(int,input().split())

AA = A*100//8 + 1 if A*100%8!=0 else A*100//8
AF = (A+1)*100//8 + 1 if (A+1)*100%8!=0 else (A+1)*100//8
BB = B*10
AAA = [i for i in range(AA,AF)]
BBB = [i for i in range(BB,(B+1)*10)]
AB_list = list(set(AAA)&set(BBB))

ans = min(AB_list) if AB_list and (12<min(AB_list)<=1000) else -1
print(ans)

Measured memory_bytes: 3064
import qualified Data.ByteString.Char8 as B
import Data.Char (isSpace)
import Data.List (unfoldr)

readInt = B.readInt . B.dropWhile isSpace
readInts = unfoldr readInt

inf = 10000

a#b = abs (a-b)

solv :: Int -> Int -> Int -> [Int] -> Int
solv a b c ls = go ls (0,0,0) 0 where
  go [] (la,lb,lc) cost
    | la==0 || lb==0 || lc==0 = inf
    | otherwise = cost + a#la + b#lb + c#lc
  go (l:ls) (la,lb,lc) cost = minimum [forA, forB, forC, unuse] where
    forA = go ls (la+l, lb, lc) $ if la>0 then cost+10 else cost
    forB = go ls (la, lb+l, lc) $ if lb>0 then cost+10 else cost
    forC = go ls (la, lb, lc+l) $ if lc>0 then cost+10 else cost
    unuse = go ls (la,lb,lc) cost

main = do
  [n,a,b,c] <- readInts <$> B.getLine
  ls <- readInts <$> B.getContents
  print $ solv a b c ls


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;

int main(){
//    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a < c){
        swap(a,c);
        swap(b,d);
    }
    int t;
    if(a >= d) t = 0;
    else if(d > a && d <= b) t = d - a;
    else t = b-a;
    cout << t;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const int INF = 1e9 + 1;

int n, x, y;
vvi g;
int main()
{
 cin >> n >> x >> y; x--;y--;
  vi ans(n);
  rep(sv, n) {
    vi dist(n, INF);
    queue<int> q;
    auto push = [&] (int v, int d) {
      if (dist[v] != INF) return ;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (q.size()) {
      int v = q.front(); q.pop();
      int d=dist[v];
      if (v) push(v-1, d+1);
      if (v+1<n) push(v+1, d+1);
      if (v==x) push(y, d+1);
      if (v==y) push(x, d+1);
    }
    rep(i, n) ans[dist[i]]++;
  }
  for (int i=1; i<n ;i++) {
    cout << ans[i]/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N; cin >> N;
    vector<ll> H(N);
    rep(i, N) cin >> H.at(i);
    string ans = "Yes";

    for(ll i = N - 2; i >= 0; i--) {
        if (H.at(i) > H.at(i + 1)) {
            if (H.at(i) - H.at(i + 1) >= 2) {
                cout << "No" << endl;
                return 0;
            }
            H.at(i)--;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long x;
    cin >> x;
    double m = 100;
    int count = 0;
    
    while(m < x){
        m = m * 1.01;
        m = floor( m );
        count++;
       // cout << m << endl;
    }
    
    cout << count << endl;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
	#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
}
/*************************************************************************************/

const ll maxn=2e5+1,mod=1e9+7;

vector<vector<int> > g(maxn); 
ll dp[2][maxn];

void dfs(int cur,int par){
	// ll val = 1,vall = 1;
	dp[0][cur] = 1,dp[1][cur] = 1;
	for(auto it:g[cur]){
		if(it==par) continue;
		dfs(it,cur);
		dp[0][cur]*=(dp[0][it]+dp[1][it]);
		dp[1][cur]*=(dp[0][it]);
		dp[0][cur]%=mod;
		dp[1][cur]%=mod;
	}

}

int main(){
    sync
   // file();
	
	int n;
	cin>>n;
	forn(i,n-1){
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,1);
	cout<<(dp[0][1]+dp[1][1])%mod;

	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int p[200003];
    int r[200003];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        p[i]--;
        r[p[i]] = i;
    }
    int l = 1;
    int ans = n - 1;
    for(int i = 0; i < n - 1; i++){
        if(r[i] < r[i + 1]) l++;
        else l = 1;
        ans = min(ans, (n - l));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);


	int n;
	cin >> n;

	set<string> its;

	string a;
	while(n--){
		cin >> a;
		its.insert(a);
	}

	cout << its.size() << endl;


	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[])
{
  string s;
  cin >> s;
  
  string result = "Good";
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      result = "Bad";
      break;
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long h,a[100100];
int n;
int main(){
	cin>>h>>n;
	long long sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>=h)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 1024
a = sorted(list(map(int, input().split())))
op = 0
while a[0] < a[1]:
    op += 1
    if a[1] < a[2]:
        a[0] += 1
        a[1] += 1
    else:
        a[0] += 2
    a.sort()
print(op + a[2] - a[0])


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+100;
vector<int>p[maxn];
int main() {
    int n;
    cin>>n;
    for(int i=2,x;i<=n;i++)
        cin>>x,p[x].push_back(i);
    for(int i=1;i<=n;i++)
        cout<<p[i].size()<<endl;

}


Measured memory_bytes: 14528
import sys
input=sys.stdin.readline

def main():
	N,K=map(int,input().split())
	#N=input().rstrip()
	#K=int(input())
	vA=list(map(int,input().split()))
	
	s = sum(vA[:K])
	res = s
	
	for p,a in zip(vA[0:], vA[K:]):
		s -= p
		s += a
		res = max(res, s)
		#print(p,a,res)
			
	#res = (A+B-1)//B
	res = (res + K)/2
	print(res)


main()


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

int main(){
    ll X; cin >> X;
    if(X >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long a,b,ans=1;
    cin>>a>>b;
    ans*=b;
    f(i,1,a){
        ans*=b-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
		s1[0]-=32;
		s2[0]-=32;
		s3[0]-=32;
	 cout<<s1[0];
	 cout<<s2[0];
	 cout<<s3[0];
      
}

Measured memory_bytes: 256
def kaibun(s)
  size = s.length / 2
  s[0..size] == s.reverse[0..size]
end
s = gets.chomp.chars
n = s.length
sl = s[0..(n-1)/2-1]
sr = s[(n+3)/2-1..n-1]
puts (kaibun(sl) && (sl==sr)) ? "Yes" : "No"


Measured memory_bytes: 1788
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
string A;

int main(){
	cin >> A;

	int s=0, k=0;
	vector<int> c(1, A.size());
	for(int i=A.size()-1; i>=0; i--){
		s |= 1<<(A[i]-'a');
		if(s == (1<<26)-1){
			s = 0;
			k++;
			c.push_back(i);
		}
	}

	reverse(c.begin(), c.end());
	//for(int i=0; i<c.size(); i++) cout << c[i] << endl;

	vector<vector<int> > p(26, vector<int>());
	for(int i=0; i<A.size(); i++){
		p[A[i]-'a'].push_back(i);
	}

	int n=0;
	string ans;
	for(int i=0; i<=k; i++){
		for(int j=0; j<26; j++){
			int lb=0, ub=p[j].size()-1;
			if(p[j].size() == 0 || p[j][ub] < n){
				ans.push_back('a'+j);
				break;
			}
			int l;
			if(p[j][lb]>=n) l=lb;
			else{
				while(ub-lb>1){
					int med = (lb+ub)/2;
					if(p[j][med]>=n) ub=med;
					else lb=med;
				}
				l = ub;
			}
			if(p[j][l]<c[i]) continue;
			ans.push_back('a'+j);
			n=p[j][l]+1;
			break;
		}
	}

	//cout << k+1 << endl;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl b = n;
    intl a = 0;
    rep(i,digit10(n)){
        a += b % 10;
        b /= 10;
    }
    fp(!(n%a));
    return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
import itertools
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def dist(x1, x2, y1, y2):
  d = sqrt((x1-x2)**2 + (y1-y2)**2)
  return d


N = INT()
b = []
for i in range(N):
  a = LIST()
  b.append(a)
# print(b)

jun = [i for i in range(N)]
c = list(itertools.permutations(jun))
# print(c)

ans2 = 0
for j in c:
  # tuple
  ans = 0
  # print(j)
  for i in range(len(j)-1):
    # print(j[i])
    # print(j[i+1])
    x1 = b[j[i]][0]
    x2 = b[j[i+1]][0]
    y1 = b[j[i]][1]
    y2 = b[j[i+1]][1]
    ans += dist(x1, x2, y1, y2)
    # print(ans)
  # print(ans)
  ans2 += ans
  # print(ans2)
    # print(dist(x1, x2, y1, y2))
print(ans2/len(c))


Measured memory_bytes: 10436
require 'set'

n = gets.to_i
g = (0..n*n).map { Set.new }
(2 * n * n - 2 * n).times do
  i, j = gets.split.map(&:to_i)
  g[i] << j
  g[j] << i
end

row = [(1..n*n).find {|i| g[i].size == 2 }]
scanned = Set[row[-1]]
(n - 1).times do
  row << g[row[-1]].select {|i| !scanned.include?(i) }.sort_by {|i| g[i].size }[0]
  scanned << row[-1]
end
puts row * " "

(n - 1).times do
  row = row.map {|i| g[i].select {|j| !scanned.include?(j) }[0] }
  row.each {|i| scanned << i }
  puts row * " "
end



Measured memory_bytes: 10328
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	ll n, m;
	cin >> n >> m;
	if (n > m)
		swap(n, m);
	if (n == 1) {
		if (m == 1)
			cout << 1 << "\n";
		else
			cout << m - 2 << "\n";
		return 0;
	}
	cout << (n - 2) * (m - 2) << "\n";
	return 0;
}




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

int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  long long ans = 999999999, tmp;
  for (int i = 0; i < n - k + 1; i++) {
    if (x[i]*x[i + k - 1] >= 0) {
      tmp = max(llabs(x[i]), llabs(x[i + k - 1]));
      if (tmp < ans) {
        ans = tmp;
      }
    }
    else {
      tmp = x[i + k - 1] - x[i];
      tmp += min(llabs(x[i]), llabs(x[i + k - 1]));
      if (tmp < ans) {
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
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;
}

int read(){
	int i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	map<int,int> dp;
	string s=readString();
	int w=0,n=s.size();
	dp[0]=0;
	REP(i,n){
		int a=s[i]-'a';
		w^=(1<<a);
		int res=inf;
		REP(k,27){
			int p=k==26?w:(w^(1<<k));
			if(dp.count(p))
				chmin(res,dp[p]+1);
		}
		if(i==n-1){
			cout<<res<<endl;
		}else{
			if(!dp.count(w)||dp[w]>res)
				dp[w]=res;
		}
	}
}

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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rb(i,x) for (auto& i : x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define UNIQUE(x) (x).resize(unique(all(x)) - begin(x))

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second

#define pow10(n) stoll("1"+string(n,'0'))

#define debug(x) cout << ">>> " << #x << ": " << x << '\n'

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

void setIO(string s) {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

int main() {
    
    setIO("input");
    ll n; cin >> n;
    ll nodes = 0;
    for(ll i=1; i<=n; ++i)
        nodes += i * (n-i+1);
    ll edges = 0;
    for(ll i=1; i<=n-1; ++i) {
        int u, v; cin >> u >> v;
        if(u > v) swap(u, v);
        edges += u * (n-v+1);
    }
    cout << nodes - edges;
    
}

/*  ! CHECK THIS IF YOU GET IT WRONG !
	* int overflow, array bounds, NO VLAs
	* uninitialized local variables, rounding errors
	* intermediate result type, scientific
	* special cases (n = 0 or 1?)
	* reset your variables in scope
	* INF not large enough for ans, adding value to _MAX
	* using wrong variables, sorting extra 0s in global array
	* comment out input from file
	* operator precedence
*/

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

vector<int>a[100005];
vector<bool>b(100005,false);

void c(int i){
  if(!b[i]){
    b[i]=true;
    for(auto v:a[i]){
      c(v);
    }
  }
}

void solve(){
  int n,m;
  int cnt=0;
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int aa,bb;
    cin >> aa >> bb;
    aa--;
    bb--;
    a[aa].push_back(bb);
    a[bb].push_back(aa);
  }
  
  for(int i=0;i<n;i++){
    if(!b[i]){
      cnt++;
      c(i);
    }
  }
  cout << cnt-1 << endl;
}

int main(){
  solve();
}

Measured memory_bytes: 9588
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
//typedef pair<int,int>P;
#define INF 1000000009

typedef struct D{int s,e;}D;//(s,e]

int N,M,P,Q,R,x,y,res;

void Qmov(queue<D> &s,queue<D> &d,int len)
{
	for(int c=0;c<len&&!s.empty();)
	{
		D now=s.front();s.pop();
		if(c+(now.e-now.s)>len)
		{
			D rev={now.s+(len-c),now.e};
			now.e=now.s+(len-c);
			queue<D>tmp;
			tmp.push(rev);
			Qmov(s,tmp,INF);
			Qmov(tmp,s,INF);
		}
		c+=(now.e-now.s);
		d.push(now);
	}
}


int main()
{
	for(;scanf("%d",&N),N;)
	{
		queue<D>q,A,B,C;
		D tmp={1,N+1};
		q.push(tmp);
		scanf("%d%d%d%d",&M,&P,&Q,&R);
		for(int i=0;i<M;i++)
		{
			scanf("%d%d",&x,&y);
			Qmov(q,A,x);
			Qmov(q,B,y-x);
			Qmov(q,C,INF);
			Qmov(C,q,INF);
			Qmov(B,q,INF);
			Qmov(A,q,INF);
		}
		P--;Q--;res=0;
		for(int i=0;i<=Q;)
		{
			D tmp=q.front();q.pop();
			int len=tmp.e-tmp.s;
			if(i+len<P||i>Q)
			{
			}
			else
			{
				int s=i>P?tmp.s:tmp.s+(P-i);
				int e=i+len<Q?tmp.e-1:tmp.s+(Q-i);
				if(s<=R)
					res+=min(R,e)-s+1;
			}
			i+=len;
			
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1280
// https://beta.atcoder.jp/contests/abc116

#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

void print_vector(const vector<int>& a, int n) {
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    cout << endl;
}

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(8
4 23 75 0 23 96 50 100
)");
#endif
    int n;
    in >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) in >> h[i];

    int ans = 0;
    vector<int> v(n);

    while (true) {
        int left = 0;
        for (int r = 0; r < n; ++r) {
            if (v[r] == h[r]) {
                for (int j = left; j < r; ++j) v[j]++;
                if (left != r) ans++;
                left = r + 1;

//                print_vector(v, n);
            }
        }

        for (int j = left; j < n; ++j) v[j]++;
        if (left != n) {
            ans++;
//            print_vector(v, n);
        }

        bool done = true;
        for (int i = 0; i < n; ++i) {
            if (v[i] != h[i]) done = false;
        }
        if (done) break;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int a[100001],d[100001];
int main(){
    ll n;
    cin>>n;
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    sum*=2;
    if(sum%(n*(n+1))!=0){
        cout<<"NO"<<endl;
        return 0;
    }
    ll k=sum/n/(n+1);
    rep(i,n){
        d[i]=a[(i+1)%n]-a[i]-k;
    }
    int cnt=0;
    rep(i,n){
        if(d[i]>0||d[i]%n!=0){
            cout<<"NO"<<endl;
            return 0;
        }
        cnt+=d[i]/n;
    }
    if(cnt==-k)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int n,t;
  cin >>n >> t;
  int x=n*t;
  int ti[n];
  for(int i=0;i<n;i++){
    cin >>ti[i];
  }
  for(int i=1;i<n;i++){
    if((ti[i]-ti[i-1])<t){
      x+=ti[i]-ti[i-1]-t;
    }
  }
  cout << x <<endl;
  return 0;
}


Measured memory_bytes: 1024
marks = ["S","H","C","D"]
all_card = []

marks.each do |mark|
	for i in 1..13
		all_card << mark + " " + i.to_s 
	end
end

N = gets.to_i
N.times do
	card = gets.chomp
	all_card.delete(card)
end
puts all_card.join("\n") if all_card.size != 0

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

int main() {
  int H, N;
  cin >> H >> N;
  int num = H - N;
  
  vector<long long> A(H) ;
  for (int i = 0; i < H; i++) {
    cin >> A.at(i);
  }
  
 sort(A.begin(), A.end());
  
 for (int j = 0; j < N; j++) {
 	A.pop_back();
 }
 
 long long sum = 0;
  
 for (int p = 0; p < num; p++) {
  sum += A.at(p);
 }
  if( 0 >= num ){
  cout << 0 << endl;
  }
  else{
  cout << sum << endl;
  }
}

Measured memory_bytes: 1792
#include <iostream>
#define SWAP(type, x, y) do { type t = x; x = y; y = t; } while (0)
#define N 3
using namespace std;

int main()
{
    int a[N];

    for (int i = 0; i < N; i++) {
        cin >> a[i];
        for (int j = i; j > 0; j--)
            if (a[j - 1] > a[j])
                SWAP(int, a[j - 1], a[j]);
    }

    for (int i = 0; i < N; i++)
        if (i != N - 1)
            cout << a[i] << ' ';
        else
            cout << a[i] << endl;
}


Measured memory_bytes: 3120
// Author : Chi
// created : Thursday 2020-06-04
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         3
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
void solve(){
    int n;
    cin>>n;
    ll a[n];
    ll s[n];
    for(auto &i:a)cin >> i;
    for(auto &i:s)cin >> i;
    map<int,long long>m;
    m[a[0]]=s[0];
    long long ma_a=s[0];

    for(int i=1; i<n; i++){
        ll an=s[i];
        auto it=m.lower_bound(a[i]+1);
        if(it!=m.begin()){
            it--;
            m[a[i]]=it->second;
        }
        m[a[i]]+=an;
        it=m.upper_bound(a[i]);
        while(it!=m.end()&&it->second <= m[a[i]]){
            auto it2=it;
            it2++;
            m.erase(it);
            it=it2;
        }
        ma_a=max(ma_a,m[a[i]]);
    }
    cout<<ma_a;
    }
// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N; int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return rights[i] < rights[j]; });

    BIT<int> bit(N + 5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]] + 2, r + 2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i] + 1, lefts[i] + 2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 1000000007
ll BIT[500005];
ll n;
ll answer(ll i)
{
	ll sum=0;
	while(i>0)
	{
		sum+=BIT[i];
		i=i-(i&(-i));
	}
	return sum;
}
void update(int i,ll val)
{
	while(i<=n)
	{
		BIT[i]+=val;
		i=i+(i&(-i));
	}
}
int main()
{   
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r",stdin);
	freopen("output.txt", "w",stdout);
#endif*/
	fast;
	ll q;
	cin>>n>>q;
	ll a[n+2];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		update(i,a[i]);
	}
	while(q--)
	{
		int k;
		cin>>k;
		if(k==0)
		{
			ll i,val;
			cin>>i>>val;
			update(i+1,val);
		}
		if(k==1)
		{
			int l,r;
			cin>>l>>r;
			cout<<answer(r)-answer(l)<<"\n";
		}
	}
    return 0;
}

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

int main() {
    int n, ans;
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        
        ans += r - l + 1;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(){

  int r, c, i, j, e[110][110]={0};

  scanf("%d %d", &r, &c);

  for(i=1;i<=r;i++){
    for(j=1;j<=c;j++){
      scanf("%d", &e[i][j]);
    }
  }
  for(i=1;i<=r;i++){
    for(j=1;j<=c;j++){
      e[i][c+1] += e[i][j];
    }
    e[r+1][c+1] += e[i][c+1];
  }
  for(j=1;j<=c;j++){
    for(i=1;i<=r;i++){
      e[r+1][j] += e[i][j];
    }
    e[r+1][c+1] += e[r+1][j];
  }
  e[r+1][c+1] /= 2;
  for(i=1;i<=r+1;i++){
    for(j=1;j<=c+1;j++){
      if(j==c+1) printf("%d", e[i][j]);
      else       printf("%d ", e[i][j]);
    }
    printf("\n");
  }
  
  return 0;
  
}

Measured memory_bytes: 660
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        Arrays.sort(l);
        Arrays.sort(r);
        int ans = r[0] - l[m - 1] + 1;
        if (ans < 0) {
            System.out.println(0);
            return;
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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 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;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

const ll MOD = 1e9+7;

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

  int N;
  cin >> N;
  vector<ll> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }

  int L = N-1;
  vector<ll> d(L);
  for(int i = 0; i < L; i++){
    d[i] = x[i+1] - x[i];
  }

  vector<ll> p(L);
  p[0] = 1;
  for(int i = 1; i < L; i++){
    // p[i] = p[i-1] + 1/(i+1)
    p[i] = (p[i-1] + modinv(i+1, MOD)) % MOD;
  }

  ll ans = 0;
  for(int i = 0; i < L; i++){
    ans = (ans + (d[i] * p[i]) % MOD) % MOD;
  }

  ll factL = 1;
  for(int i = 1; i <= L; i++){
    factL = (factL * i) % MOD;
  }

  cout << (ans * factL) % MOD << endl;

  return 0;
}


Measured memory_bytes: 2560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class EOrand {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, k, s, t;  cin >> n >> k >> s >> t;
      vector<ll> v;
      rep(i, n) {
        ll a; cin >> a;
        if ((a&s) == s && (a|t) == t) {
          v.push_back(a);
        }
      }

      int vs = v.size();
      debug(vs);
      vector<vector<ll>> comb(vs+1, vector<ll>(vs+1));
      comb[0][0] = 1;
      rep(i, vs) {
        rep(j, vs) {
          comb[i+1][j] += comb[i][j];
          comb[i+1][j+1] += comb[i][j];
        }
      }

      int r = 1<<18;
      int u = s^t;

      vector<vector<ll>> dp(vs+1, vector<ll>(r));

      ll ans = 0;
      rep(i, r) {
        if ((i&u) != i || (i|u) != u) continue;

        map<int, int> mp;
        for(auto e: v) {
          mp[e&i]++;
        }

        ll ng = 0;
        for(auto e: mp) {
          for(int j=1; j<=min(e.second, k); j++) {
            ng += comb[e.second][j];
          }
        }

        debug(i, ng);

        int cnt = __builtin_popcount(i);
        if (cnt%2 == 0) {
          ans += ng;
        } else {
          ans -= ng;
        }
      }

      cout << ans << endl;
    }
};

signed main() {
  EOrand solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 109808