akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N, M;
	cin >> N >> M;
	long long int DP[5000];
	for(int i = 0; i < 5000; i++){
		DP[i] = INF;
	}
	DP[0] = 0;
	for(int loop = 0; loop < M; loop++){
		int a, b;
		cin >> a >> b;
		int num = 0;
		for(int i = 0; i < b; i++){
			int c;
			cin >> c;
			num += (1 << (c - 1));
		}
		for(int i = 0; i < (1 << N); i++){
			DP[i | num] = min(DP[i | num], DP[i] + a);
		}
	}
	if(DP[(1 << N) - 1] == INF){
		cout << -1 << endl;
	}else{
		cout << DP[(1 << N) - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*各々が初めてルール違反を犯した時を記録　早い方が負け
どちらも違反していなければドロー
*/


int main() {
   ll N,K,S;
   cin >> N >> K >> S;
   vector<ll> A(N);
   if(S == 1){
       for(int i = 0;i<N;i++){
         if(i<K) A[i] = 1;
         else A[i] = 2;
       }
   }
  else if(S >= 2 && S <= 1000000000-1){
   //ll a = (S-1)/(N-K);
   for(int i = 0;i<N;i++){
       if(i<K) A[i] = S;
       else A[i] = S+1;
   }

  }
  else if(S == 1000000000){
      for(int i = 0;i<N;i++){
       if(i<K) A[i] = S;
       else A[i] = S-1;
   }
  }
   rep(i,N){
       cout << A[i] << " ";
   }
 cout << endl;
}

Measured memory_bytes: 2048
txt = input()
n = int(input())

for i in range(n):
    inputs = input().split()
    if inputs[0] == 'print':
        s = int(inputs[1])
        e = int(inputs[2])
        print(txt[s:e+1])
    elif inputs[0] == 'reverse':
        s = int(inputs[1])
        e = int(inputs[2])
        t_r = txt[s:e+1]
        t_r = t_r[::-1]
        txt = txt[:s] + t_r + txt[e+1:]
    elif inputs[0] == 'replace':
        s = int(inputs[1])
        e = int(inputs[2])
        rep = inputs[3]
        txt = txt[:s] + rep + txt[e+1:]
    


Measured memory_bytes: 5608
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

void solve() {
  string s, t;
  cin >> s >> t;
  {
    vector<bool> sf(26), tf(26);
    rep(i, s.size()) sf[s[i] - 'a'] = true;
    rep(i, t.size()) tf[t[i] - 'a'] = true;
    rep(i, 26) if (!sf[i] && tf[i]) {
      cout << -1 << endl;
      return;
    }
  }
  int n = s.size();
  s += s;
  vector<vi32> next(26, vi32(s.size()));
  {
    vi32 position(26, -1);
    rrep(i, s.size()) {
      position[s[i] - 'a'] = i + 1;
      rep(j, 26) next[j][i] = position[j] - i;
    }
  }
  i64 acc = 0;
  rep(i, t.size()) {
    acc += next[t[i] - 'a'][acc % n];
  }
  cout << acc << endl;
}


Measured memory_bytes: 21868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    cout<<60*(c-a)+(d-b)-e;
}


Measured memory_bytes: 3636
c = [[int(i) for i in input().split()] for i in range(3)]

if c[0][0]-c[0][1] != c[1][0]-c[1][1] or c[1][0]-c[1][1] != c[2][0]-c[2][1] or c[0][1]-c[0][2] != c[1][1]-c[1][2] or c[1][1]-c[1][2] != c[2][1]-c[2][2]:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
	let l = 0;
	let count = 0;
	while (input[l][0] != '0'){
		let H = parseInt(input[l][0], 10);
		let arr = [];
		for (let i = 0; i < H; i++){
			arr.push(input[i + l + 1].map(e => parseInt(e, 10)));
		}

		//vanish
		let ENDflag;
		let ans = 0;
		while (true){
			ENDflag = true;
			let flag;
			let vanishList = Array.from({length: 5}, () => []);
			for (let i = 0; i < H; i++){
				flag = false;
				let tmpN = -1;
				let tmpIndex = [];
				this_loop:
				for (let j = 0; j < 5; j++){
					if (arr[i][j] === 0) {
						tmpN = -1;
						tmpIndex = [];
						continue;
					}
					else if	(arr[i][j] === tmpN) {
						tmpIndex.push(j);
						if (tmpIndex.length >= 3) {flag = true; ENDflag = false;}
					}
					else {
						if (flag) break this_loop;
						tmpN = arr[i][j];
						tmpIndex = [j];
					}
				}
				if (flag){
					for (let x of tmpIndex){
						// console.log(tmpIndex);
						ans += arr[i][x];
						arr[i][x] = -1;
						vanishList[x].push(i);
					}
				}
			}
			//fall
			let tmpFallDistance;
			for (let j = 0; j < 5; j ++){
				tmpFallDistance = 0;
				for (let i = H - 1; i >= 0; i--){
					while (i - tmpFallDistance > 0 && arr[i - tmpFallDistance][j] === -1){
						tmpFallDistance ++;
					}
					if (i - tmpFallDistance >= 0) arr[i][j] = Math.max(0, arr[i - tmpFallDistance][j]);
					else arr[i][j] = 0;
				}
			}
			if (ENDflag) break;
		}
		l += H + 1;
		console.log(ans);
		count ++;
	}
	
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));





Measured memory_bytes: 25892
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    n = next_int()
    ar = next_int_array_one_line()
    num = [0] * 100001
    for a in ar:
        num[a] += 1
    q = next_int()
    res = 0
    for i in range(len(num)):
        res += num[i] * i

    for i in range(q):
        b, c = map(int, input().split())
        res += (c-b) * num[b]
        num[c] += num[b]
        num[b] = 0
        print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84724
#include <stdio.h>
#include <ctype.h>
 
int main() {
 
  char ch[1200];
  int i,n;
  n=0;
  char a[1200];
 
  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;
 
    }
     
     
    n = n +1;
     
  }
   
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
   
}


Measured memory_bytes: 2040
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	int n, m; cin >> n >> m;
	vint v;
	rep(i, n){
		v.push_back(2);
	}
	rep(i, m){
		v.push_back(1);
	}

	rep(i, v.size()){
		rep2(j, i+1, v.size()){
			if((v[i]+v[j])%2 == 0) ans++;
		}
	}

	

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


// べき乗を求める関数 : (base_number^inde_number % modulous_number), index_number ≥ 0 が必要. 計算量Θ(log N)
template <int modulous_number>
constexpr int power(int base_number, long long int index_number){
    int result_value = 1;
    while(index_number){
        if(index_number % 2 == 1) result_value = static_cast<long long int>(result_value) * base_number % modulous_number;
        base_number = static_cast<long long int>(base_number) * base_number % modulous_number;
        index_number /= 2;
    }
    return result_value;
}

constexpr int mod = 1'000'000'007;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    int n; std::cin >> n;
    const int v10 = power<mod>(10, n);
    const int v9  = power<mod>(9, n);
    const int v8  = power<mod>(8, n);
    int res = 0; {
        res = v10;
        res -= v9; if(res < 0) res += mod; 
        res -= v9; if(res < 0) res += mod;
        res += v8; if(res >= mod) res -= mod;
    }
    std::cout << res << '\n';
    return 0;
}

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

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);//CUIに入力したいから。

		int m, f, r;
		ArrayList<String> results = new ArrayList<String>();
		while(true) {
			m = scan.nextInt();
			f = scan.nextInt();
			r = scan.nextInt();
			if (m == -1 && f == -1 && r == -1) break;
			if (m == -1 || f == -1) results.add("F");
			else if (m + f >= 80) results.add("A");
			else if (m + f >=65 && m + f <80) results.add("B");
			else if (m + f >=50 && m + f<65) results.add("C");
			else if (m + f >=30 && m + f <50 && r>=50) results.add("C");
			else if (m + f >=30 && m + f < 50 && r < 50) results.add("D");
			else if (m + f <30) results.add("F");
		}
		for (int i = 0;  i < results.size(); i++) {
			System.out.println(results.get(i));
		}



 	}
}


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

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


Measured memory_bytes: 3208
N = gets.to_i
S = gets.chomp.split(" ").map(&:to_i)

ans = 0
(1..((N - 2) / 2)).each{|stp|
 sum = 0
 i = stp
 while(i < N - 1) do
   break if N - 1 - 2 * i == 0    # 同じ蓮を使う
   break if N - 1 - i - stp <= 0  # Bの値
   (i += stp; next) if (N - 1 - i) % stp == 0 && (N - 1) <= (2 * i) # A:B が n:n-1でaが全体の半分以下
   (i += stp; next) if (N - 1 - i == 2 * stp) && ((N - 1) > (N - 1 - i) + (N - 1 - i) / 2)  # A:B が 2n:nで全体の2/3でない
   sum += (S[N - 1 - i] + S[i])
   ans = sum if sum > ans
   i += stp
 end
}

puts ans


Measured memory_bytes: 9996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader fr = new FastReader();
		int n = fr.nextInt();
		int[] a = new int[10];
		for (int i=0; i<n; i++) {
			int t = fr.nextInt();
			a[Math.min(8, t/400)]++;
		}
		int colorCount = 0;
		for (int i=0; i<8; i++) {
			if (a[i] > 0) {
				colorCount++;
			}
		}
		System.out.println((colorCount > 0 ? colorCount : 1) + " " +  (colorCount + a[8]));
	}
	
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		public String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


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

using namespace std;
using ll = long long;


int main()
{
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a = b - a; //aは距離のみを表すようになった
    n--;

    //i回上にあがる
    for(ll i = n; i >= 0; i--) {
        ll up = i * d - (n - i) * c;
        ll dw = i * c - (n - i) * d;
        if(dw <= a && a <= up) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);

// 168 A
// https://atcoder.jp/contests/abc168/tasks/abc168_a

int main()
{
	string s;

	cin >> s;

	uint32_t num = s[s.size() - 1] - '0';
	switch (num) {
	case 3:
		printf("bon\n");
		break;
	case 0: case 1:case 6:case 8:
		printf("pon\n");
		break;
	default:
		printf("hon\n");
		break;

	}
	return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var list = new List<int>() { 2 };
        for(var i = 3; i <= num; i += 2)
        {
            var isPrime = true;
            for(var j = 1; j * j < i; j++)
            {
                var prime = list[j-1];
                if (i % prime == 0) { isPrime = false;break; }
            }
            if (isPrime) list.Add(i);
        }
        var dic = new Dictionary<int, int>();
        for(var i = 1; i <= num; i++)
        {
            foreach(var prime in list)
            {
                var s = i;
                if (i < prime) break;
                while (s % prime == 0)
                {
                    if (dic.ContainsKey(prime)) dic[prime]++;
                    else dic[prime] = 1;
                    s /= prime;
                }
            }
        }
        var dg74 = dic.Values.Count(v => v >= 74);
        var dg24 = dic.Values.Count(v => v >= 24);
        var dg14 = dic.Values.Count(v => v >= 14);
        var dg4 = dic.Values.Count(v => v >= 4);
        var dg2 = dic.Values.Count(v => v >= 2);
        var result = dg74;
        result += (dg2 - dg24) * dg24;
        if (dg24 > 1) result += dg24 * (dg24 - 1);
        result += (dg4 - dg14) * dg14;
        if (dg14 > 1) result += (dg14 - 1) * dg14;
        if (dg4 > 1)
            result += dg4 * (dg4 - 1) / 2 * (dg2 - dg4);
        if (dg4 > 2)
            result += dg4 * (dg4 - 1) * (dg4 - 2) / 2;
        WriteLine(result);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13396
n = int(input())
Hotel = list(map(int, input().split()))
Hotel = [0] + Hotel
cnt = 0
for i in range(1, n+1):
    look = Hotel[i]
    for j in range(i):
        if look >= Hotel[j]:
            continue
        else:
            break
    else:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

ll t1, t2, a1, a2, b1, b2;

ll ans(ll x1, ll x2, ll y1, ll y2, ll d) {
    if (x1 > y1) {
        return 0;
    } else {
        ll k = t1 * (y1 - x1) / d;
        ll r = t1 * (y1 - x1) % d;
        if (r == 0)
            return 2 * k;
        else
            return 2 * k + 1;
    }
}

int main() {
    fastio();

    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll ea = t1 * a1 + t2 * a2;
    ll eb = t1 * b1 + t2 * b2;
    if (ea == eb) {
        cout << "infinity\n";
        return 0;
    }

    // cout << ea << (ea > eb ? ">" : "<") << eb << endl;

    if (ea > eb) {
        cout << ans(a1, a2, b1, b2, ea - eb) << endl;
    } else {
        cout << ans(b1, b2, a1, a2, eb - ea) << endl;
    }

    return 0;
}

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


int main(){
    vector<intf> a(3);
    for(auto &e:a) cin >>e;
    vector<intf> list = {500,100,50};
    intf ct=0,x;
    cin >>x;

    rep(h,a[0]+1){
        rep(i,a[1]+1){
            rep(j,a[2]+1){
                if(x==(h*500+i*100+j*50)){
                    ct++;
                }
            }
        }

    }

    cout << ct <<endl;

}

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

int main() {
  long long N;
  cin >> N;
  long long n = sqrt(N);
  long long ans = 0;
  long long p;
  for (int i=1; i<n+10; i++) {
    if (N % i != 0) {
      continue;
    }
    p = N / i;
    if (p == 1) {
      continue;
    }
    if (N / (p-1) == N % (p-1)) {
      ans += (p-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *     author: qodjf
 *     created: 04.21.2020 23:24:50
 */
#include <bits/stdc++.h>
using namespace std;

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

void solve() {}

const int MAXN = 1e6 + 10;
int dp[MAXN][2];

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

  string s;
  cin >> s;
  mst(dp, 0);
  int N = s.size();
  dp[N - 1][0] = s[N - 1] - '0';
  dp[N - 1][1] = 10 - (s[N - 1] - '0');
  for (int i = N - 2; i >= 0; i--) {
    int x = s[i] - '0';
    dp[i][0] = min(x + dp[i+1][0], x + 1 + dp[i+1][1]);
    dp[i][1] = min(10 - x + dp[i+1][0], 9 - x + dp[i+1][1]);
  }

  cout << min(dp[0][0], 1 + dp[0][1]) << endl;
}


Measured memory_bytes: 9116
// #include <bits/stdc++.h>
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>
#include<functional>
#include <bitset>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 100005;
static const int ls = 101;
// static const int NMAX = 5005;
// static const lli INFTY = 1000000000000;

// typedef priority_queue<int, greater<int>> RevQ;
int N, K;
string s;
// lli A, B;
stack<int> m;
// vector<pair<int, int>> a(MAX);

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

int main(){
  cin >> s;
  cin >> K;
  int n = s.size();
  int flag = 1, cnt = 1;
  char p = s[0];
  int head, tail;
  REP(i, 1, n) {
    if (i == n-1) {
      if (p == s[i]) {
        cnt++;
        tail = cnt;
      } else {
        m.push(cnt);
        tail = 1;
        p = s[i];
      }
    } else {
      if (p == s[i]) {
        cnt++;
        continue;
      } else { // change char
        if (flag) { // first change
          head = cnt;
          flag = 0;
        } else {
          m.push(cnt);
        }
        cnt = 1;
        p = s[i];
        continue;
      }
    }
  }
  // cout << head << " " ;
  // while(!m.empty()) {
  //   int a = m.top(); m.pop();
  //   cout << a << " ";
  // }
  // cout << tail << endl;

  // all same char
  if (cnt == n) {
    lli big = (lli)n*K;
    cout << big/2 << endl;
  }
  else {
    lli ans = 0;
    if (s[0] == s[n-1]) {
      ans += (lli)((head + tail)/2 ) * (K-1);
      if (head > 1) ans += head/2;
      if (tail > 1) ans += tail/2;
    } else {
      m.push(head); m.push(tail);
    }
    while(!m.empty()){
      int a = m.top(); m.pop();
      if (a > 1) {
        int b = a/2;
        // cout << (lli)b << endl;
        // cout << (lli)K << endl;
        ans += (lli)b * K;
        // cout << (lli)b * K << endl;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
  int A, P;
  cin >> A >> P;
  cout << (3 * A + P) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999
#define MOD 1000000007

ll n,k;

bool check(ll x,ll a[]){
    ll sum=0;
    loop(i,0,n){
        if(a[i]>x){
            sum+=a[i]/x;
        }
    }
    return (sum<=k);
}
 
void func()
{
   cin>>n>>k;
   ll a[n];
   ll m=0;
   loop(i,0,n){
    cin>>a[i];
    m=max(m,a[i]);
   }
   ll ans=0;
   for(ll b=m;b>=1;b=b/2){
    while(!check(ans+b,a)) ans+=b;
   }
   ans++;
   cout<<ans<<"\n";

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }

}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans=10000;
  for(int i=0;i<s.size()-2;i++){
    int num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    ans=min(ans,abs(753-num));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  ull n,m,cnt=0;
  cin>>n>>m;
  if(2*n<=m){
    cnt+=n;
    m-=2*n;
    if(m>=4){
      cnt+=m/4;
    }
  }else{
    if(m>=2){
      cnt+=m/2;
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion

/************************************************************************/

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
 
	int n;
	cin >> n;
	vi a(n);
	LL sum = 0;
	vi csum(n);
	f(i, 0, n) {
		cin >> a[i];
		sum += a[i];
		if (i == 0) {
			csum[i] = a[i];
		}
		else {
			csum[i] = csum[i - 1] + a[i];
		}
	}
	LL x, y, d;
	d = 1e10;
	f(i, 0, n - 1) {
		d = min(d, abs(sum - csum[i] - csum[i]));
	}
	cout << d;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;
 
int main(){
    ll N;
    cin>>N;
    ll ans;
    rep(i,1,10){
        if(N<=i*111){ans=i*111;break;}
        else continue;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int A, B, C, K;
	int M;
	cin >> A >> B >> C >> K;
	if (A >= B && A >= C)cout << A * pow(2, K) + B + C << endl;
	else if(B>=A&&B>=C)cout << B * pow(2, K) + A + C << endl;
	else cout << C * pow(2, K) + B + A << endl;
	
	

	return(0);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            long x = long.Parse(str[0]);
            long k = long.Parse(str[1]);
            long d = long.Parse(str[2]);
            long ans = 0;
            long absx = Math.Abs(x);
            if(k>(absx/d))
            {
            long xx = Math.Abs(x) % d;
            long kk = k - x/d;
            //Console.WriteLine(xx);
            //Console.WriteLine(kk);
            long kkk = kk%2;
            ans = Math.Abs(xx - d*kkk);
            }
            else
            {
            ans = Math.Abs(Math.Abs(x)-k*d);
            }
            Console.WriteLine(ans);
        }
    }
    
}

Measured memory_bytes: 27460
a = list(map(int,input().split()))
cnt = 0

while 1:
    if len(set(a)) == 1:
        print(cnt)
        break
    elif len(set(a)) ==2:
        if a.count(min(a)) == 2:
            cnt += max(a)-min(a)
            print(cnt)
            break
        else:
            if (max(a)-min(a))%2==0:
                cnt += (max(a)-min(a))//2
                print(cnt)
                break
            else:
                cnt += (max(a)-min(a))//2 + 2
                print(cnt)
                break
    else:
        a.sort()
        a[0] += 2
        cnt += 1

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

int main() {
    string s[3];
    cin >> s[0] >> s[1] >> s[2];

    int now = 0; // 誰のターンであるか
    while (1) {
        if (s[now].size() == 0) {
            cout << char('A' + now) << endl;
            return 0;
        }
        int next = s[now][0] - 'a'; // 次に読み込まれるもの
        s[now].erase(s[now].begin());
        now = s[now][0] - 'a';
        now = next;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector <string> purmuratedString;
int n;
string tmp = "";
void dfs(int num){
    tmp.push_back((char)('0'+(char)num));
    // cout << "dfs " << num << " " << tmp.length()<< endl;
    // cout << tmp << endl;
    if(tmp.length()==n){
        purmuratedString.push_back(tmp);
        //cout << tmp << endl;
    }else{
        for(int i = 1; i <= n; i++){
            bool isFound = false;
            for(int j = 0; j < tmp.length(); j++){
                if(i==(tmp[j]-'0')){
                    isFound = true;
                }
            }
            if(isFound==false){
                dfs(i);
                tmp.pop_back();
            }
        }
    }
}
int main(){
    cin >> n;
    vector <int> p(n);
    vector <int> q(n);
    string sp="";
    string sq="";
    for(int i = 0; i < n; i++){
        cin >> p[i];
        sp.push_back((char)('0'+p[i]));
    }
    for(int i = 0; i < n; i++){
        cin >> q[i];
        sq.push_back((char)('0'+q[i]));
    }
    for(int i = 1; i <= n; i++){
        //cout << i << endl;
        dfs(i);
        tmp.pop_back();
    }
    sort(purmuratedString.begin(),purmuratedString.end());
    int posP = 0;
    int posQ = 0;
    for(int i = 0; i < purmuratedString.size(); i++){
        if(sp.compare(purmuratedString[i])==0){
            posP=i;
        }
        if(sq.compare(purmuratedString[i])==0){
            posQ=i;
        }
    }
    cout << abs(posP-posQ) << endl;
    #if 0
    for(int i = 0; i < purmuratedString.size(); i++){
        cout << purmuratedString[i] << endl;
    }
    cout << sq << endl;
    cout << sp << endl;
    #endif

    return 0;
}

Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;
constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#ifndef LOCAL
struct osd{template<class T>osd&operator<(const T&t){return*this;}template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;template<class...T>void _print(osd&a,T&&...t){}
#define cerr cer_
#endif
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}template<class T>istream&operator>(istream&i,T&t){return i>>t;}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<t<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}template<class...T>void dprint(T&&...t){_print(cerr,t...);}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<p.F<' '<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>p.F>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>queue<T>&operator<<(queue<T>&q,const T&t){q.push(t);return q;}template<class T>queue<T>&operator<<(T&t,queue<T>&q){t=q.front();q.pop();return q;}
template<class T>deque<T>&operator>>(const T&t,deque<T>&q){q.push_front(t);return q;}template<class T>deque<T>&operator<<(T&t,deque<T>&q){t=q.front();q.pop_front();return q;}
template<class T>deque<T>&operator<<(deque<T>&q,const T&t){q.push_back(t);return q;}template<class T>deque<T>&operator>>(deque<T>&q,T&t){t=q.back(t);q.pop_back();return q;}
template<class T>stack<T>&operator<<(stack<T>&s,const T&t){s.push(t);return s;}template<class T>stack<T>&operator>>(stack<T>&s,T&t){t=s.top();s.pop();return s;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    vi p(n);
    cin>p;
    int c=0;
    REP(i,n){
        if(p[i]!=i+1)c++;
    }
    YES(c<=2);
    return 0;
}


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

int main()
{
    long long X, K, D;
    cin >> X >> K >> D;

    X = abs(X);
    long long k = min(X / D, K);
    K -= k;
    X -= D * k;
    if (K == 0)
    {
        cout << X << endl;
    }
    else if (K % 2 == 0)
    {
        cout << min(abs(X - 2 * D), X) << endl;
    }
    else
    {
        cout << min(abs(X - D), X + D) << endl;
    }
}


Measured memory_bytes: 3632
import java.util.*;
class Main{
	public static void main(String[]args){
      	Scanner sc = new Scanner(System.in);
    	long n,k,min;
      	n = sc.nextLong();
      	k = (long)Math.sqrt(n);
      	min = n;
      	for(long i=1;i<=k;i++){
        	if(n%i==0){
            	long j=n/i;
              	if(i+j-2<min){min = i+j-2;}
            }
        }
      	System.out.println(min);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
string s,t,ans="";//ans为最后的答案，赋为空
int i,j,r;
int main(){
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE";
        return 0;
    }//大坑，必须判断s的长度会不会比t小(我被坑了3次QAQ)
    for(i=0;i<=s.size()-t.size();i++){//枚举t从哪个地方开始
        int k=i;//将i替换为k
        string ss=s;//将s替换为ss
        j=0;//初始化为0
        while(j<t.size()){
            if(ss[k]=='?')//如果为'?'，替换
                ss[k]=t[j];
            else if(s[k]!=t[j])//否则，如果不匹配，退出
                break;
            k++;//匹配则继续匹配
            j++;
        }
        if(j==t.size()){//如果完美匹配
            for(r=0;r<ss.size();r++){
                if(ss[r]=='?')//把'?'替换为'a'
                    ss[r]='a';
            }
            if(ans=="")//如果ans为空，将ans变为ss
                ans=ss;
            else ans=min(ans,ss);
        }
    }
    if(ans=="")//若ans为空
        cout<<"UNRESTORABLE\n";
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	static String s = null;
	static List<Character> list = new ArrayList<Character>();

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		s = sc.next();

		Collections.addAll(list, 'A','C','T','G');
		
		int max = 0;
		
		for(int i = 0; i < s.length(); i++) {
			if(list.contains(s.charAt(i))) {
				int j = check(i+1)-i;
				max = Math.max(j, max);
			}
		}

		System.out.println(max);
	}
	
	public static int check(int i) {
		if(i >= s.length() || !list.contains(s.charAt(i))) {
			return i;
		}else{
			return check(i+1);
		}
	}
}

Measured memory_bytes: 22484
N,M,Q=map(int,input().split())
pos=[[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
  l,r=map(int,input().split())
  pos[l][r]+=1

for l in range(N+1):
  sums=0
  for r in range(N):
    pos[l][r+1]=pos[l][r]+pos[l][r+1]
    
for r in range(N+1):
  sums=0
  for l in range(N):
    pos[l+1][r]=pos[l][r]+pos[l+1][r]

for i in range(Q):
  p,q=map(int,input().split())
  print(pos[q][q]-pos[p-1][q]-pos[q][p-1]+pos[p-1][p-1])

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

int pnjg, pnjgout, indexa=2000000, indexz=-1;
string input, A="A", Z="Z";

int main (){
    cin>>input;
    pnjg = input.length ();
    for (int i=0; i<=pnjg; i++){
        if (input [i]==A[0] && i<indexa){
            indexa=i;
        }
        if (input [i]==Z[0] && i>indexz){
            indexz=i;
        }
    }
    cout<<indexz-indexa+1<<endl;
}

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> ps;
	vector<int> rps;
	rps.resize(n);
	for (int i = 0; i < n; ++i) {
		int p;
		cin >> p;
		p--;
		ps.push_back(p);
		rps[p] = i;
	}
	vector<int> belong;
	for (int i = 0; i < n; ++i) {
		belong.push_back(i);
	}
	UnionFind uf(n);
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.unionSet(x, y);
	}
	int sum = 0;
	for (int ind = 0; ind < n; ++ind) {
		int indnum = ps[ind];
		if (uf.findSet(ind, indnum)) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1912
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)])
B=sorted([list(map(int,input().split())) for i in range(N)])
ans=0
for i in range(N):
    a=[-1,-1]
    x=-1
    for j in range(len(R)):
        if B[i][0]>R[j][0] and B[i][1]>R[j][1]:
            if a[1]<R[j][1]:
                a=R[j]
                x=j
    if x>=0:
        del R[x]
        ans+=1
print(ans)

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

int main(){
	int a,b,c;
	cin >> a>> b >> c;
	if(a==b && b==c)cout << 1 << endl;
	else if(a==b||b==c||a==c)cout << 2 << endl;
	else cout << 3 << endl;
	return 0;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, N):
        self.Parent = {i: -1 for i in range(N)}

    def root(self, A):
        if self.Parent[A] < 0:
            return A
        else:
            self.Parent[A] = self.root(self.Parent[A])
            return self.Parent[A]

    def size(self, A):
        return -self.Parent[self.root(A)]

    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)
        if A == B:
            return False
        if self.size(A) < self.size(B):
            A, B = B, A
        self.Parent[A] += self.Parent[B]
        self.Parent[B] = A
        return True


N, M = map(int, input().split())
bridge = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]
UF = UnionFind(N)
ans = {i: 0 for i in range(M)}
ans[M - 1] = N * (N - 1) // 2
for i in range(M - 1, 0, -1):
    ans[i - 1] = ans[i]
    if UF.root(bridge[i][0]) != UF.root(bridge[i][1]):
        ans[i - 1] -= UF.size(bridge[i][0]) * UF.size(bridge[i][1])
        UF.connect(bridge[i][0], bridge[i][1])
for i in range(M):
    print(ans[i])

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

unsigned long long gcd(unsigned long long C, unsigned long long D)
{
  unsigned long long tmp,min,max;
  if (C < D) {
    min = C;
    max = D;
  } else {
    min = D;
    max = C;
  }
  while (max % min != 0) {
    tmp = min;
    min = max % min;
    max = tmp;
  }
  return min;
}

unsigned long long lcm(unsigned long long C, unsigned long long D)
{
  return C*D/gcd(C,D);
}

int main() {
  unsigned long long A,B,C,D,Cdivmin,Cdivmax,Ddivmin,Ddivmax,CDlcm,CDlcmdivmin,CDlcmdivmax;
  cin >> A >> B >> C >> D;
  Cdivmax = B / C;
  Cdivmin = (A-1) / C;
  Ddivmax = B / D;
  Ddivmin = (A-1) / D;
  CDlcm = lcm(C,D);
  CDlcmdivmax = B / CDlcm;
  CDlcmdivmin = (A-1) / CDlcm;
  cout << (B-A+1-Cdivmax+Cdivmin-Ddivmax+Ddivmin+CDlcmdivmax-CDlcmdivmin) << endl;
}


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

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

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 998244353; // 1e9 + 9;

ll n, all, A[MAXN], sum[MAXN], ans[MAXN], inv[MAXN], cnt[MAXN];

int main() {
    fast_io;
    for (ll i = 1; i < MAXN; i++) inv[i] = poww(i, MOD - 2, MOD);

    cin >> n;
    for (ll i = 1; i <= n; i++) cin >> A[i], cnt[A[i]]++;

    for (ll i = 1; i < MAXN; i++) {
        for (ll j = i; j < MAXN; j += i) sum[i] = (sum[i] + j * cnt[j]) % MOD;
    }

    for (ll i = MAXN - 1; i >= 1; i--) {
        ans[i] = sum[i] * sum[i] % MOD;
        for (ll j = i * 2; j < MAXN; j += i) ans[i] = (ans[i] - ans[j] + MOD) % MOD;
        all = (all + ans[i] * inv[i]) % MOD;
    }
    cout << (all - sum[1] + MOD) % MOD * inv[2] % MOD << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 35072
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b,c;
    cin >> a >> b >> c;
    cout << max(0ll, c - (a - b)) << endl;
}


Measured memory_bytes: 764