akhauriyash/Code-Regression huggingface dataset:
n = int(input())
S = list(map(int, input().split()))
c = 0


def merge(left, mid, right):
    global c
    L = S[left:mid] + [float('inf')]
    R = S[mid:right] + [float('inf')]
    i, j = 0, 0
    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
            c += mid - left - i


def merge_sort(left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)


merge_sort(0, n)

print(c)



Measured memory_bytes: 27476
import std.stdio;
long div = 1_000_000_007;
void main() {
	long n, m;
	scanf("%ld %ld\n", &n, &m);
	auto dp = new long[n+2];
	dp[0] = 1;
	auto check = new bool[1_0000];
	long before = -1;
	foreach(_; 0..m) {
		long a;
		scanf("%ld\n", &a);
		assert(before < a);
		before = a;
		check[a] = true;
	}
	foreach(i; 0..n) {
		if (check[i]) continue;
		dp[i+1] = (dp[i+1] + dp[i]) % div;
		dp[i+2] = (dp[i+2] + dp[i]) % div;
	}
	dp[n].write;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
struct objects{
    int weight,value;
};
ll solve(){
   int n,w;
   cin>>n>>w;
   objects object[n];
   int totalvalue=0;
   for(int i=0;i<n;i++){
       cin>>object[i].weight>>object[i].value;
       totalvalue+=object[i].value;
   }
   ll dp[n+1][totalvalue+1];
    //dp[i][j] denotes the least weight to get a value of
   // j from the first i objects
   dp[0][0]=0;//It takes 0 weight here
   int ans=0;
   for(int i=1;i<=totalvalue;i++){
       dp[0][i]=1e18;
      // Just set it arbitrarily large
       //because it's not possible 
   }
   for(int i=0;i<n;i++){
       for(int j=0;j<=totalvalue;j++){
           if(j>=object[i].value){
                dp[i+1][j]=min(dp[i][j],dp[i][j-object[i].value]+object[i].weight);
                //Either don't choose this object(dp[i][j]) or choose this object
                //The value without it would be j-object[i].value
                //the minimum weight would be the minimum weight needed to
                //get a value of j- object[i].value and add the weight of this object.
           }
           else{
               //If I choose this object the value will go over j
               dp[i+1][j]=dp[i][j];
           }
           if(dp[i+1][j]<=w){//Is it possible to get value of j in less than w weight
               ans=max(ans,j);//Find maximum such j
           }
       }
   }
   return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<solve();
}

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

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

    int sum = 0, p;
    for(int i = 0; i < c; i++){
        cin >> p;
        sum += p;
    }

    cout << (sum + n) / (n+1) << endl;
    return 0;
}


Measured memory_bytes: 3096
// [Tag]
// #

#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <deque>
#include <map>
using namespace std;

#define fi     	first    
#define se     	second  

/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
typedef unsigned char           uchar;
typedef unsigned int            ui;
typedef unsigned long long int  ull;

constexpr int               inf = 2123456789;
constexpr long long 		INF = 9123456789123456789;
constexpr long long         MOD = 1000000007LL;

template<class T>
using MaxHeap = priority_queue<T>;
template<class T>
using MinHeap = priority_queue<T, vector<T>, greater<T> >;


template<class T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i];
        if (i + 1 < vec.size())os << ' ';
    }
    return os;
}
template<class T>
istream& operator >> (istream& is, vector<T>& vec) {
    for (int i = 0; i < vec.size(); i++)is >> vec[i];
    return is;
}


/*************************************************/

int N;
vector<pii> robots;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    /*INPUT*/
    cin >> N;
    robots.resize(N);
    for (int i = 0; i < N; i++) {
        int X, L;
        cin >> X >> L;
        robots[i] = { X + L, X - L };
    }
    sort(robots.rbegin(), robots.rend());
    int ans(1);
    int End(robots[0].first), Begin(robots[0].second);
    
    for (int i = 1; i < N; i++) {
        if (robots[i].first <= Begin) {
            End = robots[i].first;
            Begin = robots[i].second;
            ans++;
        }
        else if (robots[i].first > Begin) {
            if (robots[i].second > Begin) {
                End = robots[i].first;
                Begin = robots[i].second;
            }
        }
    }
    cout << ans << endl;

    //for (auto ro : robots)
    //    cout << ro.first << " " << ro.second << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

int main() {
    
    int num_left = 0;
    int num_right = 0;
    int ans_left = 0;
    int ans_right = 0;
    int n;
    string s;
    cin >> n >> s;
    for (int i=0;i<s.length();i++){
        if(s[i] == '('){
            num_left += 1;
        }else{
            num_right += 1;
        }
        if(num_left < num_right){
            ans_left += 1;
            num_left += 1;
        }
    }
    ans_right = num_left - num_right;
    for (int i=0;i<ans_left;i++){
        cout << '(';
    }
    cout << s;
    for (int i=0;i<ans_right;i++){
        cout << ')';
    }
    cout << endl;

}

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

using namespace std;
char in[120];
pair<pair<string,int>,int> p[110];
int main() {
    int a; scanf("%d", &a);
    for (int i=0; i<a; i++) {
        int t; scanf("%s%d",in,&t);
        string tmp=in;
        p[i]=make_pair(make_pair(in,-t),i);
    }
    sort(p,p+a);
    for (int i=0; i<a; i++) printf("%d\n",p[i].second+1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main() {
	int n;cin>>n;
	double a[n];
	FOR(i,0,n)cin>>a[i];
	double dp[n+1][n+1];
	FOR(i,1,n+1){
		FOR(j,0,i+1){
			if(i==1 && j==0){
				dp[i][j]=(1.0-a[i-1]);
			}else if(i==1 && j==1){
				dp[i][j]=a[i-1];
			}
			else if(j==0){
				dp[i][j]=dp[i-1][j]*(1.0-a[i-1]);
			}else if(i==j){
				dp[i][j]=dp[i-1][j-1]*a[i-1];
			}
			else{
				dp[i][j]=(1.0-a[i-1])*dp[i-1][j]+a[i-1]*dp[i-1][j-1];
			}
		}	
	}
	
/*	FOR(i,1,n+1){
		FOR(j,0,i+1){
			cout<<dp[i][j]<<" ";
		}cout<<endl;
	}
*/	double ans=0.0;
	FOR(i,(n+1)/2,n+1)ans+=dp[n][i];
	cout<<fixed<<setprecision(10)<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 49820
#include <iostream>
#define llint long long

using namespace std;

llint I, O, T, J, L, S, Z;

int main(void)
{
	cin >> I >> O >> T >> J >> L >> S >> Z;
	
	llint ans = 0;
	ans += 2 * O;
	
	llint ans1 = I/2*4 + J/2*4 + L/2*4;
	llint ans2 = 0;
	if(I > 0 && J > 0 && L > 0){
		ans2 += 6;
		ans2 += (I-1)/2*4 + (J-1)/2*4 + (L-1)/2*4;
	}
	ans += max(ans1, ans2);
	
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B] = [long(input_raw[0]), long(input_raw[1])]
    if((A + B) % 2 == 1):
        print "IMPOSSIBLE"
    else:
        print (A + B)/2

if __name__ == '__main__':
    main()


Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;

int n, k;

signed main(){
	scanf("%d %d", &n, &k);
	if(k == 1) printf("0");
	else{
		printf("%d", n-k);
	}
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {

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

    int count = 0;

    while (n > 1) {
      n = n / k;
      count++;
    }

    if (n%k != 0) {
      System.out.println(count+1);
    } else {
      System.out.println(count);
    }

  }

}


Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	map<string, int> m;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		m[s]++;
	}
	cout << m.size();
}

Measured memory_bytes: 19124
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int N;
	ll T[1005], A[1005];

	cin >> N;
	rep(i,N) cin >> T[i] >> A[i];

	ll t=1, a=1;
	rep(i,N){
		ll m = max( (t-1)/T[i]+1, (a-1)/A[i] + 1 );
		t = T[i] * m;
		a = A[i] * m;
	}

	cout << (t+a) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int room[4][3][10] = {0};
	int b, f, r, v;
	int n;
	int i, j, k;


	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);

		room[b-1][f-1][r-1] += v;
	}

	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++)
				printf(" %d", room[i][j][k]);
			printf("\n");
		}

		if(i<3){
			for(j=0;j<20;j++)
				printf("#");
			printf("\n");
		}
	}

	return 0;
}

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

int main()
{
  long long a,b,c,k;cin>>a>>b>>c>>k;
  long long ans=0;
  if(k%2==0)ans=a-b;
  else ans=b-a;
  if(abs(ans)>1000000000000000000)cout<<"Unfair"<<endl;
  else cout<<ans<<endl;
}


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

template <typename T>
struct Matrix {
    vector<vector<T>> mat;
    Matrix(int n, int m, T val = 0) : mat(n, vector<long long>(m, val)) {};
    void init(int n, int m, T val = 0) {mat.assigin(n, vector<long long>(m, val));}
    size_t size() const {return mat.size();}
    inline vector<long long>& operator[](int i) {return mat[i];}
};

long long MOD;

template <typename T>
Matrix<T> operator*(Matrix<T> A, Matrix<T> B) {
    Matrix<T> C(A.size(), B[0].size());
    for(int i = 0; i < A.size(); ++i) {
        for(int j = 0; j < B[0].size(); ++j) {
            for(int k = 0; k < B.size(); ++k) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] % MOD) % MOD;
            }
        }
    }
    return C;
}

template <typename T>
Matrix<T> pow(Matrix<T> A, long long n) {
    Matrix<T> C(A.size(), A.size());
    for(int i = 0; i < A.size(); ++i) C[i][i] = 1;
    while(n > 0) {
        if(n & 1) C = C * A;
        A = A * A;
        n >>= 1;
    }
    return C;
}

using mat = Matrix<long long>;
using vec = vector<long long>;

vec pro(mat A, vec X, long long C){
    vec ret(3, 0);
    mat Apro = pow(A, C);

    for(int i=0; i<3; ++i) {
        for(int j=0; j<3; ++j) {
            ret[i] = (ret[i] + Apro[i][j] * X[j] % MOD) % MOD;
        }
    }
    return ret;
}

long long powmod(long long x, long long n) {
    long long ret = 1;
    while(n > 0) {
        if(n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

int main() {
    long long L, A, B;
    cin >> L >> A >> B >> MOD;

    int start = 0;
    long long tmp = 1;
    for(; start < 18; ++start) {
        if(A >= tmp && A < tmp * 10) break;
        tmp *= 10LL;
    }

    vec C(18);
    long long prev = A - B, cnt = 0;

    for(int i=start; i<18; ++i) {
       C[i] = ((long long)pow(10, i + 1) - prev) / B;
       if(prev + B * C[i] == (long long)pow(10, i + 1)) --C[i];
       C[i] = min(C[i], L - cnt);
       cnt += C[i];
       if(cnt == L) break;
       prev += B * C[i];
    }

    vec X = {0, A, B};
    mat coeff(3, 3);
    coeff[0] = {1, 1, 0};
    coeff[1] = {0, 1, 1};
    coeff[2] = {0, 0, 1};
    for(int d=0; d<18; ++d) {
        coeff[0][0] = powmod(10, d + 1);
        X = pro(coeff, X, C[d]);
    }

    cout << X[0] % MOD << endl;
}

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

int main(){
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
      if(s - i - j >= 0 && s - i - j <= k){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3528
#include <map>
#include <set>
#include <unordered_set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>
#include <atomic>
#include <thread>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define DFOR(i,s,e) int i = s;for(;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define DFORR(i,s,e) int i = s;for(;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }


const int N = 100001, inf = 10000;
int a[N];
int cnt[N];
int n;

ll go(int v) {
  if (v * 3 > n) {
    ll res = 0;
    FOR(i, v, n) {
      if (i >= v + v && i % 2 == 0) continue;
      if (i + i > n) {
        if (!cnt[i]) res += max(0, a[i]);
        continue;
      }
      if (!cnt[i]) {
        if (cnt[i + i]) res += max(0, a[i]);
        else res += max(0, max(a[i], a[i] + a[i + i]));
      }
    }
    return res;
  }
  if (cnt[v]) return go(v + 1);
  ll res = a[v] + go(v + 1);
  for (int i = v; i <= n; i += v)cnt[i]++;
  Max(res, go(v + 1));
  for (int i = v; i <= n; i += v)cnt[i]--;
  return res;
}

void solve() {
  cin >> n;
  FOR(i, 1, n)cin >> a[i];
  cout << go(1) << ln;
  
}



void gen() {
  n = 5;
  //cout << n << ln;
  rep(i, n) {
    int num = rand() % (1000);
    num -= 500;
    //cout << num << ' ';
    a[i + 1] = num;
  }
  //cout << ln;
}

void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



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

int main()
{
	int n;
	cin>>n;
	int arr[n],dp[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1]<<endl;
return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> P(A), Q(B), R(C);
    rep(i, A) cin >> P[i];
    rep(i, B) cin >> Q[i];
    rep(i, C) cin >> R[i];
    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());
    ll ans = 0;
    rep(i, X) {
        R.push_back(P[i]);
    }
    rep(i, Y) {
        R.push_back(Q[i]);
    }
    sort(R.rbegin(), R.rend());
    rep(i, X + Y) ans += R[i];
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod2=998244353;
ll fpow(ll x,ll y,ll p=MOD){ if(y==0)return 1; else if(x==0)return 0; x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll spf[1000005];
void sieve()
{
  for(int i=1;i<1000005;i++)
  spf[i]=i;
  for(int i=2;i*i<=1000005;i++)
  if(spf[i]==i)
  for(int j=2*i;j<1000005;j+=i)
  spf[j]=min(spf[j],(ll)(i));
}

int main(){
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   sieve();
   ll n;
   cin>>n;
   ll g = 0;
   map<ll,ll>m;
   vector<ll>v(n);
   for(int i=0;i<n;i++){
     cin>>v[i];
     g = __gcd(g,v[i]);
     set<ll>s;
     while(spf[v[i]]>1){
       s.insert(spf[v[i]]);
       v[i]/=spf[v[i]];
     }
     for(auto u:s){
       m[u]++;
     }
   }
   if(g>1){
     cout<<"not coprime";
   }
   else{
     bool single = true;
     for(auto u:m){
       if(u.se>1)
        single=false;
     }
     if(single)
     cout<<"pairwise coprime";
     else
     cout<<"setwise coprime";
   }
}


Measured memory_bytes: 23784
N = int(input())
A = list(map(int, input().split()))

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

def f():
    if len(d) == 3:
        xor = 0
        for key in d:
            xor ^= key
        if xor == 0:
            lsit_d = list(d.keys())
            if d[lsit_d [0]] == d[lsit_d [1]] and d[lsit_d [0]] == d[lsit_d [2]]:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

    if len(d) == 1:
        lsit_d = list(d.keys())
        if lsit_d [0] == 0:
            return 'Yes'
        
    if len(d) == 2:
        if d[0] * 2 == N - d[0]:
            return 'Yes'
    
    return 'No'
    
print(f())
 


Measured memory_bytes: 60784
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;



int main(void) {
  ll i, j, k;
  string L;
  ll K;
  cin >> L;
  cin >> K;
  ll N=(ll)L.size();
  ll dp[111][5][2]={};
  
  
  dp[0][0][1]=1;
  
  //例 L=18037
  for(i=0; i<N; i++) {
    for(j=0; j<=K; j++) {
      ll LIM=L[i]-'0';
      
      //18'?'(i=2)
      if(LIM==0) {

        //18'0'
        dp[i+1][j][1]+=dp[i][j][1];
        
        
        //17'0'
        dp[i+1][j][0]+=dp[i][j][0];
        
        //17'k'(k=1~9)
        for(k=1; k<10; k++)
          dp[i+1][j+1][0]+=dp[i][j][0];
        
      }
      //1803'?'(i=4)
      else {
        
        //1803'0'
        dp[i+1][j][0]+=dp[i][j][1];
        
        //1803'k'(k=1~6)
        for(k=1; k<LIM; k++)
          dp[i+1][j+1][0]+=dp[i][j][1];
        
        //1803'7'
        dp[i+1][j+1][1]+=dp[i][j][1];
        
        
        //1752'0'
        dp[i+1][j][0]+=dp[i][j][0];
        
        //1752'k'(k=1~9)
        for(k=1; k<10; k++)
          dp[i+1][j+1][0]+=dp[i][j][0];
        
      }
      
    }
  }
  
  pt(dp[N][K][0]+dp[N][K][1]);
  
}





Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    if N == 2:
        if A[0] <= A[1]:
            return print(A[1])
        else:
            return print(A[0])
    # 以下 3<=N

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    ans = 1
    nonneed_idx = -1
    if gcd(A[0], A[1]) > gcd(A[1], A[2]) and gcd(A[0], A[1]) > gcd(A[0], A[2]):
        ans = gcd(A[0], A[1])
        nonneed_idx = 2
    elif gcd(A[0], A[2]) > gcd(A[1], A[2]) and gcd(A[0], A[2]) > gcd(A[0], A[1]):
        ans = gcd(A[0], A[2])
        nonneed_idx = 1
    else:
        ans = gcd(A[1], A[2])
        nonneed_idx = 0

    for i in range(3, N):
        if gcd(ans, A[nonneed_idx]) < gcd(ans, A[i]):
            ans = gcd(ans, A[i])
        else:
            ans = gcd(ans, A[nonneed_idx])
            nonneed_idx = i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
    cini(n);
    cins(s);
    for(int i=0; i<s.size(); i++) {
        int v=s[i]-'A';
        v=(v+n)%26;
        s[i]='A'+v;
    }
    cout<<s<<endl;
}

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int t=1;
    while(t--)
        solve();
}



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


def so_bunkai(num, dicts):
    N = num
    num = int(num**(1 / 2) // 1)
    for i in range(2, num + 2):
        while N % i == 0:
            N /= i
            if i in dicts:
                dicts[i] += 1
            else:
                dicts[i] = 1
    if N != 1:
        if N in dicts:
            dicts[int(N)] += 1
        else:
            dicts[int(N)] = 1
    return dicts


ans_dict = {}
for i in range(1, N + 1):
    ans_dict = so_bunkai(i, ans_dict)
    
asd = 10**9 + 7
ans = 1
for d in ans_dict:
    ans *= (ans_dict[d] + 1)
    ans %= asd

print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll ans=0;
  if(a>=k) cout << k << endl;
  else if(a+b>=k) cout << a << endl;
  else cout << k-b-2*(k-a-b) << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int p[200010];
double P[200010];
int main() 
{
	int N, K;
	cin >> N >> K;	
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		for (int j = 1; j <= p[i]; j++) {
			P[i] += (double)j / p[i];
		}
	}
	double ans = 0.0, sum = 0;
	for (int i = 0; i < K; i++) {
		sum += P[i];
	}
	ans = sum;
	for (int i = K; i < N; i++) {
		sum -= P[i - K];
		sum += P[i];
		ans = max(sum, ans);
	}
	printf("%.6f", ans);
}


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

void call(int n) {
	int i = 1;
	do {
		int x = i;
		if(x % 3 == 0) {
			cout << " " << i;
		}
		else do {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
		} while(x /= 10);
	} while(++i <= n);
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	call(n);
}

Measured memory_bytes: 1160
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const int mod=1000000007,MAX=100001;


vector<int> S[MAX];
vector<ll> dis(MAX);
ll ans,K;


ll BFS(){
    queue<int> Q;
    ll ans=1;
    Q.push(0);
    dis[0]=0;
    ans*=K;
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        int cnt=0;
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(dis[b]==-1){
                if(dis[a]==0){
                    ans*=(K-1-cnt);
                    ans=ans%mod;
                    cnt++;
                    dis[b]=1;
                }else{
                    ans*=(K-2-cnt);
                    ans=ans%mod;
                    cnt++;
                    dis[b]=dis[a]+1;
                }
                Q.push(b);
            }
        }
    }
    
    return ans;
}

int main(){
    
    int N;cin>>N>>K;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    for(int i=0;i<N;i++){
        dis[i]=-1;
    }
    
    cout<<BFS()<<endl;
}



Measured memory_bytes: 7288
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            list.add(sc.nextInt());
        }

        System.out.println(Collections.max(list) - Collections.min(list));
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    int i,j;
    ll sum=0;
    cin >> n;
    vector<ll> a(n),b(n),c(n-1);
    for(i=0;i<n;i++)cin >> a.at(i);
    for(i=0;i<n;i++)cin >> b.at(i);
    for(i=0;i<n-1;i++)cin >> c.at(i);
    for(i=0;i<n;i++)sum+=b.at(a.at(i)-1);

    for(i=0;i<n-1;i++){
        if(a.at(i)+1==a.at(i+1))sum+=c.at(a.at(i)-1);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
S = raw_input()
T = raw_input()
ans = "z"*100
for i in range(len(S)-len(T)+1):
    ok = True
    for j in range(len(T)):
        if S[i+j]!="?" and S[i+j]!=T[j]:
            ok = False
    if ok:
        s = S[:i]+T+S[i+len(T):]
        ans = min(ans, s.replace("?", "a"))
if ans=="z"*100:
    print "UNRESTORABLE"
else:
    print ans


Measured memory_bytes: 2568
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N;
    int xy[5] = {0};
    int tempx,tempy,tempa;
    cin >> xy[2] >> xy[4] >> N;
    REP(i,N){
        cin >>tempx >> tempy >> tempa;
        if(tempa <= 2){
            if(tempa%2){
                //1
                xy[tempa] = max(xy[tempa],tempx);
            }else{
                //2
                xy[tempa] = min(xy[tempa],tempx);
            }
        }else{
            if(tempa % 2){
                xy[tempa] = max(xy[tempa],tempy);
            }else{
                xy[tempa] = min(xy[tempa],tempy);
            }
        }
    }
    //cout << xy[1] << xy[2] << xy[3] << xy[4] << endl;
    if(xy[2] - xy[1] <= 0 || xy[4]-xy[3] <= 0){
        fin(0);
    }else{
        fin((xy[2]-xy[1]) * (xy[4]-xy[3]));
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=b/c;
    if(a-1>=0)
    {
        ans-=(a-1)/c;
    }
    else
    {
        ans++;
    }
    cout<<ans;
  	return 0;
}







Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	
	int maxA = 1_000_000;
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		
		int[] aArr = fs.nextIntArr(n);
		int[] hurui = new int[maxA+1];
		
		Arrays.sort(aArr);
		HashSet<Integer> numSet = new HashSet<>();
		
		for(int i = 0; i < n; i++) {
			int a = aArr[i];
			if(hurui[a] == 0) {
				numSet.add(a);
				for(int j = 1; j*a <= maxA; j++) {
					hurui[j*a] = 1;
				}
			}else {
				
			}
		}
		
		int[] valNum = new int[maxA+1];
		
		for(int i = 0; i < n; i++) {
			valNum[aArr[i]]++;
		}
		
		
		int ans = 0;
		for(Integer num : numSet) {
			if(valNum[num] == 1) {
				ans++;
			}
		}
		
		System.out.println(ans);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 68836
#include <stdio.h>
#include <math.h>
int isPrime(int x)
{
	int i;
	if(x<2)return 0;
	else if(x==2)return 1;
	if(x%2==0)return 0;
	for(i=3;i<=sqrt(x);i+=2)
	{
		if(x%i==0)return 0;
	}
}

int main(void)
{
	int  z,n,i;
	scanf("%d",&n);
	z=0;
	int x[n];
	for(i=0;i<n;i++)
	{
		scanf("%d", &x[i]);
		if(isPrime(x[i]))
		{
			z++;
		}
	}
	printf("%d\n",z);
	return 0;
}
	


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


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

    long long int MAX = 1000000007;

    long long int val = m;
    long long int mod = 1;
    while (n > 0) {
        if (n % 2 != 0) {
            mod = (mod * val) % MAX;
        }
        n /= 2;
        val = (val * val) % MAX;
    }
    std::cout << mod << std::endl;
}



Measured memory_bytes: 3128
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

i = 0
while n>i:
    if i != 0:
        point += b[a[i]-1]
        if a[i]-a[i-1] == 1:
            point += c[a[i-1]-1]
    else:
        point = b[a[i]-1]
    
    i += 1
print(point)

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

vector<pair<ll, ll> > pairs;

int main()
{
    ll N, X, L;
    cin >> N;
    vector<ll> dp(N + 3);
    vector<P> A(N);
    rep(i, N){
        cin >> X >> L;
        A[i] = make_pair(X + L, L - X);
    }
    sort(ALL(A));
    //rep(i, N){
    //    fprintf(stderr, "%d, (%d, %d)\n", i, -A[i].second, A[i].first);
    //}
    ll ans = 1;
    ll x = A[0].first;
    for (int i = 1; i < N; i++){
        if (-A[i].second >= x){
            x = A[i].first;
            ans++;     
        }
    }
    cout << ans;
    return 0;    
}


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

const int N=100005;
int n, m, a[N];
set<int> g[N];

// Union find
struct UnionFind {
    int n;
    vector<int> par, sz;
    UnionFind() {}
    UnionFind(int n_):n(n_) { init(n_); }
    void init(int n) {
        par.resize(n);
        sz.resize(n);
        for(int i=0; i<n; i++) {
            par[i]=i;
            sz[i]=1;
        }
    }

    int find(int x) {
        if(x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
    }
    

    bool same(int x, int y) {
        return find(x)==find(y);
    }

};


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

    cin >> n >> m;
    UnionFind uf(n+1);
    for(int i=1; i<=n; i++) {
        cin >> a[i];
    }

    for(int i=0; i<m; i++) {
        int x,y; cin >> x >> y;
        uf.unite(x, y);
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(uf.same(a[i], i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
        ll N;
        cin >> N;
        vector<ll> P(N);
        ll Count=0;
        for(ll i=0; i<N; i++){
                cin >> P[i];
                if(i+1!=P[i])Count++;
        }
        if(Count >2) cout << "NO";
        else cout << "YES";


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  string S;
  cin >> S;
  ll N = S.size(); reverse(all(S));
  auto DP = mvec<ll>(N+1,13); DP[0][0] = 1;
  auto d13 = [](ll n) -> ll{
    return (13 + n % 13)%13;
  };
  auto deal = [&](ll i, ll j, ll l) -> void{
    ll k{};
    k = l + d13(j*pow(10, i%3)) * pow(-1, i/3);
    DP[i+1][d13(k)] += DP[i][l]%MOD;
  };
  rep(i, 0, N) rep(l, 0, 13){
    if(S[i] == '?') rep(j, 0, 10) deal(i, j, l);
    else deal (i, S[i] - '0', l);
  }
  cout << DP[N][5]%MOD << rt;
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define int long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,xo;
int cev;
string s;
vector<int> v;

main(void){
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
		xo^=a[i];
	}
	FOR{
		int xo1=xo;
		xo1^=a[i];
		printf("%lld ",xo1);
	}
	return 0;
}



Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int H,W;
  cin >> H >> W;
  char Matrix[H][W];
  int alpha[26];
  for (int i = 0; i < 26; i++) alpha[i] = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> Matrix[i][j];
      alpha[Matrix[i][j] - 'a']++;
    }
  } 
  int even = 0;
  int odd = 0;
  if (H == 1 || W == 1) {
    for (int i = 0; i < 26; i++) {
      if (alpha[i] % 2 == 0) {
        even++;
      } else {
        odd++;
      }
    }
    int other = H;
    if (H == 1) {
      other = W;
    }
    if (other % 2 == 1) {
      if (odd == 1) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else {
      if (odd == 0) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  } else {
    if (H % 2 == 0 && W % 2 == 0) {
      int f = 0;
      for (int i = 0; i < 26; i++) {
        if (alpha[i] % 4 != 0) {
          f++;
        }
      }
      if (f == 0) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (H % 2 == 1 && W % 2 == 1) {
      int a = 0;
      int b = 0;
      for (int i = 0; i < 26; i++) {
        if (alpha[i] % 4 == 2) {
          a++;
        }
        if (alpha[i] % 2 == 1) {
          b++;
        }
      }
      if (a <= ((H-1)/2) + ((W-1)/2) && b == 1) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else {
      int other = H;
      if (H % 2 == 1) {
        other = W;
      }
      int c = 0;
      int d = 0;
      for (int i = 0; i < 26; i++) {
        if (alpha[i] % 4 == 2) {
          c++;
        }
        if (alpha[i] % 2 == 1) {
          d++;
        }
      }
    if (d == 0 && c <= other/2) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
  return 0;
}

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

int main(){
  int N = 5;
  int A[N];
  for (int i = 0; i < N; ++i) cin >> A[i];
  
  int i, t, r, index, min;
  int B[N];
  t = 0;
  min = 10;
  for (i=0; i<N; ++i){
    r = A[i] % 10;
    if(r > 0){
      if(r < min) min = r;
      t += A[i] + (10 - r);
    }else{
      t += A[i];
    }
  }
  t = t - (10 - min);
  cout << t << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll      int
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     10000000000000007
const int N=300004;

void run(){
    ll x,y;
    cin>>x>>y;
    if(x<=9 && y<=9) cout<<x*y;
    else cout<<-1;
}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 256
import heapq
from collections import defaultdict

N, M = map(int, input().split())
jobs = defaultdict(list)
for _ in range(N):
    day, value = map(int, input().split())
    if day <= M:
        jobs[day].append(value)

ans = 0
hq = []
for day in range(1, M+1):
    for value in jobs[day]:
        heapq.heappush(hq, - value)
    if len(hq) > 0:
        ans -= heapq.heappop(hq)

print(ans)


Measured memory_bytes: 77272
n, m = map(int, input().split())

red = [False] * n
ball = [1] * n

red[0] = True
for _ in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    if red[x]:
        red[y] = True
        if ball[x] == 1:
            red[x] = False
    ball[y] += 1
    ball[x] -= 1
print(len(list(filter(lambda x: x, red))))


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
constexpr long long MOD(long long in) {
	return in % mod;
}

int n;
ll a[100005];
ll x[100005];
int main()
{
	std::cin >> n;

	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
		x[0] += a[i];
		if (i % 2 == 1 && i != 0)
			x[0] -= 2 * a[i];
	}

	for (int i = 0; i < n; ++i)
		x[i + 1] = 2 * a[i] - x[i];

	for (int i = 0; i < n; ++i) {
		std::cout << x[i];
		if (i != n - 1)
			std::cout << " ";
		else
			std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 2816
n = int(input())

w = []
p = []
for i in range(n):
    temp = input()
    w.append(list(temp))
    p.append(temp)

if len(set(p)) != len(p):
    print('No')
    exit()

a = ""
b = w[0][len(w[0]) - 1]
for i in range(1, n):
    a = w[i][0]
    if a != b:
        print('No')
        exit()
    else:
        b = w[i][len(w[i]) - 1]

print('Yes')

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  char s[101][101];
  int h,w,hh,ww,flag,g[100]={},g2[100]={};
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++)
    scanf("%s",s[i]);
  hh=h;
  ww=w;
  for(int i=0;i<h;i++){
    flag=1;
    for(int j=0;j<w;j++)
      if(s[i][j]=='#')
        flag=0;
    g2[i]=flag;
  }
  for(int i=0;i<ww;i++){
    flag=1;
    for(int j=0;j<hh;j++)
      if(s[j][i]=='#')
        flag=0;
    g[i]=flag;
  }
  for(int i=0;i<h;i++){
    if(g2[i]==0){
      for(int j=0;j<w;j++)
        if(g[j]==0)
          printf("%c",s[i][j]);
      printf("\n");
    }
  }
}

Measured memory_bytes: 128
n,m = map(int, input().split())
an = list(map(int, input().split()))

sum = 0

for item in an:
  sum += item

num = 0

for item in an:
  if item >= sum / (4 * m):
    num += 1

if num >= m:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 2940
C = [[],[],[]]
C[0] = list(map(int,input().split()))
C[1] = list(map(int,input().split()))
C[2] = list(map(int,input().split()))

cond0_0 = C[0][0] - C[0][1] == C[1][0] - C[1][1] == C[2][0] - C[2][1]
cond0_1 = C[0][0] - C[0][2] == C[1][0] - C[1][2] == C[2][0] - C[2][2]
cond0_2 = C[0][1] - C[0][2] == C[1][1] - C[1][2] == C[2][1] - C[2][2]
cond0 = cond0_0 and cond0_1 and cond0_2

cond1_0 = C[0][0] - C[1][0] == C[0][1] - C[1][1] == C[0][2] - C[1][2]
cond1_1 = C[0][0] - C[2][0] == C[0][1] - C[2][1] == C[0][2] - C[2][2]
cond1_2 = C[1][0] - C[2][0] == C[1][1] - C[2][1] == C[1][2] - C[2][2]
cond1 = cond1_0 and cond1_1 and cond1_2

if cond0 and cond1:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    string answer = "";
    answer += toupper(s1[0]);
    answer += toupper(s2[0]);
    answer += toupper(s3[0]);
    
    p(answer);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int l;
	string a;
	cin>>a;
	l=a.size();
	if(l==2){
		cout<<a;
	} 
	if(l==3){
		reverse(a.begin(),a.end());
		cout<<a;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    ll r, D, x;
    cin >> r >> D >> x;
    
    REP(i, 10) {
        x = r*x-D;
        cout << x << endl;
    }
    
}


Measured memory_bytes: 256