akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::unordered_set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N; cin >> N;
  vector<int> A(N), B(N), C(N);
  for(auto& a : A){ cin >> a; --a;}
  for(auto& b : B) cin >> b;
  for(auto& c : C) cin >> c;

  int res{};
  for(ui i = 0; i < N; ++i)
  {
    res += B[A[i]];
    if(i)
    {
      if(A[i] - A[i - 1] == 1) res += C[A[i - 1]]; 

    }
  }

  cout << res << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    string a,b;
    cin >> a >> b;
    stringstream s;
    a=a+b;
    s << a;
    int u;
    s >> u;
    for(int i=1;i*i<=100100;i++){
        if(u==i*i){
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

ll dp[100005][3], a[100005], b[100005], c[100005], n;

ll rec(ll ind, ll type)
{
	if(dp[ind][type] != -1) return dp[ind][type];
	if(ind == n) return 0;
	if(type == 0)
		return dp[ind][type] = max(a[ind] + rec(ind + 1, 1), a[ind] + rec(ind + 1, 2));
	else if(type == 1)
		return dp[ind][type] = max(b[ind] + rec(ind + 1, 0), b[ind] + rec(ind + 1, 2));
	else
		return dp[ind][type] = max(c[ind] + rec(ind + 1, 1), c[ind] + rec(ind + 1, 0));	
}

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

	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
	memset(dp, -1, sizeof(dp));
	cout << max(max(rec(0, 0), rec(0, 1)), rec(0, 2)) << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
int main(void){
    int H,W,i,j,k;
    for(k=0; k<300; k++){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0)
        break;       
        for(j=0; j<H; j++){
            for(i=0; i<W; i++){
                if((i+j)%2==0){
                printf("#");
            }else{
                printf(".");}
            }printf("\n");
        }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
int nCr(int n, int k)
{
    int C[n + 1][k + 1];
    int i, j;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {
            //Base case
            if (j == 0 || j == i)
                C[i][j] = 1;
            else
            {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    }
    return C[n][k];
}

signed main()
{
    rootdada;
    string s;
    cin >> s;
    int l = s.length();
    int c = 0, d = 0;
    for (int i = 0; i < l; i++)
    {
        if (i % 2 == 0)
        {
            if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
                c++;
        }

        else
        {
            if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
                d++;
        }
        // cout<<c<<" "<<d<<endl;
    }
    // cout<<l<<" "<<c<<" "<<d;
    if(l==c+d)
        cout<<"Yes"<<endl;
        else
        {
            cout<<"No"<<endl;
        }
        
}

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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

string p, s;

int main(){
	cin.tie(0);
    
    cin>>s>>p;
    
    s += s;
    
    cout<<(s.find(p)!=string::npos?"Yes":"No")<<endl;
    
	return 0;
}



Measured memory_bytes: 3184
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args){

		//?????°??£?¨?
		ArrayList<String> Shin = new ArrayList<String>();

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()){
			String kari = sc.next();

			if(kari.equals("0")){
				String hyouzi = Shin.get(Shin.size()-1);
				System.out.println(hyouzi);
				Shin.remove(Shin.size()-1);		//??°????????\??£???????????±????¶????
			}else{
				Shin.add(kari);
			}
		}
	}
}

Measured memory_bytes: 26044
#include<stdio.h>
#include<math.h>
#define PA 3.1415926535
int main()
{
    double a, b, c,C;
    double S, L, h;
    double rad;
    scanf("%lf %lf %lf",&a,&b,&C);
    rad = C * 2 * PA / 360;
    S = a * b * sin(rad) / 2;
    h = 2 * S / a;
    c = sqrt(a*a + b*b - 2 * a*b*cos(rad));
    L = a + b + c;
    printf("%lf %lf %lf\n",S,L,h);
    return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 200005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

char ss[MAXN];
int n, k;
int s[MAXN * 3];

void solve() {
	read(n); read(k);
	scanf("%s", ss + 1);
	for (int i = 1; i <= n; ++i) {
		s[i] = ss[i] - 'A';
	}
	if (k > n * 2 + 1) {
		k = ((k & 1)? n * 2 + 1 : n * 2 + 2);
	}
	int L = 1, R = n, mov = 0;
	for (int i = 1; i <= k; ++i) {
		if ((s[L] ^ mov) == 0) {
			s[L] ^= 1;
		} else {
			s[++R] = s[L++];
			mov ^= 1;
		}
	}
	for (int i = L; i <= R; ++i) {
		putchar((s[i] ^ mov) + 'A');
	}
	puts("");
}

int main() {
	solve();
	return 0;
}



Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<cctype>
#include<string>
using namespace std;
int main() {
    int n;
    cin >>n;
    if(n==25)cout<<"Christmas";
    if(n==24)cout<<"Christmas Eve";
    if(n==23)cout<<"Christmas Eve Eve";
    if(n==22)cout<<"Christmas Eve Eve Eve";
}


Measured memory_bytes: 256
// C - AB Substrings

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int N;
	cin >> N;

	int cnt_ab = 0;
	int cnt_begin_b = 0;
	int cnt_end_a = 0;
	bool all_begin_b_end_a = true;

	for (int i=0; i<N; i++) {
		string s;
		cin >> s;

		for (int j=0; j<s.size()-1; j++) {
			if (s[j] == 'A' && s[j+1] == 'B') cnt_ab++;
		}

		if (s[0] == 'B') cnt_begin_b++;

		if (s[s.size()-1] == 'A') cnt_end_a++;

		if (s[0] == 'B' && s[s.size()-1] != 'A') all_begin_b_end_a = false;
		if (s[0] != 'B' && s[s.size()-1] == 'A') all_begin_b_end_a = false;
	}

	int ans = cnt_ab + min(cnt_begin_b, cnt_end_a);

	if (cnt_begin_b > 0 && all_begin_b_end_a) ans--;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
K = int(input())
ans1 = 0
ans2 = 0
ans3 = 0

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def gn(num):
    value = num[0]
    for item in num[1:]:
        value = gcd(value, item)
    return value


a = gn([3,15,18])

import itertools

seq = [x+1 for x in range(K)]
ptr = list(itertools.combinations(seq,3))

for i in range(len(ptr)):
    ans1 += gn(ptr[i])*6
    
seq2 = [x+1 for x in range(K)]
ptr2 = list(itertools.combinations(seq2,2))

for i in range(len(ptr2)):
    ans2 += gcd(ptr2[i][0],ptr2[i][1])*6
    
ans3 = K*(K+1)/2
print(int(ans1+ans2+ans3))

Measured memory_bytes: 103808
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    int x;
    cin >> x;
    if(x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n,a,b;cin >> n >> a >> b;
    string s;cin >> s;
    int ko=0,ka=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='a'){
            if(ko<a+b){
                cout << "Yes" << endl;
                ko++;
            }
            else cout << "No" << endl;
        }else if(s[i]=='b'){
            if(ko<a+b && ka<b){
                cout << "Yes" << endl;
                ko++;
                ka++;
            }
            else cout << "No" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long[] x = new long[n];
		long[] d = new long[n];
		for(int i=0; i<n; i++){
			x[i] = sc.nextLong();
			if(i==0){
				d[i] = 0;
			}else{
				d[i] = x[i] - x[i-1];
			}
		}
		sc.close();
		
		long ans = 0;
		for(int i=1; i<n; i++){
			if(d[i] * a > b){
				ans += b;
			}else{
				ans += a * d[i];
			}
		}
		
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 35652
s = input()
t = input()
temp = -1
cycle = 0
ans = True
for tt in t:
    if tt in s[temp+1:]:
        k = s[temp+1:].find(tt)
        temp += k + 1
    elif tt in s:
        temp = s.find(tt)
        cycle += 1
    else:
        ans = False
        break
if ans:    
    print((cycle*len(s)) + temp + 1)
else:
    print(-1)

Measured memory_bytes: 3316
import sys
a=[1]*500000
for i in range(3,999,2):
 if a[i//2]:a[i*i//2::i]=[0]*((499999-i*i//2)//i+1)
for e in map(int,sys.stdin):print([e-1,sum(a[:(e+1)//2])][e>3])


Measured memory_bytes: 14888
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let r: usize = iter.next().unwrap().parse().unwrap();
    let s: usize = iter.next().unwrap().parse().unwrap();
    let p: usize = iter.next().unwrap().parse().unwrap();

    let mut tt = String::new();
    std::io::stdin().read_line(&mut tt).unwrap();
    let t: Vec<char> = tt.chars().collect();

    let mut ans = 0usize;

    for i in 0..k {
        let mut rsp_cont_cnt = 0usize;
        for j in 0..(n/k+1) {
            let now = i + j * k;
            if now > n-1 {
                break;
            }

            let rsp = t[now];

            ans += if rsp_cont_cnt % 2 == 1 {
                0
            } else {
                match rsp {
                    'r' => p,
                    's' => r,
                    _ => s,
                }
            };

            let rsp_next = if now+k > n-1 { '!' } else { t[now+k] };
            if rsp == rsp_next {
                rsp_cont_cnt += 1;
            } else {
                rsp_cont_cnt = 0;
            }

        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n, i;
  cin >> n >> i;
  cout << (n + 1 - i) << endl;
}



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

int main() {
  int N; cin >> N;
  vector<double> v(N);
  rep(i, N) cin >> v[i];
  
  sort(v.begin(), v.end());
  
  rep(i, N-1) {
    v[i+1] = (v[i]+v[i+1])/2;
  }
  cout << v[N-1] << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        int[] t = new int[N];
        for (int i = 0; i < N; i++) {
            t[i] = Integer.parseInt(sc.next());
        }
        final int M = Integer.parseInt(sc.next());
        
        for (int i = 0; i < M; i++) {
            int p = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());
            int tmp = t[p-1];
            t[p-1] = x;
            long sum = 0;
            for (int j = 0; j < N; j++) {
                sum += t[j];
            }
            out.println(sum);
            t[p-1] = tmp;
        }
        
        out.flush();
    }
}

Measured memory_bytes: 22996
n = int(input())
v = []
for i in range(n):
    a = int(input())
    v.append(a)
v.sort()

cnt = 0
now = -1
ans = 0
for a in v:
    if a == now:
        cnt += 1
    else:
        ans += cnt % 2
        now = a
        cnt = 1

ans += cnt % 2
print(ans)


Measured memory_bytes: 7448
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	sc.Split(bufio.ScanWords)
	var n, k int

	fmt.Scanf("%d %d", &n, &k)
	t := make([]int, n)
	for i := 0; i < len(t); i++ {
		sc.Scan()
		j, _ := strconv.Atoi(sc.Text())
		t[i] = j
	}
	//sort.Sort(sort.IntSlice(t))
	sort.Stable(sort.IntSlice(t))
	index := sort.Search(len(t), func(i int) bool { return t[i] >= k })
	if index < n{
		fmt.Printf("%d\n",n-index)
	}else{
		fmt.Printf("0\n")
	}
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i=0;i<N;i++) a[i] =sc.nextInt();
   Arrays.sort(a);
   int ans = 0;
   for(int i=0;i<N-2;i++)
   {
     for(int k =i+1;k<N-1;k++)
     {
       for(int j =k+1;j<N;j++)
       {
         if(a[i]+a[k]>a[j]) ans++;
         else break;
       }
     }
   }
  System.out.println(ans);
 }
}

Measured memory_bytes: 26348
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
const int inf = (int)1e9 + 9;
const int MOD = (int)1e9 + 7;

int mult(int a, int b){
    return (a * 1ll * b) % MOD;
}

int powr(int n, int k){
    if(k == 0) return 1;
    int f = powr(n, k / 2);
    f = mult(f, f);
    if(k & 1) f = mult(f, n);
    return f;
}

int inv(int a){
    return powr(a, MOD - 2);
}

int f[N];

int ch(int a, int b){
    return mult(f[a],mult(inv(f[b]), inv(f[a-b])));
}

int pi[N];
int sz[N];

int fin(int a){
    if(pi[a] == a)
        return a;
    return pi[a]=fin(pi[a]);
}

void unite(int a, int b){
    a=fin(a);
    b=fin(b);
    if(a == b)
        return;
    if(sz[a] > sz[b]){
        swap(a, b);
    }
    sz[b] += sz[a];
    pi[a] = b;
}

vector<int> ord[N];
int col[N];
int wei[N];

vector<int> C[N];

int main(){
    fastIO;
    
    int n, x, y;
    cin >> n >> x >> y;
    f[0] = 1;
    for(int i = 1; i <= n; i ++ ){
        cin >> col[i] >> wei[i];
        ord[col[i]].push_back(i);
        pi[i] = i;
        sz[i] = 1;
        f[i] = mult(f[i-1],i);
    }
    int ids;
    vector<pii> zz;
    for(int i = 1; i <= n; i ++ ){
        if(ord[i].empty()) continue;
        ids = ord[i][0];
        for(auto p : ord[i]){
            if(wei[p] < wei[ids]){
                ids = p;
            }
        }
        for(auto p : ord[i]){
            if(p != ids && wei[p] + wei[ids] <= x) unite(p, ids);
        }
        zz.push_back(mp(wei[ids], ids));
    }
    sort(zz.begin(), zz.end());
    for(int i = 1; i <= n; i ++ ){
        for(int j = 0 ; j < min(2, (int)zz.size()); j ++ ){ 
            if(col[zz[j].se] != col[i]){
                if(wei[i] + wei[zz[j].se] <= y){
                    unite(i, zz[j].se);
                }
            }
        }
    }
    for(int i = 1; i <= n; i ++ ){
        C[fin(i)].push_back(col[i]);
    }
    int cnt;
    int sz;
    int res = 1;
    for(int i = 1; i <= n; i ++ ){
        if(C[i].empty()) continue;
        sort(C[i].begin(), C[i].end());
        cnt = (int)C[i].size();
        sz = 0;
        for(int j = 0 ; j < C[i].size(); j ++ ){
            sz ++ ;
            if(j + 1 == C[i].size() || C[i][j] != C[i][j + 1]){
                res = mult(res, ch(cnt, sz));
                cnt -= sz;
                sz = 0;
            }
        }
    }
    cout << res << "\n";
    return 0;
}


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

using ll = long long;
#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 INF 1e9
// constexpr ll INF = 1LL << 60;

int main(){
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<vector<int>> sum(N+1, vector<int>(N+1,0)), LR(N, vector<int>(N));
  REP(i, M){
    int L, R;
    cin >> L >> R;
    L--, R--;
    LR[L][R]++;
  }
  REP(i, N){
    REP(j, N){
      sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + LR[i][j];
    }
  }
  REP(i, Q){
    int p, q;
    cin >> p >> q;
    p--, q--;
    cout << sum[q+1][q+1] - sum[q+1][p] - sum[p][q+1] + sum[p][p] << endl;
  }
  return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = a - (2 * b);
  if(ans < 0){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include <math.h>
using namespace std;

int main() {
	int h, a;
	int count = 0;
	cin >> h >> a;

	while (h > 0) {
		count++;
		h = h - a;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n;
    cin>>n;
    ll a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    ll cur=min({a,b,c,d,e});
    cout<<(n+cur-1)/cur+4<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
#include<random>
using namespace std ;

#define MOD 1000000007
#define MAXN 3007

int n , k ;
string a ;
int mx[ MAXN ] ;
long long dp[ MAXN ][ MAXN ] ;

void input ( ) {
    cin >> n >> k ;
    cin >> a ;
    for ( int i = 0 ; i <= n ; ++ i ) {
        mx[ i ] = i ;
    }
    for ( int i = 1 ; i <= k ; ++ i ) {
        int x , y ;
        cin >> x >> y ;
        mx[ x ] = max ( mx[ x ] , y ) ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        mx[ i ] = max ( mx[ i ] , mx[ i - 1 ] ) ;
    }
}

void solve ( ) {
    dp[ 0 ][ 0 ] = 1 ;
    int cnt = 0 ;
    int pos = 0 ; 
    for ( int i = 0 ; i < n ; ++ i ) {
        while ( pos < mx[ i + 1 ] ) {
            if ( a[ pos ] == '1' ) { ++ cnt ; }
            ++ pos ;
        }
        for ( int j = 0 ; j <= cnt ; ++ j ) {
            if ( dp[ i ][ j ] == 0 ) { continue ; }
            if ( j < cnt ) {
                dp[ i + 1 ][ j + 1 ] += dp[ i ][ j ] ;
                if ( dp[ i + 1 ][ j + 1 ] >= MOD ) {
                    dp[ i + 1 ][ j + 1 ] -= MOD ;
                }
            }
            int used = i - j ;
            int lft = pos - cnt ;
            if ( used < lft ) {
                dp[ i + 1 ][ j ] += dp[ i ][ j ] ;
                if ( dp[ i + 1 ][ j ] >= MOD ) {
                    dp[ i + 1 ][ j ] -= MOD ;
                }
            }
        }
    }
    cout << dp[ n ][ cnt ] << "\n" ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 68352
<?php
/*
    Problem URL : http://abc051.contest.atcoder.jp/tasks/abc051_c

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %d %d %d", $sx, $sy, $tx, $ty);

$diff_x = $tx - $sx;
$diff_y = $ty - $sy;

$ans = "";

for ($i = 0; $i < $diff_x; $i++) {
    $ans .= "R";
}
for ($i = 0; $i < $diff_y; $i++) {
    $ans .= "U";
}
$way1 = $ans;

$way2 = $way1;
$way2 = str_replace("U", "u", $way2);
$way2 = str_replace("D", "d", $way2);
$way2 = str_replace("L", "l", $way2);
$way2 = str_replace("R", "r", $way2);

$way2 = str_replace("u", "D", $way2);
$way2 = str_replace("d", "U", $way2);
$way2 = str_replace("l", "R", $way2);
$way2 = str_replace("r", "L", $way2);

$ans .= $way2;

$diff_x++;
$diff_y++;

$way3 = "";

for ($i = 0; $i < $diff_x; $i++) {
    $way3 .= "R";
}
for ($i = 0; $i < $diff_y; $i++) {
    $way3 .= "U";
}

$way4 = $way3;

$way3 = "D" . $way3 . "L";

// echo $ans . PHP_EOL;
// echo $way3 . PHP_EOL;

$way4 = str_replace("U", "u", $way4);
$way4 = str_replace("D", "d", $way4);
$way4 = str_replace("L", "l", $way4);
$way4 = str_replace("R", "r", $way4);

$way4 = str_replace("u", "D", $way4);
$way4 = str_replace("d", "U", $way4);
$way4 = str_replace("l", "R", $way4);
$way4 = str_replace("r", "L", $way4);

$way4 = "U" . $way4 . "R";
// echo $way4 . PHP_EOL;

echo $ans . $way3 . $way4 . PHP_EOL;


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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

bool cmp(int x, int y){
    return x > y;
}

long long n, m, a[111], sum;
int main(){
    n = read(), m = read();
    for (int i = 1; i <= n; i++){
        a[i] = read();
        sum += a[i];
    }
    sort (a+1, a+n+1, cmp);
    double k = sum / 4.0 / m;
    for (int i = 1; i <= m; i++){
        if (a[i] < k){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    int n, m;
    
    while(cin >> n >> m, n+m != 0){
        int c[m];
        rep(i, m)cin >> c[i];

        int x[n];
        rep(i, n)cin >> x[i];

        //dp[i][j] : 列iのyがjであるときの二乗和の最小数
        ll dp[n+1][256];
        rep(i, n+1)rep(j, 256)dp[i][j] = INF;

        dp[0][128] = 0;
        rep(i, n)rep(j, 256)rep(k, m){
            if(dp[i][j] >= INF)continue;

            int next = max(0, (int)j + c[k]); 
            next = min(next, 255);

            ll dif = pow(x[i] - next, 2);

            dp[i+1][next] = min(dp[i+1][next], dp[i][j] + dif);
        }

        ll ans = INF;
        rep(i, 256)ans = min(ans, dp[n][i]);

        cout << ans << endl;
    }

}


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

using namespace std;

#define pb push_back

const int N = 100010;

int n, m;
int a[N], b[N];

vector<int> va, vb;

map<int, int> hmp;

int f[N], size[N];

int Gf(int k) {
    return (f[k] != k) ? (f[k] = Gf(f[k])) : k;
}

void Union(int x, int y) {
    x = Gf(x);
    y = Gf(y);
    if (x == y) return;
    if (size[x] < size[y]) swap(x, y);
    f[y] = x;
    size[x] += size[y];
    return;
}

int main() {
    scanf("%d", &n);
    if (!n) {
        puts("0");
        return 0;
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        a[0] ^= a[i];
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &b[i]);
        b[0] ^= b[i];
    }
    m = 0;
    for (int i = 0; i <= n; ++i) {
        if (!hmp[a[i]]) hmp[a[i]] = ++m;
        va.pb(a[i]);
        a[i] = hmp[a[i]];
    }
    for (int i = 0; i <= n; ++i) {
        if (!hmp[b[i]]) hmp[b[i]] = ++m;
        vb.pb(b[i]);
        b[i] = hmp[b[i]];
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    for (int i = 0; i <= n; ++i)
        if (va[i] != vb[i]) {
            puts("-1");
            return 0;
        }
    int res = 0;
    for (int i = 1; i <= m; ++i) {
        f[i] = i;
        size[i] = 1;
    }
    for (int i = 1; i <= n; ++i)
        if (a[i] != b[i]) {
            Union(a[i], b[i]);
            ++res;
        }
    if (!res) {
        puts("0");
        return 0;
    }
    for (int i = 1; i <= m; ++i)
        if (f[i] == i && size[i] > 1) ++res;
    if (size[f[1]] > 1) --res;
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 7416
#include <cstdio>
#include <cstring>
#include <cstdlib>

typedef struct tree_{
    int value;
    struct tree_ *left;
    struct tree_ *right;
}tree;

void preorder(tree *p){
    if(p==NULL)return;
    printf(" %d",p->value);
    preorder(p->left);
    preorder(p->right);
}

void inorder(tree *p){
    if(p==NULL)return;
    inorder(p->left);
    printf(" %d",p->value);
    inorder(p->right);
}

tree *insert(tree *p, int x){
    if(p==NULL){
        p = (tree *)malloc(sizeof(tree));
        p->value = x;
        p->left = NULL;
        p->right = NULL;
    }else{
        if(p->value>x)p->left = insert(p->left, x);
        else if(p->value<x)p->right = insert(p->right, x);
    }
    return p;
}

bool find(tree *p, int x){
    bool ans;
    if(p==NULL)ans = false;
    else if(p->value>x)ans = find(p->left, x);
    else if(p->value<x)ans = find(p->right, x);
    else ans = true;
    return ans;
}

tree *del(tree *p, int x){
    if(p==NULL);
    else if(p->value>x)p->left=del(p->left, x);
    else if(p->value<x)p->right=del(p->right, x);
    else{
        if(p->left==NULL)p=p->right;
        else if(p->right==NULL)p=p->left;
        else{
            tree *tmp = p->right;
            if(tmp->left==NULL){
                p->value=tmp->value;
                p->right=tmp->right;
            }else{
                while(tmp->left->left!=NULL){
                    tmp=tmp->left;
                }
                p->value=tmp->left->value;
                tmp->left=tmp->left->right;
            }
        }
    }
    return p;
}

int main(){
    int i, n, x;
    char cmd[7];
    tree *root = NULL;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",cmd);
        if(strcmp(cmd,"insert")==0){
            scanf("%d",&x);
            root = insert(root, x);
        }else if(strcmp(cmd,"print")==0){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else if(strcmp(cmd,"find")==0){
            scanf("%d",&x);
            if(find(root, x))printf("yes\n");
            else printf("no\n");
        }else if(strcmp(cmd,"delete")==0){
            scanf("%d",&x);
            root = del(root, x);
        }else return -1;
    }
    return 0;
}



Measured memory_bytes: 15104
// Author : Hardik Upadhyay
// college: SVNIT 
// slogan : Ab to phod dunga
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// hi + hj == i - j // i>=j
	// hj + j == i - hi // i >= j
	ll ans = 0;
	int n;
	cin>>n;
	vi a(n);
	rep(i,0,n-1)cin>>a[i];
	map<int,int> cnt;
	rep(i,0,n-1){
		ans+=cnt[i-a[i]];
		cnt[i+a[i]]++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 21084
/*****TEMPLATE*****/
      

#include <algorithm>
#include <array>
#include <bitset>
#include <cctype> 
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cstring>
#include <cstdio>
#include <stdio.h>
//INCLUDES
using namespace std;

#define lld long long int
#define ulld unsigned long long int
#define mod 1000000007
#define pb push_back
#define umap unordered_map
#define mp make_pair
#define fi first
#define se second 
#define rep(n) for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//DEFINES

lld gcd(lld a,lld b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){lld r=a%b; a=b; b=r;} return a;}
lld bs(lld arr[], lld l, lld r, lld x) { if (r >= l) {  lld mid = l + (r - l) / 2;  if (arr[mid] == x)  return mid; if (arr[mid] > x)  return bs(arr, l, mid - 1, x);  return bs(arr, mid + 1, r, x);  }  return -1; }
lld mypower(lld x, lld n){	if (n == 0)	return 1;	if (n & 1) 	return (((x * mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod)%mod);return (((mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod))%mod;}
lld modinv(lld a) { lld g = gcd(a, mod); if (g != 1) return -1;else{  return mypower(a, mod-2)%mod; } } 

//FUNCTIONS
void solve()
{
    string s,t;
    cin>>s>>t;
    lld n=s.length();
    lld m=t.length();
    lld dp[n+1][m+1]={};
    for (int i = 1; i <=n; i++) {
        for(int j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    vector <char> ans;
    lld i=n;
    lld j=m;
        while (1) {
            if(i==0 || j==0)
            break;
            if(s[i-1]==t[j-1])
            {
                ans.pb(s[i-1]);
                i--;
                j--;
            }
            else
            {
                if(dp[i][j]==dp[i-1][j])
                i--;
                else
                j--;
            }
            
        }
    for (int i = ans.size()-1; i >=0; i--) {
        cout<<ans[i];
    }
    cout<<"\n";
    return;
}
int main()
{
    fast
    // lld t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}



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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;


int main() {
    int H, W, A, B; cin >> H >> W >> A >> B;
    vector<vector<char>> s(H, vector<char>(W));

    rep(i, H) {
        rep(j, W) {
            if ((i < B && j < A) || (i >= B && j >= A)) s[i][j] = '1';
            else s[i][j] = '0';
            cout << s[i][j];
        }
        cout << endl;
    }

}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  set<int> s;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  vector<int> b(N);
  rep(i, 0, N) {
    cin >> b[i];
    s.insert(b[i]);
  }

  if (s.size() == N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
    int x = [&]() {
      for (auto x : a) {
        if (not s.count(x))
          return x;
      }
    }();
    s.clear();
    for (auto x : a)
      s.insert(x);
    auto d = s.begin();
    rep(i, 0, N) cout << *d << (i == N - 1 ? '\n' : ' ');
    rep(i, 0, N) {
      if (a[i] == x)
        cout << *next(d) << (i == N - 1 ? '\n' : ' ');
      else
        cout << *d << (i == N - 1 ? '\n' : ' ');
    }
  }

  return 0;
}



Measured memory_bytes: 8484
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			int ans = 0;
			for (char c : s) {
				if (c == '1') {
					ans++;
				}
			}
			System.out.println(ans);
		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

int main(){
  string s;
  cin >> s;
  int val=700;
  int topping = 0;
  if(s[0] == 'o') ++topping;
  if(s[1] == 'o') ++topping;
  if(s[2] == 'o') ++topping;
  cout << val+topping*100 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
//prototype
int main(void);

int main(void){

  int row, col;
  int i, j, n;
  int row_sum = 0;
  int col_sum = 0;
  int total = 0;


  scanf("%d %d", &row, &col);
  int str[row][col];

  //Initialize str
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      str[i][j] = 0;
    }
  }


  i = 0;
  j = 0;

  //Assign to str
  while (1) {

    scanf("%d", &n);

    str[i][j] = n;

    j++;

    if (j >= col) {
      i++;
      j = 0;
    }

    //exit condition
    if(i >= row){
      break;
    }
  }


  //Output table
  for (i = 0; i < row; i++) {
    for (j = 0; j < col; j++) {
      printf("%d ", str[i][j]);
      row_sum += str[i][j];
    }
    printf("%d\n", row_sum);
    row_sum = 0;
  }

  for (j = 0; j < col; j++) {
    for (i = 0; i < row; i++) {
      col_sum += str[i][j];
    }
    printf("%d ", col_sum);
    total += col_sum;
    col_sum = 0;
  }

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

  return 0;
}



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

using namespace std;
typedef long long ll;

int main() {
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3852
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string In = Console.ReadLine();
            char c = In[0];
            if ('A'<=c && c <='Z') Console.WriteLine("A");
            else if ('a' <= c && c <= 'z') Console.WriteLine("a");
        }
    }
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const int A_max=25;

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	vector<vector<int>> B(A_max);
	rep(i,N){
		rep(j,A_max) if(A[i]&1<<j) B[j].emplace_back(i);
	}
	vector<int> res(N+1,N);
	for(int i=N-1; i>=0; i--){
		int right=res[i+1];
		rep(j,A_max){
			if(!(A[i]&1<<j)) continue;
			auto itr=upper_bound(B[j].begin(),B[j].end(),i);
			if(itr!=B[j].end()) right=min(right,*itr);
		}
		res[i]=right;
	}
	LL ans=0;
	rep(i,N) ans+=res[i]-i;
	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back
#define K 31

LL ret1 = -1, ret2 = 0;

int n, m, x;
int mon[K];

int a[K][K];

LL b[K];

void att(int u, LL price) {
	if (u == n + 1) {
		FOE(i, 1, m) if (b[i] < x) return;
		
		if (ret1 == -1) {
			ret1 = 1;
			ret2 = price;	
		} else ret2 = min(ret2, price);
		
		return;
	}
	
	att(u + 1, price);
	
	FOE(i, 1, m) {
		b[i] += a[u][i];
	}
	
	att(u + 1, price + mon[u]);
	
	FOE(i, 1, m) b[i] -= a[u][i];
}

int main() {
	scanf("%d%d%d", &n, &m, &x);
	
	FOE(i, 1, n) {
		scanf("%d", &mon[i]);
		FOE(j, 1, m) scanf("%d", &a[i][j]);
	}
	
	att(1, 0);
	
	if (ret1 == -1) puts("-1");
	else cout << ret2 << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,M,N,W;
  cin >> N;
  vector<long long> vec(N),R(N,0);
  for (int i=0;i<N;i++) {
   cin >> vec.at(i);
   R.at(vec.at(i)-1)++;
  }  
  W=0;
  C=0;
  for (int j=0;j<N;j++) {
    C=R.at(j);
    W=W+(C*(C-1))/2;
  }
  //cout << W << endl;
  for (int k=0;k<N;k++) {
    
   cout << W-R.at(vec.at(k)-1)+1 << endl;
  }
  
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll solve(ll n) {
    ll dp[3] = {};
    dp[0] = 1;
    for (int i = 59; i >= 0; i--) {
        ll ndp[3] = {};
        if (n & (1LL << i)) {
            (ndp[0] += dp[0]) %= MOD;
            (ndp[1] += dp[0]) %= MOD;

            (ndp[2] += 2 * dp[1]) %= MOD;
            (ndp[1] += dp[1]) %= MOD;

            (ndp[2] += 3 * dp[2]) %= MOD;
        } else {
            (ndp[0] += dp[0]) %= MOD;

            (ndp[2] += dp[1]) %= MOD;
            (ndp[0] += dp[1]) %= MOD;
            (ndp[1] += dp[1]) %= MOD;

            (ndp[2] += 3 * dp[2]) %= MOD;
        }

        for (int j = 0; j < 3; j++) {
            dp[j] = ndp[j];
        }
    }

    ll res = 0;
    for (int i = 0; i < 3; i++) {
        (res += dp[i]) %= MOD;
    }
    return res;
}

using P = pair<ll, ll>;

ll solveTLE(ll n) {
    set<P> s;
    for (ll a = 0; a <= n; a++) {
        for (ll b = a; b <= n; b++) {
            ll u = (a ^ b);
            ll v = a + b;
            if (u < 0 || u > n || v < 0 || v > n) continue;
            s.emplace(u, v);
        }
    }
    return s.size();
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    cout << solve(n) << endl;

    /* 
    for (ll n = 1; n <= 1000; n++) {
        ll ans = solve(n);
        ll ans_tle = solveTLE(n);
        if (ans != ans_tle) {
            cerr << n << ": " << ans << ", " << ans_tle << endl;
            break;
        } else {
            //cerr << n << ": " << ans << endl;
        }
    }*/
    return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        for (int i = 1; i <= b; i++) cout << a;
        cout << endl;
    } else {
        for (int i = 1; i <= a; i++) cout << b;
        cout << endl;
    }
}

int main() {
	header();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
bool sankaku(int ,int,int);
int main(){
    int n;
    vector<int> l;
    cin >> n;
    for(int i = 0;i < n;i++){
        int buf;
        cin >> buf;
        l.push_back(buf);
    }
    int counter = 0;
    for(int i = 0;i < n-2;i++){
        for(int j = i+1;j < n-1;j++){
            for(int k = j+1;k < n;k++){
                if(l[i] != l[j] && l[j] != l[k] && l[i] != l[k]){
                    if(sankaku(l[i],l[j],l[k])){
                        counter ++;
                    }
                }
            }
        }
    }
    cout << counter;
    return 0;
}

bool sankaku(int a,int b,int c){
    if(a + b > c && b + c > a && a + c > b){
        return 1;
    }
    return 0;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ll x,y,a,b,c,sum=0,sum1=0,sum2=0;
    cin>>x>>y>>a>>b>>c;
  priority_queue<pair<ll,char> >p;
  ll ra[a],ga[b],ca[c];
  for(ll i=0;i<a;i++)
  { cin>>ra[i];p.push(make_pair(ra[i],'r'));}
   for(ll i=0;i<b;i++)
     cin>>ga[i];
   for(ll i=0;i<c;i++)
   {cin>>ca[i];p.push(make_pair(ca[i],'c'));}
  ll i=0,j=0;
  while(i<x)
  {
    if(p.top().second=='r')j++;
    sum+=p.top().first;
    p.pop();
    i++;
  }
  for(int i=0;i<b;i++)
    p.push(make_pair(ga[i],'g'));
  i=0;
  while(i<y)
  {
     if(p.top().second=='r'&&j>=x)
     {p.pop();continue;}
     if(p.top().second=='r'&&j<x)
       j++;
     sum+=p.top().first;
     p.pop();
    i++;
  }
  cout<<sum<<endl; 
}
  
  


Measured memory_bytes: 12908
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<math.h>

using namespace std;

int main()
{
    int N,D;
    cin >> N >> D;

    double X[N][D];
    double var = 0,distance = 0;
    int good_distance = 0;

    for(int i=0;i<N;i++)
    {
        for(int j=0;j<D;j++) cin >> X[i][j];
    }
    
    for(int i=0;i<N-1;i++)
    {
        for(int j=i+1;j<N;j++)
        {
            var = 0;
            for(int a=0;a<D;a++) var += (X[j][a] - X[i][a])*(X[j][a] - X[i][a]);
            distance = sqrt(var);

            if(ceil(distance) == floor(distance)) good_distance += 1;
        }
    }
    
    cout << good_distance << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x<0||y<0){
    printf("No\n");
  } else if(x-r<0||x+r>W||y-r<0||y+r>H){
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 2596