akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc141
{
    class abc141c
    {
        static void Main(string[] args)
        {
            var buf = Console.ReadLine().Split();
            var N = int.Parse(buf[0]);
            var K = long.Parse(buf[1]);
            var Q = int.Parse(buf[2]);
            var A = new List<int>();
            for(var i = 0; i!=Q; ++i) {
                A.Add(int.Parse(Console.ReadLine()));
            }
            var r = Solve(N, K, Q, A);
            foreach(var s in r)
                Console.WriteLine(s);
        }

        static IEnumerable<string> Solve(int n, long k, int q, IEnumerable<int> a)
        {
            var c = Enumerable.Repeat(0, n).ToList();
            foreach(var x in a) {
                ++c[x - 1];
            }
            var y = k - q;
            var b = Enumerable.Repeat("Yes", n).ToList();
            for(var i = 0; i!=n; ++i) {
                if(y + c[i] <= 0)
                    b[i] = "No";
            }
            return b;
        }
    }
}


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}


int main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	t = 1;

	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

void solve()
{
	ll n, i, k, j, p;
	cin >> n >> k;

	ll a[n];

	for (i = 0; i < n; i++)
		cin >> a[i];

	vector<ll> dp(n, INT_MAX);
	dp[0] = 0;

	for (i = 1; i <= k; i++)
	{
		dp[i] = abs(a[i] - a[0]);
	}

	for (i = k + 1; i < n; i++)
	{
		p = INT_MAX;
		for (j = i - k; j < i; j++)
		{
			p = min(p, dp[j] + abs(a[i] - a[j]));
		}

		dp[i] = p;
	}

	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll  i, j, k, l, n, m;
    cin >> n >> m;
    cout << n * m << "\n";
    return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
    long long int n;
    cin >> n;
    long long int left = 0, right = n;
    while(right - left > 1){
        long long int mid = (left + right) / 2;
        if(mid * (mid + 1) / 2 >= n) right = mid;
        else left = mid;
    }
    // cout << right << endl;
    while(n > 0 && right > 0){
        if(n >= right){
            n -= right;
            cout << right << endl;
        }
        right--;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> X(N);
	rep(i,N) cin>>X[i];
	sort(X.bg,X.ed,greater<ll>());
	ll alice=0,bob=0;
	for(int i=0;i<N;i+=2){
		alice+=X[i];
	}
	for(int i=1;i<N;i+=2){
		bob+=X[i];
	}
	cout<<alice-bob;
}

Measured memory_bytes: 256
# m1, d1 = list(map(int, input().split()))
# m2, d2 = list(map(int, input().split()))
X = int(input())

if X < 100:
    print(0)
    exit()

hasu = int(str(X)[-2:])
total = 0
# print(hasu)

div5 = hasu / 5
hasu -= 5*div5
total += 105*div5

div4 = hasu / 4
hasu -= 4*div4
total += 104*div4

div3 = hasu / 3
hasu -= 3*div3
total += 103*div3

div2 = hasu / 2
hasu -= 2*div2
total += 102*div2

div1 = hasu / 1
hasu -= 1*div1
total += 101*div1

# print((div5+div4+div3+div2+div1))
if total > X:
    print(0)
else:
    print(1)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=51;
const ll INF=1LL<<55;
int N;
vector<pair<int,int>> G[MAX];
vector<int> A(MAX),B(MAX);

bool floyd(vector<int> &use,vector<int> &use2){
    vector<vector<ll>> dis(MAX,vector<ll>(MAX,INF));
    for(int i=0;i<=50;i++){
        dis[i][i]=0;
    }
    
    for(int j=0;j<use.size();j++){
        int a=use[j];
        for(int k=0;k<G[a].size();k++){
            dis[G[a][k].first][G[a][k].second]=0;
        }
    }
    
    for(int j=0;j<use2.size();j++){
        int a=use2[j];
        for(int k=0;k<G[a].size();k++){
            dis[G[a][k].first][G[a][k].second]=0;
        }
    }
    
    for(int k=0;k<=50;k++){
        for(int i=0;i<=50;i++){
            for(int j=0;j<=50;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    
    for(int i=0;i<N;i++){
        if(dis[A[i]][B[i]]==INF) return false;
    }
    return true;
}

int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
    }
    
    for(int i=1;i<=50;i++){
        for(int j=0;j<=50;j++){
            G[i].push_back({j,j%i});
        }
    }
    
    vector<int> X,use;
    for(int i=1;i<=50;i++){
        X.push_back(i);
    }
    
    if(!floyd(X,use)) cout<<-1<<endl;
    else{
        while(X.size()){
            int a=X.back();
            X.pop_back();
            bool ok=floyd(X,use);
            if(ok) continue;
            else use.push_back(a);
        }
        
        ll ans=0;
        
        for(int j=0;j<use.size();j++){
            ans+=(1LL<<(use[j]));
        }
        
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back 
 #define fo(i,n) for(int i=0;i<n;i++)
#define ll long long 
#define int long long 
#define Mod 10000000000007 
#define maxn 200005
#define MAX 4294967296  // 2^32
const int M=1e9+7;
#define ip pair<int,int>
#define test(t) ll t;cin>>t;while(t--)
  
using namespace std;

long long gcd(int x,int y){
    if(y>x)swap(x,y);
    if(y==0)return x;
    return gcd(y,x%y);
}


void solve(){
string s;
cin>>s;
if(s[s.length()-1]!='s')s+='s';
else{
  s+='e';
    s+='s';
}
cout<<s<<endl;

}

signed main(){


    // std::string binary = std::bitset<8>(n).to_string();
    ios::sync_with_stdio(0);
    cin.tie(0);
   
solve();


  


}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <set>
#include <queue>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<ll>a(n);
	rep0(i, n - 1)cin >> a[i];
	sort(a.begin(), a.end());
	int ans = a[n / 2] - a[(n / 2) - 1];
	cout << ans << endl;
	return 0;
}

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

int main(){
	long long int k;
	cin>>k;
	long long int val = 7;

	rep(i,k){
		val = val%k;
		if(val==0){
			cout<<i+1<<endl;
			return 0;
		}
		val = val *10 + 7;
	}
	cout<<-1<<endl;


	return 0;
}

Measured memory_bytes: 3600
program abc163c
   implicit none
   integer :: N, i, j, count
   integer, allocatable :: A(:), numOfBuka(:)


   read(*,*) N
   allocate(A(N), numOfBuka(N))
   A(:) = 0
   numOfBuka(:) = 0
   read(*,*) A(2:N)

   do i = 1, N
      numOfBuka(A(i)) = numOfBuka(A(i)) + 1 
   end do

   do i = 1, N
      print *, numOfBuka(i)
   end do

end program abc163c


Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int dp[101][100005];
signed main() {
    REP(i, 101) REP(j, 100005) dp[i][j] = INF;
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    REP(i, N) {
        cin >> w[i] >> v[i];
    }

    dp[0][0] = 0;
    REP(i, N) {
        REP(j, 100005) {
            if (dp[i][j] >= INF) continue;
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
        }
    }
    REPR(i, 100004) {
        if (dp[N][i] <= W) {
            cout << i << endl;
            return 0;
        }
    }
    return (0^_^0);
}



Measured memory_bytes: 79232
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	double l,r;
	int la=0,lb=0,lc=0,ld=0,ra=0,rb=0,rc=0,rd=0;
	while(cin>>l>>r){
        if(l>=1.1)la++;
        else if(l>=0.6)lb++;
        else if(l>=0.2)lc++;
        else ld++;

        if(r>=1.1)ra++;
        else if(r>=0.6)rb++;
        else if(r>=0.2)rc++;
        else rd++;


	}
	cout<<la<<" "<<ra<<endl;
	cout<<lb<<" "<<rb<<endl;
	cout<<lc<<" "<<rc<<endl;
	cout<<ld<<" "<<rd<<endl;


	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <unordered_map>
#include <string>

using namespace std;

unordered_map<char, uint64_t> Problems;
uint64_t N, K;

bool is_ok(uint64_t n)
{
  uint64_t ps = 0;
  for (const auto& kv : Problems) {
    if (kv.second < n)
      ps += kv.second;
    else
      ps += n;
  }

  return K * n <= ps;
}


uint64_t bsearch(uint64_t ok, uint64_t ng)
{
  if (ng - ok == 1)
    return ok;

  uint64_t mid = (ok + ng) / 2;
  if (is_ok(mid))
    return bsearch(mid, ng);
  else
    return bsearch(ok, mid);
}


int main()
{
  cin >> N >> K;

  string s;
  s.reserve(10);
  for (uint64_t i=0; i<N; ++i) {
    cin >> s;
    ++Problems[s[0]];
  }

  uint64_t ret = bsearch(0, N/K+1);
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=4e4+7,mod=1e9+7,inv2=5e8+4;
int n,ans,a[N*50],b[N*50],fac[N],inv[N],f[4007][4007];
int C(int a,int b){return 1ll*fac[a]*inv[b]%mod*inv[a-b]%mod;}
int main()
{
	fac[0]=1;
	for(int i=1;i<=4e4;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	for(int i=2;i<=4e4;i++)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=2;i<=4e4;i++)inv[i]=1ll*inv[i]*inv[i-1]%mod;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]),f[2001-a[i]][2001-b[i]]++;
	for(int i=1;i<=4001;i++)
	for(int j=1;j<=4001;j++)
	{
		f[i][j]=(f[i][j]+f[i-1][j])%mod;
		f[i][j]=(f[i][j]+f[i][j-1])%mod;
	}
	for(int i=1;i<=n;i++)ans=(ans+f[2001+a[i]][2001+b[i]])%mod;
	for(int i=1;i<=n;i++)ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+mod)%mod;
	ans=1ll*ans*inv2%mod;
	printf("%d",ans);
}

Measured memory_bytes: 67840
#include <stdio.h>

int main(){
	int a=0,b=0,n=0;
	int ans=0;
	int number,count1=0,count2=0;
	scanf("%d",&n);

	for(int i=1;i<=n;i++){
		count1=0;
		number = i;
		while(number!=0){
			number /= 10;
			count1++;
			//printf("%d\n", count1);
		}
		if(count1==1){
			count2++;
		}
		else if(count1%2!=0){
			count2++;
		}
		
	}
	printf("%d\n",count2);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){

    int L,R;
    int d;

    scanf("%d",&L);
    scanf("%d",&R);
    scanf("%d",&d);

    int flag=0;

    for(int i=L;i<=R;i++){
        if(i%d==0){
            flag++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 2152
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
b = [False] * n
res = 0
for i in range(n):
    if b[i]:
        continue
    if a[a[i]-1] == i+1:
        res += 1
        b[a[i]-1] = True
print(res)

Measured memory_bytes: 52572
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
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 int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << "NO" << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N;
    int s[114514];
    cin >> N;
    REP(i,N){
        cin >> s[i];
    }
    int Ans=0;
    for(int C=1;C<=N-1;C++){
        int sum=0;
        for(int k=1;k<((N-1)%C==0?((N-1)/C+1)/2:(N-1)/C);k++){
            sum+=s[k*C]+s[N-1-k*C];
            Ans=max(Ans,sum);
            //cout << C MM k MM sum<< endl;
        }
    }
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    long long a,b,k;
    cin>>a>>b>>k;
    long long sum=a+b;
    if(k<a){
        cout<<a-k<<" "<<b<<endl;
    }
    else if(k>=a&&k<=sum){
        cout<<"0"<<" "<<b-(k-a)<<endl;
    }
    else{
        cout<<"0"<<" "<<" 0"<<endl;
    }
}


Measured memory_bytes: 256
n,x=[int(_) for _ in input().split(" ")]
a=[int(_) for _ in input().split(" ")]
y=0
for i in range(len(a)-1):
  c=a[i]+a[i+1]
  if c>x:
    a[i+1]=max(0,a[i+1]-(c-x))
    y+=c-x
print(y)

Measured memory_bytes: 14252
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define mod 1000000007
#define G() Cr=getchar()
int Xr;char Cr;
inline int rd(){   //读入优化
    Xr=0,G();
    while(Cr<'0'||Cr>'9')G();
    while(Cr>='0'&&Cr<='9')Xr=(Xr<<3)+(Xr<<1)+Cr-'0',G();
    return Xr;
}
int ans;
int k,n;
int va[200005];
int main(){
	k=rd(),n=rd();
	for(int i=1;i<=n;i++)va[i]=rd();
	sort(va+1,va+1+n);
	ans=k-va[n]+va[1];
	va[++n]=k;
	for(int i=0;i<n;i++)ans=max(ans,va[i+1]-va[i]);
	cout<<k-ans;
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
#define MAX_N 999999 + 16
 
int  prime[MAX_N];          
bool is_prime[MAX_N + 1];   
int sieve(const int& n)
{
    int p = 0;
    fill(is_prime, is_prime + n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; ++i)
    {
        if (is_prime[i])
        {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i)
            {
                is_prime[j] = false;
            }
        }
    }
    return p;
}
 

int main()
{
    int n;
    while (cin >> n)
    {
        cout << sieve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 2444
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int check(int x){
  if(x%2==0)return 1;
  else return 0;
}

int main(void){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int ans=0;
  r(i,n-1){
    if(s.at(i)==s.at(i+1))ans++;
  }
  cout<<min(n-1,ans+k*2)<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ull general(const string& S, const int P) {
  typedef ull Mod;
  unordered_map<Mod, size_t> counts; // leftまでにModが出現した回数
  counts[0] = 0;

  ull scale = 1;
  ull tmp = 0;
  for (ll left = S.size() - 1; left >= 0; --left) {
    ull c = static_cast<ull>(S[left] - 48);

    tmp += (scale * c % P);
    scale = (scale * 10 % P); // mod(P)を取らないとすぐにuint64を超える
    //cout << "tmp: " << tmp << endl;
    ull modLeft = tmp % P;
    counts[modLeft] += 1;
  }

  ull total = counts[0];
  //cout << "total: " << total << endl;
  for (auto& p : counts) {
    // Ui - Uj == 0になる組み合わせの数
    total += (p.second * (p.second - 1) / 2);
    //cout << "key: " << p.first << ", total: " << total << endl;
  }
  return total;
}

ull twoOrfive(const string& S, const ull P) {
  ull mod0 = 0;
  ull total = 0;

  for (ll left = S.size() - 1; left >= 0; --left) {
    ull c = static_cast<ull>(S[left] - 48);
    if (c % P == 0) {
      total += (left + 1);
    }
  }
  return total;
}

int main() {
  ull N, P;
  string S;
  cin >> N >> P >> S;
  //cout << N << " " << P << " " << S <<  " " << S.size() << endl;

  ull result;
  if (P == 2 || P == 5) {
    result = twoOrfive(S, P);
  } else {
    result = general(S, P);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
vector<P> house[5000];
int sx,sy,gx,gy,n,w,h;
int memo[103][103];
int dfs(int next,int y,int x);
int manha(P a,P b);
int main(){
  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    n=0;
    for(int i=0;i<5000;i++){
      house[i].clear();
    }
    memset(memo,-1,sizeof(memo));
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	string s;
	cin>>s;
	if(s=="S"){
	  sx=j;sy=i;
	}else if(s=="G"){
	  gx=j;gy=i;
	}else if(s!="."){
	  int num=atoi(s.data());
	  house[num].push_back(P(i,j));
	  if(n<num){
	    n=num;
	  }
	}
      }
    }
    cout<<dfs(1,sy,sx)<<endl;
  }
}

int dfs(int next,int y,int x){
  if(next>n){
    return manha(P(y,x),P(gy,gx));
  }
  if(memo[y][x]!=-1) return memo[y][x];
  
  int minn=(1<<30);
  for(int i=0;i<house[next].size();i++){
    minn=min(minn,dfs(next+1,house[next][i].first,house[next][i].second)+manha(P(y,x),house[next][i]) );
  }
  return memo[y][x]=minn;
}


int manha(P a,P b){
  return abs(a.first-b.first)+abs(a.second-b.second);
}

	  

Measured memory_bytes: 1760
import Data.Int (Int32)

countLecs :: Integral a => a -> a -> [a] -> Int
countLecs a b = length . filter (\t -> t < a || b <= t)

main :: IO ()
main = do
    [_, a, b] <- fmap read . words <$> getLine :: IO [Int32]
    ts <- fmap read . lines <$> getContents :: IO [Int32]
    print $ countLecs a b ts


Measured memory_bytes: 1020
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/tdpc/tasks/tdpc_game
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N;
int h[100000];

LL ans = 0;
 
void solve(){
	vector<LL> dp(N,INF);
	dp[0] = 0;
	for(int i=0;i<=N-2;i++){
		dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		if(i+2<N){
			dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
		}
	}
	ans = dp[N-1];
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> h[i];
 
	solve();
 
	cout << ans << endl;
	return 0;
}

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

signed main(){
  int N;
  cin>>N;
  map<string,int> note;
  rep(i,N){
    string I;
    cin>>I;
    note[I]+=1;
  }
  int maxs=0;
  for(auto A:note){
    int U=A.second;
    maxs=max(U,maxs);
  }
  for(auto i=note.begin();i!=note.end();i++){
    if(i->second==maxs){
      cout<<i->first<<endl;
    }
  }
}

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

int a[510][510];

void dfs(int l, int r, int deep) {
	if (l == r || l == r + 1) return ;
	int mid = l + r >> 1;
	for (int i = l; i <= mid; i++) {
		for (int j = mid + 1; j <= r; j++) {
			a[i][j] = deep;
		}
	}
	dfs(l, mid, deep + 1), dfs(mid + 1, r, deep + 1);
}

int main() {
	int n; scanf("%d", &n);
	dfs(1, n, 1);
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			printf("%d ", a[i][j]);
		}
		printf("\n");
	} 
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 1e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

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

    int r;
    cin>>r;
    cout<<fixed<<setprecision(10)<<2.0*PI*r<<endl;

}


Measured memory_bytes: 3804
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

typedef long long int ll;

ll ab(ll a){
    return a < 0 ? -a : a;
}

int main(){
    ll X, K, D;
    scanf("%lld %lld %lld", &X, &K, &D);

    ll ans;

    if(ab(X)/D >= K){
        ans = ab(ab(X) - K * D);
    }else{
        ll a = ab(X) % D;
        ll b = ab(X) / D;
        if(ab(K-b)%2 == 0){
            ans = a;
        }else{
            ans = D - a;
        }
    }

    printf("%lld\n", ans);

    return 0;

}


Measured memory_bytes: 3816
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string s;
	
	cin>>s;
	int sum=700;
	for(int i=0;i<s.size();i++)
		if(s[i]=='o')
			sum+=100;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuRangeSumQuery solver = new AizuRangeSumQuery();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuRangeSumQuery {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();

            int[] a = new int[n];
            int[] b = new int[4 * n];

            build(0, 0, n - 1, a, b);

            while (q-- != 0) {
                int o = in.nextInt();
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;

                if (o == 0) {
                    update(0, 0, n - 1, l, r + 1, a, b);
                } else {
                    out.printf("%d\n", query(0, 0, n - 1, l, r, b));
                }
            }
        }

        private void build(int n, int s, int e, int[] a, int[] b) {
            if (s == e) {
                b[n] = a[s];
            } else {
                int m = (s + e) / 2;
                build(2 * n + 1, s, m, a, b);
                build(2 * n + 2, m + 1, e, a, b);

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private void update(int n, int s, int e, int idx, int val, int[] a, int[] b) {
            if (s == e) {
                a[idx] += val;
                b[n] += val;
            } else {
                int m = (s + e) / 2;
                if (s <= idx && idx <= m) {
                    update(2 * n + 1, s, m, idx, val, a, b);
                } else {
                    update(2 * n + 2, m + 1, e, idx, val, a, b);
                }

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private long query(int n, int s, int e, int l, int r, int[] b) {
            if (r < s || e < l) {
                return 0;
            } else if (l <= s && e <= r) {
                return b[n];
            } else {
                int m = (s + e) / 2;
                long s1 = query(2 * n + 1, s, m, l, r, b);
                long s2 = query(2 * n + 2, m + 1, e, l, r, b);

                return s1 + s2;
            }
        }

    }
}




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

int main() {
  int N;
  scanf("%d",&N);
  int A[2][N];
  for (int i=0; i<2; i++) {
    for (int j=0; j<N; j++) {
      scanf("%d",&A[i][j]);
    }
  }
  int ans=0;
  for (int i=0; i<N; i++) {
    int ame=0;
    for (int j=0; j<=i; j++) {
      ame+=A[0][j];
    }
    for (int j=i; j<N; j++) {
      ame+=A[1][j];
    }
    ans=max(ans,ame);
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	if(N<=111)
	puts("111");
	else if(N>111&&N<=222)
	puts("222");
	else if(N>222&&N<=333)
	puts("333");
	else if(N>333&&N<=444)
	puts("444");
	else if(N>444&&N<=555)
	puts("555");
	else if(N>555&&N<=666)
	puts("666");
	else if(N>666&&N<=777)
	puts("777");
	else if(N>777&&N<=888)
	puts("888");
	else if(N>888&&N<=999)
	puts("999");
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma") 
 
#include<bits/stdc++.h>
 
#define CFOR(i, str) for(int i = 0; (str)[i]!='\0'; (i)++)
#define FOR(i, s, r) for(int i = (s); i < (r); i++)
#define INF 1e9
#define NINF -1e9
#define SUM(a) accumulate(a.begin(), a.end(), 0)
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.rbegin(), v.rend())
#define vmax(v) *max_element(v.begin(), v.end())
#define vmin(v) *min_element(v.begin(), v.end())
#define cnt(v, n) count(v.begin(), v.end(), (n))
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vpic vector<pair<int, char>>
#define mp make_pair
#define rot(s, k) rotate(s.begin(), s.begin()+ s.size()-(k%s.size()), s.end()); //+ve = right, -ve = left
#define lld long long int
#define ulld unsigned long long int
typedef long long ll;
using namespace std;
 
ll binpow(ll a, ll b) { 
ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res;
}
 
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
 
bool isPrime(ll n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n % 2 == 0 || n % 3 == 0) return false; 
    for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; 
    return true; 
}
void solve(){
      lld n,m;
    cin>>n>>m;
    if(n==m)
   cout<<"Yes\n";
   else
   cout<<"No\n";
}
int main(){
   ios::sync_with_stdio(0);
   cin.tie(0);
   ll t;
   t=1;
   while(t--)
   { 
   solve();
   }
   return 0;
}

Measured memory_bytes: 3644
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

x, y = li()
print(x + y//2)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  int a;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    cin >> a;
    mp[a]++;
  }
  int m=mp.size();
  vector<pair<int,int>> p(m);
  int now=0;
  for(auto &pa:mp){
    p[now]=pa;
    now++;
  }
  int ans=0;
  for(int i=m-1;i>=0;i--){
    if(p[i].second>0){
      int x=1;
      while(x<=p[i].first) x<<=1;
      if(x-p[i].first==p[i].first){
        ans+=p[i].second/2;
      }else{
        pair<int,int> s={x-p[i].first,-1};
        auto itr=lower_bound(all(p),s);
        if(itr->first!=x-p[i].first) continue;
        int u=min(p[i].second,itr->second);
        ans+=u;
        itr->second-=u;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end


N,d=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
def count2x(a)
	cnt = 0
	while(a%2==0)
		cnt+=1
		a = a/2
	end
	cnt
end

sum = 0
A.each{|a|
	sum += count2x(a)
}
puts sum


Measured memory_bytes: 2812
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 1e9
using namespace std;

int N;

int main(void)
{
    int L, R, d;
    int count = 0;
    cin >> L >> R >> d;

    for (int i = L; i <= R; i++)
    {
        if (i % d == 0)
            count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); <-- PUT IN main()/solve()!

using namespace std;

int n,k,a[200005],F[200005];
class EGluttony {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n >> k;
		f(i,0,n)
			in >> a[i];
		f(i,0,n)
			in >> F[i];
		sort(a,a+n);
		sort(F,F+n,greater<int>());
		int lo=0,hi=1e18,mid;
		while(lo<=hi)
		{
			mid=(lo+hi)/2;
			if(check(mid)&&!check(mid-1))
			{
				out << mid << "\n";
				break;
			}
			else if(check(mid)&&check(mid-1))
				hi=mid-1;
			else
				lo=mid+1;
		}
	}
	int check(int x)
	{
		if(x<0)
			return 0;
		int cost=0;
		f(i,0,n)
			cost+=max(a[i]-x/F[i],0ll);
		return cost<=k;
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	EGluttony solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int base_idx=0;
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        if(a==1) base_idx=i;
    }
    int res=1000000;
    for(int i=0; i<k; ++i){
        int low_idx=base_idx-i;
        int high_idx=low_idx+k-1;
        int low_cnt=(low_idx+k-2)/(k-1);
        int high_cnt=((n-high_idx-1)+k-2)/(k-1);
        int cnt=low_cnt+high_cnt+1;
        if(cnt<res){
            res=cnt;
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#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()
typedef long long ll;
const ll inf = 1e18; 
ll dp[45][2];
int main(){
    int n; ll k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    for(int d = 0; d <= 40; d++){
        rep(j,2){
            dp[d][j] = -inf;
        }
    }
    dp[40][0] = 0;

    for(int d = 39; d>=0; d--){
        ll mask = 1LL<<d;
        int cnt1 = 0;
        rep(i,n) if(a[i] & mask) cnt1++;
        int cnt0 = n - cnt1;

        if(mask & k){
            dp[d][0] = max(dp[d][0], dp[d+1][0] + mask*cnt0);
            dp[d][1] = max(dp[d][1], dp[d+1][0] + mask*cnt1);
        }
        else dp[d][0] = max(dp[d][0], dp[d+1][0] + mask*cnt1);

        dp[d][1] = max(dp[d][1], dp[d+1][1] + mask*max(cnt0,cnt1));
    }

    ll ans = max(dp[0][0], dp[0][1]);
    cout << ans << endl;
}


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

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

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

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}

ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}

/**
double cosine_rule(double a,double b,double c)
{
    double res=(a*a+b*b-c*c)/(2*a*b);
    res=acos(res);
    return res;
}
*/
ll arr[mx];
int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    ll tst,a,b,c,k,n,m,res=0,ans=0,neg=0,t=0;
    ll mini=inf;
    sl(n);
    for(ll i=1;i<=n;i++)
    {
        sl(a);
        arr[i]=a;
        res+=abs(a);
        if(a<0)
            neg++;
        if(a==0)t=1;
        mini=min(abs(a),mini);
    }

    if(neg%2==0||t)
    {
        cout<<res<<endl;
    }
    else
    {
        cout<<res-mini-mini<<endl;
    }


    return 0;
}


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

int BinarySearch(vector<int> &A, int key) {
    int mid;
    int left = 0;
    int right = A.size();
    while (left < right) {
        mid = (left + right) / 2;
        if (A[mid] == key) {
            return 1;
        }
        if (key < A[mid]) {
            right = mid;
        }
        else {
            left = mid + 1;
        }
    }
    return 0;
}

int main(int argc, char const *argv[])
{
    int n, m, t;
    int count = 0;
    vector<int> S, key;

    cin >> n;

    for (int i=0; i<n; i++) {
        scanf("%d", &t);
        S.push_back(t);
    }

    cin >> m;

    for (int i=0; i<m; i++) {
        scanf("%d", &t);
        key.push_back(t);
    }

    for (int i=0; i<m; i++) {
        count += BinarySearch(S, key[i]);
    }

    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 307;
int n, k, dp[N][N][N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    string s; cin >> s; n = s.size(); cin >> k;
    for (int i = 1; i <= n; ++i) dp[i][i][0] = 1;
    for (int len = 2; len <= n; ++len) 
        for (int l = 1; l + len - 1 <= n; ++l) {
            int r = l + len - 1;
            for (int u = 0; u <= k; ++u) dp[l][r][u] = max(dp[l + 1][r][u], dp[l][r - 1][u]);
            if (s[l - 1] == s[r - 1]) for (int u = 0; u <= k; ++u) dp[l][r][u] = max(dp[l][r][u], dp[l + 1][r - 1][u] + 2);
            else for (int u = 1; u <= k; ++u) dp[l][r][u] = max(dp[l][r][u], dp[l + 1][r - 1][u - 1] + 2);
            //for (int u = 0; u <= k; ++u) cout << l << ' ' << r << ' ' << u << " : " << dp[l][r][u] << '\n';
        }   
    int ans = 0;
    for (int i = 0; i < N; ++i) ans = max(ans, dp[1][n][i]);
    cout << ans << '\n';
}

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

template<typename T> 
map<T, Int> factorize(T x){
  map<T, Int> res;
  for(Int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());

  vector<Int> ans(n);

  Int m=0;
  map<Int, Int> r;

  vector<vector<Int> > G(n);
  for(Int i=0;i<n;i++){
    auto x=factorize(a[i]);
    for(auto p:x){
      if(!r.count(p.first)) r[p.first]=m++,G.emplace_back();
      G[i].emplace_back(n+r[p.first]);
      G[n+r[p.first]].emplace_back(i);
    }
  }
  
  Int color=0;
  vector<Int> cs(n+m,-1),used(n+m,0),post(n,0);
  for(Int t=0;t<n;t++){
    for(Int i=0;i<n+m;i++){
      if(used[i]||~cs[i]) continue;
      queue<Int> q;
      cs[i]=color;
      q.emplace(i);
      while(!q.empty()){
	Int v=q.front();q.pop();
	for(Int u:G[v]){
	  if(used[u]||~cs[u]) continue;
	  cs[u]=color;
	  q.emplace(u);
	}
      }
      color++;
    }
    
    Int idx=-1;
    for(Int i=0;i<n;i++){
      if(used[i]||post[i]) continue;
      idx=i;
      break;
    }
    
    used[idx]=1;
    ans[t]=idx;
    
    for(Int i=0;i<n+m;i++){
      if(used[i]||cs[idx]!=cs[i]) continue;
      if(i<n) post[i]=__gcd(a[idx],a[i])<=1;
      cs[i]=-1;
    }
  }

  vector<Int> b(n);
  for(Int i=0;i<n;i++) b[i]=a[ans[i]];
  
  vector<vector<Int> > H(n);
  for(Int i=0;i<n;i++)
    for(Int j=i+1;j<n;j++)
      if(__gcd(b[i],b[j])>1) H[i].emplace_back(j);

  vector<Int> indeg(n);
  for(Int i=0;i<n;i++)
    for(Int j:H[i]) indeg[j]++;
  
  using P = pair<Int, Int>;
  priority_queue<P> pq;
  for(Int i=0;i<n;i++)
    if(!indeg[i]) pq.emplace(b[i],i);

  vector<Int> c;
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    c.emplace_back(p.first);
    for(Int u:H[p.second]){
      indeg[u]--;
      if(!indeg[u]) pq.emplace(b[u],u);
    }
  }
  
  for(Int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<c[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 14336
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    ll N, tmp;
    string ans;    

    cin >> N;

    while(N>0) {
        N--;
        tmp = N % 26;
        ans += 'a' + tmp;
        N = N / 26;
    }

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

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3596
S = input()
N = len(S)


def judge_kaibun(S):
    n = len(S)
    center = n//2
    return S[:center] == S[-center:][::-1]


if N == 3:
    if S[0] == S[2]:
        print("Yes")
    else:
        print("No")
    exit()

full_judge = judge_kaibun(S)
pre_judge = judge_kaibun(S[:(N-1)//2])
pos_judge = judge_kaibun(S[-(N-1)//2:])

if pre_judge and pos_judge and full_judge:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int N;
int ans;
void dfs(ll x, int a, int b, int c){
    if(N < x)return;
    if(a > 0 && b > 0 && c > 0)ans++;
    dfs(10 * x + 3, a + 1, b, c);
    dfs(10 * x + 5, a, b + 1, c);
    dfs(10 * x + 7, a, b, c + 1);
    return;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> N;
    ans = 0;
    dfs(0,0,0,0);
    cout << ans << endl;
}

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

ll S(ll x) {
  ll s = 0;
  while(x) s += x % 10, x /= 10;
  return s;
}

ll fc(ll a, ll b) { return a * S(b) > b * S(a); }

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ll k; cin >> k;
  ll t = 1;
  vector<ll> ans;
  ll n = 1;
  while(n <= 1e15) {
    ans.emplace_back(n);
    if(ans.size() >= k) break;
    while(t <= 1e15 && fc(n + t, n + t + t)) t *= 10;
    n += t;
  }
  for(int i = 0; i < k; i++) cout << ans[i] << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	int N = s.size() - 1;
	ll ans = 0;
	for(int bit = 0; bit < 1 << N; bit++){
		ll tmp = s[0] - '0';
		for(int i = 0; i < N; i++){
			if(bit & 1 << i){
				ans += tmp;
				tmp = 0;
			}
			tmp = tmp * 10 + s[i + 1] - '0';
		}
		ans += tmp;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<char,bool>vis;
char a[105][5];
int main(){
	int n,dis,ans1,ans2,ans3,ans4;
	scanf("%d",&n);
	dis=0;
	ans1=0;
	ans2=0;
	ans3=0;
	ans4=0;
	for(int i=1;i<=n;i++){
		scanf("%s",a[i]+1);
		if(ans1==0&&a[i][1]=='P'){
			ans1++;
			dis++;
		}
		if(ans2==0&&a[i][1]=='W'){
			ans2++;
			dis++;
		}
		if(ans3==0&&a[i][1]=='G'){
			ans3++;
			dis++;
		}
		if(ans4==0&&a[i][1]=='Y'){
			ans4++;
			dis++;
		}
	}
	if(dis==3) printf("Three\n");
	else printf("Four\n");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.nextLine();

		if(S.equals("AAA") || S.equals("BBB")) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21844
#include <stdio.h>


int main(void)
{
	int flag;
	
	long long int n,a,b;
	
	scanf("%lld",&n);
	
	printf("%lld:",n);
	
	while(n!=1){
		flag=0;
		printf(" ");
		
		if(n==999993031){
			printf("%d",999993031);
			break;
		}
		
		for(a=2;a<=n;a++){
			flag=0;
			if(n%a==0){
				for(b=2;b<a;b++){
					if(a%b==0 && a!=b) flag=1;
				}
			}
			else flag=1;
			
			if(flag==0){
				printf("%lld",a);
				n/=a;
				break;
			}
		}
	}
	
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int num_query;
	scanf("%d",&num_query);

	ll A,B;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%lld %lld",&A,&B);

		if(A > B)swap(A,B);

		if(A == B || A+1 == B){

			printf("%lld\n",2*A-2);

		}else{

			ll C = sqrt(A*B);

			if(C*C == A*B){

				printf("%lld\n",2*C-3);
			}else if(C*(C+1) >= A*B){

				printf("%lld\n",2*C-2);

			}else{ //C*(C+1) < A*B

				printf("%lld\n",2*C-1);
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3740
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
vector<int>to[1010];
bool A[1010][1010],B[1010][1010];
void dfs1(int u,int o)
{
	if(A[o][u])return ;
	A[o][u]=true;
	for(int i=0;i<to[u].size();i++)
		dfs1(to[u][i],o);
	return ;
}
int book[1010];
bool vis[1010];
void dfs2(int u,int o,int s,bool ok=false)
{
	if(vis[u])return ;
	vis[u]=true;
	if(!ok)book[u]=s;
	else B[o][u]=(s!=book[u]);
	for(int i=0;i<to[u].size();i++)
		dfs2(to[u][i],o,s,ok);
	return ;
}
int U[200010],V[200010];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d %d",&U[i],&V[i]);
		to[U[i]].push_back(V[i]);
	}
	for(int i=1;i<=n;i++)dfs1(i,i);
	for(int i=1;i<=n;i++)
	{
		memset(book,0,sizeof(book));
		memset(vis,0,sizeof(vis));vis[i]=true;
		int num=to[i].size();
		for(int j=0;j<num;j++)
			dfs2(to[i][j],i,j);
		memset(vis,0,sizeof(vis));vis[i]=true;
		for(int j=num-1;j>=0;j--)
			dfs2(to[i][j],i,j,true);
	}
	for(int i=1;i<=m;i++)
		if(A[V[i]][U[i]]^B[U[i]][V[i]])printf("diff\n");
		else printf("same\n");
	return 0;
}

Measured memory_bytes: 6272