akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef pair<int,int> Pii;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200000, MAX_Q = 200000;
int N, Q;
string s;
char t[MAX_Q], d[MAX_Q];

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

  cin >> N >> Q;
  cin >> s;
  rep(i, Q) cin >> t[i] >> d[i];

  int l = -1, r = N;
  for (int i = Q-1; i >= 0; --i) {
      int rl = l+1, lr = r-1;
      if (rl < N && s[rl] == t[i] && d[i] == 'L') {
           ++l;
      }
      if (lr >= 0 && s[lr] == t[i] && d[i] == 'R') {
          --r;
      }
      if (l >= 0 && s[l] == t[i] && d[i] == 'R')  {
          --l;
      }
      if (r < N && s[r] == t[i] && d[i] == 'L') {
          ++r;
      }
  }

  cout << N - (l+1) - (N-r) << endl;

  return 0;
}


Measured memory_bytes: 1088
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int n, ans = 1;
    cin >> n;
    vector<int> A = {2, 4, 8, 16, 32, 64};
    for (auto &&a : A) {
        if(a <= n) ans=a;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>
#include <iostream>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef vector < int > vi;

const int N = 105;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int BASE = 31337;

int con[N][N], bio[N], mat_L[N], mat_R[N], n, m, A[N][N], B[N][N];
vector < int > trpam[N][N];

bool dfs(int x){
	if(bio[x]) return 0;
	bio[x] = 1;
	for(int i = 0;i < n;i++){
		if(!con[x][i]) continue;
		if(mat_R[i] == -1 || dfs(mat_R[i])){
			mat_L[x] = i; mat_R[i] = x;
			return 1;
		}
	}
	return 0;
} 

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			scanf("%d", &A[i][j]);
			A[i][j]--;
			con[i][A[i][j] / m]++;
			trpam[i][A[i][j] / m].PB(A[i][j]);
		}
	}
	for(int j = 0;j < m;j++){
		memset(mat_L, -1, sizeof(mat_L));
		memset(mat_R, -1, sizeof(mat_R));
		int cnt = 0;
		for(int i = 0;i < n;i++){
			memset(bio, 0, sizeof(bio));
			cnt += dfs(i);
		}
		if(cnt != n)
			printf("kriticno\n");
		for(int i = 0;i < n;i++){
			B[i][j] = trpam[i][mat_L[i]].back();
			con[i][mat_L[i]]--;
			trpam[i][mat_L[i]].pop_back();
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			printf("%d ", B[i][j] + 1);
		}
		printf("\n");
	}
	for(int j = 0;j < m;j++){
		vector < int > tmp;
		for(int i = 0;i < n;i++)
			tmp.PB(B[i][j]);
		sort(tmp.begin(), tmp.end());
		for(int i = 0;i < n;i++)
			B[i][j] = tmp[i];
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			printf("%d ", B[i][j] + 1);
		}
		printf("\n");
	}
	return 0;
}


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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class CGoToSchool {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n;
    cin >> n;
    vector<array<int, 2>> A;

    for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        A.push_back({a, i});
    }

    sort(A.begin(), A.end());

    for (auto &a: A)
        cout << a[1] << " ";

    cout << endl;

}
};

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


Measured memory_bytes: 1780
"use strict";

const stringToIntDecimal = s => parseInt(s);

const readData = input => {
  const inputArray = input.split("\n");
  const numberArray = inputArray[0].split(" ").map(stringToIntDecimal);

  return {
    length: numberArray[0],
    operandNumber: numberArray[1],
    str: inputArray[1]
  };
};

function Main(input) {
  let data = readData(input);
  const index = data.operandNumber - 1;
  const inputString = data.str;
  let outputString =
    inputString.substring(0, index) +
    inputString.charAt(index).toLowerCase() +
    inputString.substring(index + 1, data.length);
  console.log(outputString);
}

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

Measured memory_bytes: 21064
k,a,b=map(int,input().split())
if b - a <= 2:
    ans = k + 1
else:
    if 1 <= k <= a - 1:
        ans = k + 1
    else:
        if (k - (a-1)) % 2 == 0:
            ans = a + (b-a)*((k - (a-1))//2)
        else:
            ans = 1 + a + (b-a)*((k - (a-1))//2)
print(ans)

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

int main(){
  int N, T;
  cin >> N >> T;
  int ans=1001;
  int c, t;
  for(int i=0; i<N; i++){
    cin >> c >> t;
    if(t<=T) ans=min(ans, c);
  }
  if(ans==1001) cout << "TLE" << endl;
  else cout << ans << endl;
}

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

signed main(){
  
  string s;
  cin>>s;
  
  int cnt = 0;
  
  for(int i=0;i<s.size();i++){
    if( s[i] == 'o' ) cnt++;
  }
  
  cnt += 15 - (int)s.size();
  
  if( 8 <= cnt ) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;



int main(){
  int n,m;
  cin>>n>>m;
  vector<bool> gt(n,true);
  vector<int> h(n);
  rep(i,n) cin>>h[i];
  
  rep(i,m){
    int a,b;
    cin>>a>>b;
    --a; --b;
    
    if(h[a]>h[b]) gt[b]=false;
    if(h[a]<h[b]) gt[a]=false;
    if(h[a]==h[b]){
      gt[a]=false;
      gt[b]=false;
    }
  }
  
  int ans=1;
   ans=count_if(gt.begin(),gt.end(),[](bool x) { return x; });
  cout<<ans<<endl;
  return 0;
  
 
}


Measured memory_bytes: 3788
k = int(input())

now = 7
cnt = 1
used = [False] * k
ten = 10
while not used[now % k]:
    if now % k == 0:
        print(cnt)
        exit()
    used[now % k] = True
    now = (now + ten * 7) % k
    ten = ten * 10 % k
    cnt += 1
print(-1)


Measured memory_bytes: 16696
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (ll& x : A) cin >> x;
    multiset<ll> S;
    for (ll x : A) {
      auto it = S.lower_bound(x);
      if (it == S.begin()) {
        S.insert(x);
      } else {
        --it;
        S.erase(it);
        S.insert(x);
      }
    }
    cout << S.size() << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

int dp[2000];

int main() {
  IOS;
  int s; cin >> s;

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= s; j++) {
      if (i < j) break;

      dp[i] += dp[i-j];
      dp[i] %= mod;
    }
  }

  COUT(dp[s]);
  return 0;
}

Measured memory_bytes: 3584
import java.lang.Math

fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    // 2 <=n <=10**12 1000000000000


    var ans = n - 1
    val sqrt = Math.sqrt(n.toDouble())

    for (x in (1..(1 + sqrt.toInt())).reversed()) {
        if (n % x == 0L) {
            val y = n / x
            ans = Math.min(ans, (x - 1) + (y - 1))
        }
    }

    println(ans)
}



Measured memory_bytes: 33940
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<ppr, Vppr ,greater<ppr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 =3e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q,D;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;
LL A[SIZE], B[SIZE];
bool nable[SIZE2][SIZE2];
LL cost[SIZE2][SIZE2];

LL solve() {
	cin >> N >> M ;
	REP(i, M) {
		LL x;
		cin >> x;
		A[x] = 1;
	}
	LL now = INF;
	EFOR(i, 1, N) {

		if (A[i] == 1) {
			now = 0;
		}
		else {
			now++;
		}
		if (now < INF) {
			B[now] += 1;

		}
	}
	VI sum(N+1);
	sum[0] = B[0];
	LL maxim = 0;
	EFOR(i, 1, N) {
		sum[i] = B[i] + sum[i-1];
		MX(maxim, sum[i]);
		//	cout << i << " " << sum[i] << endl;
	}
	cin >> Q;
	REP(i, Q) {
		LL x;
		cin >> x;
		if (maxim < N - x) {
			cout << -1 << endl;
		}else
			cout << distance(sum.begin(),lower_bound(ALL(sum),N-x))+1 << endl;
	}
	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	solve();
	//	cin >> N;
	return 0;
}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n, m;
    cin >> n >> m;
    vector<bool> h(n, true);
    vector<int> v(n);
    roop(i, n) cin >> v[i];

    roop(i, m){
        int a, b;
        cin >> a >> b;
        if(v[a-1] < v[b-1]) h[a-1] = false;
        else if(v[a-1] > v[b-1]) h[b-1] = false;
        else{
            h[a-1] = false;
            h[b-1] = false;
        }
    }

    int ans = 0;
    roop(i, n){
        if(h[i] == true) ans++;
    }

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

Measured memory_bytes: 3784
package main

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

var (
	s = bufio.NewScanner(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	n = 0
	a = []int{}
)

func main() {
	n = nextInt(s)
	a = atoi(s)
	_ = nextInt(s)
	m := atoi(s)

	for _, v := range m {
		i := 0
		if solve(i, v) {
			fmt.Fprintln(w, "yes")
			continue
		}
		fmt.Fprintln(w, "no")
	}
	w.Flush()
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return r
}

func atoi(s *bufio.Scanner) []int {
	s.Scan()
	a := strings.Fields(s.Text())
	i := []int{}

	for _, v := range a {
		j, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		i = append(i, j)
	}
	return i
}

func solve(i, m int) bool {
	if m == 0 {
		return true
	} else if i >= n {
		return false
	}
	return solve(i+1, m) || solve(i+1, m-a[i])
}



Measured memory_bytes: 1176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		long total1 = b / x + 1;
		long total2 = 0;
		if (a == 0) {
			total2 = 0;
		} else {
			total2 = (a - 1) / x + 1;
		}
		System.out.println(total1 - total2);
	}
}


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

int main() {
  int x,y;
  cin >> x >> y;
  for(int i=0;i<=x;i++){
    int sum=0;
    sum=i*2+(x-i)*4;
    if(sum==y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
//int dx[4] = { 1,0,0,-1 };
//int dy[4] = { 0,1,-1,0 };
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9 + 7;


int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	cout << n * 32 << endl;


	
	return 0;
}



Measured memory_bytes: 3232
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 = sc.nextInt();
		System.out.println((A <= X && A + B >= X) ? "YES" : "NO");
	}
}

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

int main(){

  int n,m;

  while(cin >> n >> m, n, m){

    int a[10000] = {0},b[10000] = {0},x = 1;

    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=m;i++) cin >> b[i];

    for(int i=1;i<=m;i++){
      x += b[i];
      x = x + a[x];

      if(x >= n){
	x = i;
	break;
      }
    }

    cout << x << endl;
  }
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  vector<int>sticks(n);
  for(int i=0;i<n;i++){
  	cin>>sticks[i];
  }
  sort(sticks.begin(),sticks.end());
  int tot=0;
  for(int A=0;A<n;A++){
  	for(int B=A+1;B<n;B++){
  		int a=sticks[A],b=sticks[B];
  		int x=lower_bound(sticks.begin(),sticks.end(),a+b)-sticks.begin();
  		tot+=x-B;
  		tot--;
  	}
  }
  cout<<tot<<endl;
} 



Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
template <int size>
struct Buffer{
    char buff[size];
    int idx = 0;
    Buffer(){ read(0, buff, size); }
    template <class T>
    void next(T& ret){
        // int ret = 0;
        ret = 0;
        // while(!(buff[idx] & 0x10)){ idx++; }
        while(buff[idx] & 0x10){ ret = ret * 10 + buff[idx++] - '0'; }
        idx++;
        // while(!isdigit(buff[idx])){ idx++; }
        // while(isdigit(buff[idx])){ ret = ret * 10 + buff[idx++] - '0'; }
        // return ret;
    }
};
struct FastInput {
    Buffer<1 << 22> buf;
    template <class T>
    FastInput& operator >> (T& num) { buf.next(num); return *this; }
    // FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

enum { SIZE = 1 << 20 };
char buf[SIZE];
int accs[512][512];
pair<int, int> pqs[100000];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        accs[1][r]++;
        accs[l + 1][r]--;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
        }
    }
    char* ptr = buf + SIZE;
    for(int i = 0; i < q; i++){
        cin >> pqs[i].first >> pqs[i].second;
    }
    for(int i = q - 1; i >= 0; i--){
        int p = pqs[i].first, q = pqs[i].second;
        *--ptr = '\n';
        div_t num2;
        num2.quot = accs[p][q];
        do{
            num2 = div(num2.quot, 10);
            *--ptr = num2.rem | '0';
        }while(num2.quot);
    }
    write(1, ptr, buf + SIZE - ptr);
}


Measured memory_bytes: 6784
using System;
using System.Collections.Generic;
using System.Linq;

class Hello
{

    public enum Color
    {
        hai,
        brown,
        green,
        mizu,
        blue,
        yellow,
        daidai,
        red,
        all
        /*
 * 
 * 
 * レート 1-399：灰色
レート 400-799：茶色
レート 800-1199：緑色
レート 1200-1599：水色
レート 1600-1999：青色
レート 2000-2399：黄色
レート 2400-2799：橙色
レート 2800-3199：赤色
 * 
 * 
 * 
 * 
 * 
 * */

    }
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        int[] a = new int[n];

        var s = Console.ReadLine().Split();
        Color[] c = new Color[n];

        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(s[i]);
            int b = a[i] / 400;
            if (a[i] >= 3200)
            {
                c[i] = Color.all;
            }
            else
            {
                c[i] = (Color)b;
            }
        }

        var c_dis = c.Distinct().ToList();

        var c_dis_NoAll = c_dis.Where(e => e != Color.all);
        var c_dis_All = c_dis.Where(e => e == Color.all);
        var c_All = c.Where(e => e == Color.all);
        var min = c_dis_NoAll.Count();

        var c_AllCount = c_All.Count();
        var c_normalCount = c_dis_NoAll.Count();
        int saidai = (c_normalCount);
        saidai = saidai >= 0 ? saidai : 0;
        saidai = c_AllCount > saidai ? saidai : c_AllCount;
        var max = (min + c_AllCount);
        min = min <= 0 ? 1 : min;
        {
            Console.WriteLine((min) + " " + max);
        }


    }
}

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

int main() {
  int A, B, T;
  int sum = 0;
  cin >> A >> B >> T;

  for (int i = 1; i < (T+1) ;i++) {
    if (i % A == 0) {
      sum += B;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int A,B,X;
	scanf("%d %d %d", &A, &B, &X);
	if(B>=X-A && A<=X){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}


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

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;

#define rep(i,n) for(ll i=0;i<n;i++)

int main() {
  ll n,r; cin>>n>>r;

  if(n<10) cout<<r+(100*(10-n))<<endl;
  else cout<<r<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<int, int>::iterator;

// 最大公約数
long GreatestCommonDivisor(long a, long b) {
	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		long tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	/* 最大公約数を出力 */
	return b;
}

// 最小公倍数
long long LeastCommonMultiple(long a, long b) {
	long gcd = GreatestCommonDivisor(a, b);

	long tmp = a / gcd;
	return (long long)tmp * (long long)b;
}

int main() {
	long long A, B, C, D;
	cin >> A >> B >> C >> D;


	long long lcm = LeastCommonMultiple(C, D);

	// 1 - lcmまでの間でCの倍数とDの倍数の和
	long num = lcm / C + lcm / D - 1;
	
	long long n_a = A / lcm + 1;
	long long n_b = B / lcm;
	long long a = n_a * lcm;
	long long b = n_b * lcm;

	long nDivideOK = (n_b - n_a) * num;
	
	// A以上a以下でCもしくはDの倍数
	long n1 = 0;
	if (A < a) {
		n1 = a / C - (A - 1) / C + a / D - (A - 1) / D - 1;
		if (A % lcm == 0) {
			n1--;
		}
	}
	// b+1以上B以下でCもしくはDの倍数
	long n2 = 0;
	if (b < B) {
		n2 = B / C - b / C + B / D - b / D;
		if (B % lcm == 0) {
			n2--;
		}
	}

	nDivideOK += (n1 + n2);

	cout << B - A - nDivideOK + 1 << endl;


	return 0;
}

Measured memory_bytes: 256
//2013/10/04

#include <iostream>
using namespace std;


char F[102][102];

void APPLE(int Y, int X)
{
	if(F[Y][X] !='@')
		return;

	F[Y][X] = '.';
	APPLE(Y-1, X);	//上
	APPLE(Y, X+1);	//右
	APPLE(Y+1, X);	//下
	APPLE(Y, X-1);	//左

}
void KAKI(int Y, int X)
{
	if(F[Y][X] !='#')
		return;

	F[Y][X] = '.';
	KAKI(Y-1, X);	//上
	KAKI(Y, X+1);	//右
	KAKI(Y+1, X);	//下
	KAKI(Y, X-1);	//左
}
void ORANGE(int Y, int X)
{
	if(F[Y][X] !='*')
		return;

	F[Y][X] = '.';
	ORANGE(Y-1, X);	//上
	ORANGE(Y, X+1);	//右
	ORANGE(Y+1, X);	//下
	ORANGE(Y, X-1);	//左
}
int main()
{
	int H, W;
	while(true){
		cin >> H >> W;
		if(H==0 && W==0)
			break;

		for(int i=1; i<=102; i++)
			for(int j=1; j<=102; j++)
				F[i][j]=0;
	
		for(int i=1; i<=H; i++)
			for(int j=1; j<=W; j++)
			cin >> F[i][j];
		
		
		int cnt = 0;
		for(int i=1; i<=H; i++){
			for(int j=0; j<=W; j++){
				if(F[i][j] == '@'){
					cnt++;
					APPLE(i, j);
				} 
				else if(F[i][j] == '#'){
					cnt++;
					KAKI(i, j);
				}
				else if(F[i][j] == '*'){
					cnt++;
					ORANGE(i, j);
				}
		}
	}
	cout << cnt << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1632
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt_a = Counter(a)
q = int(input())
s = [sum(a)] + [0] * q
for i in range(q):
    b, c = map(int, input().split())
    bn = cnt_a[b]
    s[i + 1] = s[i] + (c - b)*bn
    cnt_a[b] = 0
    cnt_a[c] += bn
print(*s[1:], sep='\n')

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

int main(){
  int n;
  cin >> n;
  int one[3][10];
  int two[3][10];
  int three[3][10];
  int four[3][10];

for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 10; j++) {
   one[i][j] = 0;
  }
}
 
for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 10; j++) {
   two[i][j] = 0;
  }
}
 
for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 10; j++) {
   three[i][j] = 0;
  }
}
 
for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 10; j++) {
   four[i][j] = 0;
  }
}
 


  for (int i = 0; i < n; i++) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    if (b == 1) {
      one[f-1][r-1] += v;
    } else if (b == 2) {
      two[f-1][r-1] += v;
    } else if (b == 3) {
      three[f-1][r-1] += v;
    } else if (b == 4) {
      four[f-1][r-1] += v;
    }
  }


  for (int i = 0; i < 3; i++) {
    for (int j =0; j < 10; j++) {
    cout << " " << one[i][j] ;
    }
    cout << endl;
  }
  cout << "####################" << endl;
 
  for (int i = 0; i < 3; i++) {
    for (int j =0; j < 10; j++) {
    cout << " " << two[i][j] ;
    }
    cout << endl;
  }
  cout << "####################" << endl;
 
  for (int i = 0; i < 3; i++) {
    for (int j =0; j < 10; j++) {
    cout << " " << three[i][j] ;
    }
    cout << endl;
  }
  cout << "####################" << endl;
 
  for (int i = 0; i < 3; i++) {
    for (int j =0; j < 10; j++) {
    cout << " " << four[i][j] ;
    }
    cout << endl;
  }
 
  

  return 0;
}


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

int main() {
  int N, A;
  cin >> N;
  cin >> A;
  
  int rem;
  rem = N % 500;
  
  if (rem <= A) {
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;


int main()
{
    int x[2];
    cin >> x[0] >> x[1];

    int ans = 0;
    rep(i, 2){
        if(x[i] == 1){
            ans += 300000;
        } else if(x[i] == 2){
            ans += 200000;
        } else if(x[i] == 3){
            ans += 100000;
        }
    }

    if (ans == 600000){
        ans = 1000000;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
s = input()
t = len(s)
a = '01'*int(t/2) + '0'*int(t%2)
b = '10'*int(t/2) + '1'*int(t%2)
cta = 0
ctb = 0
for i in range(t):
    if s[i] == a[i]:
        cta += 1
    elif s[i] == b[i]:
        ctb += 1
if cta <= ctb:
    print(cta)
else:
    print(ctb)

Measured memory_bytes: 3316
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std ;

#define MAXN 300007

int n ;
int sz ;
int a[ MAXN ] ;

pair < int , int > merge ( pair < int , int > p1 , pair < int , int > p2 ) {
    if ( p1.second > p2.second ) {
        return p1 ;
    }
    else {
        return p2 ;
    }
}

class Tree {
    public :
    pair < int , int > tr[ 5 * MAXN ] ;
    void init ( int where , int IL , int IR ) {
        tr[ where ] = { IL , 0 } ;
        if ( IL == IR ) { return ; }
        int mid = ( IL + IR ) / 2 ;
        init ( 2 * where , IL , mid ) ;
        init ( 2 * where + 1 , mid + 1 , IR ) ;
    }
    void update ( int where , int IL , int IR , int pos , int val ) {
        if ( IR < pos || pos < IL ) { return ; }
        if ( IL == IR ) {
            tr[ where ] = { pos , val } ;
            return ;
        }
        int mid = ( IL + IR ) / 2 ;
        if ( pos <= mid ) {
            update ( 2 * where , IL , mid , pos , val ) ;
        }
        else {
            update ( 2 * where + 1 , mid + 1 , IR , pos , val ) ;
        }
        tr[ where ] = merge ( tr[ 2 * where ] , tr[ 2 * where + 1 ] ) ;
    }
    pair < int , int > query ( int where , int IL , int IR , int CURL , int CURR ) {
        if ( IR < CURL || CURR < IL ) { return { 0 , 0 } ; }
        if ( CURL <= IL && IR <= CURR ) { return tr[ where ] ; }
        int mid = ( IL + IR ) / 2 ;
        return merge ( query ( 2 * where , IL , mid , CURL , CURR ) , query ( 2 * where + 1 , mid + 1 , IR , CURL , CURR ) ) ;
    }
};

Tree w ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    sz = (1<<n) ;
    for ( int i = 1 ; i <= sz ; ++ i ) {
        scanf ( "%d" , &a[ i ] ) ;
        a[ i ] *= -1 ;
    }
    sort ( a + 1 , a + sz + 1 ) ;
}

void solve ( ) {
    w.init ( 1 , 1 , sz ) ;
    w.update ( 1 , 1 , sz , 1 , n ) ;
    int en = 0 ;
    for ( int i = 2 ; i <= sz ; ++ i ) {
        while ( a[ en + 1 ] < a[ i ] ) {
            ++ en ;
        }
        pair < int , int > ret = w.query ( 1 , 1 , sz , 1 , en ) ;
        if ( ret.second <= 0 ) { printf ( "No\n" ) ; return ; }
        else {
            w.update ( 1 , 1 , sz , i , ret.second - 1 ) ;
            w.update ( 1 , 1 , sz , ret.first , ret.second - 1 ) ;
        }
    }
    printf ( "Yes\n" ) ;
}

int main ( ) {
    ///freopen ( "in.txt" , "r" , stdin ) ;
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int q,num[100010]={0},A[100010]={0},l,r;
    cin>>q;
    vector<int> prime;
    rep(i,100000) prime.push_back(i+2);
    rep(i,prime.size())for(int j=i+1;j<prime.size();j++) if(prime[j]%prime[i]==0) prime.erase(prime.begin()+j);
    for(auto i:prime) num[i]++;
    rep(i,100000) if((i+2)%2&&num[i+2]&&num[(i+3)/2]) A[i+2]++;
    rep(i,100000) A[i+1]+=A[i];
    rep(i,q) cin>>l>>r,cout<<A[r]-A[l-1]<<endl;
}

Measured memory_bytes: 1912
from itertools import accumulate
from collections import Counter

def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = [0] + list(accumulate(A))
    num = Counter(a)
    lst = set(a)
    cnt = 0
    for i in lst:
        n = num[i] - 1
        cnt += n * (n + 1) // 2
    print(cnt)

main()


Measured memory_bytes: 48148
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  string S;int leng=0,ans=2;
  std::cin >> S;
  leng=S.size();
  while (S.substr(0,(leng-ans)/2)!=S.substr((leng-ans)/2,(leng-ans)/2)){
    ans+=2;
  }
  printf("%d\n",leng-ans);
  return 0;
}


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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  int A=abs(a-x);
  int B=abs(b-x);
if(A<B){
  cout << 'A' << endl;
}else{
  cout << 'B' << endl;
}
  return 0;
}
 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int a[] = new int[M];
		int b[] = new int[M];

		for (int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		int load[] = new int[N];

		for (int i = 0; i < M; i++) {
			for (int j = 0; j < N; j++) {
				if(a[i] == j+1 ) {
					load[j]++;
				}
				if (b[i] == j+1) {
					load[j]++;
				}
			}

		}
		for (int i = 0; i < N; i++) {
			System.out.println(load[i]);
		}
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll h, w, n;cin >> h >> w >> n;
	ll seica = max(h, w);
	cout << (n + seica - 1) / seica << endl;

	return 0;
}


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

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main(){
    int A, B;
    cin >> A >> B;

    int cost = 0;

    if(A >= 13){
        cost = B;
    }else if(A >= 6){
        cost = B / 2;
    }
    cout << cost << endl;
} 

Measured memory_bytes: 256
//2019.7.27 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 1e-10
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
#define Pi 2.0*acos(-1.0)
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG __int128 x){
//    if(x>10)write(x/10);
//    putchar(x%10+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int kcz=1e9+7;
const int N=1e5+10;
namespace MAIN{
    char str[N];
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int Add(const res &x,const res &y){
        return x+y>=kcz?x+y-kcz:x+y;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%13);
    }
    int n;
    int dp[N][13];
    int pw[N];
    inline void MAIN(){
        pw[0]=1;
        scanf("%s",str+1),n=int(strlen(str+1));
        for(res i=1;i<=n;i++)pw[i]=mul(pw[i-1],10);
        dp[0][0]=1;
        for(res i=1;i<=n;i++){
            if(str[i]!='?'){
                for(res j=0;j<=12;j++)dp[i][(j+mul(str[i]-'0',pw[n-i]))%13]=dp[i-1][j];
            }
            else {
                for(res j=0;j<=12;j++)
                    for(res k=0;k<=9;k++)
                        add(dp[i][(j+mul(k,pw[n-i]))%13],dp[i-1][j]);
            }
        }
        printf("%d\n",dp[n][5]);
    }
}
int main(){
//    freopen("compound1.in","r",stdin);
//    freopen("compound.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
int main(){  
  int n,i,j,count=0,minj=0,k,s=0,a=0;
  scanf("%d", &n);
  int A[n];
  
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  for (i = 0;i < n; i++){
    minj = i;
    for (j = i; j < n; j++){
      if (A[j] < A[minj]){
	minj = j;
	}
    }
    if(minj > i){
      s = A[i];
      A[i] = A[minj];
      A[minj] = s;
      count++;
    }
    
    }
  
     for(k=0; k<n; k++){
      printf("%d",A[k]);
      if ( k != n - 1)printf(" ");
    }
     printf("\n%d\n",count);
     return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<stdio.h> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 


char nl = '\n'; 
char bl = ' ';
const int MOD = 1e9 + 7; 

int main(){

ios_base::sync_with_stdio(false);
cin.tie(NULL); 
string s; 
cin >> s; 

if(s[s.length() - 1] == 's'){
    s.push_back('e');
    s.push_back('s'); 
    cout << s; 
}
else{
    s.push_back('s'); 
    cout << s; 
}


}



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

using namespace std;

typedef long long int ll;

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

  int m;
  cin >> m;
  ll sum = 0, num = 0;
  for (int i = 0; i < m; i++) {
    ll d, c;
    cin >> d >> c;
    sum += (d * c);
    num += c;
  }

  ll ans = num - 1 + ((sum - 1) / 9);
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define mkp make_pair
#define pb push_back
const ll INF=1e9;
const ll MAX=1e5+5;
const ll MOD=1e9+7;
//}}}
ll x[MAX],y[MAX];
ll C,c;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a,b;
	cin>>a>>b;
	for(ll i=1;i<=a;i++){
		cin>>x[i];
		x[i]=(x[i]+MOD)%MOD;
	}
	for(ll i=1;i<=b;i++){
		cin>>y[i];
		y[i]=(y[i]+MOD)%MOD;
		c+=y[i]; c%=MOD;
		C+=y[i]*i; C%=MOD;
	}
	c%=MOD; C%=MOD;
	debug(c,C);
	ll ans=0;
	for(ll i=1;i<=a;i++){
		ll r=0;
		r+=(i-1)%MOD*(C-c+MOD)%MOD; r%=MOD;
		r+=MOD-(a-i)%MOD*(C-c+MOD)%MOD; r%=MOD;
		r+=MOD-(i-1)%MOD*(b*c%MOD-C+MOD)%MOD; r%=MOD;
		r+=(a-i)*(b*c%MOD-C+MOD)%MOD; r%=MOD;
		ans+=r*x[i]%MOD;
		ans%=MOD;
	}
	cout<<ans<< '\n';
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  ll ans=0;
  ll pos=0;
  while(pos<n){
    ans++;
    ll r=pos+1;
    while(r<n and a[r-1]<=a[r]){
      r++;
    }
    ll tmp=r;
    r=pos+1;
    while(r<n and a[r-1]>=a[r]){
      r++;
    }
    chmax(tmp,r);
    pos=tmp;
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 1024
def main():
    N, X = map(int, input().split())
    dx = [abs(X - x) for x in map(int, input().split())]
    if N == 1:
        ans = dx[0]
    else:
        ans = 10 ** 9
    for i in range(N - 1):
        nm = dx[i]
        dm = dx[i + 1]
        while True:
            mod = nm % dm
            if mod == 0:
                break
            nm = dm
            dm = mod
        ans = min(ans, dm)
    print(ans)


main()


Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int w;
		
		while (true){
			w = input.nextInt();
			int rs = 0;
			
			if (w == -1){
				break;
			}
			
			if (w <= 10){
				rs = 1150;
			}
			else if (w <= 20){
				rs = 1150 + (w - 10) * 125;
			}
			else if (w <= 30){
				rs = 1150 + 1250 + (w - 20) * 140;
			}
			else if (30 < w){
				rs = 1150 + 1250 + 1400 + (w - 30) * 160;
			}
			
			System.out.println(4280 - rs);
		}
	}
}

Measured memory_bytes: 26140
#include <iostream>

#include <vector>

using namespace std;
#define ll long long

int mod = 1e9+7;

 pair<ll,ll> totalWays(vector<vector<ll>> &tree,ll currentNode, ll parent){

      if(tree[currentNode].size() == 1 && tree[currentNode][0] == parent)
     {
        return {1,1};
     }

     vector<pair<ll,ll>> smallAns;


     for(int i=0;i<tree[currentNode].size();i++){
         if(tree[currentNode][i] == parent)
             continue;
         int child = tree[currentNode][i];

         smallAns.push_back(totalWays(tree,child,currentNode));
     }

//     cout<<"printing smallans array {"<<currentNode+1<<"} "<<endl;
//     for(auto p : smallAns){
//         cout<<p.first<<" "<<p.second<<endl;
//     }

     pair<ll,ll> ans={1,1};

     ll sum =0;
      for(int i=0;i<smallAns.size();i++){
         sum+=(smallAns[i].first+smallAns[i].second)%mod;
         ans.first  = ((ans.first)%mod* sum%mod)%mod;

          sum=0;
     }

     for(int i=0;i<smallAns.size();i++){
         ans.second = (ans.second%mod  * smallAns[i].first%mod)%mod;
     }

     return ans;
 }

int main() {


    int n;
    cin>>n;

    vector<vector<ll>> v(n);


    for (int i = 0; i < n - 1; i++) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        v[x].push_back(y);
        v[y].push_back(x);

     }



//    for(int i=0;i<v.size();i++){
//        cout<<i+1<<" : ";
//        for(int j=0;j<v[i].size();j++){
//            cout<<v[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    pair<ll,ll> ans = totalWays(v,0,-1);
    cout<<(ans.first+ans.second)%mod;

    return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    int n;
    cin >> n;
    int a[1010][1010];

    rep(i, n) rep(j, n - 1) {
        cin >> a[i][j];
        a[i][j]--;
    }

    auto unite = [&](int ti, int tj) {
        if (ti > tj) swap(ti, tj);
        return n * ti + tj;
    };

    int d[1010 * 1010];
    rep(i, 1010 * 1010) d[i] = INF;
    const int start = n * n;
    d[start] = 0;
    vector<int> E[1010 * 1010];
    int edge_in[1010 * 1010] = {};

    rep(i, n) rep(j, n - 2) {
        E[unite(i, a[i][j])].push_back(unite(i, a[i][j + 1]));
        edge_in[unite(i, a[i][j + 1])]++;
    }

    rep(i, n) REP(j, i + 1, n) {
        E[start].push_back(unite(i, j));
        edge_in[unite(i, j)]++;
    }

    queue<int> que;
    que.push(start);
    int visit_cnt[1010 * 1010];

    while (!que.empty()) {
        int q = que.front();
        que.pop();
        for (auto to : E[q]) {
            visit_cnt[to]++;
            if (visit_cnt[to] == edge_in[to]) {
                que.push(to);
                d[to] = d[q] + 1;
            }
        }
    }

    int Max = 0;
    rep(i, n) REP(j, i + 1, n) {
        if (d[unite(i, j)] == INF) finish();
        Max = max(Max, d[unite(i, j)]);
    }
    cout << Max << endl;
    return 0;
}



Measured memory_bytes: 57844
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};


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

  while(1){
    int n, x;
    cin >> n >> x;
    if(n == 0 && x == 0) return 0;
    int cnt = 0;
    for(int i = 1; i <= n-2; i++){
      for(int j = i+1; j <= n-1; j++){
        for(int k = j+1; k <= n; k++){
          if(i+j+k == x) cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 3092