akhauriyash/Code-Regression huggingface dataset:
fun main() {
    val MOD = 998_244_353
    val (n, k) = nextIntList()
    val dp = sizedArray(n, 0L)
    dp[0] = 1
    dp[1] = -1
    val s = (0 until k).map {
        val (l, r) = nextIntList()
        l to r
    }
    repeat(n) { i ->
        if (i > 0) dp[i] = dp[i].plus(dp[i - 1]).rem(MOD)
        s.forEach { (l, r) ->
            if (i + l < n) dp[i + l] = dp[i + l].plus(dp[i]).rem(MOD)
            if (i + r + 1 < n) dp[i + r + 1] = dp[i + r + 1].minus(dp[i]).plus(MOD).rem(MOD)
        }
    }
    println(dp[n - 1])
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 65232
import sys

n, x = [int(x) for x in sys.stdin.readline().split(" ")]
m = [int(sys.stdin.readline()) for i in range(0, n)]

x2 = x
for i in m:
	x2 = x2 - i

m.sort()

y = n + int(x2 / m[0])

print(y)





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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //-freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n;
  cin >> n;

  set <string> st;

  while (n--) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}



Measured memory_bytes: 19212
#include<iostream>
#include<algorithm>
using namespace std;
int k,x;
int main(){
    cin>>k>>x;
    if(k+x>1000000){
        for(int i=x-k+1;i<=1000000;i++){
            if(i==1000000)cout<<i;
            else cout<<i<<" ";
        }
        cout<<endl;
    }
    else if(x-k+1<-1000000){
        for(int i=-1000000;i<=k+x;i++){
            if(i==k+x)cout<<i;
            else cout<<i<<" ";
        }
        cout<<endl;
    }
    else{
        for(int i=x-k+1;i<k+x;i++){
            if(i==k+x-1)cout<<i;
            else cout<<i<<" ";
        }
        cout<<endl;
    }
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0) break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(i==0 || j==0 || i==H-1 || j==W-1) System.out.printf("#");
                    else System.out.printf(".");
                }
                System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 54556
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println(run());
    }

    private static ArrayList<Integer> nScan(Scanner sc, int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            al.add(sc.nextInt());
        }
        return al;
    }

    private static Object run() {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> x = nScan(sc,5);
        sc.close();

        for (int i = 0; i < 5; i++) {
            if (x.get(i) == 0) return i + 1;
        }
        return 0;
    }
}

Measured memory_bytes: 27020
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;

int main(){
    string S, T;
    cin >> S >> T;
    ll ans = MOD;

    rep(i, S.size() - T.size() + 1){
        ll tmp_ans = 0;
        rep(j, T.size()){
            if(S[i + j] != T[j]){
                tmp_ans++;
            }
        }
        ans = min(tmp_ans, ans);
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, A: "List[int]"):
    A = [0] + list(itertools.accumulate(A))
    A = collections.Counter(A)
    s = 0
    for v in A.values():
        s += v*(v-1)//2
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main() {
    int n, p; cin>>n>>p;
    while(n != 0 && p != 0){
        int mp = p;
        vector<int> stone(n, 0);
        bool flag = false;
        while(!flag){
            for(int i=0; i<n; i++){
                if(mp != 0){
                    stone[i]++;
                    mp--;
                    if(stone[i] == p){
                        cout << i << endl;
                        flag = true;
                        break;
                    }
                }else{
                    mp += stone[i];
                    stone[i] = 0;
                }
            }
        }
        cin >> n >> p;
    }
}



Measured memory_bytes: 3088
#include <stdio.h>

int main(void)
{
    int n=0,count=0;
    char string[51]={};
    scanf("%d",&n);
    scanf("%s",string);

    for(int i=0;i<n-2;i++){
        if(string[i]=='A'){
            if(string[i+1]=='B'){
                if(string[i+2]=='C'){
                    count+=1;
                    i+=2;
                }
            }
        }
    }

    printf("%d",count);
    return 0;
}


Measured memory_bytes: 1672
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(8)]
a = 0
for i in range(N):
  if A[i] < 400:
    B[0] = 1
  elif A[i] < 800:
    B[1] = 1
  elif A[i] < 1200:
    B[2] = 1
  elif A[i] < 1600:
    B[3] = 1
  elif A[i] < 2000:
    B[4] = 1
  elif A[i] < 2400:
    B[5] = 1
  elif A[i] < 2800:
    B[6] = 1
  elif A[i] < 3200:
    B[7] = 1
  else:
    a += 1
b = sum(B)
m = b
M = b + a
if b == 0:
  m = 1
print(m, M, sep=' ')

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define flood(arr, char, size) for (int i=0; i<size; i++) arr[i] = char
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 1e5 + 2;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    cout << a[n - 1] - a[0];
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1000000 /* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M /* your task */; }
int h2(int key){ return 1+(key%(M-1)) /* your task */; }

int find(char str[]){
  
  long long key, i, h;

  i = 0;
  key = getKey(str);
  
  while(1){
    i++;
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
  }
  
  return 0;
  
    /* your task */

}

int insert(char str[]){

  long long key, i, h;

  i = 0;
  key = getKey(str);
  
  while(1){
    i++;
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  
  return 0;
  
    /* your task */

}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  int p = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (abs(a[i]) > abs(a[p])) {
      p = i;
    }
  }
  cout << 2 * n - 1 << endl;
  for (int i = 0; i < n; i++) {
    cout << p + 1 << " " << i + 1 << endl;
  }
  if (a[p] < 0) {
    for (int i = n - 1; i >= 1; i--) {
      cout << i + 1 << " " << i << endl;
    }
  } else {
    for (int i = 2; i <= n; i++) {
      cout << i - 1 << " " << i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef complex<double> Point;
const double EPS = 1.0e-9;
const double PI = acos(-1);
namespace std {
    bool operator < (const Point& a, const Point& b){
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
struct Line : public vector<Point> {
    Line(const Point& a, const Point& b){
        push_back(a);
        push_back(b);
    }
};
double cross(const Point& a, const Point& b){
    return imag(conj(a) * b);
}
double dot(const Point& a, const Point& b) {
    return real(conj(a) * b);
}
bool input(vector<Point>& vP){
    rep(i, 3) cin >> vP[i].real() >> vP[i].imag();
    if(cin.eof())
      return false;
    else
      return true;
}
int main(){
    vector<Point> t(3);
    Point p;
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(input(t)){
        cin >> p.real() >> p.imag();
        bool is_IN = false;
        rep(i, 3){
            Point a = t[i] - p, b = t[(i + 1) % 3] - p;
            if(imag(a) > imag(b)) swap(a, b);
            if(imag(a) <= 0 && 0 < imag(b))
              if(cross(a, b) < 0) is_IN = !is_IN;
            if(cross(a, b) == 0 && dot(a, b) <= 0){
                is_IN = true;
                break;
            }
        }
        if(is_IN)
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> A(m);
    for(int i=0;i<m;i++)cin>>A[i];
    auto it = upper_bound(A.begin(), A.end(), x);
    cout<<min(it-A.begin(),A.end()-it)<<endl;
}

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

int main(){
  string A, B;
  cin >> A >> B;
  int judge=0;
  if (A.size() > B.size()) cout << "GREATER" << endl;
  else if (A.size() < B.size()) cout << "LESS" << endl;
  else {
    rep(i, A.size()){
      if (A[i] > B[i]){
        judge = 1;
        break;
      }
      else if (A[i] < B[i]){
        judge = 2;
        break;
      }
      else {
        judge = 3;
      }
    }
    if (judge == 1) cout << "GREATER" << endl;
    else if (judge == 2) cout << "LESS" << endl;
    else if (judge == 3) cout << "EQUAL" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int a,b=0,c=10;
  for(int i=0;i<5;i++){
    cin>>a;
    b+=((a-1)/10+1)*10;
    if(a%10) c=min(c,a%10);
  }
  if(c!=10) b-=10-c;
  cout<<b;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
v1 = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if a[i] > a[j]:
      v1 += 1
v2 = 0      
for i in range(n):
  for j in range(n):
    if a[i] > a[j]:
      v2 += 1

t = v1 * k + v2 * k * (k - 1) // 2
print(t % (10 ** 9 + 7))


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int main() {
    int ans = 0;
    int a,b;
    float t;

    cin >> a>>b>>t;

    t += 0.5f;

    int nowt = 0;
    nowt += a;
    while(nowt < t) {
        ans += b;
        nowt += a;
    }
    
    
    cout << ans << endl;
    return 0;
}

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

map<string,int> prefix;

bool eqorgr10(const string &t){
  if( t.length() > 1 ){
    return t[1]!='.';
  }else return false;
}

bool less1(const string &t){
  return t[0] == '0';
}

int shift_floatp(string &t){
  int ret = 0;
  if( eqorgr10(t) ){
    while(eqorgr10(t)){
      ++ret;
      unsigned int pos = t.find('.');
      if( pos != string::npos ){
	swap(t[pos-1],t[pos]);
	if( t[0] == '.' ) t.insert(t.begin(),'0');
      }else{
	t.insert(t.end()-1,'.');
      }
    }
  }else if(less1(t)){
    while(less1(t)){
      --ret;
      unsigned int pos = t.find('.');
      if( pos != string::npos ){
	swap(t[pos],t[pos+1]);
	t.erase(t.begin());
      }
    }
  }
  if(t[(int)t.length()-1]=='.'){
    t.erase(t.end()-1);
  }
  return ret;
}

int main()
{
  prefix["yotta"] = 24;
  prefix["zetta"] = 21;
  prefix["exa"] = 18;
  prefix["peta"] = 15;
  prefix["tera"] = 12;
  prefix["giga"] = 9;
  prefix["mega"] = 6;
  prefix["kilo"] = 3;
  prefix["hecto"] = 2;
  prefix["deca"] = 1;
  prefix["deci"] = -1;
  prefix["centi"] = -2;
  prefix["milli"] = -3;
  prefix["micro"] = -6;
  prefix["nano"] = -9;
  prefix["pico"] = -12;
  prefix["femto"] = -15;
  prefix["ato"] = -18;
  prefix["zepto"] = -21;
  prefix["yocto"] = -24;
  int T;
  cin >> T;
  for(int tc=1;tc<=T;++tc){
    int b=0;
    string a;
    string pre;
    string unit;
    cin >> a >> pre;
    if( prefix.find(pre) != prefix.end() ){
      cin >> unit;
    }else{
      unit = pre;
      pre = "";
    }
    b += prefix[pre] + shift_floatp( a );
    cout << a << ' ' << "* 10^" << b << ' ' << unit << endl;
    
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define de(x) cout << #x << " = " << x << endl
#define dd(x) cout << #x << " = " << x << " "
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pw(x) (1ll << (x))
#define endl '\n'
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;

const ll inf = 1e18;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	int n; cin >> n;
	__int128 ans = 1;
	bool ok = 1;
	bool z = 0;
	rep(i, 1, n + 1) {
		ll x; cin >> x;
		if(ans * x > inf) ok = 0;
		if(!x) z = 1;
		ans *= x;
	}
	if(z) {
		cout << 0 << endl;
		return 0;
	}
	if(!ok) {
		cout << -1 << endl;
		return 0;
	}
	vi res;
	while(ans) res.pb(ans % 10), ans /= 10;
	if(!sz(res)) res.pb(0);
	reverse(all(res));
	for(auto u : res) cout << u; cout << endl;
	return 0;
}


Measured memory_bytes: 3656
x, y = map(int, input().split())

px = 0
if x >= 0:
    px = 1
    
py = 0
if y >= 0:
    py = 1

x = abs(x)
y = abs(y)
ans = max(x,y) - min(x,y)
if x == 0 and py or px == 0 and y == 0:
    pass
elif px and py:
    if y == 0:
        ans += 1
    elif x > y:
        ans += 2
elif px or py:
    ans += 1
else:
    if x < y:
        ans += 2
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair<int, int>>PP;
typedef long long ll;
ll inf = -1;

int main() {
	int n; cin >> n;
	int u, v, w;
	vector<vector<int>>grid(n),cost(n);
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v >> w;
		u--; v--;
		grid[u].push_back(v);
		grid[v].push_back(u);
		cost[u].push_back(w);
		cost[v].push_back(w);
	}
	vector<int> ans(n,inf);
	queue<int>que;
	ans[0] = 0;
	que.push(0);
	while (que.empty() == false) {
		int V = que.front();
		que.pop();
		for (int i = 0; i < grid[V].size(); i++) {
			if (ans[grid[V][i]] != -1) {
				continue;
			}
			ans[grid[V][i]] = (ans[V] + cost[V][i]) % 2;
			que.push(grid[V][i]);
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, k;
  cin >> n >> k;
  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  vector<ll> psum{0};
  partial_sum(va.begin(), va.end(), back_inserter(psum));
  transform(psum.begin(), psum.end(), psum.begin(),
            [&](ll a) { return a % k; });

  map<int, int> cnt;
  ll ans = 0;
  auto msub = [](int a, int b, int md) { return ((a - b) % md + md) % md; };
  for (int i = 0; i < psum.size(); ++i) {
    int x = msub(psum[i], i, k);
    ans += cnt[x];
    cnt[x]++;
    if (i - k + 1 >= 0) {
      int y = msub(psum[i - k + 1], i - k + 1, k);
      cnt[y]--;
    }
  }

  cout << ans << '\n';
}

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

bool lun(string n){
    int len = n.length();
    for(int i=1;i<len;i++){
        if(abs(n[i]-n[i-1]) > 1) return false;
    }
    return true;
}

string nxt(string n){
    int len = n.length();
    for(int i=len-2;i>=0;i--){
        if(n[i]+1 != n[i+1] && n[i+1] != '9'){
            n[i+1] += 1;
            for(int j=i+2;j<len;j++){
                if(n[j-1] == '0') n[j] = '0';
                else n[j] = n[j-1]-1;
            }
            return n;
        }
    }
    if(n[0] == '9') n = '1' + string(len, '0');
    else{
        n[0]++;
        for(int i=1;i<len;i++){
            if(n[i-1] == '0') n[i] = '0';
            else n[i] = n[i-1]-1;
        }
    }
    return n;
}

int main(void){
    int k;
    string n = "10";
    cin >> k;
    if(k <= 10){
        cout << k << endl;
        return 0;
    }
    for(int i=10;i<k;i++){
        // cout << n << endl;
        n = nxt(n);
    }
    cout << n << endl;
}


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

int next_n(int n) {
  int maximum = -1;
  for (int p = 1; pow(10, p) < n; p++) {
    int base = pow(10, p),
        right = n % base,
        left = (n - right) / base;
    maximum = max(maximum, right * left);
  }
  return maximum;
}

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

    int count = 0;
    while (N > 9) {
      N = next_n(N);
      count++;
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int w,h;
ll p[1000000],q[1000000];
ll ans;
ll a,b;

int main(){
  cin>>w>>h;
  rep(i,w){
    cin>>p[i];
  }
  rep(i,h){
    cin>>q[i];
  }
  sort(p,p+w);
  sort(q,q+h);

  for(ll i=0;i<h+w;i++){
    if(a<w&&p[a]<q[b]||b==h){
      ans+=p[a]*(h+1-b);
      a++;
    }
    else{
      ans+=q[b]*(w+1-a);
      b++;
    }
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int xv[4] = {1,1,-1,-1};
int yv[4] = {1,-1,-1,1};

int main() {
	int K;
	cin >> K;
	vector<int> X(K), Y(K);
	rep(i,K) {
		cin >> X[i] >> Y[i];
	}
	vector<int> perm(8);
	rep(i,8) perm[i] = i;
	vector<vector<bool> > B(8,vector<bool>(8));
	vector<int> ans(8);
	do {
		//rep(i,8) fill(B[i].begin(), B[i].end(), true);
		bool flag = true;
		rep(i,K) if(perm[X[i]] != Y[i]) flag = false;
		if(!flag) continue;
		rep(i,8) {
			//if(!B[i][perm[i]]) flag = false;
			//if(!flag) break;
			rep(j,4) {
				//B[i][perm[i]] = true;
				int x = i, y = perm[i];
				while(x >= 0 && x <= 7 && y >= 0 && y <= 7) {
					rep(k,8) if((x == k && y == perm[k]) && (x != i && y != perm[i])) {
						flag = false;
						//rep(p,8) cout << perm[p] << " ";
						//cout << endl;
						//cout << i << " " << perm[i] << " " << j << " " << x << " " << y << endl;
					}
					/*if(B[x][y]) B[x][y] = false;
					else {
						rep(i,8) cout << perm[i] << " ";
						cout << endl;
						cout << i << " " << perm[i] << " " << j << " " << x << " " << y << endl;
						flag = false;
					}*/
					x += xv[j];
					y += yv[j];
					if(!flag) break;
				}
				if(!flag) break;
			}
			if(!flag) break;
		}
		if(flag) {
			break;
		}
	} while (next_permutation(perm.begin(), perm.end()));
	rep(i,8) {
		rep(j,8) {
			if(perm[i] == j) cout << 'Q';
			else cout << '.';
		}
		cout << endl;
	}
	

  return 0;
}


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


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

string s;
cin>>s;
ll ans=0;
for(int i=0;i<s.size();i++)
{
    ans+=(s[i]-'0');
}
if(ans%9==0)
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}

return 0;
}


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

int main(int argc, char** argv)
{
   int N;
   int W[110];
   int S1=0;
   int S2=0;
   int sum = 0;
   int min;

   std::cin >> N ;
   for(int i=0; i<N; i++){
      std::cin >> W[i];
      sum += W[i];

   }

   min = sum;
   for(int T=1;T<=N;T++){
      S1 = 0;
      for(int j=0; j<T; j++){
         S1 += W[j];

      }
      //std::cout << "S1:" << S1 <<std::endl;
     // std::cout << "abs" << std::abs(2*S1 - sum) << std::endl;
      if(std::abs(2*S1 - sum) < min){

         min= std::abs(2*S1 - sum);

      }
   }

   std::cout << min << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    string str;
    cin >> str;
    REP(i,0,str.L)
    {
        if (i % 2 == 0 && str[i] == 'L')
        {
            cout << "No";
            return 0;
        }
        if (i % 2 == 1 && str[i] == 'R')
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}


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++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  ll N, A, B; cin >> N >> A >> B;
  ll result = ((N>=2&&A<B)||(A==B)) ? (N-2) * (B-A) + 1 : 0;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i + k - 1 <= n) ans++;
    }
    cout << ans << 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 all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int a, b, c;
    cin >> a >> b >> c;

    bool ok = false;
    for (int i = 1; i <= b; ++i) {
        if(i*a % b == c){
            ok = true;
        }
    }

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
int MOD=1e9+7;
char ar[1001][1001];
int a[1001][1001]={-1};

long long find (int i,int j,int h,int w)
{   
	if (a[i][j]!=-1)
	    return a[i][j];
	if (ar[i][j]=='#')
		a[i][j]=0;
	else if (i==h && j==w)
		a[i][j]=1;
	else if (i==h)
		a[i][j]=find(i,j+1,h,w);
	else if (j==w)
		a[i][j]=find(i+1,j,h,w);
	else
		a[i][j]=(find(i+1,j,h,w)+find(i,j+1,h,w))%MOD;
	return a[i][j];
}
signed main()
{
   faster;
  // #ifndef ONLINE_JUDGE
    // freopen("ip.txt", "r", stdin);
     //freopen("op.txt", "w", stdout);
   //#endif
     //int t;cin>>t;
     //while(t--)
     {
        
     	int h,w;
     	cin>>h>>w;
     	for (int i=1;i<=h;i++)
     		for (int j=1;j<=w;j++)
     			cin>>ar[i][j] , a[i][j]=-1;
     	cout<<find(1,1,h,w)<<endl;
     				//cout<<a[4][5]<<endl;
     }
}

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

using namespace std;
typedef long long ll;

ll mod = 1e9 + 7;

vector<ll> fact;

void init_fact(int n) {
    fact = vector<ll>(n);
    fact[0] = 1;
    for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % mod;
}

ll calc_pow(ll x, ll pow) {
    if (pow <= 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % mod;
    if (pow % 2 == 1) a *= x;
    return a % mod;
}

ll calc_div(ll a, ll b) {
    return a * calc_pow(b, mod - 2) % mod;
}

int main() {
    init_fact(1000000);

    int n;
    cin >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++)cin >> c[i];
    sort(c.begin(), c.end(), greater<>());

    ll ret = 0;
    for (int i = 0; i < n; i++) {
        ll now = calc_pow(2, i) * (i + 2);
        now %= mod, now = calc_div(now, 2);
        now *= calc_pow(2, n - 1 - i), now %= mod;

        now *= c[i], now %= mod;
        ret += now, ret %= mod;
    }

    ret *= calc_pow(2, n), ret %= mod;
    cout << ret << endl;
    return 0;
}

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

using namespace std;

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

    int num ;
    string s1  , s2 , temp ;
    cin>>num>>s1>>s2 ;
    for(int i=num ; i>=0 ; i--){
        temp=s2.substr(0,i) ;
        if(s1.find(temp)!=-1){
            cout<<2*(num-i)+i<<endl;
            return 0 ;
        }
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, p int
	fmt.Scan(&a, &b)
	p = a
	var cnt int
	if b > 1 {
		cnt++
		for a < b {
			a = a - 1 + p
			cnt++
		}
	}
	fmt.Println(cnt)
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] a = in.nextIntArray(3);

            out.println((a[0] + a[1] >= a[2]) ? "Yes" : "No");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

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

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

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

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

    }
}



Measured memory_bytes: 23508
#include<stdio.h>

int main(){
  int i,j,n,a,b,c,temp=0;
  
  scanf("%d %d %d", &a, &b, &c);
  
  for(i=0;i<1;i++){
      temp=a;
      a=b;
      b=temp;
      
      temp=a;
      a=c;
      c=temp;
    
  }
  
  printf("%d %d %d", a, b, c);
  
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<iostream>
#include<string>
using namespace std;
int main()
{
	priority_queue<long long>q;
	int m,n,op;
	long long sum=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
    {
		cin>>op;
		q.push(op);
	}
	while(m--)
	{
		op=q.top()/2;
		q.pop();
		q.push(op);
	}
	while(!q.empty())
	{
		sum+=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}



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

void trace(int A[], int N){
    int i;
    for(i = 0; i < N; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << "" << endl;
}

void insertionSort(int A[], int N){

    for(int i = 1; i < N; i++){
        int v = A[i];
        int j = i - 1;

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

        A[j+1] = v;
        trace(A, N);
    }
}

int main(void){
    
    int A[100], n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    trace(A, n);
    insertionSort(A, n);

    return 0;
    
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> strVec(n);
  for (int i = 0; i < n; i++) {
    cin >> setw(l) >> strVec[i];
  }
  sort(strVec.begin(), strVec.end());
  string res = "";
  for (int i = 0; i < n; i++) {
    res = res + strVec[i];
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x=0,y=0;
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<n; i++){
        if(s[i]=='R')x++;
        else y++;
    }
    if(x>y)cout<<"Yes";
    else cout<<"No";

}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <vector>
#include <bitset>
#include <string>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <climits>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#define itn int
#define scnaf scanf
#define pritnf printf
using namespace std;
typedef long long LL;
typedef long double LD;
int main () {
    string s;
    cin >> s;
    string t = s;
    reverse (t.begin (), t.end ());
    for (string::iterator it = t.begin (); it != t.end (); ++it) {
        switch (*it) {
            case 'b':
                *it = 'd';
                break;
            case 'd':
                *it = 'b';
                break;
            case 'p':
                *it = 'q';
                break;
            case 'q':
                *it = 'p';
                break;
        }
    }
    if (s == t) {
        printf ("Yes");
    }
    else {
        printf ("No");
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <set>

int main() {

        int n;
        std::cin >> n;
        std::vector<std::string> words(n);

        for (auto& w : words) {
                std::cin >> w;
        }

        for (auto i = 0; i < words.size() - 1; ++i) {
                if (words[i].back() != words[i + 1].front()) {
                        std::cout << "No" << std::endl;
                        return 0;
                }
        }

        std::set<std::string> words_set;
        for (auto& w : words) {
                words_set.insert(w);
        }

        if (words.size() != words_set.size()) {
                std::cout << "No" << std::endl;
        }
        else {
                std::cout << "Yes" << std::endl;
        }

        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000000;

int main(){
  long long n;

  cin >> n;

  vector<long long>lucas = vector<long long>(n + 1);

  REP(i,n+1){
    if (i == 0) {
      lucas[i] = 2;
      continue;
    }
    if (i == 1) {
      lucas[i] = 1;
      continue;
    }
    lucas[i] = lucas[i - 1] + lucas[i - 2];
  }

  cout << lucas[n] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  
  long long n;
  cin>>n;
  long long ans;
  ans = n*(n-1)/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
s = list(map(str, input()))

pm = ["+", "-"]

for op_1 in pm:
    for op_2 in pm:
        for op_3 in pm:
            formula = s[0]+op_1+s[1]+op_2+s[2]+op_3+s[3]
            if eval(formula) == 7:
                print(formula+"=7")
                exit()
            

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7ll;

int n;
int a[205];
int cnt;

int main(){

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

cin>>n;

for(int i=0; i<n; i++){
  cin>>a[i];
}

for(int i=0; i<100; i++){
  for(int j=0; j<n; j++){
    if(a[j]%2){
      cout<<cnt<<endl;
      return 0;
    }else{
      a[j]/=2;
    }
  }
  cnt++;
}

}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut changes = vec![(0, 0); m];
    for i in 0..m {
        changes[i].1 = read::<usize>();
        changes[i].0 = read::<usize>();
    }
    seq.sort();
    changes.sort();
    changes.reverse();
    let mut pos = 0;
    let mut ans = 0;
    for i in 0..m {
        for _j in 0..changes[i].1 {
            let v = changes[i].0;
            if pos == n {
                break;
            }
            if seq[pos] < v {
                ans += v;
                pos += 1;
            } else {
                break;
            }
        }
    }
    for i in pos..n {
        ans += seq[i];
    }
    println!("{}", ans);
}


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

#define int long long

int N, M;

bool check(int n) {
   // 約数nをN-1個取ると、最後のひとつはMこの式になる
   int lastOne = M - (n * (N-1));
   // 最後のひとつが0より大きく、nの倍数であるならOK
   if (lastOne > 0 && lastOne % n == 0) {
      return true;
   }
   return false;
}

signed main() {
   cin >> N >> M;

   int ans = 1;
   // i, jはMの約数
   for (int i = 1; i*i <= M; i++) {
      if (M % i != 0) continue;

      int j = M / i;
      if (check(i)) {
         ans = max(ans, i);
      }
      if (check(j)) {
         ans = max(ans, j);
      }
   }

   cout << ans << endl;

   return 0;
}

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

using namespace std;

int main() {

	string s;
	cin>>s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	
	return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const ll INF = LONG_LONG_MAX / 2;

// points larger than or equal to 0.
vector<int> ps;
// points smaller than zero.
vector<int> ms;

ll solve(const int N, const int K) {
    // maybe int is enough...
    ll ans = INF;

    for (int num_of_ps = 0; num_of_ps <= K; num_of_ps++) {
        int num_of_ms = K - num_of_ps;
        if (num_of_ps > (int) (ps.size() - 1) || num_of_ms > (int) (ms.size() - 1)) {
            continue;
        }

        // printf("num_of_ps: %d, num_of_ms: %d\n", num_of_ps, num_of_ms);

        // p -> m
        {
            ll cand = 0;
            cand += ps[num_of_ps];
            if (num_of_ms > 0) {
                cand += ps[num_of_ps] - ms[num_of_ms];
            }
            // printf("p->m: %lld\n", cand);
            chmin(ans, cand);
        }

        // m -> p
        {
            ll cand = 0;
            cand += abs(ms[num_of_ms]);
            if (num_of_ps > 0) {
                cand += ps[num_of_ps] - ms[num_of_ms];
            }
            // printf("m->p: %lld\n", cand);
            chmin(ans, cand);
        }
    }

    return ans;
}

int main(void) {
    int N, K;
    cin >> N >> K;

    ps.push_back(0); // dummy
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        if (x >= 0) {
            ps.push_back(x);
        } else {
            ms.push_back(x);
        }
    }
    ms.push_back(0); // dummy
    reverse(ms.begin(), ms.end());

    cout << solve(N, K) << endl;

    return 0;
}


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	if(k == 0){
		ans = (ll) n * n;
	}else{
		for(int i = 1; i <= n; i++){
			if(i > k){
				ans += (ll) (n / i) * (i - k);
				ans += max(0, (n % i) - k + 1);
			}
			// cout << i << " " << ans << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256