akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n, sum = 0, a, ans1 = 0, ans2 = 0, sum1 =0 ,sum2=0;
	cin >> n;
	

	for (int i = 0; i < n; ++i) {
		cin >> a;
		sum1 += a;
		sum2 += a;
		if (i % 2 == 0) {
			if (sum1 <= 0) {
				ans1 += 1 - sum1;
				sum1 = 1;
			}
			if (sum2 >= 0) {
				ans2 += 1 + sum2;
				sum2 = -1;
			}
		}
		else {
			if (sum1 >= 0) {
				ans1 += 1 + sum1;
				sum1 = -1;
			}
			if (sum2 <= 0) {
				ans2 += 1 - sum2;
				sum2 = 1;
			}
		}
	}
	cout << min(ans1,ans2) << endl;
	return 0;
}


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

using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> p(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	vector<int> a;
	for (int i = 1; i <= n; i++) {
		if (p[i] == i) {
			int temp = 0;
			for (; i <= n; i++) {
				if (p[i] == i) {
					temp++;
				}
				else {
					break;
				}
			}
			a.push_back(temp);
		}
	}
	int ans = 0;
	for (int x : a) {
		ans += (x + 1) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <bitset>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
int main(){
    int n; cin >> n;
    if(n%2==0){
        cout << 0.5000 << endl;
        return 0;
    }
    else cout << fixed << setprecision(10) << (double)(n+1)/(2*n);
    return 0;
}



Measured memory_bytes: 256
package main

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

// EDPC(B) - Frog2
// https://atcoder.jp/contests/dp/tasks/dp_b

const inf = int(1e9)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	h := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		h[i] = nextInt(sc)
	}
	dp := make([]int, N+10)
	for i := 0; i < len(dp); i++ {
		dp[i] = inf
	}
	dp[0] = 0 // 初期条件(0-indexed)
	for i := 1; i < N; i++ {
		// chmin(&dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		// chmin(&dp[i], dp[i-2]+abs(h[i]-h[i-2]))
		// ...
		// chmin(&dp[i], dp[i-K]+abs(h[i]-h[i-K]))
		for j := 1; j <= K && i-j >= 0; j++ {
			chmin(&dp[i], dp[i-j]+abs(h[i]-h[i-j]))
		}
	}
	fmt.Println(dp[N-1])
}


Measured memory_bytes: 2816
from collections import deque, defaultdict

N = int(input())
A = [deque(map(lambda a: int(a) - 1, input().split())) for _ in range(N)]

D = [0] * N
canBattle = defaultdict(lambda: False)
que = deque(range(N))

while que:
    i = que.popleft()
    j = A[i][0]
    canBattle[(i, j)] = True

    if canBattle[(j, i)]:
        A[i].popleft()
        A[j].popleft()
        day = max(D[i], D[j])
        D[i] = D[j] = day + 1

        if A[i]:
            que.append(i)
        if A[j]:
            que.append(j)

if all(len(a) == 0 for a in A):
    print(max(D))
else:
    print(-1)




Measured memory_bytes: 154204
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
 
LL n, x;
LL sum[55];
LL sump[55];
 
LL calc(int level,LL num){
    if(level == 0)return 1LL;
    if(num == 1LL)return 0LL;
    else if(num <= 1LL + sum[level - 1])return calc(level - 1, num - 1LL);
    else if(num == 2LL + sum[level - 1])return sump[level - 1] + 1LL;
    else if(num <= 2LL + 2LL*sum[level - 1])return sump[level - 1] + 1LL + calc(level - 1, num - 2LL - sum[level - 1]);
    else return sump[level];
}
 
int main(){
    INIT;
    cin >> n >> x;
    sum[0] = 1LL, sump[0] = 1LL;
    for(int i = 1;i <= 50;i++)sum[i] = 3LL + sum[i - 1]*2LL;
    for(int i = 1;i <= 50;i++)sump[i] = 1LL + sump[i - 1]*2LL;
    cout << calc(n, x) << endl;
}

Measured memory_bytes: 256
class Tree:
    def __init__(self):
        self.parent = None
        self.left = None
        self.right = None
        self.key = -1


def preparse(u):
    if u is None: return
    print(" ", end="")
    print(u.key, end="")
    preparse(u.left)
    preparse(u.right)


def inparse(u):
    if u is None: return
    #???????????????????§????
    inparse(u.left)
    #??¨???
    print(" ", end="")
    print(u.key, end="")
    #??????????§????
    inparse(u.right)
    

def insert(key):
    global root
    y = None
    sch = root
    # ?????\????±?Node?????????
    z = Tree()
    z.key = key

    while sch is not None:
        # ???????????????tree????????????????????§?????°??????Key??????????´?(y)?????¢??????
        y = sch
        # key?????¢??????tree????´????key??????????°????????????°??????????´¢?????§???????????°??????????´¢
        sch = sch.left if key < sch.key else sch.right

    # ???????´??±????
    z.parent = y

    if y is None:
        root = z
    else:
        if key < y.key:
            # ???????´??????????????°????????????°????????´???????´??????????
            y.left = z
        else:
            # ???????´???????????????§???????????°????????´???????´??????????
            y.right = z

    # ???????????????
    trees.append(z)


def showresult():
    inparse(root)
    print("")
    preparse(root)
    print("")


N = int(input())
# ?????????
trees = []
root = None

for i in range(N):
    l = list(input().split())
    com = l[0]
    if com == "insert":
        key = int(l[1])
        # ????´???????????¨????
        insert(key)
    elif com == "print":
        showresult()

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int h, w;
vector<string> fie(50);

const int di[] = {-1,0,0,1};
const int dj[] = {0,-1,1,0};
bool check(int sy, int sx, int k){
	if(sy + di[k] < 0 || sx + dj[k] < 0) return false;
	if(sy + di[k] >= h || sx + dj[k] >= w) return false;
	int ny = sy + di[k];
	int nx = sx + dj[k];
	if(fie[ny][nx] == '#') return true;
	else return false;
}
int main()
{
	cin >> h >> w;
	rep(i, h)cin>>fie[i];

	// 全てのマスに対して、上下左右の4マスに黒があるかみる。
	rep(i,h){
		rep(j,w){
			bool ng = true;
			if(fie[i][j] == '.'){
				continue;
			} else {
				rep(k,4){
					if(check(i,j,k)){
						// ok; 4回のうちどれかしらが通ればいい。
						ng = false;
					}	
				}
				if(ng) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//                    #include <ext/pb_ds/assoc_container.hpp>
//                    #include <ext/pb_ds/tree_policy.hpp>

                    using ll = long long;
                    using ld = long double;
                    #define rep(i, a, n) for(ll i = (a); i < (n); i++)
                    #define per(i, a, n) for(ll i = (n-1); i >= (a); i--)
                    #define F first
                    #define S second
                    #define maxx(a, b) a = max(a, b)
                    #define minn(a, b) a = min(a, b)
                    #define db(x) cerr << #x << " = " << x << endl
                    #define N 1111111
                    #define mod 1000000007
                    #define rt return
                    #define inf 1234567891123456789ll

                    using namespace std;
                    random_device rd;
                    mt19937 mt(rd());
//                    using namespace __gnu_pbds;
//
//                    typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

                    #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

                    void err(istream_iterator<string> it) {}
                    template<typename T, typename... Args>
                    void err(istream_iterator<string> it, T a, Args... args)
                    {
                        cerr << *it << " = " << a << endl;
                        err(++it, args...);
                    }

                    ll modlaber(ll a, ll m = mod)
                    {
                        rt ((a+m)%m+m)%m;
                    }

                    int main()
                    {
                        ios_base::sync_with_stdio(0);
                        cin.tie(0);
                        cout.tie(0);

                        int n; cin>>n;
                        if(n%10 == 2 ||
                           n%10 == 4 ||
                           n%10 == 5 ||
                           n%10 == 7 ||
                           n%10 == 9)
                            cout<<"hon";
                        else
                        if(n%10 == 3)
                            cout<<"bon";
                        else
                            cout<<"pon";

                        rt 0;
                    }























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

public class Main {
	public static void main(String[] args) {
		Scanner src = new Scanner(System.in);

		//配列array
		ArrayList<Integer> array = new ArrayList<Integer>();

		int n  = src.nextInt();

		//nに入力された数だけ繰り返し、配列に要素を代入
		for(int i=0; i<n; i++) {
			array.add(src.nextInt());
		}

		int q = src.nextInt();

		for(int i=0; i<q; i++) {

			int com = src.nextInt();
			int b = src.nextInt();
			int e = src.nextInt();

			int min, max = 0;
			max	=	array.get(b);		
			min = max;

			if(com == 0) {
				for(int j = b+1; j < e; j++)
		            min = Math.min(min,array.get(j));
				System.out.println(min);

			}else if(com == 1) {
				for(int j = b+1; j < e; j++)
		            max = Math.max(max,array.get(j));
				System.out.println(max);
			}
		}
	}
}


Measured memory_bytes: 34180
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename Iter, typename T> int gt(Iter L, Iter R, T v) { return upper_bound(L, R, v) - L; }
template <typename Iter, typename T> int ge(Iter L, Iter R, T v) { return lower_bound(L, R, v) - L; }
template <typename Iter, typename T> int lt(Iter L, Iter R, T v) { return lower_bound(L, R, v) - L - 1; }
template <typename Iter, typename T> int le(Iter L, Iter R, T v) { return upper_bound(L, R, v) - L - 1; }
template <typename Bst, typename T> typename Bst::const_iterator gt(const Bst& bst, T v) { return bst.upper_bound(v); }
template <typename Bst, typename T> typename Bst::const_iterator ge(const Bst& bst, T v) { return bst.lower_bound(v); }
template <typename Bst, typename T> typename Bst::const_iterator lt(const Bst& bst, T v) { return bst.lower_bound(v) == bst.begin() ? bst.end() : --bst.lower_bound(v); }
template <typename Bst, typename T> typename Bst::const_iterator le(const Bst& bst, T v) { return bst.upper_bound(v) == bst.begin() ? bst.end() : --bst.upper_bound(v); }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    while(q--) {
        ll x;
        cin >> x;
        ll ans = lim<ll>::max();
        for(int dir = 0; dir < 4; dir++) {
            bool dir_s = dir & 1, dir_t = dir & 2;
            auto ptr_s = dir_s ? ge(s.begin(), s.end(), x) : le(s.begin(), s.end(), x);
            auto ptr_t = dir_t ? ge(t.begin(), t.end(), x) : le(t.begin(), t.end(), x);
            if(0 <= ptr_s and ptr_s < a and 0 <= ptr_t and ptr_t < b) {
                ll ds = abs(s[ptr_s] - x), dt = abs(t[ptr_t] - x);
                ans = min(ans, dir_s == dir_t ? max(ds, dt) : ds + dt + min(ds, dt));
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int a = input[0];
		int b = input[1];

		long ans = 0;
		if (a == b) { ans = 0; }
        else if ((a+b)%2!=0)
		{
			Console.WriteLine("IMPOSSIBLE");
			return;
		}
		else { ans = (a + b) / 2; }
	
       
		Console.WriteLine(ans);
	}
}

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

#define pb push_back
#define MAX 100005
#define ff first
#define ss second
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;


int n,d,x,a[105];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>d>>x;
    for(int i=0; i<n;++i)
        cin>>a[i];
    int ans=0;
    for(int i =0;i<d; ++i){
        for(int j =0; j<n;++j)
            if(i%a[j]==0)
                ans++;
    }
    cout<<ans+x<<"\n";
    return 0;
}

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

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}
/*
think fast
think simple
*/

void mysol()
{
    string s; cin >> s;
    int ans = 0;
    for (char ch : s)
    {
        ans += ch - '0';
    }
    if (ans % 9)
        cout << "No\n";
    else
        cout << "Yes\n";
}

int32_t main()
{
    fast();
    // w(t)
    {
        mysol();
    }
    //cerr << sizeof(dp)*(1e-6) << " megabytes\n";
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

ll f(ll x) {
    if (x % 2 == 0) {
        if (x % 4 == 0) {
            return 0 ^ x;
        } else {
            return 1 ^ x;
        }
    } else {
        if ((x+1) % 4 == 0) {
            return 0;
        } else {
            return 1;
        }
    }
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll a, b;
    cin >> a >> b;

    if (a == 0) {
        cout << f(b) << endl;
    } else {
        cout << (f(a-1) ^ f(b)) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

using namespace std;

signed main() {
    int N, L;
    cin >> N >> L;

    vector<string> strs;
    rep(i, N) {
	strs.push_back(nextString());
    }
    sort(all(strs));

    rep(i, N) {
	cout << strs[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        要素xが属するグループの根を返す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        要素xが属するグループと要素yが属するグループとを併合する
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        要素xが属するグループのサイズ（要素数）を返す
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        要素x, yが同じグループに属するかどうかを返す
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        要素xが属するグループに属する要素をリストで返す
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        すべての根の要素をリストで返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        グループの数を返す
        """
        return len(self.roots())

    def all_group_members(self):
        """
        {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        """
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
    N, M = map(int, input().split())
    A_B = [list(map(int, input().split())) for i in range(M)]

    uf = UnionFind(N)
    for i in range(M):
        x = A_B[i][0] - 1
        y = A_B[i][1] - 1
        uf.union(x, y)

    ans = 1
    for i in range(N):
        ans = max(ans, uf.size(i))

    print(ans)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 50020
def main():
    n = int(input())

    mod = 10**9 + 7

    # すべての組み合わせから、いずれかの条件を満たさないパターンを引く

    pattern = 10 ** n
    not_pattern = (9 ** n) + (9 ** n) - (8 ** n)

    answer = (pattern - not_pattern) % mod

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 86740
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n,a;
n=in.nextInt();
a=n%10;
if(a==2 || a==4 || a==5 || a==7 || a==9)
{
System.out.println("hon");
}
else if(a==3)
{
System.out.println("bon");
}
else
{
System.out.println("pon");
}
}
}

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

ll solve() {
    ll N, M, Q, l, r, p, q;
    cin >> N >> M >> Q;
    vector<vector<ll>> c(N+1, vector<ll>(N+1));
    for ( int i = 0; i < M; i++ ) {
        cin >> l >> r;
        c[l][r]++;
    }
    for ( int i = 1; i <= N; i++ ) {
        for ( int j = 1; j <= N; j++ ) {
            c[i][j] += c[i-1][j];
        }
    }
    for ( int i = 1; i <= N; i++ ) {
        for ( int j = 1; j <= N; j++ ) {
            c[i][j] += c[i][j-1];
        }
    }
    vector<ll> ans;
    for ( int i = 0; i < Q; i++ ) {
        cin >> p >> q;
        ll x = c[N][q] - c[p-1][q];
        ans.push_back(x);
    }

    for ( int i = 0; i < Q; i++ ) {
        cout << ans[i] << "\n";
    }    

    return 0;
}

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

Measured memory_bytes: 3828
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n>=1 && n<=100)
    {
        int a[n];
        int flag = 1;
        for(int i=0; i<n; i++)
        {
            cin >> a[i];
            if(a[i]<-100 || a[i]>100)flag = 0;
        }
        if(flag)
        {
            int finalans=0;
            int sum = 0;
            for(int i=0; i<n; i++)
            {
                sum += a[i];
            }
            float mean = 1.0*sum/n;
            if((mean - floor(mean))>0.5)
            {
                for(int i=0; i<n; i++)
                {
                    finalans += (ceil(mean)-a[i])*(ceil(mean)-a[i]);
                }
            }
            else {
                for(int i=0; i<n; i++)
                {
                    finalans += (floor(mean)-a[i])*(floor(mean)-a[i]);
                }
            }
            cout << finalans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3724
main :: IO()
main = do
  [a, b] <- map (read :: String -> Int) . words <$> getLine
  putStrLn $ unwords $ map show $ solve [(l,m,n) | l <- [0..a], m <- [0..(a-l)], let n = a - l -m, 10000*l+5000*m+1000*n==b]

solve :: [(Int, Int, Int)] -> [Int]
solve [] = [-1, -1, -1]
solve ((l, m, n) : xs) = [l, m, n]

Measured memory_bytes: 636
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 x = a + b;
		int y = a - b;
		int z = a * b;

		int result = x;
		if (x < y && z < y) {
			result = y;
		} else if (x < z && y < z) {
			result = z;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 21716
from collections import defaultdict

H,W,N=map(int,input().split())
ab=[]
dict=defaultdict(int)
for i in range(N):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    for x in [-1,0,1]:
        for y in [-1,0,1]:
            Y=a+y
            X=b+x
            if 0<=Y-1 and Y+1<H and 0<=X-1 and X+1<W:
                dict[(X,Y)]+=1
M=H*W-2*W-2*H+4
v=[0]*10
for i,j in dict.items():
    v[j]+=1
v[0]=M-sum(v[1:])
for i in range(10):
    print(v[i])


Measured memory_bytes: 181464
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        String s = r.s();
        char[] c = new char[(s.length()+1)/2];
        for(int i = 0, j = 0; j < s.length(); i++, j+=2)
            c[i] = s.charAt(j); 
        println(new String(c));
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 23252
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;


int main(void){
  int H,W;

  cin >> H >> W ;
  vector<vector<char>>C(H,vector<char>(W)); 

  for(int i = 0; i < H ; i++){
    for(int j = 0; j < W ;j++){
      char tmp;
      cin >> tmp;

      C[i][j] = tmp;

    }
  }

  int H_copy = 0;
  for(int i = 0; i < H ; i++){
    int count = 0;
    while(count < 2){
    for(int j = 0; j < W ;j++){

      cout<< C[i][j];

    }
    count++;
    cout<< endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

typedef long long i64;
typedef unsigned long long u64;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

int isnp[105];
int cc[105];

void _p(void){
        isnp[1] = 1;
        for (int i=2; i<105; i++) {
                if (isnp[i] == 1)
                        continue;
                for (int j=2; i*j<105; j++) {
                        isnp[i*j] = 1;
                }
        }
}

void cnt(u64 m) {
        for (int i=2; i<=m; i++) {
                if (isnp[i])
                        continue;
                u64 t = 0;
                u64 j = i;
                while (j <= m) {
                        t += m / j;
                        j *= i;
                }
                cc[i] = t;
        }
}

u64 n;


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

        _p();

        cin >> n;
        cnt(n);

        int r = 0;
        int f=0,t=0;
        for(int i=2; i<105; i++) {
                if (cc[i] >= 2) t++;
                if (cc[i] >= 4) f++;
        }
        t -= f;
        r +=  3*f*(f-1)*(f-2)/6 + t*f*(f-1)/2;

        t = f = 0;
        for(int i=2; i<105; i++) {
                if (cc[i] >= 4) t++;
                if (cc[i] >= 14) f++;
        }
        t -= f;
        r +=   t*f + 2*f*(f-1)/2;

        t = f = 0;
        for(int i=2; i<105; i++) {
                if (cc[i] >= 2) t++;
                if (cc[i] >= 24) f++;
        }
        t -= f;
        r +=   t*f + 2*f*(f-1)/2;

        t = f = 0;
        for(int i=2; i<105; i++) {
                if (cc[i] >= 74) f++;
        }
        r +=   f;

        cout << r << endl;


        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
  cin.tie(0);  \
  ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (int i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size() - 1; ++i) {
    os << v[i] << " ";
  }
  if (v.size() > 0) {
    os << v[v.size() - 1] << endl;
  }
  return os;
}

int main() {
  int n,t;
  cin >> n >> t;
  vint a(n), b(n);
  REP(i, n) { cin >> a[i] >> b[i]; }
  vector<vll> dp(n + 1, vll(6000 + 1, 0)), dp2(n + 1, vll(6000 + 1, 0));
  //REP(i, n + 1) { REP(j,6000) {dp[i][j] = 0;} }
  REP(i,n){
    REP(j,6000){
      if (dp[i][j] != -1) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        if (j + a[i]<= 6000) dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
      }
      if (j > 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - 1]);
    }
  }
  //REP(i, n + 1) { dp2[i][0] = 0; }
  IREP(i, n) {
    REP(j, 6000) {
      if (dp2[i][j] != -1) {
        dp2[i][j] = max(dp2[i][j], dp2[i + 1][j]);
        if (j + a[i] <= 6000)
          dp2[i][j + a[i]] = max(dp2[i][j + a[i]], dp2[i + 1][j] + b[i]);
      }
      if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  ll ans = 0;
  REP(i,n){
    REP(j, t) { ans = max(ans, b[i] + dp[i][j] + dp2[i+1][t - 1 - j]); }
  }
  cout << ans << endl;
}

Measured memory_bytes: 281856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define INX(x) (cin >> x)
#define INXV(vec, cnt) for(ll i; i < cnt; i++) INX(vec[i])
#define OUTX(x) (cout << x << endl)
#define OUTXV(vec) for(ll i; i < (ll)vec.size(); i++) OUTX(vec[i])

#define ADD emplace_back
#define MP make_pair

ll N, A, B, C, D;
map<ll, ll> fn;
ll f(ll n)
{
    if(fn.find(n) == fn.end())
    {
        ll c1, c2, c3, c4, c5, c6, c7;
        ll tmp;
        
        //c1 = n * D; //overflow
        c1 = __LONG_LONG_MAX__ / n > D ? n * D : __LONG_LONG_MAX__;

        tmp = ceil(ld(n) / 2);
        c2 = abs(n - 2 * tmp) * D + A + f(tmp);

        tmp = floor(ld(n) / 2);
        c3 = abs(n - 2 * tmp) * D + A + f(tmp);

        tmp = ceil(ld(n) / 3);
        c4 = abs(n - 3 * tmp) * D + B + f(tmp);

        tmp = floor(ld(n) / 3);
        c5 = abs(n - 3 * tmp) * D + B + f(tmp);

        tmp = ceil(ld(n) / 5);
        c6 = abs(n - 5 * tmp) * D + C + f(tmp);

        tmp = floor(ld(n) / 5);
        c7 = abs(n - 5 * tmp) * D + C + f(tmp);

        tmp = min(c1,c2);
        tmp = min(tmp,c3);
        tmp = min(tmp,c4);
        tmp = min(tmp,c5);
        tmp = min(tmp,c6);
        tmp = min(tmp,c7);
        fn.emplace(MP(n,tmp));
        return tmp;
    }
    else
    {
        return fn[n];
    }
}

void exe(ll Nt, ll At, ll Bt, ll Ct, ll Dt)
{
    N = Nt;
    A = At;
    B = Bt;
    C = Ct;
    D = Dt;

    fn.clear();
    fn.emplace(MP(0,0));
    fn.emplace(MP(1,D));
    
    OUTX(f(N));
}

int main()
{
    ll T;
    cin >> T;

    vector<vector<ll>> inp;
    for (ll i = 0; i < T; i++)
    {
        vector<ll> tmp(5);
        cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3] >> tmp[4];
        inp.ADD(tmp);
    }
    for (ll i = 0; i < T; i++)
    {
        vector<ll> &tmp = inp[i];
        exe(tmp[0], tmp[1], tmp[2], tmp[3], tmp[4]);
    }
    
    return 0;
}


Measured memory_bytes: 4472
#include<iostream>
#include<vector>
using namespace std;
int N;
vector<int>G[1<<17];
bool re[1<<17];
void dfs(int u,int p)
{
	int cnt=0;
	for(int v:G[u])
	{
		if(v!=p)
		{
			cnt++;
			dfs(v,u);
		}
	}
	re[u]=cnt==0;
}
bool rre[1<<17];
bool ansflag;
pair<int,int>dfs3(int u,int p)
{
	int a=0,b=0,ecnt=0;
	for(int v:G[u])
	{
		ecnt+=v!=p;
		if(v==p||re[v])continue;
		pair<int,int>q=dfs3(v,u);
		a+=q.first;
		b+=q.second;
	}
	if(rre[u])
	{
		a++;
	}
	if(a>=2)ansflag=true;
	if(b!=ecnt)b=0;
	else if(p==-1)ansflag=true;
	return make_pair(b>0,a>0);
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	bool flag=true;
	for(int i=0;i<N;i++)flag&=G[i].size()<=2;
	if(flag)
	{
		cout<<(N%2?"First":"Second")<<endl;
		return 0;
	}
	int r=0;
	while(G[r].size()<3)r++;
	dfs(r,-1);
	for(int i=0;i<N;i++)
	{
		int cnt=0;
		for(int v:G[i])cnt+=re[v];
		if(cnt>=2)
		{
			cout<<"First"<<endl;
			return 0;
		}
		else if(cnt==1)
		{
			rre[i]=true;
		}
	}
	dfs3(r,-1);
	if(ansflag)
	{
		cout<<"First"<<endl;
		return 0;
	}
	cout<<"Second"<<endl;
}

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

#define rpt(i, n) for(i = 0; i < (n); i++)
typedef long long ll;

int main(void) {
	int n, l, a[100], i, s = 0, flag = 0;
	cin >> n >> l;

	rpt(i, n) {
		a[i] = l + i;
	}

	rpt(i, n) {
		s += a[i];
	}
	
	rpt(i, n) {
		if (a[i] == 0) {
			cout << s;
			flag = 1;
			break;
		}
	}
	
	if (flag == 0) {
		if (a[0] > 0) {
			s -= a[0];
			cout << s;
		}
		else {
			s -= a[n - 1];
			cout << s;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k;
  cin >> n >> k;
  long long count=0;
  for(long long i=k+1;i<=n;i++){
    long long a = n/i;
    count+=a*(i-k);
    if(a*i+k<=n){
      count+=n-(a*i+k)+1;
    }
    if(k==0){
      count--;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
maxT = int(N**.5)+1
ans = 0
cnt = 0
while N%2 == 0:
    cnt += 1
    N //= 2
i = 1
while cnt >= i:
    ans += 1
    cnt -= i
    i += 1
t = 3
while t <= maxT:
    if N%t == 0:
        cnt = 0
        while N%t == 0:
            cnt += 1
            N //= t
        i = 1
        while cnt >= i:
            ans += 1
            cnt -= i
            i += 1
    t += 2
if N > 1:
    for i in range(3, int(N**.5)+1, 2):
        if N%i == 0:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 9488
// finish date: 2018/10/08

#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

//足し算
int add(int a, int b) {
    return (int) (((ll) a + b + bigmod) % bigmod);
}

//引き算
int sub(int a, int b) {
    return (int) (((ll) a - b + bigmod) % bigmod);
}

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int modpow(int a, int b) {
    if (b == 0) return 1;
    int temp = modpow(a, b / 2);
    if (b % 2 == 1) return mul(mul(temp, temp), a);
    else {
        return mul(temp, temp);
    }
}

//割り算(分母だけ)  -  逆元(求めたい数とbigmodを渡す)
int divide(int a, int p = bigmod, int b = -1) {
    if (b < 0) b = p - 2;  //int gyakugen(int a, int p, int b = p - 2とできなかったため。)
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        int d = divide(a, p, b / 2);
        return mul(d, d);
    } else {
        return mul(a, divide(a, p, b - 1));
    }
}


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    int factN = 1;
    FOR(i, 1, N + 1) factN = mul(factN, i);
    vi E(N + 1, 0);
    FOR(i, 1, N + 1) {
        E[i] = mul(factN, divide(i));
        E[i] = add(E[i], E[i - 1]);
    }
    int ans = 0;
    rep(i, N) {
        ans = add(ans, mul(A[i], sub(E[i + 1], E[1])));
        ans = add(ans, mul(A[i], E[N - i]));
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 1024
/**
*    author:  boutarou
*    created: 28.06.2020 20:54:48
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

int d;
int c[26];
int s[365][26];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) {
        rep(j, 26) cin >> s[i][j];
    }
    rep(i, d) {
        int ma = 0;
        rep(j, 26) chmax(ma, s[i][j]);
        int ans;
        rep(j, 26) if (ma == s[i][j]) ans = j;
        cout << ans + 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3688
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

S = defaultdict(set)
for i in range(M):
    k, *s = map(int, input().split())
    for j in s:
        S[j - 1].add(i)

p = list(map(int, input().split()))

ans = 0
for i in range(2 ** N):
    on = [(i & (1 << j)) > 0 for j in range(N)]
    count = defaultdict(int)
    for j, ok in enumerate(on):
        if ok:
            for k in S[j]:
                count[k] += 1
    if all(count[j] % 2 == p[j] for j in range(M)):
        ans += 1
print(ans)


Measured memory_bytes: 45804
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let s = i.read_line().as_bytes();
    writeln!(o, "{}", solve(s)).unwrap();
}
fn solve(s: &[u8]) -> usize {
    let mut c0 = 0;
    let mut c1 = 0;

    for i in 0..s.len() {
        let value = s[i] == b'0';

        if value == (i % 2 == 0) {
            c0 += 1;
        } else {
            c1 += 1;
        }
    }
    min(c0, c1)
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 998244353;

template<class T>
class segtree {
	int n;
	vector<T> data;
	T def;
	function<T(T, T)> operation;
	function<T(T, T)> update;
	T _query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return def;
		if (a <= l && r <= b) return data[k];
		T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
		T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
		return operation(c1, c2);
	}
public:
	segtree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
		:def(_def), operation(_operation), update(_update) {
		n = 1;
		while (n < _n) {
			n *= 2;
		}
		data = vector<T>(2 * n - 1, def);
	}
	void change(int i, T x) {
		i += n - 1;
		data[i] = update(data[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
		}
	}
	T query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}
	T operator[](int i) {
		return data[i + n - 1];
	}
};

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

	int n;
	cin >> n;
	vector<int> x(n), d(n), y(n);
	vector<P> p(n);
	rep(i, n) {
		cin >> x[i] >> d[i];
		y[i] = x[i] + d[i];
		p[i].first = x[i];
		p[i].second = y[i];
	}
	sort(all(p));
	rep(i, n) {
		x[i] = p[i].first;
		y[i] = p[i].second;
	}
	p.pb(P(INF, INF));
	vector<int> use(n);
	for (int i = 0; i < n; i++) {
		int g = lower_bound(all(x), y[i]) - x.begin();
		use[i] = g - 1;
	}
	segtree<int> segmax(n + 2, 0, [](int a, int b) {return max(a, b); }, [](int a, int b) {return b; });
	rep(i, n) segmax.change(i, use[i]);
	for (int i = n - 1; i >= 0; i--) {
		int maxv = segmax.query(i, segmax[i] + 1);
		segmax.change(i, maxv);
	}
	vector<int> dp(n + 1);
	dp[n] = 1;
	for (int i = n - 1; i >= 0; i--) {
		dp[i] = dp[i + 1] + dp[segmax[i] + 1];
		dp[i] %= mod;
	}
	cout << dp[0] << endl;
}

Measured memory_bytes: 17096
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll dp[64][512][512];
ll a[64],b[64],c[64];

int main(){
    int N,Ma,Mb;
    cin >> N >> Ma >> Mb;
    rep(i,N) cin>>a[i]>>b[i]>>c[i];
    rep(i,64) rep(j,512) rep(k,512) dp[i][j][k]=INF;
    dp[0][0][0] = 0;

    for(int i=0;i<N;i++){
        for(int j=0;j<=400;j++){
            for(int k=0;k<=400;k++){
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
            }
        }
    }

    ll mini = INF;


    for(int i=1;i<=400;i++) for(int j=1;j<=400;j++){
        if(i*Mb == j*Ma) mini = min(mini,dp[N][i][j]);
    }
    if(mini==INF) cout << -1 << endl;
    else cout << mini << endl;
}


Measured memory_bytes: 131328
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String a = scan.next();
    if ((a.charAt(2) == a.charAt(3)) && (a.charAt(4) == a.charAt(5))){
      System.out.println("Yes");
      return;
    }
    System.out.println("No");
  }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<vvvll> vvvvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define MOD 1000000007

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

int main()
{
	IOS;
	ll n;
	cin>>n;
	map<ll,ll> m;
	vll v(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
		m[v[i]]++;
	}
	vll ans;
	for(auto it:m)
	{
		while(it.ss>=2)
		{
			ans.pb(it.ff);
			it.ss-=2;
		}
	}
	if(ans.size()<2)
	{
		cout<<"0";
		return 0;
	}
	sort(ans.rbegin(),ans.rend());
	ll area=ans[0]*ans[1];
	cout<<area;
	return 0;
}

Measured memory_bytes: 7296
def main():
    n = int(input())
    A = list(map(int, input().split()))

    res = 0
    i = 0
    while i + 1 <= n:
    		while i + 1 < n and A[i] == A[i + 1]:
        	 i += 1
    		
    		if i + 1 < n and A[i] < A[i + 1]:
    			while i + 1 < n and A[i] <= A[i + 1]:
    				i += 1
    				        
    		elif i + 1 < n and A[i] > A[i + 1]:
    			while i + 1 < n and A[i] >= A[i + 1]:
    				i += 1
    		i += 1
    		res += 1
    
    print(res)
    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 14436