akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	string s;cin>>s;

	int x = (s.length()/2);

	string ss =s;

	reverse(ss.begin(),ss.end());

	int ans=0;
	for(int i=0; i<x; i++){
		if(s[i] != ss[i])ans++;
	}

	writeln(ans);

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(0); cin.tie(0); } } _io;
typedef long long ll; typedef long double db;

ll exgcd(ll a, ll b, ll& x, ll& y)
{
	if (!b)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - (a / b) * y;
	return d;
}
ll getInv(ll a, ll mod)
{
	ll x, y;
	return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

int main()
{
	ll x;
	cin >> x;
	cout << !x << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

  bool ok = true;
  vector<vector<bool>> flags(n, vector<bool>(n, true));
  for (int i = 0; i < n && ok; i++) {
    for (int j = 0; j < n && ok; j++) {
      for (int k = 0; k < n && ok; k++) {
        ll new_dist = d[j][i] + d[i][k];
        if (d[j][k] > new_dist) {
          ok = false;
          break;
        }

        if (d[j][k] == new_dist && j != i && i != k) {
          flags[j][k] = false;
        }
      }
    }
  }

  if (!ok) {
    cout << -1 << '\n';
    return 0;
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (flags[i][j]) {
        ans += d[i][j];
      }
    }
  }

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

Measured memory_bytes: 4344
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		mut a: [isize; 3],
	}

	let mut ans = 999999999999999isize;
	a.sort();
	loop {
		ans = min(ans, (a[1] - a[0]).abs() + (a[2] - a[1]).abs());
		if !a.next_permutation() {
			break;
		}
	}

	println!("{}", ans);
}


Measured memory_bytes: 2200
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
	ll x;
	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 {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=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.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

typedef vector<mint> vm;
void solve() {
    ll n, s;
    cin >> n >> s;
    vll a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];
    vector<vm> dp(n + 1, vm(s + 1));
    dp[0][0] = 1;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j <= s; j++) {
            dp[i + 1][j] += dp[i][j] * 2;
            if(j >= a[i]) dp[i + 1][j] += dp[i][j - a[i]];
        }
    }
    cout << dp[n][s].x << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 73644
#include <bits/stdc++.h>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> x(N), y(N), h(N);
    for (int i = 0; i < N; i++) {
        std::cin >> x[i] >> y[i] >> h[i];
    }
    auto ok = [&](const int X, const int Y) {
        int l = 0, r = 1001001001;
        for (int i = 0; i < N; i++) {
            const int H = std::abs(X - x[i]) + std::abs(Y - y[i]) + h[i];
            if (h[i] == 0) {
                r = std::min(r, H);
            } else {
                l = std::max(l, H), r = std::min(r, H);
            }
        }
        return l <= r ? l : -1;
    };
    for (int X = 0; X <= 100; X++) {
        for (int Y = 0; Y <= 100; Y++) {
            if (ok(X, Y) != -1) {
                return std::cout << X << " " << Y << " " << ok(X, Y) << std::endl, 0;
            }
        }
    }
    return 0;
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
(N,K),P,C = $<.map{|ln| ln.split.map(&:to_i) }

Max = lambda{|a,k|
	k = a.size if a.size<k
	next 0 if k <= 0

	l = r = -k
	sl = sr = 0
	ss = [[-Float::INFINITY,0]]
	max = -Float::INFINITY
	while l < a.size-1
		while r < l+k && r < a.size-1
			sr += a[r+=1]
			ss.pop while ! ss.empty? && ss[-1][0] <= sr
			ss << [sr,r]
		end
		xs,xi = ss[0]
		max = xs-sl if max < xs-sl
		sl += a[l+=1]
		ss.shift if ss[0][1] == l
	end

	next max
}

A = P.map{|p|
	a,f = [],lambda{|p|
		a << C[p-1]
		C[p-1] = nil
		next P[p-1]
	}
	q = f[p]
	next unless a[0]
	q = f[q] until q == p
	next a
}.compact

p A.map{|a|
	s = a.sum
	(a.size<K && 0<s) ? s*(K/a.size-1) + Max[a+a,a.size+K%a.size] : Max[a,K]
}.max


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

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> a(n), b(n), c(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
  }
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());
  long long ans=0;
  for(int i=0;i<n;i++){
    auto IterA = upper_bound(a.begin(),a.end(),b[i]-1);
    auto IterC = lower_bound(c.begin(),c.end(),b[i]+1);
    ans += (IterA-a.begin()) * (c.end()-IterC);
  }
  cout<<ans<<endl;
}

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

int main()
{
    int a, p;
    cin >> a >> p;
    p += a * 3;
    int ans = p / 2;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a % 2 == 0 || b % 2 == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 62) - 1;

int main(void)
{
    string s;

    cin >> s;

    if (s[0] == 'S')
    {
        cout << "Cloudy" << endl;
    }
    else if (s[0] == 'C')
    {
        cout << "Rainy" << endl;
    }
    else if (s[0] == 'R')
    {
        cout << "Sunny" << endl;
    }
}

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

int main(void){
  int k, md, i;
  char flg[1000000]={0};
  
  cin >> k;
  i = 1;
  if ((md = 7%k)==0){
    cout << i << endl;
    return 0;
  }
  flg[md]=1;
  while (i++){
    md = (md*10+7)%k;
    if (md==0) {
      cout << i << endl;
      break;
    } else if (flg[md]){
      cout << -1 << endl;
      break;
    }
    flg[md]=1;
   // cout << md << endl;
  }
  return 0;
}

Measured memory_bytes: 4612
/*#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >>n;
  ll a[n];
  for(ll i=0;i<n;i++) cin >>a[i];
  ll sum=0;
  for(ll i=0;i<n;i++){
    if(sum+a[i]==0)
  }

}*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  string s;
  cin >>s;
  ll k;
  cin >>k;
  ll ss=s.size(),fl=0;
  if(ss==1) cout <<s[0]<<endl;
  else if(s[0]!='1') cout <<s[0]<<endl;
  else{
    ll m;
    for(ll i=0;i<k;i++){
    if(i==ss-1) break;
    if(s[i]!='1') {
      m=i;
      fl=1;
      break;
    }
  }
  if(fl==1) {
    cout <<s[m]<<endl;
  }
  else cout <<1<<endl;
  }
  }


Measured memory_bytes: 256
N = input()
a = list(map(int, input().split()))
     
answer = 0
flg = True
while flg:
    
    for i, m in enumerate(a):
        if m%2 == 1:
            flg = False
            break
        a[i] = m/2
    if flg:
        answer += 1

print(answer)


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

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

  for (int i = A; i <= B; i++) {
    int a = i % 10; //12345 5
    int b = i / 10000 % 10; //12345

    int c = i / 10 % 10;
    int d = i / 1000 % 10;

    if ( a == b && c == d) {
      sum++;
    }
  }

  cout << sum << endl;

}

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

int minCost( int a[], int n){

    int dp[n]={0};

    dp[0]=0;

    for(int i=1;i<n;i++){
        dp[i]=INT_MAX;

        if(i-1>=0){
            dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1]));
        }

        if(i-2>=0){
            dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
        }

    }

    return dp[n-1];



}

int main() {
    int n;
    cin>>n;
    int a[n];

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



}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,K;
    cin >> N >> K;
    double ans = 0;
    repX(i,N+1,1){
        int score = i;
        int ren = 0;
        while(score<K){
            score*=2;
            ren ++;
        }
        ans += (1/(double)(N))*(double)(pow(0.5,ren));
    }
    printf("%.10f\n",ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    string c;
    cin >> c;
    ll rcnt = 0;
    rep(i, n) {
        if (c[i] == 'R') rcnt++;
    }
    ll ans = 0;
    rep(i, rcnt) {
        if (c[i] != 'R') ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	ll n; cin>>n;
	vl a(n);
	rep(i,0,n)cin>>a[i];
	vl r(n+10),l(n+10);
	r[n+1]=0; l[0]=0;
	rep(i,1,n+1){
		l[i]=gcd(l[i-1],a[i-1]);
		r[n+1-i]=gcd(r[n+2-i],a[n-i]);
	}
		
	ll ans=1;
	rep(i,1,n+1){
		ll g=gcd(l[i-1],r[i+1]);
		ans=max(ans,g);
	}
	cout<<ans<<endl;
	
	return 0;
}


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

struct Card{char suit, value;};

void bubble(struct Card A[], int N){
	for( int i = 0; i < N; i++ ){
		for(int j = N - 1; j>= i+1;j--){
			if( A[j].value < A[j - 1].value){
				Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
			}
		}
	}
}

void selection(struct Card A[], int N){
	for(int i = 0; i < N; i++){
		int minj = i;
		for(int j = i; j < N; j++){
			if( A[j].value < A[minj].value) minj = j;
		}
		Card t = A[i]; A[i] = A[minj]; A[minj] = t;
	}
}

void print(struct Card A[] ,int N){
	for(int i = 0;i < N; i++){
		if( i > 0) cout << " ";
		cout << A[i].suit << A[i].value;
	}
	cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
	for(int i = 0; i < N; i++){
		if( C1[i].suit != C2[i].suit ) return false;
	}
	return true;
}

int main(){
	Card C1[100], C2[100];
	int N;
	char ch;
	
	cin >> N;
	for(int i = 0;i < N; i++){
		cin >> C1[i].suit >> C1[i].value;
	}
	
	for(int i = 0;i < N;i++) C2[i] = C1[i];
	
	bubble(C1, N);
	selection(C2, N);
	
	print(C1, N);
	cout << "Stable" << endl;
	print(C2, N);
	if( isStable(C1, C2, N)){
		cout << "Stable" <<endl;
	}else{
		cout << "Not stable" << endl;
	}
	return 0;
}



Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int selectionSort(int *A, int N) {
	int i, j;
	int minj;
	int sw = 0;
	for (i = 0; i < N; i++) {
		minj = i;
		for (j = i; j < N; j++) {
			if (A[j] < A[minj])
				minj = j;
		}
		if(i != minj) {
			swap(A[i], A[minj]);
			sw++;
		}
	}
	return sw;
}

int main(void)
{
	int A[100];
	int N;
    cin>>N;
	int i, sw;
	for(i = 0; i < N; i++) {
		cin>>A[i];
	}
	sw = selectionSort(A, N);
	
	for(i = 0; i< N; i++) {
		if(i > 0) cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	cout<<sw<<endl;
}

Measured memory_bytes: 3084
#include<stdio.h>
void call(int n);
int cas, loop;
int main(){
	int n;
	cas = 0;
	loop = 1;
	scanf("%d", &n);
	call(n);
}

void call(int n){
	int i = 1;
	int x;
	while(loop){
		switch(cas){
			case 0:	// CHECK_NUM
				x = i;
				if(x%3==0){
					printf(" %d", i);
					cas = 2;
					break;
				}
				cas = 1;
				break;
			case 1:	// INCLUDE3
				if(x%10 == 3){
					printf(" %d", i);
					cas = 2;
					break;
				}
				x /= 10;
				if(x) {
					cas = 1;
					break;
				}
				cas = 2;
				break;
			case 2:	// END_CHECK_NUM
				if(++i <= n){
					cas = 0;
					break;
				}
				printf("\n");
				loop = 0;
				break;
			default:
				break;	
		}
	}
}


Measured memory_bytes: 2048
#include<stdio.h>
#include<math.h>

#define N 8

int n, p[N], q[N];

int matchSeq(int *seq1, int *seq2){
  for(int i=0; i<n; i++){
    if(seq1[i]!=seq2[i]){
      return 0;
    }
  }
  return 1;
}

int permSearch(int noArray, int *isStoraged, int *seq, int *ans, int *cnt){
  if(noArray==n){
//    for(int i=0; i<n; i++){printf("%d ",seq[i]); } printf("\n");
    *cnt=*cnt+1;
    int isP=0, isQ=0;
    isP = matchSeq(seq, p);
    isQ = matchSeq(seq, q);
    if(isP && isQ){
      *ans = 0;
    }
    else if(isP || isQ){
//      printf("%d\n",*cnt);
      if(*ans==0){
        *ans = *cnt;
      }
      else{
        *ans = *ans - *cnt;
        if(*ans<0){
          *ans = (-1)*(*ans);
        }
      }
    }    
  }
  else{
//    for(int i=0; i<n; i++){printf("%d ",isStoraged[i]); } printf("\n");
    for(int i=0; i<n; i++){
      if(isStoraged[i]==0){
        isStoraged[i] = 1;
        seq[noArray] = i+1;
        permSearch(noArray+1, isStoraged, seq, ans, cnt);
        isStoraged[i] = 0;
      }
    }
  }
  return 0;
}

int main(){
  scanf("%d",&n);
  for(int i=0; i<n; i++){
    scanf("%d",&p[i]);
  }
  for(int i=0; i<n; i++){
    scanf("%d",&q[i]);
  }
  
  int isStoraged[N]={0}, seq[N]={0}, diff=0, cnt=0;
  permSearch(0, isStoraged, seq, &diff, &cnt);
  
  printf("%d",diff);
  
  return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

for i in range(N):
    A[i + 1] += A[i]

B = [A[j] - A[i] for i in range(N) for j in range(i + 1, N + 1)]

ans = 0
t = 40
while t:
    count = 0
    tmp = pow(2, t -1)
    for b in B:
        if ((b & (tmp + ans)) == (tmp + ans)):
            count += 1
    if count >= K:
        ans += tmp
    t -= 1

print (ans)

Measured memory_bytes: 65788
n=gets.to_i
d=1<<(n.bit_length-1)
if d==n
puts "No"
else
puts "Yes"
if d*2-1==n
(1...n*2).map{|i|puts "#{i} #{i+1}"}
else
d-=1
(1...d).map{|i|puts "#{i} #{i+1}"}
puts "#{d} #{n+1}"
(n+1...n+d).map{|i|puts "#{i} #{i+1}"}
d+=1

if n>d
puts "#{d} 1"
puts "#{d+1} 1"
puts "#{n+d} #{d+1}"
puts "#{n+d+1} #{d}"
(d+2..n).map{|i|
puts "#{i} #{i-d}"
puts "#{n+i} #{i-1}"
}
end
end
end

Measured memory_bytes: 7676
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX= 3e3+100;


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

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=e[i].nxt)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=2e5+5;
const ll mod=1e9+7;
int n,k;
ll sum[MAX_N],ans; 
int main()
{
	si(n),si(k);
	repi(i,1,n+1) sum[i]=1ll*(i-1)+sum[i-1];
	repi(i,k,n+1){
		ll mn=sum[i],mx=sum[n+1]-sum[n+1-i];
		ans=(ans+(mx-mn+1))%mod; 
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5372
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

string S;
int n0, n1;

int main() {
    cin >> S;
    rep(i, S.size()) {
        if (S[i] == '0') n0++;
        else n1++;
    }
    cout << min(n0, n1) * 2 << endl;
    return 0;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 444;

int n;
int a[N][4];
ll form[N];

template<class T>
ll id(T a) {
    ll res = 1e18;
    forn(off,4) {
        ll tmp = 0;
        forn(i,4) tmp = 1000*tmp + a[(i+off)%4];
        res = min(res, tmp);
    }
    return res;
}

int rotations(int a[]) {
    int res = 0;
    forn(off,4) {
        bool ok = true;
        forn(i,4) if (a[i] != a[(i+off)%4]) ok = false;
        res += ok;
    }
    return res;
}



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

    cin >> n;
    map<ll,int> cnt, mult;
    forn(i,n) {
        forn(j,4) cin >> a[i][j];
        form[i] = id(a[i]);
        cnt[form[i]]++;
        mult[form[i]] = rotations(a[i]);
    }

    ll res = 0;
    forn(j,n) forn(i,j) {
        cnt[form[i]]--; cnt[form[j]]--;
        forn(oi,4) {
            forn(oj,4) {
                ll tmp = 1;
                ll x = id(vi{a[i][3], a[i][2], a[j][1], a[j][0]});
                ll y = id(vi{a[j][3], a[j][2], a[i][1], a[i][0]});
                ll z = id(vi{a[i][2], a[i][1], a[j][2], a[j][1]});
                ll w = id(vi{a[i][0], a[i][3], a[j][0], a[j][3]});

                tmp *= mult[x] * cnt[x]--;
                tmp *= mult[y] * cnt[y]--;
                tmp *= mult[z] * cnt[z]--;
                tmp *= mult[w] * cnt[w]--;
                cnt[x]++; cnt[y]++; cnt[z]++; cnt[w]++;
                res += tmp;
                rotate(a[j], a[j]+1, a[j]+4);
            }
            rotate(a[i], a[i]+1, a[i]+4);
        }
        cnt[form[i]]++; cnt[form[j]]++;
    }
    res /= 12;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 159872
// 2020-08-22 23:03:05
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int inf = 1e9;
int h, w, S[2], G[2];
void answer() {
  cin >> h >> w >> S[0] >> S[1] >> G[0] >> G[1];
  S[0]--;
  S[1]--;
  G[0]--;
  G[1]--;
  vector<vector<int> > wall(h, vector<int>(w, 0));
  vector<vector<int> > dist(h, vector<int>(w, inf));
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) wall[i][j] = (s[j] == '#');
  }
  using T = tuple<int, int, int>;
  deque<T> que;
  que.emplace_front(T(0, S[0], S[1]));
  dist[S[0]][S[1]] = 0;
  while(!que.empty()) {
    auto [cd, cy, cx] = que.front(); que.pop_front();
    if(dist[cy][cx] < cd) continue;
    REPC(ny, cy-2, cy+2) REPC(nx, cx-2, cx+2) {
      if(ny < 0 || h <= ny || nx < 0 || w <= nx || wall[ny][nx]) continue;
      if(cy == ny && cx == nx) continue;
      else if(abs(cy-ny) + abs(cx-nx) == 1) {
        int nd = cd;
        if(chmin(dist[ny][nx], nd)) {
          que.emplace_front(T(nd, ny, nx));
        }
      }
      else {
        int nd = cd + 1;
        if(chmin(dist[ny][nx], nd)) {
          que.emplace_back(T(nd, ny, nx));
        }
      }
    }
  }
  int ans = dist[G[0]][G[1]];
  if(ans == inf) ans = -1;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 11548
#include<bits/stdc++.h>
#define F first
#define S second
#define INF (1<<30)
#define LINF (1LL<<60)
using namespace std;
typedef pair<long long,long long> P;
long long a,b,c,d;
string s,s2,s3;
long long  sum=0,ans=0,pos=0;
long long n,m,h,w;
main(){
  cin>>n;
  if(n<1200) cout<<"ABC"<<endl;
  else cout<<"ARC"<<endl;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct edge {int to, cap, rev;};

vector <edge> G[105];
bool used[105];

void add_edge(int from, int to, int cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, 0, G[from].size() - 1});
}

int dfs(int v, int t, int f){
  if (v == t) return f;
  used[v] = true;

  for (int i = 0; i < G[v].size(); i++){
    edge &e = G[v][i];
    if (!used[e.to] && e.cap > 0){
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int main(){
  int V, E; cin >> V >> E;
  for (int i = 0; i < E; i++){
    int u, v, c;
    cin >> u >> v >> c;
    add_edge(u, v, c);
  }

  int ans = 0;
  while (true){
    fill(used, used + V, false);
    int f = dfs(0, V - 1, 1e9);
    if (f == 0) break;
    ans += f;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3216
#include <algorithm>
#include <iostream>
#include<string>

 using namespace std  ;

   int main ()

   {
       int a ,b ,k;
       while (cin >> a >> b>> k)
      {
          int who =1 ;
          while (k--)
          {
              if (who )
              {
                  if (a%2) a-=1 ;

                      a/=2;
                      b+=a;

              }
              else
              {
                  if (b%2) b-=1 ;

                      b/=2;
                      a+=b;


            }
        who=!who ;
      }
    cout<<a<<" "<<b<<endl ;
   }
       return 0;

   }


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String N[] = br.readLine().split("");
		int K = Integer.parseInt(br.readLine());

		long dp[][][] = new long[105][2][5]; // i 桁目までで 0 以外の数を使用したのが k 個である数の個数。
		dp[0][0][0] = 1;

		for (int i = 0; i < N.length; i++) {
			for (int j = 0; j < K + 1; j++) {
				// i桁目まででNより小さいならi+1桁目は何でも良い
				dp[i + 1][1][j + 1] += dp[i][1][j] * 9; // i+1桁目が0以外なら0以外の個数jも+1
				dp[i + 1][1][j] += dp[i][1][j]; // i+1桁目が0なら0以外の個数jは不変

				// i桁目までNと同じで、i+1桁目はNより小さい数の時
				int ni = Integer.parseInt(N[i]); // i桁目の数
				if (ni > 0) {
					dp[i + 1][1][j + 1] += dp[i][0][j] * (ni - 1); // i+1桁目が0以外
					dp[i + 1][1][j] += dp[i][0][j]; // i+1桁目が0
				}

				// i桁目までNと同じで、i+1桁目もNと同じ数の時
				if (ni > 0) { // i+1桁目が0かどうか
					dp[i + 1][0][j + 1] = dp[i][0][j]; // i+1桁目が0以外
				} else {
					dp[i + 1][0][j] = dp[i][0][j]; // i+1桁目が0
				}
			}
		}

		long ans = dp[N.length][0][K] + dp[N.length][1][K];
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(20);
    double ans = (double)w*h /2.0;
    bool f = (x*2 == w && y*2 == h);
    cout << ans << " " << (f?1:0) << '\n';
    return 0;
}

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

using ll = long long;

struct Ans {
    int N;
    int M;
    int u[60];
    int v[60];
    int w[60];
};

struct Ans solve(int L) {
    struct Ans ret;
    if (L < 5) {
        ret.N = 2;
        ret.M = L;
        rep(i, L) {
            ret.u[i] = 0;
            ret.v[i] = 1;
            ret.w[i] = i;
        }
        return ret;
    }
    if (L % 2 == 1) {
        ret = solve(L - 1);
        ret.u[ret.M] = 0;
        ret.v[ret.M] = ret.N - 1;
        ret.w[ret.M] = L - 1;
        ret.M++;
    } else {
        ret = solve(L / 2);
        ret.u[ret.M] = ret.N - 1;
        ret.v[ret.M] = ret.N;
        ret.w[ret.M] = 0;
        ret.u[ret.M + 1] = ret.N - 1;
        ret.v[ret.M + 1] = ret.N;
        ret.w[ret.M + 1] = L / 2;
        ret.N++;
        ret.M += 2;
    }
    return ret;
}

int main() {
    int L;
    cin >> L;
    struct Ans a = solve(L);
    cout << a.N << " " << a.M << endl;
    rep(i, a.M) cout << a.u[i] + 1 << " " << a.v[i] + 1 << " " << a.w[i] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
main(){
    char a[10];
    int n,i,out=0,base=0,score=0;
    scanf("%d",&n);
    while(n!=0){
        scanf("%s",a);
        if(!strcmp(a,"HIT")){
            base++;
            if(base>3){
                base--;
                score++;
            }
        }
        if(!strcmp(a,"OUT")){
        out++;
        }
        if(!strcmp(a,"HOMERUN")){
            score+=base+1;
            base=0;
        }
        if(out==3){
            n--;
            out=0;
            printf("%d\n",score);
            score=0;
            base=0;
        }
    }
}

Measured memory_bytes: 1024
n,u,v=map(int,input().split())
u-=1;v-=1
edge=[[]*n for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1;b-=1
  edge[a].append(b)
  edge[b].append(a)
  
  
# from u 逃げる
# uはvからみた距離が大きい方に進むのかな
# from v 追う
# v始点でBFSして各頂点への距離を持つ
dist=[-1]*n

from collections import deque
q=deque()
q.append(v)
dist[v]=0
while q:
  p=q.popleft()
  d=dist[p]
  for i in edge[p]:
    if dist[i]==-1:
      dist[i]=d+1
      q.append(i)

# print(dist)

far=[-1]*n
q=deque()
q.append(u)
far[u]=0
while q:
  p=q.popleft()
  d=far[p]
  for i in edge[p]:
    if far[i]==-1:
      if dist[i]>d+1:
        far[i]=d+1
        q.append(i)

# print(far)
  

far_mx=max(far)
if far_mx==-1:
  print(0)
  exit()
  
ind=[i for i,v in enumerate(far) if v!=-1]

to=max(dist[i] for i in ind)
ans=(to-1)
print(ans)


Measured memory_bytes: 90984
S = list(input())
tmp = ''
L = len(S)
S = S[-1:-L-1:-1]
Kouho = ['maerd','remaerd','esare','resare']
ans = 0
for i in range(L):
    
    tmp += str(S[i])
    if tmp in Kouho:
        ans += len(tmp)
        tmp = ''
if ans == L:
    print('YES')
else:
    print('NO')

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

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

    int q, max_r = -1e9;
    cin >> q;
    vector<int> L(q), R(q);
    for(int i = 0; i < q; i++){
        cin >> L[i] >> R[i];
        max_r = max(max_r, R[i]);
    }

    // 念のため
    max_r += 10;

    vector<bool> F(max_r, true);
    F[0] = false;
    F[1] = false;
    for(int i = 2; i < (int)(sqrt(max_r)); i++){
        if(F[i] == true){
            for(int j = i + i; j < max_r; j += i){
                F[j] = false;
            }
        }
    }

    vector<int> A(max_r, 0);
    for(int i = 3; i < max_r; i += 2){
        if(F[i] && F[(i + 1) / 2]){
            A[i]++;
        }
    }

    for(int i = 3; i < max_r; i++){
        A[i] += A[i - 1];
    }

    for(int i = 0; i < q; i++){
        cout << A[R[i]] - A[L[i] - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        d: i32,
    }
    let mut a = a;
    let mut c = c;
    loop {
        c -= b;
        if c <= 0 { break; }
        a -= d;
        if a <= 0 { break; }
    }
    if c <= 0  {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

long long int calc(long long int n){
  long long int t = 1, l = 1, ret = 0;
  while(10*t <= n){
    ret += 9*t*l;
    t *= 10;
    ++l;
  }
  ret += (n - t + 1)*l;
  return ret;
}

int main(){
  int N, K;
  while(cin >> N >> K, N||K){
    long long int ok = 0, ng = 1e9;
    while(ng - ok > 1){
      long long int m = (ok + ng)/2LL;
      if(calc(m) >= N) ng = m;
      else ok = m;
    }
    int t = N - calc(ok) - 1;
    ++ok;
    string s = to_string(ok), s_ = s.substr(t,min(K,(int)s.size()-t));
    cout << s_;
    K -= s_.size();
    ++ok;
    while(K > 0){
      string s = to_string(ok);
      if(s.length() <= K){
        cout << s;
        K -= s.length();
        ++ok;
        continue;
      }
      for(int i = 0; i < s.length(); ++i){
        if(K == 0) break;
        cout << s[i];
        --K;
      }
      ++ok;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    vp vec(m);
    REP(i,m){
        cin>>vec[i].se>>vec[i].fi;
    }
    sort(all(vec));
    int ans=0;
    int r=-1;
    REP(i,m){
        if(vec[i].se>r){
            ans++;
            r=vec[i].fi-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


int r,d,x;

int solve(int a){
	int ans;
	if(a==0) return r*x-d;
	else{
		a--;
		ans =solve(a);
	}
	return(ans);
}

int main(){
	cin>>r>>d>>x;
	for(int i=0;i<10;i++){
	    int u = solve(d);
	    x=u;
	    cout<<u<<endl;
	}
}

Measured memory_bytes: 3600
n = int(input())
lis = list(map(int,input().split()))
li = [0]
for num in lis:
    li.append(li[-1] + num)
ans = 0
mod = 10 ** 9 + 7
for i in range(n):
    ans += (lis[i] * li[i]) % mod
    ans %= mod
print(ans)

Measured memory_bytes: 102128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return a % 1000000007;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n,d,x; cin >> n >> d >> x; ll sum = 0;
  
  for(ll i=0; i < n; i++){
    ll a; cin >> a;
    sum += 1 + (d-1)/a;
  }
  
  cout << sum + x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int table[500000];
int prime[100000];
int main(){
    table[0]=-1;
    table[1]=-1;
    for(int i=2;i<500000;i++){
        if(table[i]!=-1){
            table[i]=1;
            for(int j=i*2;j<500000;j+=i){
                table[j]=-1;
            }
        }
    }
    int now=0;
    for(int i=0;i<500000;i++){
        if(table[i]==1)prime[now++]=i;
    }
    int a;
    while(scanf("%d",&a),a){
        long long int ret=0;
        for(int i=0;i<a;i++){
            ret+=prime[i];
        }
        printf("%lld\n",ret);
    }
}

Measured memory_bytes: 3148
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
 ll n,m,ac=0,wa=0; cin>>n>>m;
  vector<ll>p(m);
  vector<string>s(m);
  vector<bool>que(n);
  rep(i,n)que[i]=0;
  rep(i,m){
  cin>>p[i]>>s[i];
  }
  rep(i,m){
  if(s[i]=="AC"&& !que[p[i]]){ac++; que[p[i]]=1;}
    else if(s[i]=="WA"&&!que[p[i]]){wa++;}
  }
  rep(i,m){
  if(s[i]=="WA"&&!que[p[i]])wa--;
  }
  cout<<ac<<' '<<wa<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

vector<pair<ll,int>> factorize(ll n) {
    vector<pair<ll,int>> ans;
    for (ll i = 2; i*i <= n; ++i) {
        if (n%i) continue;
        ans.emplace_back(i,0);
        while (n%i == 0) {
            n /= i;
            ans.back().second++;
        }
    }
    if (n != 1) ans.emplace_back(n,1);
    return ans;
}

int calc(int a) {
    int res = 0;
    while (a > 0) {
        a -= res;
        if (a <= res) return res;
        res++;
    }
    return res;
}

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

    int ans = 0;
    auto f = factorize(n);
    for (auto x : f) {
        ans += calc(x.se);
    }


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

Measured memory_bytes: 3628
import math

def isprime(n):
    if n == 1: return 0
    
    for k in range(2, int(math.floor(math.sqrt(n))) + 1):
        if n % k == 0:
            return 0
    
    return 1

while True:
    a,d,n = map(int,input().split())
    
    if a==d==n==0:
        break
    
    kazu=0
    num=0
    for i in range(10**6):
        kazu = a + i*d
        
        if isprime(kazu) == 1:
            num+=1
        
        if num == n:
            print(kazu)
            break


Measured memory_bytes: 5668
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 4e5+10;
const int OFFSET = MAX/2;

int N, M;
int A[MAX];
int cnt[MAX], section[MAX];

void setSection(int i, int v) { section[OFFSET+i] = v; }
void addSection(int i, int v) { section[OFFSET+i] += v; }
int getSection(int i) { return section[OFFSET+i]; }

int main() {
    cin >> N >> M;
    REP (i, N) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    int cnt0 = 0;
    FOR (i, 1, N+1) {
        int n = cnt[i];
        addSection(i-n+1, 1);
        addSection(i+1, -1);
    }
    REP(i, MAX-1)
        section[i+1] += section[i];
    FOR (i, 1, N+1) 
        if (getSection(i) == 0) cnt0++;

    cout << endl;
    REP (q, M) {
        int x, y;
        cin >> x >> y; x--;
        int a = A[x];
        A[x] = y;
        if (a != y) {
            cnt[a]--;
            cnt[y]++;
            addSection(a-cnt[a], -1);
            if (a-cnt[a] >= 1 && getSection(a-cnt[a]) == 0) cnt0++;
            addSection(y-cnt[y]+1, 1);
            if (y-cnt[y]+1 >= 1 && getSection(y-cnt[y]+1) == 1) cnt0--;
        }
        /*
        FOR (i, 1, N+1) cout << getSection(i) << " ";
        cout << endl;
        */
        cout << cnt0 << "\n";
    }
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
int main()
{
long a,b,c,d;
   while(cin>>a>>b>>c>>d)
   {
       cout<<max(a*b,c*d)<<"\n";
   }
    return 0;
}


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

int main(int argc, char* argv[]) {
  using std::cin;
  using std::cout;
  using std::vector;
  
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; ++i) {
    cin >> x[i];
  }
  if (m <= n) {
    cout << 0;
    return 0;
  }
  sort(x.begin(), x.end());
  vector<int> d(m - 1);
  for (int i = 0; i < m - 1; ++i) {
    d[i] = x[i + 1] - x[i];
  }
  sort(d.begin(), d.end());
  int result = 0;
  for (int i = 0; i < m - n; ++i) {
    result += d[i];
  }
  cout << result;
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll cnt1 = (a-1)/d+1;
    ll cnt2 = (c-1)/b+1;
    if (cnt1>=cnt2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;

int main ()
{
   int a[1001],n;
   long long int y;
   while (scanf ("%d%lld",&n,&y)!=EOF)
   {
       int flag=0;
        for (int i=y/10000; i>=0;i--)
        for (int j=n-i; j>=0;j--)
     {
         if (flag) break;
         int k=n-i-j;
         long long int sum = (long long int) i *10000+ (long long int)j*5000 + (long long int)k*1000;
         if (sum==y) {printf ("%d %d %d\n",i,j,k); flag=1;}
     }
     if (!flag) printf ("-1 -1 -1\n");
   }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
bool dp[88][88][50000] = {};
const int M = 25000;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int h, w;
  cin >> h >> w;
  vector<vector<int>> g(h, vector<int>(w));
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    cin >> g[i][j];
  }
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    int a;
    cin >> a;
    g[i][j] = abs(g[i][j] - a);
  }
  dp[0][0][M + g[0][0]] = 1;
  dp[0][0][M - g[0][0]] = 1;
  queue<pair<int, int>> que;
  que.push({0, 0});
  vector<vector<int>> vis(h, vector<int>(w));
  vis[0][0] = 1;
  while (que.size()) {
    auto cur = que.front();
    que.pop();
    for (int dx : {1, 0}) for (int dy : {0, 1}) {
      if (dx == dy) continue;
      int x = dx + cur.first;
      int y = dy + cur.second;
      if (x >= h || y >= w) continue;
      for (int i = 0; i < 50000; i++) {
        if (dp[cur.first][cur.second][i]) {
          if (i - g[x][y] >= 0) dp[x][y][i - g[x][y]] = 1;
          if (i + g[x][y] < 50000) dp[x][y][i + g[x][y]] = 1;
        }
      }
      if (!vis[x][y]) {
        vis[x][y] = 1;
        que.push({x, y});
      }
    }
  }
  int ans = 1 << 30;
  for (int i = 0; i < 50000; i++) {
    if (dp[h - 1][w - 1][i]) {
      ans = min(ans, abs(i - M));
      //cerr << i << endl;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl


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

int main(void) {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }

  sort(all(a));

  ll f = a.size();

  a.erase(unique(all(a)), a.end());

  ll l = a.size();

  if(f==l){
    prt("YES");
  } else
  {
    prt("NO");
  }
}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S;
bool op[3];

int main(){
  cin >> S;
  for (int i = 0; i < 8; i++){
    int num = i, sum = S[0] - '0';
    for (int j = 0; j < 3; j++){
      op[j] = num % 2; num /= 2;
      if (op[j]) sum += S[j + 1] - '0';
      else sum -= S[j + 1] - '0';
    }

    if (sum != 7) continue;

    for (int j = 0; j < 3; j++){
      printf("%c", S[j]);
      if (op[j]) printf("+");
      else printf("-");
    }
    printf("%c=7\n", S[3]);
    return 0;
  }
  


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a=0;cin>>n;
  m=n;
  while(m>0){
    a+=m%10;
    m=m/10;
  }
  if(n%a==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
     


Measured memory_bytes: 256