akhauriyash/Code-Regression huggingface dataset:
//containing t test cases
#include<bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define scan(n) ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define rep(i,x,y) for(ll i=x;i<y;i++)
//#define int long long
using namespace std;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ; 
typedef pair<ll,ll> pll ;
typedef vector<pair<ll,ll> > vpll;
vi v[200005];
ll vis[200005];
ll parent[200005];
ll level[200005];
ll arr[200005];
ll size[200005];
//endl mut bhool!!
int main()
{
	fast;
	int test=1;
	//cin>>test;
	while(test--)
	{
		ll n,m;
		cin>>n>>m;
		ll h[n+1];
		for(ll i=1;i<=n;i++)
		{
			cin>>h[i];
		}
		for(ll i=0;i<m;i++)
		{
			ll x,y;
			cin>>x>>y;
			v[x].pb(y);
			v[y].pb(x);
		}
		ll flag,cnt=0;
		for(ll i=1;i<=n;i++)
		{
			flag=0;
			if(v[i].size()==0)
			{
				cnt++;
				continue;
			}
			for(ll j=0;j<v[i].size();j++)
			{
				if(h[v[i][j]]>=h[i])
				{
					flag=1;
					break;
				}
			}
			if(!flag)
				cnt++;
		}
		cout<<cnt;
	}
	return 0;
}
/*
cout<<"YES"<<endl;
cout<<"NO"<<endl;
*/

Measured memory_bytes: 11912
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}
const int N_MAX = 1e3+10;
int N;
vector<vector<int> > v(N_MAX,vector<int>(N_MAX));
vector<vector<int> > w(N_MAX,vector<int>(N_MAX,-1));
vector<int> ind(N_MAX,0);
vector<int> day(N_MAX,0);
vector<bool> used(N_MAX,false);

bool dfs(int x, int until){
  if(ind[x] == until) return true;
  if(used[x]) return false;
  used[x] = true;
  while(ind[x] < until){
    int y = v[x][ind[x]];
    if(!dfs(y,w[y][x])) return false;
    day[x] = day[y] = max(day[x],day[y])+1;
    ++ind[x];
    ++ind[y];
  }
  used[x] = false;
  return true;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> N;
  rep(i,N)rep(j,N-1){
    cin >> v[i][j];
    --v[i][j];
    w[i][v[i][j]] = j;
  }

  bool issat = true;
  rep(i,N) if(!dfs(i,N-1)){
    issat = false;
    break;
  }
  int daym = 0;
  rep(i,N)daym = max(daym,day[i]);
  if(issat) cout << daym << endl;
  else cout << -1 << endl;
  return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

LL dpb[2001][2001];
LL dpv[2001][2001];
LL dph[2001][2001];
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int H, W, Q;
  cin >> H >> W >> Q;
  VS vs(H);
  REP(y,H) cin >> vs[y];

  REP(y,H){
	REP(x,W){
	  dpb[y+1][x+1] = dpb[y+1][x] + dpb[y][x+1] - dpb[y][x] + (vs[y][x] == '1');
	  dph[y+1][x+1] = dph[y+1][x] + dph[y][x+1] - dph[y][x]
		+ (x>0 && vs[y][x] == '1' && vs[y][x-1] == '1');
	  dpv[y+1][x+1] = dpv[y+1][x] + dpv[y][x+1] - dpv[y][x]
		+ (y>0 && vs[y][x] == '1' && vs[y-1][x] == '1');
	}
  }

  REP(q,Q){
	int x1, y1, x2, y2;
	cin >> y1 >> x1 >> y2 >> x2;
	--x1;
	--y1;
	int b = dpb[y2][x2] - dpb[y1][x2] - dpb[y2][x1] +  dpb[y1][x1];
	int v = dpv[y2][x2] - dpv[y1+1][x2] - dpv[y2][x1] +  dpv[y1+1][x1];
	int h = dph[y2][x2] - dph[y1][x2] - dph[y2][x1+1] +  dph[y1][x1+1];
	cout << b - v - h << endl;
  }

  return 0;
}


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

namespace AOJ.Volume0
{
    class Program0005
    {
        static void Main(string[] args)
        {
            string input;
            Queue<int[]> queue = new Queue<int[]>();

            while ((input = Console.ReadLine()) != null)
            {
                string[] splitedInput = input.Split(' ');
                int[] param = new int[2];

                for (int i = 0; i < 2; i++)
                {
                    param[i] = int.Parse(splitedInput[i]);
                }

                int maxKoyaku, minKobai;
                maxKoyaku = GetMaxKoyaku(param[0], param[1]);
                minKobai = GetMinKobai(param[0], param[1], maxKoyaku);

                queue.Enqueue(new[] { maxKoyaku, minKobai });
            }

            foreach (var ans in queue)
            {
                Console.WriteLine("{0} {1}", ans[0], ans[1]);
            }
        }

        static int GetMaxKoyaku(int x, int y)
        {
            int maxKoyaku = 1;
            int end = Math.Min(x, y) / 2;

            if (Math.Max(x, y) % Math.Min(x,y) == 0)
            {
                return Math.Min(x, y);
            }

            for (int i = 2; i <= end; i++)
            {
                if (x % i == 0 && y % i == 0)
                {
                    maxKoyaku = i;
                }
            }

            return maxKoyaku;
        }

        static int GetMinKobai(int x, int y, int maxKoyaku)
        {
            long kobai = Math.BigMul(x, y);
            return (int)(kobai / maxKoyaku);
        }
    }
}

Measured memory_bytes: 5968
n = int(input())
p = list(map(int,input().split()))
m = list(range(1,n+1))
count = 0
for i in range(n):
    if p[i] != m[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
from operator import itemgetter
import heapq
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, i))
    Y.append((y, i))
X.sort(key=itemgetter(0))
Y.sort(key=itemgetter(0))
G = [[] for _ in range(N)]
for i in range(N-1):
    G[X[i][1]].append((X[i+1][0]-X[i][0], X[i+1][1]))
    G[X[i+1][1]].append((X[i+1][0]-X[i][0], X[i][1]))
    G[Y[i][1]].append((Y[i+1][0]-Y[i][0], Y[i+1][1]))
    G[Y[i+1][1]].append((Y[i+1][0]-Y[i][0], Y[i][1]))

q = []
heapq.heapify(q)
for elem in G[0]:
    heapq.heappush(q, elem)
used = [False] * N
used[0] = True
ans = 0
while q:
    res = heapq.heappop(q)
    cost, nq = res
    if not used[nq]:
        used[nq] = True
        ans += cost
        for elem in G[nq]:
            heapq.heappush(q, elem)
print(ans)


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

//#define DEBUG

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const int N = 1e5+5;
int arr[N];
int rep[44];
ll n, k;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll res = 0;
	cin >> n >> k;
	lp(i, n){
		ll num, idx = 0;
		cin >> num;
		arr[i] = num;
		while(num > 0){
			rep[idx] += num%2;
			num /= 2;
			++idx;
		}
	}
	ll x = 0;
	lpd(i, 39, 0){
		ll power = pow(2, i);
		if(rep[i] >= n-rep[i])
			res += power * rep[i];
		else if(x+power <= k){
			x = x+power;
			res += power * (n - rep[i]);
		}
		else
			res += power * rep[i];
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXM=MAXN-1;

int n;
int val[MAXN];
int ghead[MAXN],gnxt[2*MAXM],gto[2*MAXM];
bool ret;

int dfs(int at,int par) {
	int have=0,cnt=0,mx=0;
	for(int x=ghead[at];x!=-1;x=gnxt[x]) {
		int to=gto[x]; if(to==par) continue;
		int cur=dfs(to,at);
		have+=cur; ++cnt; if(cur>mx) mx=cur;
	}
	if(cnt==0) return val[at];
	if(have<val[at]||have>2*val[at]) ret=false;
	int use=have-val[at];
	if(mx>val[at]) ret=false;
	// y connections -> y=have-val[at], return 2*val[at]-have
	//printf("%d: val=%d, mx=%d, have=%d (between %d and %d) -> %d connections, returning %d\n",at+1,val[at],mx,have,val[at],2*val[at],have-val[at],2*val[at]-have);
	return 2*val[at]-have;
}

bool solve() {
	if(n==2) return val[0]==val[1];
	int root=0; while(root<n&&(ghead[root]==-1||gnxt[ghead[root]]==-1)) ++root; if(root>=n) return false;
	//printf("root=%d\n",root+1);
	ret=true;
	if(dfs(root,-1)!=0) ret=false;
	return ret;
}

void run() {
	scanf("%d",&n);
	REP(i,n) scanf("%d",&val[i]);
	REP(i,n) ghead[i]=-1;
	REP(i,n-1) {
		int a,b; scanf("%d%d",&a,&b); --a,--b;
		gnxt[2*i+0]=ghead[a]; ghead[a]=2*i+0; gto[2*i+0]=b;
		gnxt[2*i+1]=ghead[b]; ghead[b]=2*i+1; gto[2*i+1]=a;
	}
	printf("%s\n",solve()?"YES":"NO");
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<cmath>
#define EPS 1e-8
using namespace std;

double getEntropy(int s,int a,int c,int *l,int n){
  double sum[256]={0};
  double res=0;
  int r=s;
  for(int i=0;i<n;i++){
    r=(a*r + c)&255;
    sum[(r + l[i])&255]++;
  }

  for(int i=0;i<256;i++){
    //cout << "sum["<<i<<"]:"<<sum[i] << endl;
    if(sum[i]==0)continue;
    res-=sum[i]/n * log(sum[i]/n);
    //cout << "res:" << res << endl;
  }
  return res;
}

int main(){
  int n;
  while(cin>>n,n){
    int l[n];
    double mn=100000000;
    int S,A,C;
    for(int i=0;i<n;i++)cin>>l[i];
    for(int s=0;s<16;s++){
      for(int a=0;a<16;a++){
	for(int c=0;c<16;c++){
	  double tmp=getEntropy(s,a,c,l,n);
	  if(mn-tmp>EPS){
	    mn=tmp;
	    S=s;
	    A=a;
	    C=c;
	    //cout << "S:" <<  S << " A:" << A << " C:" << C << endl;
	    //cout << "res:" << mn << endl;
	  }
	}
      }
    }
    cout << S << " " << A << " " << C << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
s = gets.chomp.split('')

if s.size <= 2
  if s[0] == s[1]
    puts "1 2"
    exit
  end
else
  (s.size - 2).times do |i|
    if s[i] == s[i+1]
      puts "#{i+1} #{i+2}"
      exit
    elsif s[i] == s[i+2]
      puts "#{i+1} #{i+3}"
      exit
    end
  end
end
puts "-1 -1"


Measured memory_bytes: 6908
S = input()
for i in range(len(S)-1, 0, -1):
    tmp = S[:i]
    len_t = len(tmp)
    if len_t % 2:
        continue
    mididx = len_t // 2
    if tmp[:mididx] == tmp[mididx:]:
        print(len_t)
        break


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
using Graph = vector<vector<int>>;



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

    int N,M;
    cin>>N>>M;
    int a[M],b[M];

    scc_graph g(N);
    rep(i,M){
        cin>>a[i]>>b[i];
        g.add_edge(a[i],b[i]);
    }

    auto ans=g.scc();
    cout<<ans.size()<<endl;

    for(auto v:ans){
        cout<<v.size()<<" ";
        for(auto x:v){
            cout<<x<<" ";
        }
        cout<<endl;
    }




}


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

int main()
{
  char a;
  
  cin>>a;
  
  if(a>='a'&&a<='z')
  {
    cout<<"a"<<endl;
  }
  else
  {
    cout<<"A"<<endl;
  }
  
  return 0;
}

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

cnt=[[0]*10 for _ in range(10)]

for i in range(1,N+1):
    if i%10==0:
      continue
    s=str(i)
    up=int(s[0])
    down=int(s[-1])
    cnt[up][down]+=1

ans=0
for i in range(1,10):
    for j in range(1,10):
        a=cnt[i][j]
        b=cnt[j][i]
        ans+=a*b

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair
#define pll pair
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll dp[maxn];
ll a[maxn];
int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i];
    }
    dp[1]=0;
    dp[0]=0;
    dp[2]=abs(a[2]-a[1]);
    repd(i,3,n)
    {
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));

    }
    cout<<dp[n];
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}
	
	
	
	
	
	
	
	



Measured memory_bytes: 5196
#include <bits/stdc++.h> 
#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif


using namespace std;
#define M 1000000001
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repb(i,a,b) for(int i=a;i>=b;--i)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();++it)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define vc vector<char>
#define sz(a) (int)a.size()
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define ssortB(arr)   stable_sort(arr.begin(),arr.end(),greater<int>());
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define fi first
#define se second
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define mp make_pair
#define endl "\n" 
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define check(ds,x) (int)(ds.find(x)!=ds.end()?1:0)
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int k;
    cin>>k;
    vb visited(k,false);
    int count=1;
    int sept=7;
    int flag=0;
    while(1){
        if(sept%k==0){
            flag=1;
            break;
        }
        else{
            if(visited[sept%k]){
                break;
            }
            else{
                visited[sept%k]=true;
                sept%=k;
                ++count;
                sept*=10;
                sept+=7;
            }
        }
    }
    if(flag)
    cout<<count<<endl;
    else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 3708
#include <iostream>
using namespace std;
typedef long long ll;
ll f[200001], M=1e9+7;
ll p(ll a, ll b){
    if(b==0)return 1;
    if(b%2==0)return p((a*a)%M, b/2);
    return (a*p(a, b-1))%M;
}
ll c(int a, int b){
    return ((f[a]*p(f[b], M-2))%M * p(f[a-b], M-2))%M;
}
int main() {
    ll h, w, a, b, ans=0;
    cin >> h >> w >> a >> b;
    f[0] = 1;
    for(int i=1;i<200001;i++){
        f[i] = (f[i-1] * i) % M;
    }
    for(int i=h-a;i>0;i--){
        int x=b+1+h-a-i;
        
        if(x>w)break;
        ans += (c(i+x-2, i-1) * c(h-i+w-x, h-i))%M;
        ans %= M;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
S = input()
T = input()

ls = len(S)
lt = len(T)
ans = lt
for i in range(ls):
    dif = 0
    for j in range(lt):
        if ls <= i+j:
            break
        if S[i+j] != T[j]:
            dif += 1
    else:
        ans = min(ans,dif)

print(ans)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#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 pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll k(n+1);
  for(int i=1;i<=n;i++){
    ll cu=1;
    while(cu*i<=n){
      k[cu*i]++;
      cu++;
    }
  }
  ll ans=0;
  rep(i,n+1){
    ans+=i*k[i];
  }
  COUT(ans);
}

Measured memory_bytes: 81372
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
static const int N_MAX=100000;
static const int NINF=-1000000000;
int N,P[N_MAX],ans;
int dp[N_MAX][3];//0:1p,1:0p,2:2p
vector<int> T[N_MAX];
bool V[N_MAX];

void dfs(int u){
	V[u]=true;
	vector<int> C;
	rep(i,T[u].size()){
		int v=T[u][i];
		if(!V[v]){
			C.push_back(v);
			dfs(v);
		}
	}
	//子cがすべて訪問・決定済み
	
	if(C.size()==0){
		rep(i,3)dp[u][i]=P[u];
	}else if(C.size()==1){
		int v=C[0];
		dp[u][0]=max(dp[v][0]-1+P[u],P[u]);
		dp[u][1]=max(dp[v][1]-2+P[u],P[u]);
		dp[u][2]=max(dp[v][2]-2+P[u],P[u]);
	}else{
		int a1,a2,c1;//candidate child
		a1=a2=c1=C[0];
		rep(i,C.size()){
			int v=C[i];
			if(dp[a1][0]-1-max(dp[a1][1]-2,0)<=dp[v][0]-1-max(dp[v][1]-2,0))a1=v;
			if(dp[c1][2]-2-max(dp[c1][1]-2,0)<=dp[v][2]-2-max(dp[v][1]-2,0))c1=v;
		}
		rep(i,C.size())if(C[i]!=a1){a2=C[i];break;}
		rep(i,C.size()){
			int v=C[i];
			if(v==a1)continue;
			if(dp[a2][0]-1-max(dp[a2][1]-2,0)<=dp[v][0]-1-max(dp[v][1]-2,0))a2=v;
		}
		int sumA1=0;//bbbbab
		int sumB1=0;//bbbbbb
		int sumC1=0;//bbbcbb
		int sumC2=0;//abbabb
		for(int i=0;i<C.size();i++){
			int v=C[i];
			sumA1+=(v==a1)?(dp[v][0]-1):max(dp[v][1]-2,0);
			sumB1+=max(dp[v][1]-2,0);
			sumC1+=(v==c1)?(dp[v][2]-2):max(dp[v][1]-2,0);
			sumC2+=(v==a1||v==a2)?(dp[v][0]-1):max(dp[v][1]-2,0);
		}
		int sumA=sumA1;
		int sumC=max(sumC1,sumC2);
		int sumB=sumB1;
		dp[u][0]=max(P[u],sumA+P[u]);
		dp[u][1]=max(P[u],sumB+P[u]);
		dp[u][2]=max(P[u],sumC+P[u]);
	}
	rep(i,3)ans=max(ans,dp[u][i]);
}
int solve(int s){
	rep(i,N)rep(j,3)dp[i][j]=NINF;
	rep(i,N)V[i]=false;
	ans=NINF;
	dfs(s);
	return ans;
}

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>P[i];	
	}
	for(int i=0;i<N-1;i++){
		int s,t;cin>>s>>t;
		s--;t--;
		T[s].push_back(t);
		T[t].push_back(s);
	}
	
	int a=solve(0);
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 25912
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>

using namespace std;

const auto INF = numeric_limits<long long>::max();

long long solve(int N, const vector<long long>& A)
{
	if (N % 2 == 0) {
		vector<vector<long long>> dp(2, vector<long long>(N, -INF));

		dp[0][0] = A[0];
		for (int i = 2; i < N; i += 2) {
			dp[0][i] = dp[0][i - 2] + A[i];
		}
		dp[1][1] = A[1];

		for (int i = 3; i < N; i += 2) {
			dp[1][i] = dp[1][i - 2] + A[i];
			dp[1][i] = max(dp[1][i], dp[0][i - 3] + A[i]);
		}

		auto ans = max(dp[0][N - 2], dp[1][N - 1]);

		return ans;
	}
	else {

		vector<vector<long long>> dp(3, vector<long long>(N, -INF));

		dp[0][0] = A[0];
		for (int i = 2; i < N - 2; i += 2) {
			dp[0][i] = dp[0][i - 2] + A[i];
		}
		dp[1][1] = A[1];
		dp[2][2] = A[2];

		for (int i = 3; i < N; i += 2) {
			dp[1][i] = dp[1][i - 2] + A[i];
			dp[1][i] = max(dp[1][i], dp[0][i - 3] + A[i]);
			if (i + 1 < N) {
				dp[2][i + 1] = dp[2][i - 1] + A[i + 1];
				dp[2][i + 1] = max(dp[2][i + 1], dp[1][i - 2] + A[i + 1]);
				dp[2][i + 1] = max(dp[2][i + 1], dp[0][i - 3] + A[i + 1]);
			}
		}

		auto ans = max({ dp[0][N - 3], dp[1][N - 2], dp[2][N - 1] });

		return ans;
	}
}

int main()
{
	int N;
	cin >> N;
	vector<long long> A(N);
	for (auto& x : A) {
		cin >> x;
	}
	cout << solve(N, A) << endl;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define ar array
#define sz(a) (int) a.size()
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define ii pair<int, int>
#define bit(x, y) ((x >> y) & 1)
#define lwb lower_bound
#define upb upper_bound

#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

const ll mod = 998244353;

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

  int n;
  cin >> n;
  vi d(n), cnt(n, 0);
  FOR(i, n) cin >> d[i];
  if (d[0] != 0) {
    cout << 0 << '\n';
    return 0;
  }
  sort(all(d));
  if (d[1] != 1) {
    cout << 0 << '\n';
    return 0;
  }
  ll ans = 1;
  cnt[0]++;
  FOR(i, 1, n) {
    ans = ans * cnt[d[i] - 1] % mod;
    cnt[d[i]]++;
  }

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


Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007
int r, s, p;

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}
int tt(char x)
{
	if (x == 'r')
		return r;
	else if (x == 's')
		return s;
	else if (x == 'p')
		return p;
	else
		return 0;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, k;
	cin >> n >> k;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	string ans = "";
	int l = t.size();
	zip(i, 0, k)
	{
		if (t[i] == 'r')
		{
			ans += "p";
		}
		else if (t[i] == 's')
		{
			ans += "r";
		}
		else
		{
			ans += "s";
		}
	}
	zip(i, k, n)
	{
		if (t[i] == 'r')
		{
			if (ans[i - k] != 'p' || ans[i - k] == '#')
			{
				ans += "p";
			}
			else
			{
				ans += "#";
			}
		}
		else if (t[i] == 's')
		{
			if (ans[i - k] != 'r' || ans[i - k] == '#')
			{
				ans += "r";
			}
			else
			{
				ans += "#";
			}
		}
		else
		{
			if (ans[i - k] != 's' || ans[i - k] == '#')
			{
				ans += "s";
			}
			else
			{
				ans += "#";
			}
		}
	}
	int cnt = 0;
	//cout << ans << en;
	zip(i, 0, ans.size())
	{
		cnt += tt(ans[i]);
	}
	cout << cnt << en;
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i < n; i++) {
        a[i] += a[i - 1];
    }
    ll ans = LLINF;
    for(int i = 1; i <= n - 1; i++) {
        ll l = a[i - 1];
        ll r = a[n - 1] - a[i - 1];
        chmin(ans, llabs(r - l));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> vec(n);
  REP(i,n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  vec[n-1] /= 2;
  int ans = 0;
  REP(i,n) ans += vec[i];
  cout << ans << endl;
}

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


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int c[500005]={0};
int main()
{ios_base::sync_with_stdio(false);
int n,m;
cin>>n>>m;

while(m--)
{
	int a,b;
	cin>>a>>b;
	if(a==1)c[b]++;
	if(b==n)c[a]++;
}

int f=0;
rep(i,1,n)
{
	if(c[i]>=2)f++;
}

if(f)ol("POSSIBLE\n");
else ol("IMPOSSIBLE\n");

return 0;
}



Measured memory_bytes: 1024
/*input
5
1 7 2 11 15
*/

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

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define endl "\n"
#define sp " " 
#define all(v) v.begin(),v.end()
#define makepr(a,b) make_pair(a, b)
#define loop(i,k,n) for(ll i=k;i<n;i++)
#define rlop(i,n,k) for(ll i=n-1;i>=k;i--)
#define lop(i ,a) for(auto i : a)
#define vecl vector<ll>
#define vecprl vector<pair<ll, ll> > v;
#define mpll map<ll, ll>
#define mpsl map<string, ll>
#define setl set<ll>
#define mod(a,b) a%b
#define PI 3.14159265

typedef long long ll;
typedef long double ld;

int main()
{
    fast;
    string s;
    cin >>s;
    ll ans =0;
    loop(i ,1,s.size())
    {
        if(s[i]==s[i-1])
        {
            ans ++;
            (s[i-1]=='1')?s[i]='0':s[i]='1';
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(1e7+1,1);

    for(int i=2; i<n+1; i++){
        for(int j=i; j<n+1; j+=i){
            a[j]++;
        }
    }

    int res=0;
    for(int i=1; i<=n; i++){
        res+=i*a[i];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 81308
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    string S,T;
    cin >> S >> T;
    cout << T+S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=55;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
char st[MAXN];
vector<PR> V[MAXN*MAXN];
int n,m,flag[MAXN][MAXN],vis[MAXN][MAXN];
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
int bfs(int x1,int y1,int x2,int y2)
{
	for (int i=0;i<=n*m;i++) V[i].clear();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) vis[i][j]=0;
	V[0].PB(MP(x1,y1));
	for (int i=0;i<=n*m;i++)
		for (auto v:V[i])
		{
			if (v.fi==x2&&v.se==y2) return i;
			if (vis[v.fi][v.se]) continue;
			vis[v.fi][v.se]=1;
			for (int j=0;j<4;j++)
			{
				int xx=v.fi+dx[j],yy=v.se+dy[j];
				if (xx>0&&yy>0&&xx<=n&&yy<=m&&flag[xx][yy]&&!vis[xx][yy]) V[i+1].PB(MP(xx,yy));
			}
		}
}
int main()
{
	n=read(),m=read();
	for (int i=1;i<=n;i++)
	{
		scanf("%s",st+1);
		for (int j=1;j<=m;j++) flag[i][j]=(st[j]=='.')?1:0;
	}
	int ans=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) if (flag[i][j])
			for (int k=1;k<=n;k++)
				for (int t=1;t<=m;t++) if (flag[k][t])
				{
					int p=bfs(i,j,k,t);
					upmax(ans,p);
				}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python
# -*- coding: utf-8 -*-

group = [0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

a, b = map(int, input().split(' '))
print('Yes' if group[a - 1] == group[b - 1] else "No")


Measured memory_bytes: 3316
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s;
	cin >> s;
	int n = s.size();
	reverse(s.begin(),s.end());

	vector<int> mod_digit(n);
	mod_digit[0] = 1;
	for(int i = 0;i < n-1;i++){
		mod_digit[i+1] = mod_digit[i] * 10 % 13;
	}
	vector<vector<ll>> dp(n+1,vector<ll>(13,0));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 13;j++){
			if(s[i] == '?'){
				for(int k = 0;k <= 9;k++){
					dp[i+1][(j+k*mod_digit[i])%13] += dp[i][j];
					dp[i+1][(j+k*mod_digit[i])%13] %= MOD;
				}
			}
			else{
				dp[i+1][(j+(s[i]-'0')*mod_digit[i])%13] += dp[i][j];
				dp[i+1][(j+(s[i]-'0')*mod_digit[i])%13] %= MOD;
			}
		}
	}

	cout << dp[n][5] << endl;
}


Measured memory_bytes: 14080
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    l,r=MAP()

    if l//2019==r//2019:
        l%=2019
        r%=2019
        mi=INF
        for i in range(l,r):
            for j in range(i+1,r+1):
                mi = min(mi,(i*j)%2019)
        print(mi)

    else:
        print(0)


if  __name__=='__main__':
    main()


Measured memory_bytes: 5400
#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.at(i);
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n-i-1; j++){
      if(a.at(j) < a.at(j+1)){
        int w = a.at(j);
        a.at(j) = a.at(j+1);
        a.at(j+1) = w;
      }
    }
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0) sum += a.at(i);
    else sum -= a.at(i);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    string s;
    vector<ll> a;
    cin>>s;
    rep(i,n) {
        if (s[i]=='R') {
            a.push_back(0);
        }
        else if (s[i]=='G') {
            a.push_back(1);
        }
        else {
            a.push_back(2);
        }
    }
    vector<vector<ll>> csum(3,vector<ll>(n+40));
    rep(i,n) {
        rep(j,3) {
            csum[j][i+1] = csum[j][i];
        }
        csum[a[i]][i+1]++;
    }
    ll res = 0;
    rep(i,n) {
        repr(j,i+1,n) {
            if (a[i]!=a[j]) {
                ll cur = 3 - a[i] - a[j];
                res += csum[cur][n] - csum[cur][j];
                if (2*j-i<n&&a[2*j-i]==cur) {
                    res--;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    string S;
    cin >> S;

    if (S == "SSS") {
        cout << 0 << endl;
    } else if (S == "RSS") {
        cout << 1 << endl;
    } else if (S == "SRS") {
        cout << 1 << endl;
    } else if (S == "SSR") {
        cout << 1 << endl;
    } else if (S == "RRS") {
        cout << 2 << endl;
    } else if (S == "RSR") {
        cout << 1 << endl;
    } else if (S == "SRR") {
        cout << 2 << endl;
    } else if (S == "RRR") {
        cout << 3 << endl;
    } else {
        cout << "illegal input: " + S << endl;
        abort();
    }

    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SIZE 3010
const ll mod = 998244353;
ll n, s, a[SIZE], dp[SIZE], ans;

int main() {
	 cin >> n >> s;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n;i++)  {
		for (int j = s; j >= a[i]; --j) {
			dp[j] += dp[j - a[i]];
			dp[j] %= mod;
		}
		if (a[i] <= s) dp[a[i]] = (dp[a[i]] + i) % mod;
		ans = (ans + dp[s]) % mod;
		//for(int i=1;i<=s;i++) cout<<dp[i]<<" "; 
		//cout<<endl;
	}	
	cout << ans;
}

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

using namespace std;

string s;
int ans,n;

int main(){
	cin>>n;
	cin>>s;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    int c;
    cin>>c;
    int s=0;
    bool a[1005]={0,1};
    for(int i=2;i<=1000;i++)
        if(a[i]==0)
            for(int j=i*i;j<=1000;j*=i)
            a[j]=1;
        for(int i=c;i>=0;i--)
            if(a[i])
            {
                cout<<i<<endl;
                break;
            }
    return 0;
}


Measured memory_bytes: 256
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
import math
def get_koch_curve_points(curve_num, points):

    result = points
    for i in range(curve_num):
        next_list = []
        for j in range(len(result) - 1):
            next_list.append(result[j])
            next_list.extend(koch_curve(result[j], result[j + 1]))
        next_list.append(result[-1])
        result = next_list
        
    return result

def koch_curve(left_points, right_points):
    len_x = right_points[0] - left_points[0]
    len_y = right_points[1] - left_points[1]

    distance_x = len_x / 3
    distance_y = len_y / 3

    s = (left_points[0] + distance_x, left_points[1] + distance_y)
    t = (right_points[0] - distance_x, right_points[1] - distance_y)

    cos60 = math.cos(math.radians(60))
    sin60 = math.sin(math.radians(60))
    u = (s[0] + distance_x * cos60 - distance_y * sin60, s[1] + distance_x * sin60 + distance_y * cos60)
    return [s, u, t]

if __name__ == "__main__":

    curve_num = int(input())
    res = get_koch_curve_points(curve_num, [(0,0),(100,0)])
    print("\n".join([str(x) + " " + str(y) for x,y in res]))

Measured memory_bytes: 8580
package main

import (
	"fmt"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	
	ss := make([]int,m)
	cs := make([]string,m)
	
	for i := 0; i < m; i++ {
		fmt.Scan(&ss[i], &cs[i])
		ss[i]--
	}
	
	for i := 0; i <= 999; i++ {
		if n != len(fmt.Sprintf("%d", i)) {
			continue
		}
		
		str := fmt.Sprintf("%0"+fmt.Sprint(n)+"d",i)
		
		ok := true
		for j := 0; j < m; j++ {
			if string(str[ss[j]]) != cs[j] {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main()
{
	int a[4], e, f, sum = 0, tmp, i;
	scanf("%d%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &e, &f);
	sum +=( e > f ? e : f);
	int min = a[0];
	for (i = 0;i < 4;i++) {
		if (min > a[i])min = a[i];
	}
	sum += a[0] + a[1] + a[2] + a[3] - min;
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 600
#再帰
def gcd(a, b):
	if b==0:
		return a
	return gcd(b, a%b)
#ループ
def gcd(a,b):
  while b:
    a,b = b,a%b
  return abs(a)

def solve(x_list):
	ans=0
	for x in x_list:
		ans=gcd(ans, x)
	return ans

N, X = map(int, input().split())
x_list=list(abs(int(x)-X) for x in input().split())

print(solve(x_list))

Measured memory_bytes: 19952
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    fastio
    ll h;
    cin>>h;
    ll result=0,i=0;
    while(h)
    {
        result+=pow(2,i);
        i++;
        h/=2;
    }
    cout<<result<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

map<uint64_t, uint64_t> cache;

inline uint64_t int_floor(uint64_t x, uint64_t y) { return x / y; }
inline uint64_t int_ceil(uint64_t x, uint64_t y) {
  return int_floor(x, y) + (x % y == 0 ? 0 : 1);
}

uint64_t search(uint64_t N, uint64_t A, uint64_t B, uint64_t C, uint64_t D)
{
  if (cache.find(N) != cache.end()) {
    return cache[N];
  }

  if (N == 0) { return 0; }
  if (N == 1) { return D; }

  auto cost = [&](uint64_t k) {
    switch(k) {
    case 2: return A;
    case 3: return B;
    case 5: return C;
    default: return static_cast<uint64_t>(-1);
    }
  };

  cache[N] = 1e+19;
  if (N < cache[N] / D) {
    cache[N] = N * D;
  }

  for (uint64_t k : {2, 3, 5}) {
    uint64_t P = int_floor(N, k), Q = int_ceil(N, k);
    uint64_t s = N - (P * k), t = (Q * k) - N;

    cache[N] = min(cache[N], search(P, A, B, C, D) + cost(k) + s * D);
    cache[N] = min(cache[N], search(Q, A, B, C, D) + cost(k) + t * D);
  }

  return cache[N];
}

int main()
{
  uint64_t T;
  cin >> T;

  N_TIMES(t, T) {
    uint64_t N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    cache = map<uint64_t, uint64_t>();
    cout << search(N, A, B, C, D) << endl;
  }

  return 0;
}

Measured memory_bytes: 4428
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
ll A,B,M;
ll a[100010],b[100010];
int main(){
	cin>>A>>B>>M;
	rep(i,A)cin>>a[i];
	rep(i,B)cin>>b[i];
	ll ans=1e17;
	rep(i,M){
		ll x,y,c;
		cin>>x>>y>>c;
		x--,y--;
		chmin(ans,a[x]+b[y]-c);
	}
	sort(a,a+A);
	sort(b,b+B);
	chmin(ans,a[0]+b[0]);
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main(void){
  int n,l,i;
  char s[1024],*t;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    memset(s,0,sizeof(s));
    fgets(s,1024,stdin);
    while(t=strstr(s,"Hoshino"),t!=NULL){
      t[6]='a';
    }
    printf("%s",s);
  }
  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string q;
  cin >> q;
  int ans=0;
  rep(i,n){
    if(i>=k){
      if(q[i]==q[i-k]){
        q[i]='t';
        continue;
      }  
    }
    if(q[i]=='r') ans+=p;
    if(q[i]=='s') ans+=r;
    if(q[i]=='p') ans+=s;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512