akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30
#define MAX_P 300000

int main(){
  bool p[MAX_P+1] = {};
  rep(i, MAX_P+1) if(i % 7 == 1 || i % 7 == 6) p[i] = true;
  p[1] = false;
  rep(i, MAX_P+1 / 2){
    if(p[i]){
      for(int j = i+i; j < MAX_P+1; j+=i) p[j] = false;
    }
  }

  //  rep(i, 100) if(p[i]) printf("%d ", i); puts("");

  int n;
  while(scanf("%d", &n) && n != 1){
    printf("%d:", n);
    REP(i, 1, MAX_P+1) if(p[i] && (n % i == 0)) printf(" %d", i);
    puts("");
  }
  return 0;
}

Measured memory_bytes: 1496
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var a = (1..N-1).map{
        readLine()!!.split(" ").map(String::toInt)
    }
    for( i in 0..N-2){
        var ans = 0
        for(j in i..N-2){
            var C = a[j][0]
            var S = a[j][1]
            var F = a[j][2]
            if(S>ans) ans = S
            else if(ans.toDouble()%F == 0.0) ans += 0
            else ans = F+ans - (ans.toDouble()%F).toInt()
            ans += C
            
        }
        println(ans)
    }
    println(0)
   
}


Measured memory_bytes: 38020
#include<bits/stdc++.h>
using namespace std;
int res=100000000;
int cnt=0;
int main()
{
	int a;
	int x,y;
	cin>>x>>y;
	for(int i=1;i<=x;i++)
	{
		cin>>a;
		cnt+=a;
		res=min(res,a);
	}
	cout<<x+((y-cnt)/res)<<endl;
	return 0;
}

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

using namespace std;
const int maxn=2e5+5;
int a[maxn],b[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]);
    for(int i=1;i<=n;++i)scanf("%d",&b[i]);
    reverse(b+1,b+1+n);
    int h1=n,q1=1,mx=-1;
    for(int i=1;i<=n;++i){
        if(a[i]==b[i]){
            mx=a[i];
            h1=i;
            while(a[i]==b[i])i++;
            q1=i-1;
        }
    }
    for(int i=1;i<=n;++i){
        if(a[i]!=mx&&b[i]!=mx&&h1<=q1){
            swap(b[i],b[h1]);
            h1++;
        }
    }
    if(h1<=q1){puts("No");return 0;}
    else {
        puts("Yes");
        for(int i=1;i<n;++i)printf("%d ",b[i]);
        cout<<b[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5352
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
//123456 246912  17 19 23 
int prime[246920]={0};
int sum[246920]={0};

int main(){
	int tt=246920;
	rep(i,tt) prime[i]=1;
	prime[0]=prime[1]=0;
	for(int i=0;i*i<tt;i++){
		if(prime[i]==1){
			//cout<<i<<endl;
			for(int j=i*i;j<tt;j+=i){
				prime[j]=0;
			}
		}
	}
	rep(i,tt){
		if(i==0) continue;
		sum[i]=sum[i-1];
		if(prime[i]==1) sum[i]++;
	}
	//cout<<"    "<<sum[100]<<endl;
	int n;
	while(cin>>n,n){
		int ans=sum[2*n]-sum[n];
		cout<<ans<<endl;
	}
	return 0;
}

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

const int INF = 1 << 30;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
int W, H;
int tx, ty;
int kx, ky;
int d[50][50];
int dist[50][50][50][50];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> W >> H, W) {
    cin >> tx >> ty >> kx >> ky;
    tx--, ty--, kx--, ky--;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> d[i][j];
      }
    }
    fill_n((int*)dist, 50 * 50 * 50 * 50, INF);
    dist[ty][tx][ky][kx] = 0;
    using P = tuple<int, int, int, int>;
    queue<P> que;
    que.emplace(ty, tx, ky, kx);
    bool na = true;
    while (!que.empty()) {
      int ay, ax, by, bx;
      tie(ay, ax, by, bx) = que.front(); que.pop();
      if (dist[ay][ax][by][bx] >= 100) break;
      if (pii(ay, ax) == pii(by, bx)) {
        cout << dist[ay][ax][by][bx] << endl;
        na = false;
        break;
      }
      for (int i = 0; i < 4; i++) {
        int any = ay + dy[i];
        int anx = ax + dx[i];
        int bny = by + dy[(i + 2) % 4];
        int bnx = bx + dx[(i + 2) % 4];
        if (any < 0 || any >= H || anx < 0 || anx >= W || d[any][anx]) any = ay, anx = ax;
        if (bny < 0 || bny >= H || bnx < 0 || bnx >= W || d[bny][bnx]) bny = by, bnx = bx;
        if (dist[any][anx][bny][bnx] > dist[ay][ax][by][bx] + 1) {
          dist[any][anx][bny][bnx] = dist[ay][ax][by][bx] + 1;
          que.emplace(any, anx, bny, bnx);
        }
      }
    }
    if (na) cout << "NA" << endl;
  }  

  return 0;
}


Measured memory_bytes: 27792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#define loop(i,n) for(int i = 0; i < n; i++)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define INF 999999999;
#define VEC vector<int>
#define in push_back
#define ans(x) cout<<x<<endl
#define ll long long int 

using namespace std;

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size()-1] == b[0]&&b[b.size() - 1] == c[0])ans("YES");
	else ans("NO");
}


Measured memory_bytes: 764
#include<stdio.h>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef pair<int,int> P;
int x[200000];
int y[200000];
int b[200000];
P s[200000];

long long max(long long a,long long b){return a>b?a:b;}

int main(){
	int n,d,i;
	scanf("%d %d",&n,&d);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&x[i],&y[i],&b[i]);
		s[i]=P(b[i],i);
	}
	sort(s,s+n);
	priority_queue<P, vector<P>, greater<P> > que_xl;
	priority_queue<P> que_xr;
	priority_queue<P, vector<P>, greater<P> > que_yl;
	priority_queue<P> que_yr;
	int r=0;
	long long ans=0;
	for(i=0;i<n;i++){
		while(r<n&&s[r].first<=s[i].first+d){
			que_xl.push(P(x[s[r].second],s[r].second));
			que_xr.push(P(x[s[r].second],s[r].second));
			que_yl.push(P(y[s[r].second],s[r].second));
			que_yr.push(P(y[s[r].second],s[r].second));
			r++;
		}
		while(b[que_xl.top().second]<s[i].first)que_xl.pop();
		while(b[que_xr.top().second]<s[i].first)que_xr.pop();
		while(b[que_yl.top().second]<s[i].first)que_yl.pop();
		while(b[que_yr.top().second]<s[i].first)que_yr.pop();
		long long x=que_xr.top().first-que_xl.top().first;
		long long y=que_yr.top().first-que_yl.top().first;
		ans=max(ans,x*y);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11244
#include <stdio.h>

int main(int ac, char **av) {
  double a,b,c,d,s,t,det,x,y;
  char buf[256];
  while(fgets(buf, 256, stdin)) {
    sscanf(buf, "%lf %lf %lf %lf %lf %lf\n", &a, &b, &s, &c, &d, &t);
    det = (a*d - b*c);
    x = (s*d - b*t) / det;
    y = (a*t - s*c) / det;
    if(x == 0) x = 0; // -0 -> 0
    if(y == 0) y = 0; // -o -> 0
    printf("%.3lf %.3lf\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 660
import re
s = input()
s = s.replace('BC', 'x')
sl = re.findall(r'[^BC]+', s)
n = 0
for s in sl:
    xs = 0
    for c in reversed(s):
        if c == 'x':
            xs += 1
        else:
            n += xs
print(n)

Measured memory_bytes: 5284
#include <iostream>
using namespace std;
const int MAX = 100;

int main()
{
	int n, mini, temp, count=0;
	int A[MAX];

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

	for(int i = 0; i < n; i++)
	{
		mini = i;
		for(int j = i+1; j < n; j++)
		{
			if(A[mini] > A[j])
				mini = j;
		}
		if(i != mini)
		{
			count++;
			temp = A[mini];
			A[mini] = A[i];
			A[i] = temp;
		}
	}

	for(int i = 0; i < n-1; i++)
	{
		cout << A[i] << ' ';
	}
	cout << A[n-1] << endl;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3100
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int k = scan.nextInt();
		int have[] = new int[n];
 		
		for(int i=0;i<k;i++) {
			int d = scan.nextInt();
			for(int j=0;j<d;j++) {
				int take = scan.nextInt();
				have[take-1] = 1;
			}
		}
		
		int ans = 0;
		for(int i=0;i<n;i++) {
			if(have[i] == 0) {
				ans += 1;
			}
		}
		
		System.out.println(ans);
		
	}	
	
	
	//最小公約数
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
}


Measured memory_bytes: 46452
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int k;
  cin >> k;
  int x;
  cin >> x;
  if(500*k>=x) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  
  return 0;
}


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

char s[125];
int it;

int dfs(){
  int ret = 0;
  int tail = 0;
  int sign = 1;
  // first operand
  int a = 0;
  if(s[it]=='('){
    it++;
    a = dfs();
    assert(s[it]==')');
    it++;
  }else{
    while(isdigit(s[it])){
      a *= 10;
      a += s[it]-'0';
      it++;
    }
  }
  tail = a;
  while(true){
    // operator
    char op = s[it];
    if(op == '=' || op == ')'){
      // end
      ret += sign * tail;
      return ret;
    }
    it++;
    // second operand
    int b = 0;
    if(s[it]=='('){
      it++;
      b = dfs();
      assert(s[it]==')');
      it++;
    }else{
      while(isdigit(s[it])){
        b *= 10;
        b += s[it]-'0';
        it++;
      }
    }
    if(op == '+' || op == '-'){
      // tail end
      ret += sign * tail;
      tail = b;
      sign = op=='+' ? 1 : -1;
    }else if(op == '*'){
      tail *= b;
    }else if(op == '/'){
      tail /= b;
    }
  }
}

void solve(){
  REP(i,125)s[i] = '\0';
  scanf("%s",s);
  it = 0;
  int ans = dfs();
  printf("%d\n",ans);
}

int main(){
  int t;
  scanf("%d",&t);
  while(t--)solve();
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.text","r",stdin); //freopen("output.txt","w",stdout)
#define LL long long int
#define ull unsigned long long int
#define wh int T;cin >> T;while(T--)
#define REP(i,n) for(int i=0;i<n;i++)
#define forn(i,k,n) for(int i=k;i<n;i++)
#define PB push_back
#define mod 1000000007 
#define UMP unordered_map<int,int>
#define MP map<int,int> 
#define stack stack<int>
#define stackL 	stack<LL>
#define take(x) int x;cin >> x; 

int gcd(int a, int b) { 
    return  (!a)? b : gcd(b%a,a);      
} 
void solve(){
	int x; cin >> x;
		if(x == 0){
			cout << 1 << endl;
		}
		else if(x == 1){
			cout << 0 << endl;
		}
} 


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


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define vi vector<int>

using ll = long long;
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
inline ll inv(ll x, ll div){return pow(x, div - 2, div);}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int a,b; cin >> a >> b;
  rep(i,1000000){
    double j = i * 0.08;
    double k = i * 0.10;
    j += eps; k += eps;
    if(floor(j)  == a && floor(k) == b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
using namespace std;
string s[55];
int h,w,i,j;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>h>>w;
	for(i=0;i<h;i++){
		cin>>s[i];
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j]=='#'){
				if(i!=0){
					if(s[i-1][j]=='#'){
						continue;
					}
				}
				if(j!=0){
					if(s[i][j-1]=='#'){
						continue;
					}
				}
				if(i!=h-1){
					if(s[i+1][j]=='#'){
						continue;
					}
				}
				if(j!=w-1){
					if(s[i][j+1]=='#'){
						continue;
					}
				}
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110
int L[Max];
int N;

int main(int argc, const char * argv[]) {
    N = inputValue();
    inputArray(L, N);
    sort(L, L+N);
    int sum = 0;
    rep(i, N-1) {
        sum += L[i];
    }
    if (sum > L[N-1]) {
        output("Yes");
    } else {
        output("No");
    }

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>                                                           
#define rep(i,a,b) for(int i=a;i<b;i++)                                            
#define rrep(i,a,b) for(int i=a;i>=b;i--)                                          
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll>::iterator iter;
    ll dis;

    rep(i,0,N){
        cin >> A[i];
    }

    ll max,maxsec;

    max = *max_element(A.begin(),A.end());
    iter = max_element(A.begin(),A.end());
    *max_element(A.begin(),A.end())=0;
    maxsec = *max_element(A.begin(),A.end());
    dis =distance(A.begin(),iter);

    rep(i,0,N){
        if(i!=dis){
            cout << max <<endl;;
        }else{
            cout << maxsec <<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3200
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    int n,k;
    cin>>n>>k;
    int ans = 1;
    for(int i=0;i<n;i++){
        if(ans*2 < ans+k) ans *= 2;
        else ans += k;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int, Int> P;

using mint = modint998244353;

vector<mint> pow10(200010, 1);
vector<mint> ones(200010, 0);

struct S { mint x; int l; }; // x: 区間の値, l:区間の長さ
S op(S a, S b){ return S{a.x * pow10[b.l] + b.x, a.l + b.l}; }
S e() { return S{0, 0}; }
using F = mint; // x-> F に更新
S mapping(F f, S a) {return (f == 0) ? a : S{ones[a.l] * f, a.l};}
F composition(F f, F g){ return (f==0) ? g : f; };
F id() { return 0; }

int main(){
    rep(i,200010){
        pow10[i+1] = pow10[i] * 10;
        ones[i+1] = ones[i]*10 + 1;
    }

    int N, Q; cin >> N >> Q;

    vector<S> V(N, S{1,1});
    lazy_segtree<S, op, e, F, mapping, composition, id> LST(V);

    rep(i,Q){
        int L, R, D;
        cin >> L >> R >> D;
        L--; R--;
        LST.apply(L, R+1, D);

        cout << LST.all_prod().x.val() << endl;
    }
}

Measured memory_bytes: 11480
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

struct UnionFind {
    size: Vec<usize>,
    parent: Vec<Option<usize>>,
    diff: Vec<i32>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            size: vec![1; n],
            parent: vec![None; n],
            diff: vec![0; n],
        }
    }

    fn get_parent_diff(&mut self, x: usize) -> (usize, i32) {
        match self.parent[x] {
            None => (x, 0),
            Some(y) => {
                let (p, d) = self.get_parent_diff(y);
                self.parent[x] = Some(p);
                self.diff[x] = d + self.diff[x];
                (p, self.diff[x])
            }
        }
    }

    fn relate(&mut self, x: usize, y: usize, z: i32) {
        let (xp, dx) = self.get_parent_diff(x);
        let (yp, dy) = self.get_parent_diff(y);

        if xp != yp {
            let sxp = self.size[xp];
            let syp = self.size[yp];
            if sxp < syp {
                self.parent[xp] = Some(yp);
                self.diff[xp] = z + dy - dx;
                self.size[yp] = sxp + syp;
            } else {
                self.parent[yp] = Some(xp);
                self.diff[yp] = dx - dy - z;
                self.size[xp] = sxp + syp;
            }
        }
    }

    fn diff(&mut self, x: usize, y: usize) -> Option<i32> {
        let (xp, dx) = self.get_parent_diff(x);
        let (yp, dy) = self.get_parent_diff(y);
        if xp != yp {
            None
        } else {
            Some(dx - dy)
        }
    }
}

fn main() {
    let nq: Vec<usize> = read_vec();
    let n = nq[0];
    let q = nq[1];

    let coms: Vec<Vec<usize>> = read_vec2(q as u32);

    let mut uf = UnionFind::new(n);

    for cv in coms {
        if cv[0] == 0 {
            uf.relate(cv[1], cv[2], cv[3] as i32);
        } else {
            if let Some(d) = uf.diff(cv[1], cv[2]) {
                println!("{}", d);
            } else {
                println!("?");
            }
        }
    }
}



Measured memory_bytes: 19356
#include <iostream>
#include <cmath>
#include <string>
#include<algorithm>
using namespace std;
int main(){

    
    int a ,b;
    cin>>a>>b;
    int d = a*b;
    if(d%2==1){
        cout<<"Yes"<<endl;
        return 0;
    }else if((d*2)%2==1){
        cout<<"Yes"<<endl;
        return 0;
    }else if(d*3%2==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    
    cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  
  int n;
  cin>>n;
  
  string s;
  vector<P> v;
  
  int si=-1,gi=-1,flag=0;
  
  for(int i=0;i<n;i++){
    cin>>s;

    int l=0,r=0,cnt=0;
    
    for(int j=0;j<s.size();j++){
      
      if(s[j]=='(')cnt++;
      else{
	if(!cnt)l++;
	else cnt--;
      }

    }
    r=cnt;
    
    if(l||r){
      flag=1;
      v.push_back(P(l,r));

      if(!l)si=v.size()-1;
      if(!r)gi=v.size()-1;
    }
    
  }
  
  vector<bool> used(v.size(),0);
  
  bool ans=true;

  if(si!=-1&&gi!=-1){
    used[si]=used[gi]=true;
    
    int cnt=v.size()-2,L=v[si].second,pL=L;
    
    while(cnt--){
      int maxL=-1,maxl=-1,idx=-1;
      
      for(int i=0;i<v.size();i++){
	if(used[i])continue;

	if(L-v[i].first<0)continue;
		
	if(maxL<L-v[i].first+v[i].second){
	  maxL=L-v[i].first+v[i].second;
	  maxl=v[i].first;
	  idx=i;
	}
	
	if(maxL!=-1&&maxL==L-v[i].first+v[i].second){
	  if(maxl<v[i].first){
	    maxL=L-v[i].first+v[i].second;
	    maxl=v[i].first;
	    idx=i;
	  }
	}

      }
      
      if(idx==-1){
	ans=false;
	break;
      }

      if(pL>maxL){
	maxL=maxl=idx=-1;
	
	for(int i=0;i<v.size();i++){
	  if(used[i])continue;
	
	  if(L-v[i].first<0)continue;

	  if(maxl<v[i].first){
	    maxL=L-v[i].first+v[i].second;
	    maxl=v[i].first;
	    idx=i;
	  }
	  
	  if(maxl!=-1&&maxl==v[i].first){
	    if(maxL<L-v[i].first+v[i].second){
	      maxL=L-v[i].first+v[i].second;
	      maxl=v[i].first;
	      idx=i;
	    }
	  }

	}


      }
      
      L=maxL;
      pL=L;
      
      used[idx]=true;
      
    }
    
    if(ans&&!(L-v[gi].first==0))  ans=false;
    
  }else if(flag)ans=false;
  
  if(!ans)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  
  return 0;
}

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

int main(){
  ll N, K; cin >> N >> K;
  if(N == 2){
    if(K == 0) cout << 1 << endl << 1 << ' ' << 2 << endl;
    else cout << -1 << endl;
    return 0;
  }
  if(K > ((N-1) * (N-2)) / 2){
    cout << -1 << endl;
    return 0;
  }
  
  vector<pair<int, int>> ret;
  for(int i = 2; i <= N; i++){
    ret.push_back(make_pair(1, i));
  }
  int cnt = ((N-1) * (N-2)) / 2 - K;
  for(int i = 2; i <= N; i++){
    for(int j = i + 1; j <= N; j++){
      if(cnt){ret.push_back(make_pair(i, j)); cnt--;}
      else break;
    }
    if(!cnt) break;
  }
  
  cout << ret.size() << endl;
  
  for(int i = 0; i < ret.size(); i++){
    cout << ret[i].first << ' ' << ret[i].second << endl;
  }
}

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

int main(){
	int x,y;	cin>>x>>y;

	int ans=0;
	ans+=max((4-x)*100000,0);
	ans+=max((4-y)*100000,0);

	if(x==1 && y==1)ans+=400000;

	cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  if(s.length()<=n){
    cout << s;
  }else{
    for(int i = 0;i<n;i++){
      cout << s[i];
    }
    cout << "...";
  }
  return 0;
}

Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
T LCM(T a, T b) {
	return a / GCD(a, b) * b;
}
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

class mint {
    ll x; // typedef long long ll;
public:
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }

    friend ostream& operator<<(ostream& s, const mint& x) {
        return s << x.x;
    }
};

mint f(int v) {
    mint res = 1;
    for (int i = v; i >= 1; i--) {
        res *= i;
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;

    if (n == m) {
        mint n_factorial = f(n);
        mint m_factorial = f(m);

        mint ans = n_factorial * m_factorial;
        ans *= 2;
        cout << ans << endl;
    }
    else if (abs(n - m) <= 1) {
        mint n_factorial = f(n);
        mint m_factorial = f(m);

        cout << n_factorial * m_factorial << endl;
    }
    else if (abs(n - m) >= 2) cout << 0 << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


void solve()
{
	int n, m;
	cin >> n >> m;
	vector<ll> f(n);
	for(int i = 0; i < n; ++i) cin >> f[i];
	vector<pll> s(m);
	ll sum = 0;
	for(int i = 0; i < m; ++i){
		cin >> s[i].S >> s[i].F;
	}
	sort(all(f));
	sort(all(s));
	reverse(all(f));
	while(!s.empty() && !f.empty()){
		if(f.back() >= s.back().F){
			sum += f.back();
		}
		else{
			sum += s.back().F;
			s.back().S--;
			if(!s.back().S) s.pop_back();
 		}
		f.pop_back();
	}
	rep(i, sz(f)) sum += f[i];
	cout << sum;
	
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 2560
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 510;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, h[MAXN][MAXN], g[MAXN][MAXN];
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};

void dfs(int x, int y) {
    int k = h[x][y] + g[x][y];
    FOR(i,0,3) {
        int u = x + dx[i], v = y + dy[i];
        if (u >= 1 && u <= n && v >= 1 && v <= n && k < h[u][v]) {
            h[u][v] = k;
            dfs(u, v);
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;

    FOR(i,1,n)
        FOR(j,1,n) {
            h[i][j] = min(min(i, n+1-i), min(j, n+1-j)) - 1;
            g[i][j] = 1;
        }

    int res = 0;
    FOR(i,1,n*n) {
        int w;
        cin >> w;
        int x, y;
        if (w % n == 0) {
            x = w / n;
            y = n;
        }
        else {
            x = w / n + 1;
            y = w % n;
        }
        res += h[x][y];
        g[x][y] = 0;
        dfs(x, y);
    }
    cout << res;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool black[100000];
  int n=0;
  for(int i=0;i<s.length(); i++){
    if(s[i]=='0'){
      black[i] = true;
    }else{
      black[i] = false;
    }
    n++;
  }

    int ans1 = 0;
    for(int i=0;i<n;i++){
      if(i%2==0){
        if(black[i]) ans1++;
      }else{
        if(!black[i]) ans1++;
      }
    }
    //wbwbwbw
    int ans2 = 0;
    for(int i=0;i<n;i++){
      if(i%2==1){
        if(black[i]) ans2++;
      }else{
        if(!black[i]) ans2++;
      }
    }
    cout << min(ans1,ans2);



  return 0;
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N; cin>>N;
    vector<ll>a(N);
    rep(i,N)cin>>a[i];
    deque<ll>d;
    d.push_back(a[0]);
    if(N%2==0){
        for(int i=1;i<N;i++){
            if(i%2!=0){
                d.push_front(a[i]);
            }
            else d.push_back(a[i]);
        }
    }
    else {
        for (int i=1;i<N;i++){
            if(i%2!=0){
                d.push_back(a[i]);
            }
            else d.push_front(a[i]);
        }
    }
    rep(i,N){
        cout<<d[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 5376
import java.util.Scanner;
public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        int A,B,C,D;
        D=input%10;
        input/=10;
        C=input%10;
        input/=10;
        B=input%10;
        input/=10;
        A=input;
        if(A+B+C+D==7){
            System.out.println(A+"+"+B+"+"+C+"+"+D+"=7");
        }else if(A+B+C-D==7){
            System.out.println(A+"+"+B+"+"+C+"-"+D+"=7");
        }else if(A+B-C+D==7) {
            System.out.println(A+"+"+B+"-"+C+"+"+D+"=7");
        }else if(A+B-C-D==7){
            System.out.println(A+"+"+B+"-"+C+"-"+D+"=7");
        }else if(A-B+C+D==7){
            System.out.println(A+"-"+B+"+"+C+"+"+D+"=7");
        }else if(A-B+C-D==7){
            System.out.println(A+"-"+B+"+"+C+"-"+D+"=7");
        }else if(A-B-C+D==7) {
            System.out.println(A+"-"+B+"-"+C+"+"+D+"=7");
        }else if(A-B-C-D==7){
            System.out.println(A+"-"+B+"-"+C+"-"+D+"=7");
        }
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if(s[0]==s[1] or s[1]==s[2] or s[2] == s[3])
  {
 	cout << "Bad" << endl; 
  }
  else
  {
  	cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 300000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 19;

pii dp[N];
int n, a[N], k;

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	n = (1 << n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++)  dp[i] = {a[i], -INF};
	for (int i = 0; i < LOG; i++) for (int mask = n - 1; mask >= 0; mask--){
		if (mask & (1 << i)){
			vi V;
			V.pb(dp[mask ^ (1 << i)].F);
			V.pb(dp[mask ^ (1 << i)].S);
			V.pb(dp[mask].F), V.pb(dp[mask].S);
			sort(all(V));
			dp[mask] = {V[3], V[2]};
		}
	}
	for(int i = 1; i < n; i++){
		k = i + 1;
		int ans = 0;
		int num = (1 << LOG) - 1;
		for (int j = LOG - 1; j >= 0; j--){
			if (k & (1 << j)){
				num ^= (1 << j);
				ans = max(ans, dp[num].F + dp[num].S);
				num ^= (1 << j);
			}else{
				num ^= (1 << j);
			}
		}
		cout << ans << '\n';
	}










	return 0;
}


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

int main(void){
  int n ;
  while(cin>>n,n){
    int t; cin>>t;
    string s; cin>>s;
    static int dp[1000010];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i = 0 ; i < s.size()-1 ; i ++){
      if(s[i]!=s[i+1])dp[i+1]=dp[i]+1;
      else dp[i+1]=1;
    }
    
    int ans = 0;
    for(int i = s.size() - 1 ; i >= 0  ; i --){
      if(s[i]=='I' && dp[i]>=n*2+1)ans++;
    }
    cout<<ans<<endl;
  }
}

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

template <typename A, typename B>string to_string(pair<A, B> p);template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);string to_string(const string& s) {  return '"' + s + '"';}string to_string(const char* s) {  return to_string((string) s);}string to_string(bool b) {  return (b ? "true" : "false");}string to_string(vector<bool> v) {  bool first = true;  string res = "{";  for (int i = 0; i < static_cast<int>(v.size()); i++) {    if (!first) {      res += ", ";    }    first = false;    res += to_string(v[i]);  }  res += "}";  return res;}template <size_t N>string to_string(bitset<N> v) {  string res = "";  for (size_t i = 0; i < N; i++) {    res += static_cast<char>('0' + v[i]);  }  return res;}template <typename A>string to_string(A v) {  bool first = true;  string res = "{";  for (const auto &x : v) {    if (!first) {      res += ", ";    }    first = false;    res += to_string(x);  }  res += "}";  return res;}template <typename A, typename B>string to_string(pair<A, B> p) {  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) {  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {  cerr << " " << to_string(H);  debug_out(T...);}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define set0(x) memset(x,0,sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
	read(first);
	read(args...);
}

char S[200020];
ll ans = 0;
int main() {
	cin>>S;
	int n = strlen(S);
	ll cnt = 0;
	rep(i,0,n){
		if(S[i] == 'B')cnt+=1;
		else ans+=cnt;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int N, X, x;
  cin >> N;
  X = N;
  int f = 0;
    
  for(int i = 8; i >= 0; i--){
    x = std::pow(10, i);
    int a = X / x;

    if(a >= 1){
      f += a;
      X -= a * x;
    }
  }
  int H;
  H = N % f;

  if(H == 0){
    cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

/*
func readLine(r *bufio.Reader) []byte {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := r.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return buf
}
	r := bufio.NewReaderSize(os.Stdin, 4096)
*/

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func show(dp [3001][3001]int, N int) {
	out("-------------------------------")
	for i := 0; i <= N; i++ {
		for j := 0; j <= N; j++ {
			if i == j {
				fmt.Print("*\t")
			} else {
				fmt.Printf("%d\t", dp[i][j])
			}
		}
		fmt.Println("")
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	var dp [3001][3001]int

	for len := 1; len <= N; len++ {
		for i := 0; i+len <= N; i++ {
			j := i + len
			//out(a[i:j], a[i]-dp[i+1][j], a[j-1]-dp[i][j-1])
			dp[i][j] = max(a[i]-dp[i+1][j], a[j-1]-dp[i][j-1])
		}
		//show(dp, N)
	}

	out(dp[0][N])
}


Measured memory_bytes: 72320
object Main {
	def main(args: Array[String]): Unit = {
		val sc = new java.util.Scanner(System.in)

    	val a: Int = sc.nextInt
    	val op: String = sc.next
    	val b: Int = sc.nextInt

    	op match {
    		case "+" => println(a + b)
    		case "-" => println(a - b)
    	}
	}
}

Measured memory_bytes: 22736
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        c = 'a'
        for i in range(ord('a'), mx + 1):
            c = chr(i)
            if c == chr(mx):
                dfs(s + c, mx + 1)
            else:
                dfs(s + c, mx)

dfs('', ord('a'))

Measured memory_bytes: 4340
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  ll N; cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll res = 0;
  for (ll k = 1; k <= N; ++k) {
    if (k * k > N) break;

    ll mhi = N / k;
    ll lo = 1, hi = mhi;
    while (hi - lo > 1) {
      ll mid = (lo + hi) / 2;
      if (N / mid != k) lo = mid;
      else hi = mid;
    }
    ll mlo = hi;

    ll llo = (N - k + (mhi - 1)) / mhi;
    ll lhi = (N - k) / mlo;

    for (ll el = llo; el <= lhi; ++el) {
      if ((N - k) % el != 0) continue;
      ll m = (N - k) / el;
      // assert(N % m == k);
      // assert(N / m == k);
      if (N % m == k && N / m == k) res += m;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
N,M = [int(x) for x in input().split()]

AC=[0]*N
WA=[0]*N
OK = 0
NG = 0
for i in range(M):
    p,S=input().split() 
    p = int(p)
    
    if AC[p-1] == 0:        
        if S=='AC':
            AC[p-1]=1
            OK+=1        
        else:
            WA[p-1]+=1
    
for i in range(N):
    if AC[i]==1:
        NG +=WA[i]
        
print(OK,NG)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
#define TYPE(x) typeid(x).name()
#define MAXN 100001
int h[MAXN];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	cin>>h[i];
	unordered_map<int,int>node;
	for(int i=1;i<=m;++i){
		int a,b;
		cin>>a>>b;
		if(h[a]>h[b])node[b]=1;
		if(h[b]>h[a])node[a]=1;
		if(h[a]==h[b]){node[b]=1;node[a]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		if(node[i]==0)++ans;
	}
	cout<<ans;
}


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

using namespace std;

int main(){
    int n, k;
    cin >>n>>k;
    vector<int> h(n);

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

    long long sum = 0;
    sort(h.begin(), h.end());

    for(int i=n-1-k;i>=0;i--){
        sum+=h[i];
    }

    cout <<sum;
}


Measured memory_bytes: 1024
n=int(input())
ans=2*(n*(n+1))//2-1
a=2
while n//a>1:
  # aを約数に持つ整数を数えて足す
  # 項数：n//a-1
  # 初項：2*a
  # 最終：n-n%a
  ans+=((n//a-1)*(2*a+n-n%a))//2
  a+=1
print(ans)

Measured memory_bytes: 8976
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define debug1(a) cout<<" a : "<<a<<"\n"
#define debug2(a,b) cout<<" a : "<<a<<" b : "<<b<<"\n"
#define debug3(a,b,c) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<" d : "<<d<<"\n"
// #define M 421412341324321
#define MOD 998244353 

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	int a[n];
	rep(i,n)
	{
		cin>>a[i];
	}
	sort(a, a+n);
	int mul = 1;
	long double ans = (a[0]);
	REP(i,1,n-1)
	{
		ans += mul*a[i];
		mul = mul*2;
	}
	ans = ans/(((long double)1.0)*mul);
	cout<<fixed<<setprecision(10)<<ans;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,d,a,x[200010],h[200010];
	vector<P> vec;
	cin >> n >> d >> a;
	for(int i = 0;i < n;i++){
		cin >> x[i] >> h[i];
		vec.emplace_back(x[i],h[i]);
	}
	sort(all(vec));
	for(int i = 0;i < n;i++){
		x[i] = vec[i].first;
		h[i] = vec[i].second;
	}
	int imos[200010] = {},ans = 0;
	for(int i = 0;i < n;i++){
		if(i) imos[i] += imos[i - 1];
		h[i] -= imos[i];
		if(h[i] <= 0) continue;
		int ind1 = lower_bound(x,x + n,x[i]) - x;
		int ind2 = upper_bound(x,x + n,x[i] + d * 2) - x;
		int kai = (h[i] + a - 1) / a; 
		ans += kai;
		imos[ind1] += kai * a;
		imos[ind2] -= kai * a;
	}
	cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int cnt[26];

int main(){
  string s;

  cin >> s;
  char tmp = s[0];
  bool isfirst = false;
  if(s[0]==s[1] && s[2]==s[3] && s[0] != s[2])  { cout << "Yes" << endl; return 0; }
  if(s[0]==s[2] && s[1]==s[3] && s[0] != s[1]) { cout << "Yes" << endl; return 0; }
  if(s[0]==s[3] && s[1]==s[2] && s[0] != s[1]) { cout << "Yes" << endl; return 0;}
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let n: i64 = readln();
    let bounce = min((n as f64).sqrt() as i64 + 10, n);
    let answer = (1..bounce+1).map(|x| {
        if n % x == 0 {
            let y = n / x;
            let a = x.to_string().len();
            let b = y.to_string().len();
            max(a, b)
        } else {
            usize::max_value()
        }
    }).min().unwrap();
    println!("{}", answer);
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);

Measured memory_bytes: 4352
package main

import "fmt"

func main() {
	a := 0
	b := 0
	c := 0
	k := 0

	fmt.Scanf("%d %d %d", &a, &b, &c)
	fmt.Scanf("%d", &k)

	for i := 0; i < k; i++ {
		if c <= b {
			c *= 2
		} else if b <= a {
			b *= 2
		} else {
			c *= 2
		}

	}

	if a < b && b < c {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N,M;
    cin >> N >> M;
    int P[M];
    string S[M];
    REP(i,M) cin >> P[i] >> S[i];
    int ac = 0;
    int wrong[N];
    int wa = 0;
    bool checked[N];
    REP(i,N) checked[i] = false;
    REP(i,N) wrong[i] = 0;

    REP(i,M){
        int p = P[i];
        p--;
        if(!checked[p]){
            if(S[i] == "AC"){
                ac++;
                checked[p] = true;
                wa += wrong[p];
            }
            else if(S[i] == "WA") wrong[p]++;
        }
    }
    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 7500