akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int A,B,C,D,E,F,s[3001],a,b;
int main(){
    cin>>A>>B>>C>>D>>E>>F;
    for(int i{};i*C<=F;++i)
        for(int j{};i*C+j*D<=F;++j)
            s[i*C+j*D]=1;
    for(int i{};i*A*100<=F;++i)
        for(int j{};j*B*100+i*A*100<=F;++j){
            int n{j*B*100+i*A*100};
            for(int k{};k+n<=F;++k)
                if(s[k]&&k*100<=n*E)
                    if(!a||b*(n+k)<k*(a+b))
                        a=n,b=k;
        }
    cout<<a+b<<' '<<b<<endl;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>

using namespace std;

int main() {
	int n, y, a, b, c,ans;
	cin >> n >> y;
	for (int a = 0; a <= n; a++) {
		for (int b = 0; b <= n-a; b++) {
			c = n - a - b;
				if (10000 * a + 5000 * b + 1000 * c == y) {
					cout << a <<" "<< b << " " << c << endl; 
					return 0;
				}
			
		}
	}

		cout << "-1 -1 -1" << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,K;
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N;i++) {
        cin >> a[i];
    }
    int testN = K;
    int ans = 1;
    while(testN < N) {
        testN += K -1;
        ans++;
    } 

    cout << ans;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  if (a > b){
    printf("%d",2*a-1);
  }else if (a < b){
    printf("%d",2*b-1);
  }else{
    printf("%d",2*a);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

vector<ll>v[100005];

ll dfs(ll k,ll now,ll p)
{
	ll x;
	if(p==-1)
		x=k-1;
	else
		x=k-2;
	if(v[now].size()>k)
		return 0;
	else
	{
		ll y=1;
		for(auto e:v[now])
		{	if(e==p)
				continue;
			y=y*x;
			x--;
			y%=mod;


		}

	
	for(auto e:v[now])
	{
		if(e==p)
			continue;
		y*=dfs(k,e,now);
		y%=mod;
	}
	return y;
}

}
int main() {
	ll n,k;
	cin>>n>>k;
	//vector<ll>v[n+1];
	for(int i=0;i<n-1;i++)
	{
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);

	}
ll ans=k*dfs(k,0,-1);
ans%=mod;
cout<<ans;
	
}


Measured memory_bytes: 11520
function main(input){
  var args = input.split(" ").map(x=>parseInt(x));
  if(args[0]<9 && args[1]<9){
  	console.log("Yay!");
  }else{
  	console.log(":(");
  }

}



main(require("fs").readFileSync("/dev/stdin","utf-8"));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), s(n);
  rep(i, n){
    cin >> a.at(i);
    s.at(i) = a.at(i);
  }
  sort(s.rbegin(), s.rend());
  rep(i, n) {
    if(a.at(i) == s.at(0)) cout << s.at(1);
    else cout << s.at(0);
    cout << endl;
  }
}

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

template <typename T>
class FenwickTreeAdd{
  using value_type = T;
  
  int size;
  std::vector<value_type> data;
  
public:
  FenwickTreeAdd(){}
  FenwickTreeAdd(int size): size(size), data(size + 1, 0){}
  
  void update(int i, value_type val){
    i += 1; // 1-index
    
    while(i <= size){
      data[i] = data[i] + val;
      i += i & (-i);
    }
  }
  
  value_type get(int i) const { // [0, i)
    value_type ret = 0;
    i += 1; // 1-index

    while(i > 0){
      ret = ret + data[i];
      i -= i & (-i);
    }

    return ret;
  }

  value_type get(int l, int r) const { // [l, r)
    return get(r-1) - get(l-1);
  }
};


template <typename T>
struct RangeCountQuery{
  std::vector<int> a;
  std::vector<std::pair<int, int>> qs;
  std::map<std::pair<int, int>, std::vector<int>> index;
  int N;

  RangeCountQuery(std::vector<T> a_): N(a_.size()){
    auto temp = a_;
    std::sort(temp.begin(), temp.end());
    temp.erase(std::unique(temp.begin(), temp.end()), temp.end());

    for(auto x : a_){
      int i = std::lower_bound(temp.begin(), temp.end(), x) - temp.begin(); 
      a.push_back(i);
    }
  }

  void add(int l, int r){ // [l, r)
    index[{l, r}].push_back(qs.size());
    qs.emplace_back(r, l);
  }

  auto solve(){
    std::sort(qs.begin(), qs.end());

    FenwickTreeAdd<int> b(N);

    const int Q = qs.size();
    std::vector<int> last_index(N, -1);
    std::vector<int> ret(Q);
  
    int cur = 0;
    for(auto [r, l] : qs){
      while(cur < r){
        if(last_index[a[cur]] != -1){
          b.update(last_index[a[cur]], -1);
        }

        last_index[a[cur]] = cur;
        b.update(last_index[a[cur]], 1);

        ++cur;
      }

      for(auto i : index[{l, r}]){
        ret[i] = b.get(l, r);
      }
    }
    
    return ret;
  }
};


int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N, Q; std::cin >> N >> Q;
  std::vector<int> c(N);
  for(int i = 0; i < N; ++i) std::cin >> c[i];

  RangeCountQuery<int> rcq(c);

  for(int i = 0; i < Q; ++i){
    int l, r; std::cin >> l >> r;
    rcq.add(l - 1, r);
  }

  auto ans = rcq.solve();

  for(auto x : ans) std::cout << x << "\n";

  return 0;
}


Measured memory_bytes: 72224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static const unsigned long long MOD = 1000000007LL;

int main(){
    string s;
    cin >> s;
    int c;
    ll length = s.length();
    ll dp[length+1000][13];
    dp[0][0] = 1;
    for(ll n = 0; n < length; n++){
        if(s[n] == '?') c = -1;
        else c = s[n] - '0';

        for(int j = 0; j < 10; j++){
            if(c != -1 && c != j) continue;
            for(int ki = 0; ki < 13; ki++){
                dp[n+1][(ki * 10 + j) % 13] += dp[n][ki];
            }
        }

        for(int j = 0; j < 13; j++) dp[n+1][j] %= MOD;
    }
    ll res = dp[length][5];

    cout << res << endl;
  //cout << length << endl;
    return 0;
}

Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();

        String[] image = new String[h];
        for (int i = 0; i < h; i++) {
            image[i] = sc.next();
        }

        String wall = "##";
        for (int i = 0; i < w; i++) {
            wall += "#";
        }

        System.out.println(wall);
        for (int i = 0; i < h; i++) {
            image[i] = "#" + image[i] + "#";
            System.out.println(image[i]);
        }
        System.out.println(wall);
    }
}

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

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

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

template <LL MOD=1000000007> class MODLL {
public:
  LL x;
  MODLL(const LL _x) : x(_x % MOD) {};
  MODLL operator+(const MODLL rhs) const { return MODLL(*this) += rhs; }
  MODLL operator-(const MODLL rhs) const { return MODLL(*this) -= rhs; }
  MODLL operator*(const MODLL rhs) const { return MODLL(*this) *= rhs; }
  MODLL operator/(const MODLL rhs) const { return MODLL(*this) /= rhs; }
  MODLL& operator+=(const MODLL rhs) { x += rhs.x; x %= MOD; return *this; }
  MODLL& operator-=(const MODLL rhs) { x -= rhs.x; x %= MOD; if(x<0) x += MOD; return *this; }
  MODLL& operator*=(const MODLL rhs) { x *= rhs.x; x %= MOD; return *this; }
  MODLL inv() const {
    if(x == 0) { throw "does not have inverse"; }
    LL a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return MODLL(u);
  }
  MODLL& operator/=(const MODLL rhs) { (*this) *= rhs.inv(); return *this; }
  MODLL pow(ULL n) const {
    MODLL res = 1;
    MODLL a = x;
    while (n > 0) {
      if (n & 1) res *= a;
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef MODLL<> ML;

void test() {
  {
    ML x = 3;
    assert(x.pow(45).x == 644897553);
  }
  {
    for(int i=1; i<13; i++) {
      MODLL<13> x = i;
      assert( (x.inv().x * i) % 13 == 1 );
    }
  }
}


int main() {
  LL N,K;
  std::cin >> N >> K;

  LL x = N / K;
  LL ans = x * x * x;
  if(K%2 == 0) {
    if( N % K >= K/2 ) {
      ans += (x+1) * (x+1) * (x+1);
    }
    else {
      ans += x * x * x;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

vi dst,par;
  
int main() {
  int N,M;
  cin >> N >> M;
  vvi G(N);
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dst = vi(N,-1);
  par = vi(N,-1);
  queue<P> que;
  que.push(P(0,0));
  while(!que.empty()) {
    int p = que.front().second;
    int now = que.front().first;
    que.pop();
    if(dst[now]!=-1) continue;
    par[now]=p;
    dst[now]=dst[p]+1;
    for(int q:G[now]) {
      if(q==p) continue;
      if(dst[q]!=-1) continue;
      que.push(P(q,now));
    }
  }
  rep(i,N) {
    if(dst[i]==-1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  srep(i,1,N) {
    cout << par[i]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 11076
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pll pair<ll, ll>
#pragma GCC optimize ("O3")
using namespace std;
int main () {
    #ifdef LOCAL
        freopen ("input.txt", "r", stdin);
        freopen ("output.txt", "w", stdout);
        freopen ("error.txt", "w", stderr);
    #else
        ios::sync_with_stdio(false);
        cin.tie (NULL);
    #endif
    int n; cin>>n;
    vector <double> a (n);
    for (auto &i : a) cin>>i;
    sort (a.begin(), a.end());
    double now=a[0];
    for (int i=1;i<n;++i) {
        now+=a[i];
        now/=2;
    }
    cout<<fixed<<setprecision(10)<<now;
    return 0;
}


Measured memory_bytes: 256
def f(s):
  A=s[0]
  for i in range(0,len(s),3):
    if s[i:i+3]==(A[-1]+"->"): A+=s[i+3]
    elif s[i:i+3]==(A[0]+"<-"): A=s[i+3]+A
  return "".join(A)

n=input()
for _ in [0]*n:
  s=raw_input()
  print f(s)

Measured memory_bytes: 4224
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define yn(i) ((i)?"Yes":"No")
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}




string key="keyence";

void add(char m,string s,set<string> st){
  int n=s.size();
  rep(i,n){
    if(s[i]!=m) continue;
    string t;
    repa(j,i,n){
      t.push_back(s[j]);
      st.insert(t);
    }
  }
}

int main(){
  int n; cin >>n;
  vector<int> a(n+1,0);
  rep(i,n) cin >>a[i+1];
  vector<int> b(n+1,0);
  int m=0;
  rep(_i,n){                    // 0 .. n-1
    int i=n-_i,s=0;             // n .. 1
    if(df)print("i",i);
    repa(j,1,n+1){
      int p=i*j;
      if(df)print("p",p);
      if(p>n) break;
      s+=b[p];
    }
    if(df)print("a,s:",a[i],s);
    b[i]=a[i]^(s%2);
    m+=b[i];
  }
  if(df) print(b);
  print(m);
  rep(i,n+1){
    if(b[i]) cout << (i) << " ";
  }
}





Measured memory_bytes: 4816
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  
  int ans = 0;
  int now = 0;
  for( int i = 0; i < N; i++ ){
    int A;
    cin >> A;
    if( A == 0 ){
      ans += now/2;
      now = 0;
    }else now += A;
  }
  ans += now/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
def Q2(x):
    A, B, C, D = x[0], x[1], x[2], x[3]
    time_lower = max(A, C)
    time_upper = min(B, D)
    return max(0, time_upper - time_lower)

l = [int(i) for i in input().split()]
print(Q2(l))

Measured memory_bytes: 3316
import numpy as np

i = list(map(int, input().split()))
a = i[0]
b = i[1]
h = i[2]
m = i[3]
arg1 = (float((h * 60 + m)*2)/float((12 * 60)))
arg2 = float(m*2 )/60
arg = abs(arg1 - arg2) * np.pi
print(np.sqrt(a*a + b*b - 2*a*b*np.cos(arg)))

Measured memory_bytes: 27064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    int ans = 0;
    REP(i, s.size()){
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
	string st;
	cin>>st;
	int ans=0;
	for(int i=0;i<st.size()/2;i++)
	{
		if(st[i]!=st[st.size()-1-i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
int main() 
{ 
	ll n;
	cin >> n;
	ll p;
	ll ans=0;
	ll st=n+1;
	for(ll i=0;i<n;i++)
		{
			cin >> p;
			if(p<st)
				{
					ans+=1;
					st=p;
				}
		}
	cout << ans << "\n";
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define MOD 1000000007
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	ll n,x;
	cin>>n>>x;
	ll a[n+1];
	for(ll i=0; i<n; i++)
		cin>>a[i];
	ll sum=0,count=1;
	for(ll i=0; i<n; i++)
	{
		sum+=a[i];
		if(sum<=x)
			count++;
		else break;
	}
	cout<<count;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double dist(double* x,double* y){
	return sqrt(*x**x + *y**y);
}
int main(){
  long long int n=0;
  double d=0;
  cin>>n>>d;
  double x=0,y=0;
  long long int count=0;
  while(n--){
    cin>>x>>y;
    if(dist(&x,&y)<=d){
    count++;
    }
  }
  cout<<count<<'\n';
  return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

const int MOD = 1e9 + 7;

int main(){

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

    int n; cin >> n;
    string s1, s2; cin >> s1 >> s2;

    vector<bool> isVert;
    rep(i, n){
        if(s1[i] == s1[i+1]){
            isVert.push_back(false);
            i++;
        }
        else{
            isVert.push_back(true);
        }
    }

    ll cnt = 0;
    if(isVert[0] == true){
        cnt = 3;
    }
    else{
        cnt = 6;
    }

    reps(i, 1, isVert.size()){
        if(isVert[i-1] == true){
            cnt = (cnt * 2) % MOD;
        }
        else{
            if(isVert[i] == false){
                cnt = (cnt * 3) % MOD;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

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

using namespace std;

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

    string s;
    cin >> s;
    string g = s;
    reverse(s.begin(), s.end());
    int cnt = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != g[i]) cnt++;
    }
    cout << cnt / 2 << "\n";

    return 0;
}


Measured memory_bytes: 256
OP = ["+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"]
N = input()
for operation in OP:
    formula = N[0] + operation[0] + N[1] + operation[1] + N[2] + operation[2] + N[3]
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin>>a>>b>>c;
    vector<int> vec = {a, b, c};
    sort(vec.begin(), vec.end());
 
    c=vec.at(0)+vec.at(1);
        cout << c ;
    
}

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

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, m;
	cin >> n >> m;
    vector<vector<int> > parts(m);

    for (int i = 0; i < n; i++) {
    	int days, reward;
    	cin >> days >> reward;

    	if (days <= m) {
    		parts[days - 1].push_back(reward);
    	}
    } 


    priority_queue<int> q;
    long long ans = 0;
    for (int i = 0; i < m; i++) {
    	for (int j : parts[i]) {
    		q.push(j);
    	}

    	if (q.size()) {
    		ans += q.top();
    		q.pop();
    	}
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 5632
function main(input) {
  input=input.trim();
  const n = parseInt(input.split(" ")[0], 10);
  const a = Math.floor(n/10);
  const b = n%1000;
  if(a%111==0 || b%111==0){
    console.log("Yes");
  }else{
    console.log("No");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 21064
def factorization(n):
    arr = [[1, 1]]
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
a, b = map(int, input().split())
g = gcd(a, b)
l = factorization(g)
print(len(l))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
 
 
int main(){
    
    ll a,b;cin>>a>>b;
    a-=2*b;
    cout<<max(a,0)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int64_t Q, H, S, D, N, M1;
    cin >> Q >> H >> S >> D >> N;
    M1 = min({4 * Q, 2 * H, S});
    if (D > 2 * M1){
        cout << M1 * N << endl;
    }
    else {
        cout << N / 2 * D + N % 2 * M1 << endl;
    }
}




Measured memory_bytes: 256
n=int(input())
num=[3,5,7]
#a[0]=3,a[1]=5,a[7]=5
ans=[3,5,7]
answ=[]
for i1 in range(3):
  for i2 in range(3):
    for i3 in range(3):
      a=set([i1,i2,i3])
      if len(a)>2:
        answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])))
      for i4 in range(3):
        a=set([i1,i2,i3,i4])
        if len(a)>2:
          answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i4])))
        for i5 in range(3):
          a=set([i1,i2,i3,i4,i5])
          if len(a)>2:
            answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i5])+str(num[i4])))
          for i6 in range(3):
            a=set([i1,i2,i3,i4,i5,i6])
            if len(a)>2:
              answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i6])+str(num[i5])+str(num[i4])))
            for i7 in range(3):
              a=set([i1,i2,i3,i4,i5,i6,i7])
              if len(a)>2:
                answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
              for i8 in range(3):
                a=set([i1,i2,i3,i4,i5,i6,i7,i8])
                if len(a)>2:
                  answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
                for i9 in range(3):
                  a=set([i1,i2,i3,i4,i5,i6,i7,i8,i9])
                  if len(a)>2:
                    answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i9])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
answ.sort()
left=0
right=len(answ)
while right-left>1:
  mid=(left+right)//2
  
  if n<answ[mid]:
    right=mid
  else:
    left=mid
if 357>n:
  print(0)
else:
  print(left+1)
                    
                

Measured memory_bytes: 10108
import queue
K = int(input()) -1
q = queue.Queue()
for i in range (1,10):
    q.put(i)
while K > 0:
    x = q.get()
    if x %10 != 0:
        q.put(10*x +x%10 -1)
    q.put(10*x + x%10)
    if x % 10 != 9:
        q.put(10*x + x%10 +1)
    K -= 1
ans = q.get()
print(ans)

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

int main(){

  int N=0;
  cin>>N;

  int A[N];

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

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

    }
    
  }
  cout<<sum;
  
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;

    int count = 0;
    rep(i,n-2) {
        if (s.substr(i,3) == "ABC") count += 1;
    }

    cout << count << endl;
}

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

int main(){
  vector <int> x(4),y(4);
  for(int i=0;i<2;i++){
    cin >> x.at(i) >> y.at(i);
  }
  y.at(3)=y.at(0)+(x.at(1)-x.at(0));
  x.at(3)=x.at(0)-(y.at(1)-y.at(0));
  y.at(2)=y.at(3)+(x.at(0)-x.at(3));
  x.at(2)=x.at(3)-(y.at(0)-y.at(3));
  cout << x.at(2) << " " << y.at(2) << " " << x.at(3) << " " << y.at(3) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>

typedef long long ll;

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

int min(int a,int b){
    if(a<b) return a;
    else return b;
}

/*qsort(array,num_of_index,sizeof(int),compare_int); */
 int compare_int(const void *a,const void *b){
     return *(int*) a - *(int *) b; 
 } 
 
int b_search(int* array,int left,int right,int key){
    int mid = left - (right - left)/2;
     if( right - left == 1){
         if(array[mid]==key)
             return mid;
          else
               return -1;
     }
     if(array[mid]==key)
         return mid;
     else if(array[mid]>key)
         b_search(array,left,mid,key);
     else if(array[mid]<key)
         b_search(array,mid,right,key);
}

/*lower_bound(key以上のイテレータを返す)*/
 /*例えば,2,2,5,5,9でkey=2なら(2),2,5,5,9を返す*/
 int lower_bound(int  *array,int left,int right,int key){
     if(right-left==1)
         return left;
     int mid = left + (right - left)/2;
     if(array[mid]<key)
         return lower_bound(array,mid,right,key);
     else
         return lower_bound(array,left,mid,key);
 }

int main(){
    int d,t,s;
    scanf("%d%d%d",&d,&t,&s);
    if (d <= s*t)
        printf("Yes");
    else
        printf("No");
}


Measured memory_bytes: 1732
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#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 F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x1f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	while(cin>>n>>m,n){
		vvll land;
		vvll sea;
		initvv(land,n,n,INFL);
		initvv(sea,n,n,INFL);
		rep(i,m){
			int a,b;
			ll c;
			char t;
			cin>>a>>b>>c>>t;
			a--;
			b--;
			if(t=='L') land[a][b]=mins(land[b][a],c);
			else sea[a][b]=mins(sea[b][a],c);
		}
		rep(j,n) land[j][j]=sea[j][j]=0;
		rep(k,n) rep(i,n) rep(j,n) mins(land[i][j],land[i][k]+land[k][j]);
		rep(k,n) rep(i,n) rep(j,n) mins(sea[i][j],sea[i][k]+sea[k][j]);
		int r;
		cin>>r;
		vint v(r);
		rep(i,r){
			cin>>v[i],v[i]--;
		}
		vll pre(n,INFL);
		pre[v[0]]=0;
		rep(i,r-1){
			vll dp(n,INFL);
			rep(k,n){
				mins(dp[k],pre[k]+land[v[i]][v[i+1]]);
				rep(l,n){
					mins(dp[l],pre[k]+land[v[i]][k]+sea[k][l]+land[l][v[i+1]]);
				}
			}
			swap(dp,pre);
		}
		cout<< *min_element(ALL(pre))<<endl;
	}
}


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

Measured memory_bytes: 1844
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
l=[]
for i in range(h):
  if i%2==0:
    for j in range(w):
      l.append((i,j))
  else:
    for j in range(w)[::-1]:
      l.append((i,j))
ans=[]

for i in range(len(l)-1):
  if a[l[i][0]][l[i][1]]%2==1:
    ans.append([l[i][0]+1,l[i][1]+1,l[i+1][0]+1,l[i+1][1]+1])
    a[l[i][0]][l[i][1]]-=1
    a[l[i+1][0]][l[i+1][1]]+=1
print(len(ans))
for i in ans:
  print(*i)

Measured memory_bytes: 51960
#include<iostream>
#include<string>
#include<map>
#include<math.h>
#include <stdlib.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    long long ans=0;
    for(int i=0;i<pow(2,s.size()-1);i++){
        int x=i,z=0;
        for(int j=1;j<s.size();j++){
            if(x%2==1) ans+=atol(s.substr(z,j-z).c_str()),z=j;
            x=x/2;
        }
        ans+=atol(s.substr(z,s.size()-z).c_str());
    }
    cout<<ans;
}

Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-09 19:16:44
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
#include<vector>
const int N=100010;
i64 n,m,a[N],b[N],f[N],F[N],rk[N],s[N];
int getf(int u){ return u==F[u]?u:F[u]=getf(F[u]); }
std::vector<int> E[N],e[N];
int cmp(int x,int y){ return a[x]-b[x]>a[y]-b[y]; }
void dfs(int u)
{
	s[u]=b[u]; f[u]=a[u]-b[u];
	fr(i,0,e[u].size()-1)
	{
		dfs(e[u][i]);
		s[u]+=s[e[u][i]]; f[u]=std::min(f[u],std::max(a[u]-b[u]-s[e[u][i]],f[e[u][i]]));
	}
}
int main()
{
	n=read(); m=read();
	fr(i,1,n){ a[i]=read(); b[i]=read(); a[i]=std::max(a[i],b[i]); }
	fr(i,1,m)
	{
		int u=read(),v=read();
		E[u].push_back(v); E[v].push_back(u);
	}
	fr(i,1,n) rk[i]=i;
	std::sort(rk+1,rk+n+1,cmp);
	fd(I,n,1)
	{
		int i=rk[I]; F[i]=i;
		fr(j,0,E[i].size()-1) if(F[E[i][j]])
		{
			int p=getf(E[i][j]);
			if(p!=i){ F[p]=i; e[i].push_back(p); }
		}
	}
	dfs(rk[1]);
	printf("%lld\n",f[rk[1]]+s[rk[1]]);
	return 0;
}

Measured memory_bytes: 18172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/



int main(){
  int s;
  cin >> s;
  vector<int> a;
  a.push_back(s);
  while(1){
    int x = a[a.size() - 1];
    if(x % 2 == 0) x /= 2;
    else x = x * 3 + 1;
    a.push_back(x);
    for(int i = 0; i < a.size(); i++){
      for(int j = i + 1; j < a.size(); j++){
	if(a[i] ==  a[j]){
	  cout << j + 1 << endl;
	  return 0;
	}
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
n,k,q=map(int,input().split())

pointl=[k-q for i in range(n)]

for i in range(q):
    a=int(input())
    pointl[a-1]=pointl[a-1]+1

for i in range(n):
    if pointl[i]<=0:
        print("No")
    else:
        print("Yes")
    

Measured memory_bytes: 7844
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    lint x;
    cin >> x;

    lint cur = 100;

    for (int i = 1; ; i++) {
        cur = cur * 1.01;
        if (x <= cur) {
            cout << i << endl;
            exit(0);
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int mod = (int) 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}

int main() {
  string s;
  int n;
  cin >> s;
  n = s.size();
  int dp[n + 2][13];
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '?') {
      for (int x = 0; x < 13; x++) {
        for (int y = 0; y <= 9; y++) {
          add(dp[i + 1][(x * 10 + y) % 13], dp[i][x]);
        }
      }
    } else {
      int el = (s[i] - '0');
      for (int x = 0; x < 13; x++) {
        add(dp[i + 1][(x * 10 + el) % 13], dp[i][x]);
      }
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}


Measured memory_bytes: 5504
def gcd(a,b):
    a,b=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        while a%b!=0:
            c=a%b
            a=b
            b=c
        return c

[A,B,C,D]=[int(_) for _ in input().split()]
E=C*D//gcd(C,D)
X=(B//C)-((A-1)//C)
Y=(B//D)-((A-1)//D)
Z=(B//E)-((A-1)//E)
N=B-A+1
print(N-(X+Y-Z))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<math.h>
#include <iomanip>
#include<queue>
using namespace std;
const double PI=3.14159265358979323846;
void a(){
    int n;
    cin >>n;
    n = n%10;
    if(n==3)
    {
        cout<<"bon";
    }
    else if(n==0 ||n==1 ||n==6 ||n==8)
    {
        cout<<"pon";
    }
    else cout<<"hon";
    return;
}

void b(){
    int k;
    string s;
    cin >> k>>s;
    if(s.length()<=k)cout<<s;
    else
    {
        cout<<s.substr(0,k)+"...";
    }
}

void c(){
    int a,b,h,m;
    cin >>a>>b>>h>>m;
    double t1 = (((double)h/12)+((double)m/720))*2*PI;
    //cout<<(double)h/12<<endl;
    double t2 = ((double)m/60)*2*PI;
    double t3 = (t1 - t2);
    double l = sqrt(a*a+b*b-2*a*b*cos(t3));
    //cout<<t1<<" "<<t2;
    cout<< setprecision(12)<<l;
    return;
}

void d(){
    int n;
    int m;
    cin >> n>>m;
    vector<vector<int> >room(n);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin >>a>>b;
        room[a-1].push_back(b-1);
        room[b-1].push_back(a-1);
    }
    int dist[n]={0};
    for(int i=0;i<n;i++)dist[i]=-1;
    dist[0] = 0;
    queue<int> move;
    move.push(0);
    while(!move.empty())
    {
        int temp = move.front();
        move.pop();
        for(int i=0;i<room[temp].size();i++)
        {
            int see = room[temp][i];
            if(dist[see]==-1)
            {
                dist[see] = temp;
                move.push(see);
            }
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++)cout<<dist[i]+1<<endl;
    return;
    
}
void e(){
    int n;
    cin>>n;
    long long int a[n] ={0};
    long long int b[n] ={0};
    for(int i=0;i<n;i++)
    {
        cin >>a[i]>>b[i];
    }
   
}
int main(void){
    //a();
    //b();
    c();
    //d();
    //e();

}

Measured memory_bytes: 4128
h, w = map(int, input().split())

GRID = [["#"] * (w + 2)]
for _ in range(h):
    GRID.append(["#"] + list(map(int, input().split())) + ["#"])
GRID.append(["#"] * (w + 2))

PATH = []
for i in range(1, h + 1):
    if i % 2 == 1:
        for j in range(1, w + 1):
            PATH.append((i, j))
    else:
        for j in range(w, 0, -1):
            PATH.append((i, j))

n = 0
OPERATIONS = []
for k in range(h * w - 1):
    a, b = PATH[k]; c, d = PATH[k + 1]
    if GRID[a][b] % 2 == 1:
        GRID[a][b] -= 1; GRID[c][d] += 1
        n += 1
        OPERATIONS.append((a, b, c, d))

print(n)
for operation in OPERATIONS:
    print(*operation)


Measured memory_bytes: 40200
using System;
using System.Collections.Generic;

class Program {
  static void Main (string[] args) {
    string[] ss = Console.ReadLine().Split(' ');
    int n = int.Parse(ss[0]);
    int k = int.Parse(ss[1]);
    string s = Console.ReadLine();
    s = ((k != 0) ? s.Substring(0, k - 1) : "") + s[k - 1].ToString().ToLower() + ((k != n) ? s.Substring(k) : "");
    Console.WriteLine(s);
  }
}

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

int main(){
  int m,d;
  cin >> m >> d;
  if(d < 22){
    cout << 0 << endl;
  }else{
    int count = 0;
    for(int i = 1; i <= m; i++){
      for(int j = 22; j <= d; j++){
        if(j - (j/10) * 10 > 1){
          if((j / 10)*(j - (j/10)*10) == i){
            count ++;
          }
        }
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll A[100010], B[100010];
    cin >> N >> M;
    vector<lpair> lp;
    rep(i,0,N){
        cin >> A[i] >> B[i];
        lp.push_back(make_pair(A[i], B[i]));
    }
    sort(lp.begin(), lp.end());
    ll ans = 0;
    ll sum = 0;
    rep(i,0,N){
        ans += lp[i].first * min(lp[i].second, M - sum);
        sum += min(lp[i].second, M-sum);
    }
    print(ans);
 }

Measured memory_bytes: 4468
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    map<string, int> V;
    rep(i,N) {
        string s;
        cin >> s;
        V[s]++;
    }
    int M = 0;
    for (const auto& x : V) {
        M = max(M, x.second);
    }
    for (auto x : V) {
        if (x.second == M) {
            cout << x.first << endl;
        }
    }
}


Measured memory_bytes: 25216
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(D)]

last=[0]*26


for d in range(1,D+1):
    ans=[]
    for choice in range(1,27):
        ans_tmp=0
        ans_tmp+=s[d-1][choice-1]
        for i in range(26):
            if i+1==choice:
                continue
            ans_tmp-=c[i]*(d-last[i])*(D-d)//18
        ans.append((ans_tmp,choice))
    _,case=max(ans)
    last[case-1]=d
    print(case)



Measured memory_bytes: 9252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	int box = 0;
	string S;
	cin >> S;
 	
 	int C0 = 0;
 	int C1 = 0;

	for (int i = 0; i < S.size(); i++){
		if(S[i] == '0'){
			C0 += 1;
		}
		else {
			C1 += 1;  
		}
	}

	box = 2 * min(C0,C1);

	cout << box << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static int max = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int x = getInt(sc);
		int a = getInt(sc);
		int b = getInt(sc);

		int distA = Math.abs(x - a);
		int distB = Math.abs(x - b);
		if (distA < distB) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	int row = 0;
	int col = 0;
	int candies = 0;

	public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
using namespace std;
int data[15][15]={0};
int main(){
	
	int x,y,s;
	char c;
	while(scanf("%d,%d,%d",&x,&y,&s)!=EOF){
		
		while(1){
			data[x][y]++;
			if(y-1>=0)data[x][y-1]++;
			if(x+1<10)data[x+1][y]++;
			if(y+1<10)data[x][y+1]++;
			if(x-1>=0)data[x-1][y]++;
			if(s==1)break;
			if(x+1<10 && y+1<10)data[x+1][y+1]++;
			if(x+1<10 && y-1>=0)data[x+1][y-1]++;
			if(x-1>=0 && y-1>=0)data[x-1][y-1]++;
			if(x-1>=0 && y+1<10)data[x-1][y+1]++;
			if(s==2)break;
			if(x+2<10)data[x+2][y]++;
			if(y-2>=0)data[x][y-2]++;
			if(y+2<10)data[x][y+2]++;
			if(x-2>=0)data[x-2][y]++;
			break;
		}
		
	}
	int white=0,ma=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(data[i][j]==0)white++;
			ma=max(ma,data[i][j]);
		}
	}
	
	cout<<white<<endl<<ma<<endl;
}
	

Measured memory_bytes: 1208
# フェルマーの小定理
N, K = map(int, input().split())
A = list(map(int, input().split()))

m = 1000000007

fac = [0] * (N + 1)
fac[0] = 1
for i in range(N):
    fac[i + 1] = fac[i] * (i + 1) % m


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


A.sort(reverse=True)
maxX = 0
for i in range(N - K + 1):
    maxX += A[i] * mcomb(N - (i + 1), K - 1)
    maxX %= m

A.sort()
minX = 0
for i in range(N - K + 1):
    minX += A[i] * mcomb(N - (i + 1), K - 1)
    minX %= m

print((maxX - minX) % m)


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

int map[501][501];
int ans[250001][4];

typedef pair<int, int> P;


int N, H, W;

vector<P> odd_point;

int main() {

    cin >> H >> W;

    for (int i = 0 ; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> map[i][j];
        }
    }


    vector<P> route;
    for (int i = 0 ; i < H; i++) {

        if (i % 2 == 0) 
            for (int j = 0; j < W; j++)
                route.push_back(make_pair(i, j));
        else 
            for (int j = W - 1; j >= 0; j--) 
                route.push_back(make_pair(i, j));
    }

    bool odd = false;
    int N = 0;
    for (int i = 0; i < route.size() - 1; i++) {
        if (odd == false) {
            if (map[route[i].first][route[i].second] % 2 == 1) {
                odd = true;
                ans[N][0] = route[i].first;
                ans[N][1] = route[i].second;
                ans[N][2] = route[i+1].first;
                ans[N][3] = route[i+1].second;
                N++;
            }
        }
        else {
            if (map[route[i].first][route[i].second] % 2 == 1) {
                odd = false;
                continue;
            }
            ans[N][0] = route[i].first;
            ans[N][1] = route[i].second;
            ans[N][2] = route[i+1].first;
            ans[N][3] = route[i+1].second;
            N++;
        }
    }
    cout << N << '\n';
    for (int i = 0; i < N; i++) {
    cout << ans[i][0] + 1 << ' ' << ans[i][1] + 1 << ' ' 
                    << ans[i][2] + 1 << ' ' << ans[i][3] + 1 << '\n';
    }

}


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

int main() {
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++) cin>>h[i];
  sort(h,h+n);
  int ans=1e9+7;
  for(int i=0;i<n-k+1;i++){
    ans =min(ans,h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vi l(n);
	rep(i, n) cin >> l[i];
	ll ans = 0;
    vsort(l);
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l[k] < l[i] + l[j]) ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256