akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n ;
	cin >> n ;
	vector <int > v ;
	ll a[n + 1] , ball[n + 1] = {0} ;
	for(int i = 1 ; i  <= n ; i++) cin >> a[i] ;
	for(int i = n ; i >= 1 ; i--){
		int j = 1 ;
		ll sum = 0 ;
		while(i*(j) <= n){
			sum += ball[i*j] ;
			j++ ;
		}
		if((sum % 2) != (a[i]%2)){
			v.pb(i) ;
			ball[i]++ ;
		}
	}
	cout << v.size() << '\n' ;
	// sort(v.begin() , v.end()) ;
	for(int i = v.size() - 1 ; i >= 0 ; i--) cout << v[i] << " " ;
}

Measured memory_bytes: 4600
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	long a, b, c, d;
	readf("%s %s %s %s", &a, &b, &c, &d);

	long r = long.min;
	if (r < a * c) {
		r = a * c;
	}
	if (r < a * d) {
		r = a * d;
	}
	if (r < b * c) {
		r = b * c;
	}
	if (r < b * d) {
		r = b * d;
	}

	writeln(r);
}


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

#define _GLIBCXX_DEBUG
#define rep(i, V) for (int i = 0; i < V; i++)
#define repr(i, V) for (int i = V-1; i >= 0; i--)
#define repval(i, a, V) for (int i = a; i < V ; i++)
#define all(x) x.begin(), x.end()
#define ld long double
#define eps 0.0000000001
#define mod 1000000007
#define inf 1e9
#define vec vector
#define each(i, mp) for(auto& i:mp)

int N, C, X;
int D[30][30];
int t[3][30]; //余り毎に、何色が何個あるか

int main(){
    cin >> N >> C;
    rep(i, C) rep(j, C) cin >> D[i][j];
    rep(i, N) rep(j, N){
        cin >> X;
        t[(i+j)%3][X-1]++;
    }
    int res = inf;
    rep(i, C)rep(j, C)rep(k, C){
        int sum = 0;
        if(i!=j && k!=i && k!=j){
            rep(l, C) sum += D[l][i] * t[0][l];
            rep(l, C) sum += D[l][j] * t[1][l];
            rep(l, C) sum += D[l][k] * t[2][l];
            if (sum < res) res = sum;
        }
    }
    cout << res << endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
static const int INF = 1e9;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

vector<int> reg;
vector<int> visited(8);
vector<vector<int>> adjmat;
int ans = INF, n, m ,r;

void dfs(vector<int> &a) {
    if(a.size()==r) {
        int anstmp = 0, pre, next;
        for(int ir=0;ir<r-1;ir++) {
            pre = a.at(ir);
            next = a.at(ir+1);
            anstmp += adjmat.at(pre).at(next);
        }
        chmin(ans, anstmp);
        return;
    }

    for(int v=0;v<r;v++) {
        if(visited.at(v)==false) {
            visited.at(v) = true;
            a.push_back(reg.at(v));
            dfs(a);
            a.pop_back();
            visited.at(v) = false;
        }
    }
}

int main(void) {
    cin >> n >> m >> r;
    
    reg.resize(r);
    for(int ir=0;ir<r;ir++) {
        cin >> reg.at(ir); reg.at(ir)--;
    }

    int a, b, c;
    adjmat.resize(n, vector<int>(n, INF));
    for(int im=0;im<m;im++) {
        cin >> a >> b >> c; a--; b--;
        if(adjmat.at(a).at(b)>c) {
            adjmat.at(a).at(b) = c;
            adjmat.at(b).at(a) = c;
        }
    }

    for(int kn=0;kn<n;kn++) {
        for(int in=0;in<n;in++) {
            for(int jn=0;jn<n;jn++) {
                if(adjmat.at(in).at(jn)>adjmat.at(in).at(kn)+adjmat.at(kn).at(jn)) {
                    adjmat.at(in).at(jn)=adjmat.at(in).at(kn)+adjmat.at(kn).at(jn);
                }
            }
        }
    }

    vector<int> argv;
    dfs(argv);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;

char s[maxn];
char t[maxn];

int qs[maxn], qt[maxn];

int main()
{
	scanf("%s %s", s+1, t+1);
	int n = strlen(s+1), m = strlen(t+1);
	for(int i = 1; i<= n; i++)
	{
		qs[i] = (s[i] == 'A')?1:2;
		qs[i] += qs[i-1];
	}
	for(int i = 1; i<= m; i++)
	{
		qt[i] = (t[i] == 'A')?1:2;
		qt[i] += qt[i-1];
	}
	int q; scanf("%d", &q);
	while(q--)
	{
		int a, b, c, d;
		scanf("%d %d %d %d", &a, &b, &c, &d);
		int x = qs[b]-qs[a-1];
		int y = qt[d]-qt[c-1];
		if(x%3 == y%3) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=1;
template<typename T=int>
T gi() {
	T x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
string to_string(string s) { return '"'+s+'"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b?"true":"false"); }
template<typename A,typename B> string to_string(pair<A,B> p) {
	return "("+to_string(p.fi)+","+to_string(p.se)+")";
}
template<typename T> string to_string(T v) {
	int fst=1;string ret="{";
	for(auto x:v) {
		if(!fst) ret+=",";
		fst=0,ret+=to_string(x);
	}
	ret+="}";return ret;
}
void dbg_out() { cerr<<endl; }
template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {
	cerr<<" "<<to_string(H);
	dbg_out(T...);
}
#define dbg(...) cerr<<"{"<<#__VA_ARGS__<<"}:",dbg_out(__VA_ARGS__)

template<typename T>
int qpow(int a,T b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod,b>>=1;
	}
	return ret;
}

const int N=1e5+10;
vector<int> unit;

vector<int> pinv(vector<int> a) {
	int n=sz(a);
	vector<int> ret(n);
	for(int i=0;i<n;i++) ret[a[i]]=i;
	return ret;
}

vector<int> pmul(vector<int> a,vector<int> b) {
	int n=sz(a);
	vector<int> ret(n);
	for(int i=0;i<n;i++) ret[i]=b[a[i]];
	return ret;
}

vector<int> ppow(vector<int> a,int b) {
	vector<int> ret=unit;
	while(b) {
		if(b&1) ret=pmul(ret,a);
		a=pmul(a,a),b>>=1;
	}
	return ret;
}

int n,k;

int main() {
	n=gi(),k=gi()-1;
	for(int i=0;i<n;i++) unit.pb(i);
	vector<vector<int>> a(6,vector<int>(n));
	for(int i=0;i<n;i++) a[0][i]=gi()-1;
	for(int i=0;i<n;i++) a[1][i]=gi()-1;
	for(int i=2;i<6;i++) a[i]=pmul(pinv(a[i-2]),a[i-1]);
	vector<int> A=a[0];
	A=pmul(A,pinv(a[1]));
	A=pmul(A,pinv(a[0]));
	A=pmul(A,a[1]);
	vector<int> ans=ppow(pinv(A),k/6);
	ans=pmul(ans,a[k%6]);
	ans=pmul(ans,ppow(A,k/6));
	for(auto x:ans) printf("%d ",x+1);
	return 0;
}


Measured memory_bytes: 6024
function main(input) {
    const args = input.split('\n');
    const N = parseInt(args[0], 10),
          S = args[1];
    var s = S.split('');
    for (var i = 0; i < s.length; i++) {
        if (s[i] == s[i + 1]) s[i] = null;
    }
    console.log(s.join('').length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9676
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;
bool chk(ll n)
{
    set<ll> num;
    while(n)
    {
        num.insert(n%10);
        n/=10;
    }
    return num.size()==1;
}
int main()
{
    fast();
    ll n;
    cin>>n;

    while(1)
    {
        if(chk(n))
        {
            cout<<n;
            return 0;
        }
        n++;
    }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int count = 0;
    for (int i = min(a, b); i >= 1; i--)
    {
        if (a % i == 0 && b % i == 0)
        {
            count++;
        }
        if (count == k)
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a = sorted(a, reverse=True)[:X]
b = sorted(b, reverse=True)[:Y]
print(sum(sorted(a + b + c, reverse=True)[:X+Y]))


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // ROF(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define SUM(a) accumulate(all(a),int(0))
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n; cin >> n;
  set<int> st;
  rep(i,n){
    int a; cin >> a; st.insert(a);
  }
  if(st.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int main(){

  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
  	cin >> a[i];
  }
  
  sort(a.begin(),a.end());
    
  int d;
  d=a[N-1]-a[0];
  
  cout << d << endl;
  
}

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

int main()
{
  ll a,b,x;
  cin >> a >> b >> x;
  
  if(a == b && b % x == 0){
    cout << 1 << endl;
  }else if(a == b){
    cout << 0 << endl;
    return 0;
  }else if(a == 0){
    cout << b / x + 1 << endl;
    return 0;
  }else{
    ll ansa = (a-1) / x + 1;
    ll ansb = b / x + 1; 
    cout << ansb - ansa << endl;
  }
  
}

Measured memory_bytes: 3596
#include<stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;


int main(){
   int n, m;
   cin >> n >> m;
   if(n==m) out("Yes");
   else out("No");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve(){
    int N;
    cin >> N;

    int ans = 0;
    for(int n=1; n<=N; n++){
        if(n%2 == 0){ continue; }

        // 約数がちょうど8このものを探す
        int yakusu_count = 0;
        for(int i=1; i<=n; i++){
            if(n%i == 0){ yakusu_count++; }
        }

        if(yakusu_count == 8){
            ans++;
        }
    }

    cout << ans << endl;
    return;
}

int main(){
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
#define S_MAX 10000
#define T_MAX 10000

int main()
{
  int S[S_MAX], n, T[T_MAX], exi[S_MAX], q, C=0, flag=0;
  int i, j, k;

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

  scanf("%d", &q);
  for(i=0 ; i<q ; i++){
    scanf("%d", &T[i]);
  }

  for(i=0 ; i<n ; i++){
    for(j=0 ; j<q ; j++){
      if(T[j] == S[i]){
	flag=1;
	for(k=0 ; k<C ; k++){
	  if(exi[k] == S[i]){
	    flag=0;
	    break;
	  }
	}
      }
    }
    if(flag == 1){
      exi[C]=S[i];
      C++;
    }
    flag=0;
  }

  printf("%d\n", C);

  return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w,s;
    cin>>h>>w>>s;
    int a=s;
    if(h>w){
        if(a%h==0)
        {
            cout<<(a/h)<<endl;
        }
        else
        {
            cout<<((a/h)+1)<<endl;
        }
    }
    else
    {
       if(a%w==0)
        {
            cout<<(a/w)<<endl;
        }
        else
        {
            cout<<((a/w)+1)<<endl;
        } 
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,T,A;
	long long t=1,a=1;
	cin>>n;
	while(cin>>T>>A){
		t=max((t+T-1)/T*T,(a+A-1)/A*T);
		a=max((a+A-1)/A*A,(t+T-1)/T*A);
	}
	cout<<t+a<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

char A[55][55];
char B[55][55];

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int i,j,x,y;

	for(i=0;i<N;i++){
		scanf("%s",A[i]);
	}

	for(i=0;i<M;i++){
		scanf("%s",B[i]);
	}

	i=0;
	j=0;

	while(1){
		if(i+M-1>=N){break;}
		int cnt=0;
		for(y=0;y<M;y++){
			for(x=0;x<M;x++){
				if(A[y+i][x+j]==B[y][x]){cnt++;}
			}
		}
		if(cnt==M*M){
			printf("Yes\n");
			return 0;
		}
		j++;
		if(j+M-1>=N){
			i++;
			j=0;
		}
	}
	printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

int main()
{
	ll A; string B;
  	cin >> A >> B;
  	B.erase(B.begin()+1);
  	ll C=stoll(B);
  	cout << (A*C)/100 << "\n";
  	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a % 2 != b % 2){
        cout<<"IMPOSSIBLE";
    }
    else{
    cout<<(a+b)/2 <<endl;
    }

    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,mx,cnt=0;
  cin>>N>>mx;
  for(int i=1;i<N;i++){
    int a;
    cin>>a;
    mx=max(mx,a);
    cnt+=mx-a;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3616
x, k, d = gets.split(" ").map(&:to_i)
x = x.abs
m = x % d
s = x / d

if s > k
  ans = x - k*d
  puts ans
  exit
end

t = k-s

if t.even?
  puts m
else
  m_1 = m - d
  m_2 = m_1.abs
  puts m_2
end


Measured memory_bytes: 14300
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int R, C, n;
  cin >> R >> C >> n;
  vector<pair<int, int>> v1, v2, v3, v4;
  for (int i = 1; i <= n; i++) {
    int q = 2;
    while (q--) {
      int x, y;
      cin >> x >> y;
      if (y == 0) v1.push_back({x, i});
      else if (x == R) v2.push_back({y, i});
      else if (y == C) v3.push_back({x, i});
      else if (x == 0) v4.push_back({y, i});
    }
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  sort(v3.begin(), v3.end());
  reverse(v3.begin(), v3.end());
  sort(v4.begin(), v4.end());
  reverse(v4.begin(), v4.end());
  vector<int> v;
  for (auto p : v1) v.push_back(p.second);
  for (auto p : v2) v.push_back(p.second);
  for (auto p : v3) v.push_back(p.second);
  for (auto p : v4) v.push_back(p.second);
  map<int, int> mp;
  for (int crr : v) mp[crr]++;
  stack<int> stk;
  for (int crr : v) {
    if (mp[crr] == 2) {
      if (!stk.empty() && stk.top() == crr) stk.pop();
      else stk.push(crr);
    }
  }
  if (stk.empty()) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}

Measured memory_bytes: 7764
#include <iostream>
#include <vector>
#include <cmath>

int main(int argc, char const *argv[]){
	
	int side_1,side_2,side_3;
	int N;

	std::cin >> N;

	std::vector<bool> result(N);

	for (int i = 0; i < N; ++i){
		std::cin >> side_1 >> side_2 >> side_3;

		side_1 = pow(side_1,2);
		side_2 = pow(side_2,2);
		side_3 = pow(side_3,2);

		if( side_1+side_2==side_3 ||
			side_2+side_3==side_1 || 
			side_3+side_1==side_2 	){

			result[i] = true;
		}else{
			result[i] = false;
		}
	}

	for (int i = 0; i < result.size(); ++i){
		if(result[i]) std::cout << "YES" << std::endl;
		else std::cout << "NO" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
ll f(ll b, ll n) {
	ll ans=0;
	while (n) {
		ans += (n % b);
		n /= b;
	}
	return  ans;
}
int main()
{
	ll n, s;
	scanf("%lld%lld", &n, &s);
	if (s == n) {
		printf("%lld\n", n + 1);
		return 0;
	}
	ll t = (ll)sqrt(n)+1;
	for(ll i=2;i<=t;i++)
		if (f(i, n) == s) {
			printf("%d\n", i);
			return 0;
		}
	n -= s;
	ll r = (ll)1e11 + 10;
	for (ll p = 1; p * p <= n; p++) {
		if (n % p == 0) {
			ll b = n / p + 1;
			ll a0 = s - p;
			ll a1 = p;
			if (b >= 2 && a0 >= 0 && a0 < b && a1 >= 0 && a1 < b) {
				r = min(r, b);
			}
		}
	}
	if (r != (ll)1e11 + 10) {
		printf("%lld\n",r);
		return 0;
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define nax 1009
long long maxF(int a , int b){
	return a>b ? a:b;
}

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

long long Abs(int a){
	return a>0? a:-a;
}

int main(){
	char tab[nax][nax];
	long long h,w, dp[nax][nax],mod = 1000000007LL;
	scanf("%ld %ld",&h,&w);
	for(int i = 0 ; i < h;i++){
		for(int j = 0 ; j <w;j++){
			scanf(" %c",&tab[i][j]);
		}
	}

	for(int i = 0; i < h;i++){
		for(int j = 0 ; j < w; j++){
			dp[i][j] = 0LL;
			if(tab[i][j] == '#') continue;
			if(i==0LL && j == 0LL){
				dp[0][0] = 1LL;
				continue;
			}
			if(i-1>=0) dp[i][j] =(dp[i][j] + dp[i-1][j])%mod;
			if(j-1>=0) dp[i][j] =(dp[i][j] + dp[i][j-1])%mod;
		}
	}

	printf("%ld",dp[h-1][w-1]);

	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <cstdint>

using namespace std;

int32_t main()
{
  uint32_t n;
  cin >> n;

  uint64_t days_of_a_year = 5 * 20 + 5 * 19;
  uint64_t millenium = (1000 - 1) * days_of_a_year + (1000 - 1) / 3 * 5;

  for(uint32_t i = 0; i < n; i++){
    uint32_t Y, M, D;
    cin >> Y >> M >> D;
    uint64_t day = (Y - 1) * days_of_a_year + (Y - 1) / 3 * 5;
    if(Y % 3 == 0){
      day += (M - 1) * 20;
    } else {
      for(uint32_t j = 1; j < M; j++){
        if(j % 2 == 0) {
          day += 19;
        } else {
          day += 20;
        }
      }
    }
    day += D - 1;
    cout << millenium - day << endl;
  }

  return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

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

const double R = 6378.1;
const double DPI = 180;
const double EPS = 0.00001;

bool ism1(double f)
{
    return (-1 - EPS < f && f < -1 + EPS );
}

int main()
{
    double x[2], y[2], z[2], th[2], al[2], l, l2,  len, r;
    while(cin >> al[0] >> th[0] >> al[1] >> th[1])
    {
        if(ism1(th[0]) && ism1(th[1]) && ism1(al[0]) && ism1(al[1])) break;

        REP(2)
        {
            x[i] = cos(al[i] * M_PI / DPI) * cos(th[i] * M_PI / DPI);
            y[i] = cos(al[i] * M_PI / DPI) * sin(th[i] * M_PI / DPI);
            z[i] = sin(al[i] * M_PI / DPI);

        }
        l =sqrt( (x[1] - x[0]) * (x[1] - x[0]) 
            + (y[1] - y[0]) * (y[1] - y[0])
            + (z[1] - z[0]) * (z[1] - z[0]));
        
        //cout << asin(l / 2) << endl;
        r = R * 2 * asin(l / 2 ) ;
        printf("%.0f\n", r);
    }
    return 0;
}

Measured memory_bytes: 1284
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vi a(n),b(n);
    for (int i=0;i<n;i++){
        cin >> a[i] ; 
        b[i] = a[i] ; 
    }
    sort(a.begin(), a.end());
    int f=a[n-1],s=a[n-2];
    for (int i=0;i<n;i++){
        if (b[i]!=f) cout << f << endl;
        else cout << s << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 6360
H, W, K = map(int, input().split())

ans = [[0 for _ in range(W)] for _ in range(H)]
not_ichigo_row = []
ichigo_row = []

cnt = 0 #イチゴのカウント、フラグが立っていない場合はカウントしない
for i in range(H):
    s = list(input())
    # print(s)
    if "#" not in s:
        not_ichigo_row.append(i)
        continue

    ichigo_row.append(i)
    f = 0 #行内の1つめのイチゴか判定
    cnt += 1
    for j in range(W):
        # print(s[j])
        if s[j] == "#":
            if not f:
                f = 1
            else:
                cnt += 1
        # print("cnt", cnt)
        ans[i][j] = cnt

# print(not_ichigo_row)
for i in not_ichigo_row:
    row = i
    f = 0
    while row in not_ichigo_row:
        if row == H-1:
            f = 1
        if f:
            row -= 1
        else:
            row += 1
    # print(row)
    ans[i] = ans[row].copy()

for r in ans:
    print(*r)


Measured memory_bytes: 7504
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

ll N;
ll a[200000];

int main(){
    cin>>N;
    rep(i,N) cin>>a[i];

    ll sum=a[0];
    repn(i,N-1) sum^=a[i];

    rep(i,N){
        ll ans=sum^a[i%N];
        cout<<ans<<' ';
    }
    cout<<endl;
}

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

int main(){
	int a, mn = 10, ans = 0;
	for(int i = 0; i < 5; i++){
		cin >> a;
		if(a % 10 > 0){
			mn = min(mn, a % 10);
		}
		ans += (a + 9) / 10 * 10;
	}
	cout << ans - 10 + mn;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Serval vs Monster
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int h, a;
  scanf("%d%d", &h, &a);
  printf("%d\n", (h + a - 1) / a);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int a,b,c;
    cin >> a >> b >> c;
    int e = max(a+b,c);
    if(a+b < c){
        cout << b + (a+b) + 1 << endl;
    }else{
        cout << b + c << endl;
    }

}


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

#define ll long long
#define ar array

int n, k, c[2000001][26], m, cnt[2000001];
int ans;

void dfs(int u=0, int d=0) {
	for(int v=0; v<26; ++v)
		if(c[u][v])
			dfs(c[u][v], d+1), cnt[u]+=cnt[c[u][v]];
	ans += (cnt[u] / k ) * d;
	cnt[u] %= k;
}
bool fun(string a){
	string s = a;
	for(int x =0; x<a.length(); x++){
		if(s[x] != s[a.length() - 1- x])return 0;
	}
	return 1;
}
void solve() {
	long double n;
	cin >> n;
	n /= 3;
	printf("%Lf" ,n * n * n );
}

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

	int t= 1, i=1;
	// cin >> t;
	while(t--) {
		// cout << "Case #" << i << ": ";
		solve();
		++i;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[214514],f[214514];
int main(){
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>f[i];
	ll ma=0;
	sort(a,a+n);
	sort(f,f+n);
	for(int i=0;i<n;i++)ma=max(ma,a[i]*f[n-i-1]);
	//cout<<ma<<endl;
	ll ok=ma,ng=-1;
	while(ok-ng>1){
		ll mid=(ok+ng)/2;
		//cout<<mid<<endl;
		ll x=k;
		bool yan=0;
		for(int i=0;i<n;i++){
			if(a[i]*f[n-i-1]>mid){
				ll num=mid/f[n-i-1];
				x-=a[i]-num;
			}
			if(x<0){
				yan=1;
				break;
			}
		}
		if(yan)ng=mid;
		else ok=mid;
	}
	cout<<ok<<endl;
	return 0;
}


Measured memory_bytes: 6696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;cin >> n;
  int h[n],dp[n] = {};
  for(i=0;i<n;i++) scanf("%d",&h[i]);
  for(i=1;i<n;i++){
    if(i==1) dp[i] = abs(h[i]-h[i-1]);
    else dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  printf("%d\n",dp[n-1]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	int n;
	string s;
	int q;
	cin>>n>>s>>q;
	
	set<int> st[26];				//aからzそれぞれの位置を記録.
	REP(i,n) st[s[i]-'a'].insert(i);
	REP(i,26) st[i].insert(n);		//番兵.
	
	REP(i,q){
		int t;
		cin>>t;
		
		if(t==1){
			int j;
			char c;
			cin>>j>>c;
			j--;
			
			REP(k,26){
				if(st[k].find(j)==st[k].end()){}
				else st[k].erase(j);
			}
			st[c-'a'].insert(j);
		}else{
			int l,r;
			cin>>l>>r;
			l--, r--;
			
			int ans=0;
			REP(j,26){
				int p=*st[j].lower_bound(l);	//l以上の値を習得.
				if(p<=r) ans++;					//上記の値がr以下だったらok.
			}
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 24196
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;

  int max_val = 0, ans = 1;
  rep(i, 1, n + 1) {
    int c = 0;
    int t = i;
    while (t % 2 == 0) {
      c++;
      t /= 2;
    }
    if (max_val < c) {
      max_val = c;
      ans = i;
    }
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

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

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

    int h, w; cin >> h >> w;
    vector<string> field(h);
    rep(i, h) cin >> field[i];

    vector<vector<int>> dist(h, vector<int> (w, INF));
    queue<P> que;
    rep(i, h) rep(j, w) {
        if(field[i][j] == '#') {
            que.push({i, j});
            dist[i][j] = 0;
        }
    }
    while(que.size()) {
        P p = que.front();
        que.pop();
        int x = p.second, y = p.first;
        rep(i, 4) {
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(nx < 0 || ny < 0 || w <= nx || h <= ny) continue;
            if(dist[ny][nx] != INF) continue;
            que.push({ny, nx});
            dist[ny][nx] = dist[y][x]+1;
        }
    }
    int ans = 0;
    rep(i, h) rep(j, w) ans = max(ans, dist[i][j]);
    cout << ans << '\n';
    return 0;
}

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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  
  string ans = "Yes";
  REP(i, a + b + 1) {
    if (i == a) {
      if (s.at(i) != '-') {
        ans = "No";
        break;
      }
    }
    else {
      int num = (int)s.at(i) - (int)'0';
      if (num < 0 || num > 9) {
        ans = "No";
        break;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int N=3000+10;
int dp[N][N];
char ans[N];
string s1,s2;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s1>>s2;
    int n=s1.length(),m=s2.length();
    for(int i=0;i<n;i++){
    	for(int j=0;j<m;j++){
    		if(s1[i]==s2[j])dp[i+1][j+1]=dp[i][j]+1;
    		else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
    	}
    }
    int len=dp[n][m];
    while(dp[n][m]){
    	if(s1[n-1]==s2[m-1]){
    		n--;
    		m--;
    		ans[dp[n+1][m+1]]=s1[n];
    	}
    	else if(dp[n-1][m]==dp[n][m])n--;
    	else m--;
    }
    //cout<<len<<"\n";
    for(int i=1;i<=len;i++)cout<<ans[i];
    return 0;
}

Measured memory_bytes: 35584
n = int(input())
s = input().split()

sum = 0
for i in range(n):
  sum += int(s[i])

a = float(sum)/float(n)
if int(a)+0.5 <= a:
  a = int(a)+1
else:
  a = int(a)
  
ans = 0
for i in range(n):
  ans += (int(s[i])-a)**2

print(ans)

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

int main(){
  int n, t, mod = 1e9 + 7;
  std::cin >> n >> t;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    std::cin >> d[i];
  }
  sort(d.begin(), d.end());
  vector<int> dp(n);
  vector<int> hoge(n, 1);
  for (int i = 1; i < n; i++) {
    hoge[i] = (d.begin() + i) -
      lower_bound(d.begin(), d.end(), d[i] - t) + 1;
  }
  long long int ans = 1;
  for (int i = 0; i < n; i++) {
    ans *= hoge[i];
    ans %= mod;
  }
  std::cout << ans << std::endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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

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



int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 1; i < n-1; ++i) {
    int t = 0;
    string a = s.substr(0, i);
    string b = s.substr(i, n-i);
    sort(ALL(a)); sort(ALL(b));
    for(char c = 'a'; c <= 'z'; ++c) if(binary_search(ALL(a), c) && binary_search(ALL(b), c)) ++t;
    chmax(ans, t);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
field = [list(input()) for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
count = 0
for i in range(h):
    for j in range(w):
        if field[i][j] == '#':
            count = 0
            for d in range(4):
                if 0<=i+dy[d]<h and 0<=j+dx[d]<w:
                    count += 1 if field[i+dy[d]][j+dx[d]]=='#' else 0

            if count<1:
                print('No')
                exit()
print('Yes')


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
bool comp(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second<b.second);
}

int main(){
    map<int,pair<int,int> >m;
    int a;
    vector<pair<int,int> >row,col,dia,v;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)
        {
            cin>>a;
            m[a]={i+1,j+1};
        }
    }
    int n;
    cin>>n;
    int r[3]={0},c[3]={0},d[2]={0},d1=0,d2=0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(m[a].first==0 && m[a].second==0)
            continue;
        else{
//            row.push_back(m[a]);
//            col.push_back(m[a]);
            //if(m[a].first==1)
            r[m[a].first-1]++;
            c[m[a].second-1]++;
            v.push_back(m[a]);
        }
    }
    sort(r,r+3,greater<int>());
    sort(c,c+3,greater<int>());
    bool f=0;
    if(r[0]==3 || c[0]==3){
        f=1;
    }
    else{
            vector<pair<int,int> >x,y;
            x.push_back({1,1});
            x.push_back({2,2});
            x.push_back({3,3});
            y.push_back({1,3});
            y.push_back({2,2});
            y.push_back({3,1});
        sort(v.begin(),v.end());
        for(int i=0,j=0,k=0;i<v.size();i++){
            if(d1==3 || d2==3){
                f=1;break;
            }
            if(v[i]==x[j]){
                d1++;j++;
            }
            if(v[i]==y[k]){
                d2++;k++;
            }
        }
        if(d1==3 || d2==3)
            f=1;
    }
    if(f)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      s: String
   }

   let mut b = s.as_bytes().to_vec();
   b.reverse();
   let mut pos = 0;
   let s1 = b"maerd";
   let s2 = b"remaerd";
   let s3 = b"esare";
   let s4 = b"resare";
   while pos < b.len() {
      if check(&b, pos, s1) {
         pos += 5;
      } else if check(&b, pos, s2) {
         pos += 7;
      } else if check(&b, pos, s3) {
         pos += 5;
      } else if check(&b, pos, s4) {
         pos += 6;
      } else {
         break;
      }
   }
   if pos == b.len() {
      println!("YES");
   } else {
      println!("NO");
   }
}

fn check(a: &[u8], k: usize, b: &[u8]) -> bool {
   let n = b.len();
   let mut flag = true;
   if a.len() - k < n {
      flag = false;
   }
   for i in 0..n {
      if a[k + i] != b[i] {
         flag = false;
         break;
      }
   }
   flag
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod=1e9+7;

ll power(ll a,ll b,ll c){
    ll res=1;
    while(b){
        if(b%2)res=res*a%c;
        a=a*a%c;
        b/=2;
    }
    return res;
}

ll c(ll a,ll b,ll c){
    ll res=1;
    for(ll i=1;i<=b;i++)res=res*(a+1-i)%c *power(i,c-2,c) %c;
    return res;
}

map<ll,ll> primef(ll nn){
    ll n=nn;
    map<ll,ll> m;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            m[i]++;
            n/=i;
        }
        if(n==1)break;
    }
    if(n!=1)m[n]=1;
    return m;
    
}

int main(){
   ll n,mm;cin>>n>>mm;//cout<<c(6,3,mod);
   ll ans=1;
   map<ll,ll> m=primef(mm);
   if(n==1){cout<<1;return 0;}
   else {
       for(auto it=m.begin();it!=m.end();it++){
           ll a=it->second;//cout<<a<<endl;
           ans=ans*c(n-1+a,a,mod)%mod;
       }
   }
 while(ans<0)ans+=mod;
   cout<<ans%mod;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;

int main() {
  int N,K;
  cin >> N >> K;
  if (N % K == 0) {
    cout << 0 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int N, D;
  cin >> N >> D;
  vector< vector<int> > X(N, vector<int>(D));

  rep(i, N) {
    rep(j, D) cin >> X[i][j];
  }

  int ans = 0;
  for (int i = 0; i <= N-2; i++) {
    for (int j = i+1; j <= N-1; j++) {
      int tmp = 0;
      rep(k, D) tmp += pow((X[i][k]-X[j][k]), 2);

      if (ceil(sqrt(tmp)) == floor(sqrt(tmp))) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;
 
int main(){

    
    int h,w,d;
    cin >> h>>w>>d;

    map<int,pair<int,int>> m;
    REP(i,h) REP(j,w){
        int a;
        cin >> a;
        m[a] = MP(i,j);
      	//cout << m[a].fi <<" "<<m[a].se <<endl;
    }
    ll data[d][(h*w)/d + 1];
    for(int i=0;i<d;i++){
        for(int j=0;j<(h*w)/d;j++){
            if(j == (h*w)/d-1 && i >= (h*w)%d ){break;}
            else if(j == 0) data[i][j] = abs(m[i+1+j*d+d].fi - m[i+1+j*d].fi) + abs(m[i+1+j*d+d].se - m[i+1+j*d].se);
            else data[i][j] = data[i][j-1] + abs(m[i+1+j*d+d].fi - m[i+1+j*d].fi) + abs(m[i+1+j*d+d].se - m[i+1+j*d].se);
          	//cout << i<<" "<<j<< " "<< data[i][j] << endl;
        }
    }

    int q;
    cin >> q;
    REP(i,q){
        ll l,r;
        cin >> l >> r;
      	if(l == r) cout << 0 <<endl;
      	else if(l <= d) cout << data[(l-1)%d][(r-1-(l-1)%d)/d - 1] <<endl;
        else cout <<  data[(l-1)%d][(r-1-(l-1)%d)/d - 1] - data[(l-1)%d][(l-1-(l-1)%d)/d - 1] << endl;
        
      	//cout << (l-1)%d <<" "<< (r-1-(l-1)%d)/d - 1 << " "<<(l-1-(l-1)%d)/d - 1<<endl;
      	//cout << data[l%d-1][(l-l%d)/d - 1] <<endl;
    }

}

Measured memory_bytes: 7424
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	static int a,b,c,d,e,f;
	static int w,s;
	
	// ABC 074c 

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		 a = Integer.parseInt(sc.next()) * 100;
		 b = Integer.parseInt(sc.next()) * 100;
		 c = Integer.parseInt(sc.next());
		 d = Integer.parseInt(sc.next());
		
		 e = Integer.parseInt(sc.next());
		 f = Integer.parseInt(sc.next());
		 
		 
		 Set<Integer> w = new HashSet<Integer>();
		 Set<Integer> s = new HashSet<Integer>();
		 
		 for(int i = 0 ; i <= 30 ; i++) {
			 for(int j = 0 ; j <= 30 ;j++) {
				int wa = (a * i + b * j);
				if(wa > 3000 || wa == 0) {
					continue;
				}
				w.add(wa);
			 }
		 }
		 
		 for(int i = 0 ; i <= 3000 ;i++) {
			 for(int j = 0 ; j <= 3000 ;j++) {
				int su = c * i + d * j;
				if(su > 3000) {
					continue;
				}
				s.add(su);
			 }
		 }
		 
		 int ans1 = a;
		 int ans2 = 0;
		 
		 double temp = 0;
		 
		 for(int p : w) {
			 for(int q : s) {
				
				 if(p + q > f || p + q == 0) {
					 continue;
				 }
				 double den =(double)q / (p + q);
				// System.out.println(p+" "+q);
				// System.out.println(den +" "+((double)(e/(100+e))));
				 if(den > (double)e/(100+e)) {
					 continue;
				 }
				 if(den > temp) {
					
					 temp = den;
					 ans1 = p;
					 ans2 = q;
 				 }
				 
			 }
		 }
		 
		 System.out.println((ans1+ans2)+" "+ans2);
		 
	}
}

Measured memory_bytes: 41812
#include<bits/stdc++.h>
using namespace std;
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define pr printf
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+6;
const int mod=998244353;
template<typename T>int O(T s){cout<<s<<endl;return 0;}
template<typename T>void db(T *bg,T *ed){while(bg!=ed)cout<<*bg++<<' ';pr("\n");}
template<typename T>void db(vector<T>it){for(auto i:it)cout<<i<<' ';pr("\n");}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
inline void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=(a/b)*x;}
ll dp[3005];;
int n,s;
int a[N];
int main(){ 
    //IN
    cin>>n>>s;
    for(int i=0;i++<n;sc("%d",&a[i]));
    ll ans=0;
    for(int i=1;i<=n;i++){
        dp[0]++;
        for(int j=s;j>=a[i];j--){
            dp[j]+=dp[j-a[i]];
            dp[j]%=mod;
        }
        ans+=dp[s];
        ans%=mod;
    }
    O(ans);
}

Measured memory_bytes: 256
require 'pp'

# n件読み込んだ結果を数値の配列で返却する
def gets_n_iarray
  n = gets.chomp.to_i
  array = []
  n.times do
    array.push(gets.chomp.to_i)
  end
  return n, array
end

N, s_list = gets_n_iarray

total = s_list.inject(:+)

not10x_list = s_list.select do |s|
  s % 10 != 0
end

if total % 10 != 0
  puts total
elsif !not10x_list.empty?
  puts total - not10x_list.min
else
  puts 0
end


Measured memory_bytes: 2172
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt a, b, c;
    cin >> a >> b >> c;
    if ((10 * b + c) % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 4032
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

char mat[100][100];

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

int main() {
	int a, b;
	scanf("%d %d", &a, &b);

	memset(mat, '#', sizeof(mat));

	int x = 0, y = -2;
	while (a--) {
		y += 2;

		if (y >= 100) {
			x += 2;
			y = 0;
		}

		mat[x][y] = '.';
	}

	y = 0;
	mat[x + 1][y] = mat[x + 2][y] = '.';
	x += 3; y += 1;

	while (--b) {
		int xx, yy;
		for (int i = 0; i < 8; i++) {
			xx = x + dx[i]; yy = y + dy[i];
			mat[xx][yy] = '.';
		}

		y += 2;
		if (y >= 99) {
			y = 1;
			x += 2;
		}
	}

	printf("%d %d\n", 100, 100);
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++)
			printf("%c", mat[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 256