akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
	int A,B,C;
	cin >> A >> B >> C;
  	if((A == 7 && B == 5 && C == 5) || (A == 5 && B == 7 && C == 5) || (A == 5 && B == 5 && C == 7) ){
     cout << "YES" << endl; 
    }else{
      cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
 
int main(){
    string S, S_; ll K; cin >> S >> K;
    S_ = S;
    ll ans = 0;
    if((S.size() * K)%2 == 1){
        bool flag = true;
        for(int i = 1; i < S.size(); i++) if(S[i-1] != S[i]) flag = false;
        if(flag){
            cout << (ll)((ll)S.size() * K) / 2 << endl;
            return 0;
        }
    }
    for(int i = 1; i < S.size(); i++){
        if(S[i-1] == S[i]) { S[i] = '*'; ans++;}
    }
    ans = ans * K;
    if(S[0] == S[S.size()-1]) {
        string temp1={S[0]}, temp2 = {S[S.size()-1]};
        int i = 0, j = S.size()-1;
        //cout << S[i] << " " << S[i+1] << endl;
        while(S_[i] == S_[i+1]){temp1+=S[i+1]; i++;}
        while(S_[j] == S_[j-1]){temp2+=S[i+1]; j--;}
        if((temp1.size() + temp2.size()) % 2 == 0) ans+= K-1;
        //cout << temp1.size() << " " << temp2.size() << endl;
        //ans += K-1;
    }
    cout << ans << endl;
 
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int l, r;
  int min = 2018;
  scanf("%d%d", &l, &r);
  
  if (r-l >= 2019) {
    puts("0");
    return 0;
  }
  
  l %= 2019;
  r %= 2019;
  if (l > r) {
    puts("0");
    return 0;
  }
  
  for (int i = l; i < r; i++)
    for (int j = i+1; j <= r; j++) {
      int f = (i * j + 2019 * 2018) % 2019;
      if (min > f) min = f;
    }
  
  printf("%d", min);
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main(void){
    
    int x,n;
    scanf("%d %d",&x,&n);
    
    int p[101]={0};
    
    for(int i=1;i<=n;i++){
    scanf("%d",&p[i]);
    }
    int tmp;
    
    for (int i=1; i<=n; ++i) {
        for (int j=i+1; j<=n; ++j) {
              if (p[i] > p[j]) {
               tmp =  p[i];
              p[i] = p[j];
              p[j] = tmp;
             }
        }
    }
    
    for (int i=1; i<=n; i++) {
        if(x<p[i]){
        printf("%d",x);
        return 0;
        }
        
        if(x==p[i]){
            for(int j=1;j<i;j++){
             if(p[i-j]!=x-j){
                printf("%d",x-j);
                return 0;
             }   
             if(p[i+j]!=x+j){
                printf("%d",x+j);
                return 0;
             }     
            }
                printf("%d",x-i);
                return 0;
        }
    }
    
    printf("%d",x);
    return 0;
}

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


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int x;
  cin >> x;
  if (x >= 30) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(void)
{
	int k, n, x, y;
	int i, a;
	
	scanf("%d", &n);
	scanf("%d", &k);
	scanf("%d", &x);
	scanf("%d", &y);
	
	a = 0;
	for (i = 0; i < n; i++){
		if(i < k){
			a += x;
		}
		else {
			a += y;
		}
	}
	
	printf("%d\n", a);
	
	return (0);
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	char a[10], b[10], c[10];
	scanf("%s%s%s", a, b, c);

	int i, j;
	for (i = 0; a[i] != '\0'; i++) {
		;
	}
	for (j = 0; b[j] != '\0'; j++) {
		;
	}

	if (a[i-1] == b[0] && b[j-1] == c[0]) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; ++i)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
using namespace std;
 
#define int long long



signed main(){
	
	int n;
	cin>>n;

	string tmp;
	int m=0,a=0,r=0,c=0,h=0;

	REP(i,n){
		
		cin>>tmp;

		//march

		if(tmp[0]=='M'){
			m++;
		}else if(tmp[0]=='A'){
			a++;
		}else if(tmp[0]=='R'){
			r++;
		}else if(tmp[0]=='C'){
			c++;
		}else if(tmp[0]=='H'){
			h++;
		}
	}

	int ans=0;


	// cout<<m<<a<<r<<c<<h<<endl;
	// cout<<endl;

	REP(i,2){
		REP(j,2){
			REP(k,2){
				REP(l,2){
					REP(o,2){
						
						int sum=i+j+k+l+o;
						if(sum==3){
							

							int tmp=1;

							if(i)tmp*=m;
							if(j)tmp*=a;
							if(k)tmp*=r;
							if(l)tmp*=c;
							if(o)tmp*=h;

							ans+=tmp;


						}						
					}
				}	
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
count = {}
n.times do |i|
  count[i+1] = 0
end
m.times do |i|
  a, b = gets.split.map(&:to_i)
  count[a] += 1
  count[b] += 1
end
n.times do |i|
  puts count[i+1]
end


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

//#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX


int main(){
    int x,a,t;
    cin>>x>>a;
    if (x<a){
        t=0;
        cout<<t<<endl;
    }
    else{
        t=10;
        cout<<t<<endl;
    }
}

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

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


int main() {
	int n;
	cin >> n;
	int A[n];
	rep(i, n) cin >> A[i];
	int odd_cnt = 0;
	int quad_cnt = 0;
	rep(i, n) {
		if (A[i]%4==0) quad_cnt++;
		if (A[i]%2==1) odd_cnt++;
	}
	if (quad_cnt>=n/2) {
		cout << "Yes" << endl;
		return 0;
	}
	if (quad_cnt >= odd_cnt) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int q = scan.nextInt();
		DisjointSet ds = new DisjointSet(n);

		for(int i = 0; i < q; i++) {
			int com = scan.nextInt();
			int x = scan.nextInt();
			int y = scan.nextInt();
			if(com == 0) {
				ds.unite(x, y);
			}else if(com == 1) {
				if(ds.same(x, y)) {
					System.out.println(1);
				}else {
					System.out.println(0);
				}
			}
		}
		scan.close();
	}
	static class DisjointSet {
        int[] p;
        int[] rank;
        int[] size;
        DisjointSet(){}
        DisjointSet(int size){
            this.rank = new int[size];
            this.p = new int[size];
            this.size = new int[size];
            for(int i = 0; i < size; i++) {
                makeSet(i);
            }
        }
        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
            size[x] = 1;
        }
        boolean same(int x, int y) {
            return findSet(x) == findSet(y);
        }
        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }
        void link(int x, int y) {
            if(rank[x]  > rank[y]) {
                p[y] = x;
                size[x] = size[x] + size[y];
            }else if(rank[x] < rank[y]){
                p[x] = y;
                size[y] = size[x] + size[y];
            }else if(x != y) {
            	p[y] = x;
            	rank[x]++;
            	size[x] = size[x] + size[y];
            }
        }
        int findSet(int x) {
            if(x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
        int size(int x) {
        	if(x != p[x]) {
        		size[x] = size(findSet(x));
        	}
        	return size[x];
        }
    }
}


Measured memory_bytes: 101460
#include <stdio.h>

int main()
{
    int m, f, r;
    do
    {
        scanf("%d %d %d", &m, &f, &r);
        if (m != -1 || f != -1 || r != -1)
        {

            if (m == -1 || f == -1)
            {
                printf("F\n");
            }
            else if (m + f >= 80)
            {
                printf("A\n");
            }
            else if (m + f >= 65)
            {
                printf("B\n");
            }
            else if (m + f >= 50)
            {
                printf("C\n");
            }

            else if (m + f >= 30 )
            {
                if (r >= 50)
                {
                    printf("C\n");
                }
                else
                {
                    printf("D\n");
                }
            }
            else
            {
                printf("F\n");
            }
        }
     } while (m != -1 || f != -1 || r != -1);

        return 0;
    }
    


Measured memory_bytes: 2112
N, = map(int, input().split())
from collections import defaultdict
D = defaultdict(lambda : defaultdict(list))
D2 = defaultdict(lambda : defaultdict(list))

def Fm(d1, d2):
    alist = D[d1]
    blist = D[d2]
    R = 10**18
    for key in alist:
        if key not in blist:
            continue
        A, B = alist[key], blist[key]
        X=sorted(A+B, key=lambda x:x[0])
        for a, b in zip(X, X[1:]):
            if a[2] != b[2] and (a[2] == "R" or a[2] == "D"):
                R = min(R, 10*(b[0]-a[0]))
    return R

def Fm2(d1, d2):
    alist = D2[d1]
    blist = D2[d2]
    R = 10**18
    for key in alist:
        if key not in blist:
            continue
        A, B = alist[key], blist[key]
        X=sorted(A+B, key=lambda x:x[0])
        for a, b in zip(X, X[1:]):
            if a[2] != b[2] and (a[2] == "R" or a[2] == "U"):
                R = min(R, 10*(b[0]-a[0]))
    return R


Dx = defaultdict(list)
Dy = defaultdict(list)
for _ in range(N):
    x, y, d = input().split()
    x, y = int(x), int(y)
    D[d][x+y].append((x, y, d))
    D2[d][x-y].append((x, y, d))
    if d in {"R", "L"}:
        Dx[y].append((x, d))
    else:
        Dy[x].append((y, d))

R = 10**18
for key in Dx:
    X = sorted(Dx[key])
    for (x, d), (xx, d2) in zip(X, X[1:]):
        if d == "R" and d2 == "L":
            R = min(R, (xx-x)*5)
for key in Dy:
    X = sorted(Dy[key])
    for (x, d), (xx, d2) in zip(X, X[1:]):
        if d == "U" and d2 == "D":
            R = min(R, (xx-x)*5)

R = min(R, Fm("D", "L"))
R = min(R, Fm("U", "R"))
R = min(R, Fm2("D", "R"))
R = min(R, Fm2("U", "L"))
if R != 10**18:
    print(R)
else:
    print("SAFE")
#for key in D["R"]:
#    if key not in D["U"]:
#        continue
#    print(D["R"][key], D["U"][key])
#for key in D["D"]:
#    if key not in D["L"]:
#        continue
#    print(D["D"][key], D["L"][key])


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

void output(int A[], int N)
{
    for( int loop = 0;loop < N;loop++ )
    {
        if(loop != 0)
        {
            cout << " ";
        }
        cout << A[loop];
    }
    cout << endl;
    return;
}

void insertionSort(int A[], int N)
{
    output(A,N);
    int v;
    int j;
    for( int i = 1; i <= N-1; i++ )
    {
        v = A[i];
        j = i - 1;
        while( (j >= 0) && (A[j]>v) )
        {
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        output(A,N);
    }
    return;
}

int main(void){
    string maxNumSentence="";
    int input[1000];
    int rows;
    
    cin >> rows;
    int inputNum = 0;
    while( cin >> input[inputNum] )
    {
        inputNum++;
    }
    
    insertionSort(input,rows);
    return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD=1000000007;
//Ax=bをとくAは正方行列
//rankA<=min(m,n)ならば配列０のvecが帰る
int main(){
  int N,M,A[1004];
  cin >> N >> M;
  int cnt =0;
  vector<int> odd;
  rep(i,M){
    cin >> A[i];
    if(A[i]&1){
      cnt++;
      odd.push_back(i);
    }
  }
  vector<int>a,b;
  if(M==1){
    a.push_back(1);
    a.push_back(A[0]-1);
    b.push_back(A[0]);
  }
  else if(M==2){
    a.push_back(A[0]-1);
    a.push_back(A[1]+1);
    b.push_back(A[0]);
    b.push_back(A[1]);
  }else {
    if(cnt>2){
      cout<<"Impossible"<<endl;
      return 0;
    }
    else if(cnt!=0) {
      a.push_back(A[odd[0]]-1);
      b.push_back(A[odd[0]]);
      rep(i,M){
        if(i!=odd[0]&&i!=odd[1]){
          b.push_back(A[i]);
          a.push_back(A[i]);
        }
      }
      a.push_back(A[odd[1]]+1);
       b.push_back(A[odd[1]]);
    }
    
    else{
      rep(i,M){
        a.push_back(A[i]);
        b.push_back(A[i]);
      }
      a[0]++;
      a[M-1]--;
    }
  }
  vector<int>c;
  rep(i,a.size()){
    if(a[i]!=0)c.push_back(a[i]);
  }
  rep(i,b.size())cout<<b[i]<<' ';
  cout<<endl;
  cout<<c.size()<<endl;
  rep(i,c.size())cout<<c[i]<<' ';
  cout<<endl;
} 


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

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let(a, b, m) = input_tuple();
    let mut a_vec = input_vec();
    let mut b_vec = input_vec();
    let mut x_vec: Vec<usize> = Vec::new();
    let mut y_vec: Vec<usize> = Vec::new();
    let mut c_vec: Vec<u64> = Vec::new();
    for _ in 0..m {
        let (x, y, c) = input_tuple();
        x_vec.push((x - 1) as usize);
        y_vec.push((y - 1) as usize);
        c_vec.push(c);
    }

    let mut min = 1_000_000;
    for i in 0..m as usize {
        let sum = a_vec[x_vec[i]] + b_vec[y_vec[i]] - c_vec[i];
        // println!("sum = {}", sum);
        if sum < min {
            min = sum;
        }
    }
    a_vec.sort();
    b_vec.sort();
    if a_vec[0] + b_vec[0] < min {
        min = a_vec[0] + b_vec[0];
    }
    println!("{}", min);

}


Measured memory_bytes: 14580
import java.io.*;
import java.math.*;
import java.util.*;
@SuppressWarnings("Duplicates")
// author @mdazmat9
public class Main{
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        int test = 1;
        //test=sc.nextInt();
        for (int ind = 0; ind < test; ind++) {
            solve();
        }
        out.flush();
    }
    static void solve(){
        int a=sc.nextInt();
        int b=sc.nextInt();

        int num=1,count=0;
        while (num<b){
            count++;
            num+=(a-1);
        }
        out.println(count);

    }







    static int[] intarray(int n){ int [] a=new int[n];for(int i=0;i<n;i++)a[i]=sc.nextInt();return a; }
    static long[] longarray(int n){ long [] a=new long[n];for(int i=0;i<n;i++)a[i]=sc.nextLong();return a; }
    static ArrayList<Integer> intlist(int n){ArrayList<Integer> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextInt());return list; }
    static ArrayList<Long> longlist(int n){ArrayList<Long> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextLong());return list; }
    static int[][] int2darray(int n,int m){ int [][] a=new int[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextInt(); } }return a; }
    static long[][] long2darray(int n,int m){ long [][] a=new long[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextLong(); } }return a; }
    static char[][] char2darray(int n,int m){ char [][] a=new char[n][m];for(int i=0;i<n;i++){ String s=sc.next(); a[i]=s.toCharArray(); }return a; }

    static double pi=3.14159265358979323846264;
    public static double logb( double a, double b ) {return Math.log(a) / Math.log(b); }
    static long fast_pow(long a, long b,long abs) {
        if(b == 0) return 1L;
        long val = fast_pow(a, b / 2,abs);
        if(b % 2 == 0) return val * val % abs;
        else return val * val % abs * a % abs;
    }
    static long abs = (long)1e9 + 7;
    static   void shuffle(int[] a) { int n = a.length;for(int i = 0; i < n; i++) { int r = i + (int) (Math.random() * (n - i));int tmp = a[i];a[i] = a[r];a[r] = tmp; } }
    static long gcd(long a , long b) {
        if(b == 0) return a;
        return gcd(b , a % b);
    }
}

class Scanner {
    public BufferedReader reader;
    public StringTokenizer st;
    public Scanner(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }
    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            } catch (Exception e) {
                throw (new RuntimeException());
            }
        }
        return st.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n,k;
    cin>>n>>k;
    ll ans=0,left=0,right=0,rc=n;
    for(ll i=0;i<k;i+=1LL)
    {
        left+=i;
        right+=rc;
        left%=MOD;
        right%=MOD;
        rc-=1LL;
    }
    ans+=(MOD+right-left+1LL)%MOD;
    for(int i=k+1;i<=n+1;i++)
    {
        left+=i-1LL;
        right+=rc;
        left%=MOD;
        right%=MOD;
        rc-=1LL;
        ans+=(MOD+right-left+1LL)%MOD;
        ans%=MOD;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3652
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
w = na()
a = sum(w)
ans = 10000000000

for i in range(1,n):
    w[i] = w[i-1]+w[i]
    ans = min(ans,abs(a-2*w[i]))

print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
 
class Main {
	public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int y = sc.nextInt();
    if (y == 3 || y == 5 || y == 7) {
      System.out.print("YES");
    } else {
      System.out.print("NO");
    }
	}
}

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

using namespace std;

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

int l[1005];
int n;

int find(int start, int x) {
    int left = start, right = n - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (l[mid] >= x) {
            right = mid - 1;
        } else if (l[mid] < x) {
            left = mid + 1;
        }
    }
    return n - right - 1;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &l[i]);
    }

    sort(l, l + n);

    int total = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int a = l[i], b = l[j];
            int c1 = find(j + 1, b - a + 1);
            int c2 = find(j + 1, a + b);

            total += c1 - c2;
        }
    }
    printf("%d\n", total);
    return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())

N, M = map(int, input().split())
uf = UnionFind(N+1)
for _ in range(M):
  x, y, z = map(int, input().split())
  uf.Unite(x, y)

roots = {i:0 for i in range(1, N+1)}
for i in range(1, N+1):
  r = uf.Find_Root(i)
  roots[r] += 1 

ans = 0
for v in roots.values():
  if v > 0:
    ans += 1
print(ans)

Measured memory_bytes: 76504
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	unsigned long long max, min, cnt = 0, ans = 0;
	for (unsigned long long i = K; i <= N + 1; i++) {
		min = (0 + i - 1)*i / 2;
		max = (N + N - i + 1)*i / 2;
		//cout << min << " " << max << endl;
		cnt += max - min + 1;
	}
	ans = cnt % 1000000007;
	cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
long long n,k;
void solve()
{
    if (k%2) cout<<(n/k)*(n/k)*(n/k);
    else cout<<(n/k)*(n/k)*(n/k)+((2*n+k)/(2*k))*((2*n+k)/(2*k))*((2*n+k)/(2*k));
    cout<<endl;
}
int main()
{
    while(cin>>n>>k)
        solve();
}

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

#define sz(s) (int)(s).size()
#define sqr(x) (x) * (x)
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define pi acis(-1)
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 1000000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	string  s;
	set<string> se;
	for (int i = 1; i <= n; i ++)
	{
		string x;
		cin >> x;
		se.I(x);
	}
	cout << sz(se);






}



Measured memory_bytes: 19276
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int h,w,n;
	std::cin >> h >> w >> n;
	auto f = [&] (int x, int y) -> int {
		if(y==0) return x;
		if(x==h) return h+y;
		if(y==w) return 2*h+w-x;
		if(x==0) return 2*h+2*w-y;
		return -1;
	};
	std::vector<std::pair<int,int> > v;
	rep(i,n) {
		int a,b,c,d;
		std::cin >> a >> b >> c >> d;
		if(f(a,b)!=-1 && f(c,d)!=-1) {
			v.emplace_back(f(a,b),i);
			v.emplace_back(f(c,d),i);
		}
	}
	std::sort(all(v));
	std::stack<int> stack;
	rep(i,v.size()) {
		if(stack.empty()) {
			stack.emplace(v[i].second);
		} else {
			int x=stack.top();
			if(x==v[i].second) stack.pop();
			else stack.emplace(v[i].second);
		}
	}
	if(stack.empty()) print("YES");
	else print("NO");
	return 0;
}


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

// グローバル変数
ll n;
vector<ll> d;

// 関数プロトタイプ
void input();
void solve();

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> n;
    d.resize(n);
    for (int i = 0; i < n;i++) {
        cin >> d[i];
    }
}

void solve() {
    sort(d.begin(), d.end());
    cout << d[n/2]-d[n/2-1] << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        double a = 100;
        
        for(long i = 0; i < X;i++){
            a = Math.floor(a * 1.01);
            if(a >= X){
                System.out.print(i + 1);
                i = X;
            }
        }
    
    }
}

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

using namespace std;

int main(){
    int K, A, B, P;
    cin>>K;
    cin>>A>>B;
    int flag = 0;
    for (int i = 1; i < 1000; i++){
        P = K*i;
        if (P >= A & P <= B){
            cout<<"OK";
            flag = 1;
            break;
        }
    }
    if (flag == 0){
        cout<<"NG";
    }
    return 0;
}


Measured memory_bytes: 3560
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.IArrayI32(n: int) =
        [|for i in 0 .. n - 1 -> this.NextI32(), i|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.IArrayI64(n: int) =
        [|for i in 0 .. n - 1 -> this.NextI64(), i|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.IArrayF32(n: int) =
        [|for i in 0 .. n - 1 -> this.NextF32(), i|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public this.IArrayF64(n: int) =
        [|for i in 0 .. n - 1 -> this.NextF64(), i|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

[<EntryPoint>]
let main _ =
#if DEBUG
    printfn "debuged"
#endif

    let scanner = Scanner()
    let n = scanner.NextI32()
    let m = scanner.NextI32()
    let arriPY = [|for i in 0..m-1 -> i, scanner.NextI32(), scanner.NextI64()|]
    let f a = (string a).PadLeft(6, '0')

    arriPY
    |> Array.groupBy (fun (_, i, _) -> i)
    |> Array.collect (fun (_, b) ->
        b
        |> Array.sortBy (fun (_, _, x) -> x)
        |> Array.mapi (fun i (x, y, _) -> x, (f y) + (f (i + 1)))
    )
    |> Array.sortBy fst
    |> Array.map snd
    |> String.concat "\n"
    |> printfn "%s"


    0


Measured memory_bytes: 57684
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////

ll Gcd(ll x, ll y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return Gcd(y, x%y);
}
bool is_prime(ll n) {
	for (ll i = 2; i*i <= n; ++i) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
vector<ll>divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i*i <= n; ++i) {
		if (n%i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}
int main() {
	ll A, B; cin >> A >> B;
	vector<ll>a;
	ll key = Gcd(A, B);
	a = divisor(key);
	ll ans = 1;
	for (ll i = 0; i < a.size(); ++i) {
		if (is_prime(a[i])) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> mp(h);
	rep(i, h) cin >> mp[i];
	rep(i, h)rep(j, w) {
		if (mp[i][j] != '#') {
			int cnt = 0;
			if (j < w - 1 && mp[i][j + 1] == '#') cnt++;
			if (j < w - 1 && i>0 && mp[i - 1][j + 1] == '#') cnt++;
			if (i > 0 && mp[i - 1][j] == '#') cnt++;
			if (i > 0 && j > 0 && mp[i - 1][j - 1] == '#') cnt++;
			if (j > 0 && mp[i][j - 1] == '#') cnt++;
			if (i < h - 1 && j>0 && mp[i + 1][j - 1] == '#') cnt++;
			if (i < h - 1 && mp[i + 1][j] == '#') cnt++;
			if (i < h - 1 && j < w - 1 && mp[i + 1][j + 1] == '#') cnt++;
			mp[i][j] = '0' + cnt;
		}
	}
	rep(i, h) cout << mp[i] << endl;
}

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


struct UnionFind {
    vector<int> d;
    UnionFind(int n = 0): d(n, -1) {}
    int find(int x) {
        if (d.at(x) < 0) {
            return x;
        }
        return d.at(x) = find(d.at(x));
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        if (d.at(x) > d.at(y)) {
            swap(x, y);
        }
        d.at(x) += d.at(y);
        d.at(y) = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d.at(find(x));
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Roop(int N, int i, int[] takelen, int[] takenum,int[] target,ref int min)
        {
            if (N > i)
            {
                for(int j = 0; j < 4; j++)
                {
                    takenum[i] = j;
                    Roop(N, i+1, takelen,takenum,target,ref min);
                }
            }
            else if (takenum.Any(t => t == 0) && takenum.Any(t => t == 1) && takenum.Any(t => t == 2))
            {
                int MP = GetMP(N, takelen, takenum, target);
                if (MP < min)
                {
                    min = MP;
                }
            }
        }

        static int GetMP(int N, int[] takelen, int[] takenum, int[] target)
        {
            int MP = 0;
            int[] temp = { 0, 0, 0 };
            for(int i = 0; i < N; i++)
            {
                if (takenum[i] != 3)
                {
                    temp[takenum[i]] += takelen[i];
                }
            }
            for(int i = 0; i < 3; i++)
            {
                if (takenum.Where(t => t == i).Count() > 1)
                {
                    MP += (takenum.Where(t => t == i).Count() - 1) * 10;
                }
                MP +=Math.Abs(temp[i] - target[i+1]);
            }

            return MP;
        }

        static void Main()
        {
            IO io = new IO();

            //ここから

            int[] target = io.ReadLineToIntArray();
            int N = target[0];
            int[] takelen = new int[N];
            for(int i = 0; i < N; i++)
            {
                takelen[i] = io.ReadLineToInt();
            }
            int[] takenum = new int[N];

            int min = int.MaxValue;

            Roop(N, 0, takelen, takenum,target,ref min);

            Console.Write(min);

            Console.ReadKey();
        }
    }

    //IOを担う関数群
    public class IO
    {
        //stringの入力
        public string ReadLineToString()
        {
            return Console.ReadLine();
        }

        //intの入力
        public int ReadLineToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        //空白区切りの複数の文字列の入力をstring[]にして返す
        public string[] ReadLineToStringArray()
        {
            return Console.ReadLine().Split(' ').ToArray();
        }


        //空白区切りの複数の整数の入力をint[]にして返す
        public int[] ReadLineToIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        //空白区切りの複数の文字列の入力をList<string>で受け取る
        public List<string> ReadLineToStringList()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        //空白区切りの複数の整数の入力をList<int>で受け取る
        public List<int> ReadLineToIntList()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }

    }

}


Measured memory_bytes: 15528
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,a[100100],c[100100],ans=0;
    map<ll,ll> mp;
    mp[0]++;
    cin>>n>>m;
    rep(i,n) cin>>a[i];
    rep(i,n){
        c[i+1] = (c[i]+a[i]) % m;
        mp[c[i+1]]++;
    }
    for(auto p : mp){
        ans += (p.second-1)*p.second /2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    
    int h[N+1];
    for(int i = 1; i <= N; i++) cin >> h[i];
    
    int A[N+1];
    A[1] = 0;
    for(int i = 2; i <= N; i++)
    {
        A[i] = INT_MAX;
        for(int j = max(i-K, 1); j < i; j++) A[i] = min(A[i], A[j] + abs(h[i] - h[j]));
    }
    
    cout << A[N] << '\n';
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    map<int,int>mp;
    for (int i = 1; i <=n; ++i) {
        int c=i;
        for (int j = 2; j*j<=c; ++j) {
            while(c%j==0){
                mp[j]++;
                c/=j;
            }
        }
        if(c!=1)mp[c]++;
    }
    ll cnt3,cnt5,cnt15,cnt25,cnt75;
    cnt3=cnt5=cnt15=cnt25=cnt75=0;
    for(auto u:mp){
        if(u.second>=2)cnt3++;
        if(u.second>=4)cnt5++;
        if(u.second>=14)cnt15++;
        if(u.second>=24)cnt25++;
        if(u.second>=74)cnt75++;
    }
    ll ans=0;
//    cout <<cnt3<<" "<<cnt5<<" "<<cnt15<<" "<<cnt25<<" "<<cnt75<<endl;
    ans+=cnt75;
    if(cnt3-1>=0) {
        ans += (cnt3 - 1) * cnt25;
    }
    if(cnt5>=1) {
        ans += cnt15 * (cnt5 - 1);
    }
    if(cnt5>=2&&cnt3>=2) {
        ans += (cnt5 * (cnt5 - 1) / 2) * (cnt3-2);
    }
    cout <<ans <<endl;
    return 0;
}


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

using namespace std;

int main ()
{
    int n;
    cin >> n;
    if (n == 1)
        cout << 2;
    else {
        if (n % 2 == 0)
            cout << n;
        else
            cout << (long long)n*2; 
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll N, K;

    cin >> N >> K;

    ll A[N];
    ll o[N];
    ll p;
    ll counter;
    ll l;

    for(ll i = 0; i < N; i++){
        cin >> A[i];
        o[i] = -1;
    }

    p = 0;
    counter = 0;
    while(o[p] == -1){
        o[p] = counter;
        counter++;
        p = A[p] - 1;
    }

    l = counter - o[p];
    if(K > o[p]){
        K = (K - o[p]) % l + o[p];
    }
    p = 0;
    for(ll i = 0; i < K; i++){
        p = A[p] - 1;
    }

    cout << p + 1 << endl;

    return 0;
}


Measured memory_bytes: 6744
long d[2<<17],*p;main(a,k){scanf("%*d%d",&k);p=d+k;for(*p=1;~scanf("%d",&a);){for(;d-p--;)*p+=p[1];for(;*++p;*p%=k=1e9+7)*p-=p[a+1];}printf("%ld",*d);}

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

int main()
{
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int i, j, k;
  int count = 0;
  for(i = 0; i <= a; i++)
  {
    for(j = 0; j <= b; j++)
    {
      for(k = 0; k <= c; k++)
      {
        if(500*i+100*j+50*k == x)
        {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#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 sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, h;
  cin >> n >> h;
  priority_queue<int> que;
  int mx = 0;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    que.push(b);
    mx = max(mx, a);
  }
  int ans = 0;
  while(sz(que) && h > 0) {
    int b = que.top();
    if(b < mx) break;
    ans++;
    h -= b;
    que.pop();
  }
  h = max(0,h);
  ans += ceil(h,mx);
  cout << ans << endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	for (int i = 0; i < a; i++) {
		if (s[i] >= '0'&&s[i] <= '9') {
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	if (s[a] != '-') {
		cout << "No" << endl;
		return 0;
	}
	for (int i = a + 1; i < a+b+1; i++) {
		if (s[i] >= '0'&&s[i] <= '9') {
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int h,w;
int count;
    scanf("%d %d\n",&h,&w);
    char p[h][w+1];
    
    int i,j;
    for(i=0;i<=h;i++){
        for(j=0;j<=w;j++){
            char a;
            scanf("%c",&a);
            if(a=='#'){
count++;} 
        }
    }

    if(count==h+w-1){
        printf("Possible");
    }else{
        printf("Impossible");
    }
    
    
    return 0;
    
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)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()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

  int n;
  cin>>n;
  FOR(i,1,10){
    FOR(j,1,10){
      if(i*j==n){
        Yes(true);
        return 0;
      }
    }
  }

  Yes(false);


}

Measured memory_bytes: 764
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- VU.map pred . unsafeTextToVectorInt <$> T.getLine :: IO (VU.Vector Int)
  let
    rho = VU.unfoldr next (Just 0, IS.empty) :: VU.Vector Int
      where
        next (Just i, s) | IS.member i s = Just (i, (Nothing, s))
                         | otherwise     = Just (i, (Just (as VU.! i), IS.insert i s))
        next _                           = Nothing
    start = until ((== VU.last rho) . (rho VU.!)) succ 0 :: Int
    period = pred (VU.length rho) - start
  print .succ $ if k < start then rho VU.! k else rho VU.! (start + (k - start) `mod` period)

unsafeTextToVectorInt :: T.Text -> VU.Vector Int
unsafeTextToVectorInt = VU.unfoldr next
  where
    next :: T.Text -> Maybe (Int, T.Text)
    next s | T.null s  = Nothing
           | otherwise = Just . either undefined (T.stripStart <$>) . T.signed T.decimal $ s
{-# INLINE unsafeTextToVectorInt #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 17140
import scala.io.StdIn

object Main extends App {

  val s = StdIn.readLine()
  val K = StdIn.readLine().toInt

  // i <- 0 until s.size
  //   j <- 1 until s.size - i
  // println(s"$i $j")
  val r = {
    for (i <- 0 until s.size;
         j <- 1 to s.size - i; if j <= K)
      yield s.substring(i, i + j)
  }.toSet.toList.sorted.apply(K - 1)

  println(r)
}


Measured memory_bytes: 84504
/*___________Bismillahir Rahmanir Rahim__________*/
//Think positive, be positive and never use negative words
#include<bits/stdc++.h>
#define RON              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll               long long int
#define test             ll t;cin>>t;while(t--)
#define v_sum(a)         accumulate(a.begin(),a.end(),0)
#define v_max(a)         *max_element(a.begin(),a.end())
#define v_min(a)         *min_element(a.begin(),a.end())
#define v_uni(a)         a.erase(unique(a.begin(),a.end()),a.end())
#define yes              cout<<"Yes"<<endl
#define no               cout<<"No"<<endl
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b
using namespace std;
int main()
{
    RON;
    string s;
    cin>>s;
    ll i, sum=0;
    ll l=s.size();
    for(i=0; i<l; i++)
    {
        sum+=s[i]-'0';
    }
    if(sum%9LL==0) yes;
    else no;
    return 0;
}
/*_________________Alhamdulillah_________________*/


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define BASE 1000000007
using namespace std;

int main() {
    string l;
    cin >> l;
    int n = l.size();
    long dp[2][n];
    dp[0][0] = 1;
    dp[1][0] = 2;
    for (int i = 1; i < n; i++) {
        if (l[i] == '0') {
            dp[0][i] = (dp[0][i - 1] * 3) % BASE;
            dp[1][i] = dp[1][i - 1];
        } else {
            dp[0][i] = (dp[0][i - 1] * 3 + dp[1][i - 1]) % BASE;
            dp[1][i] = (dp[1][i - 1] * 2) % BASE;
        }
    }
    cout << (dp[0][n - 1] + dp[1][n - 1]) % BASE << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

bool check_alp(char c){
    if(c>='a' && c<='z')return true;
    else return false;
}

int main(void){
    int n;
    cin >> n;
    string p="ixcm";
    while(n--){
       string s,t;
       cin >> s >> t;
       map<char,int> mp;
       map<char,char> f;
       f['i']='x';
       f['x']='c';
       f['c']='m';
       int si=s.size(),ti=t.size();
       int i,j,k,num=1;
       for(i=0;i<si;i++){
           if(check_alp(s[i])){
               mp[s[i]]+=num;
               num=1;
           }else{
               num=s[i]-'0';
           }
       }
       for(i=0;i<ti;i++){
           if(check_alp(t[i])){
               mp[t[i]]+=num;
               num=1;
           }else{
               num=t[i]-'0';
           }
       }
       for(i=0;i<3;i++){
           if(mp[p[i]]>=10){
               mp[p[i+1]]+=mp[p[i]]/10;
               mp[p[i]]%=10;
           }
       }
       
       for(i=3;i>=0;i--){
           if(mp[p[i]]>1)cout << mp[p[i]] << p[i];
           else if(mp[p[i]]==1)cout << p[i];
       }
       cout << endl;
   }
    return 0;
}



Measured memory_bytes: 3056