akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf INT_MAX
#define mod 1000000009
using namespace std;

int main() {
	speed;
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	int ans = 0, a;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (v[i] > a)
			ans += v[i] - a;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
loop do
    n = gets.to_i
    break if n == 0
    pos = Array.new(n)
    pos[0] = [0,0]
    r = l = t = b = 0
    (n-1).times do |i|
        a = gets.split.map(&:to_i)
        pp = pos[a[0]]
        case a[1]
        when 0
            pos[i+1] = [pp[0]-1, pp[1]]
        when 1
            pos[i+1] = [pp[0], pp[1]-1]
        when 2
            pos[i+1] = [pp[0]+1, pp[1]]
        when 3
            pos[i+1] = [pp[0], pp[1]+1]
        end
        r = [r, pos[i+1][0]].max
        l = [l, pos[i+1][0]].min
        t = [t, pos[i+1][1]].max
        b = [b, pos[i+1][1]].min
    end
    puts "#{r-l+1} #{t-b+1}"
end

Measured memory_bytes: 6104
n = int(input())
b = list(map(int,input().split()))
a = [0] * n
a[0] = b[0]
a[n-1] = b[n-2]
sum = a[0] + a[n-1]
for i in range(1,n-1):
    a[i] = min(b[i-1],b[i])
    sum += a[i]
print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int main(void){
	int N, Z, W; cin >> N >> Z >> W;
	int a[2010];
	for(int i = 0; i < N; i++) cin >> a[i];

	if(N >= 2) cout << max(abs(a[N-1] - a[N-2]), abs(W - a[N-1])) << '\n';
	else if(N == 1) cout << abs(W - a[N-1]) << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int f[N], cur, s[N];

void pn() {puts("No");}
void py() {puts("Yes");}

void add(int x, int val) {
	if(!x) return;
	while(x < N) {
		s[x] += val;
		x += x & -x;
	}
}

int query(int x) {
	int ret = 0;
	while(x) {
		ret += s[x];
		x -= x & -x;
	}
	return ret;
}

void Add(int t) {
	while(t) {
		if(!f[t]) break;
		f[t]--;
		add(t, -1);
		t--;
	}
	f[t]++;
	add(t, 1);
}

int main() {
	int n, x;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if(f[0]) pn();
		else {
			//printf("%di\n", i);
			if(x >= N) {
				cur = 1;
				py();
			} else {
				//printf("%d %d\n", x, query(x));
				if(query(x) == x) {
					if(query(N-1) > x || cur) pn();
					else {
						py();
						Add(x);
					}
				} else {
					py();
					Add(x);
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 7008
#include <stdio.h> 
#include <string.h>
const int N=100+5;
void rotate(char*,int);

int main()
{
	char s1[N],s2[N];
	scanf("%s%s",s1,s2);
	int n=strlen(s1);
	int f=0;
	for(int i=1;i<=n;i++){
		if(strcmp(s1,s2)==0){
			f=1;	break;
		}
		rotate(s1,n);
	}
	if(f)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

void rotate(char *s,int n)
{
	char t=s[0];
	for(int i=1;i<n;i++)
		s[i-1]=s[i];
	s[n-1]=t;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int x[10000],y[10000],a,s,i=0,j,sum=0,z[10000]={};
	while(1){
		scanf("%d,%d",&s,&a);
		if(s==0) break;
		x[s-1]=a;
		y[s-1]=x[s-1];
		sum++;
	}
	sort(x,x+sum);
	int r=100;
	for(i=0;i<sum;i++){
		for(j=0;j<sum;j++){
		if(x[i]<x[j]){
			if(r!=x[j]){
			z[i]++;
			r=x[j];
		}
		}} r=100;}
int d;
				while(scanf("%d",&d)!=EOF){
					for(i=0;i<sum;i++){
						if(x[i]==y[d-1]){
					printf("%d\n",z[i]+1);
					goto yu;
						}}yu:;
				}
				return 0;
}

Measured memory_bytes: 1100
w,h,X,Y,C,t,b,d[9][9],q[9][9],a[]={-1,0,1,0};Z(x,y){int i=0,s=1;if(q[y][x])return 0;q[y][x]=1;if(d[y][x])return y==Y&&x==X;for(;i<4;)s+=Z(x+a[i%4],y+a[i++]);return s;}B(x,y,c){int i=0;if(!(c||x-X||y-Y))return 1;memset(q,0,324);if(d[y][x]||Z(x,y)!=c+(x-X||y-Y))return 0;if(b++>120000)return 2;for(d[y][x]=1;i<4;)if(t=B(x+a[i%4],y+a[i++],c-1))return t;return d[y][x]=0;}main(i,j){for(;C=b=j=0,memset(d,-1,324),scanf("%d%d\n",&w,&h),h;puts(C<4||B(X,Y,C)-1?"No":"Yes"))for(;j++<h;)for(i=0;i++<w;)scanf("%d",&t),(d[j][i]=t)||(++C,X=i,Y=j);exit(0);}

Measured memory_bytes: 388
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
#include <limits.h>

#define ll long long

using namespace std;

int main(){

    
    int n;
    cin >> n;
    vector<int> d;

    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        d.push_back(tmp);
    }

    sort(d.begin(),d.end());

    int d1 = d[n / 2 - 1];
    int d2 = d[n / 2];

    cout << d2 - d1 << endl;

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
//void dfs(unordered_map<int,unordered_set<int>>&m,int st)
 int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    long long int t;
    int mod=1000000007;

    int n;
    cin>>n;
    long long int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long int pa[n];
    long long int c=0;
    for(int i=0;i<n;i++)
    {
        c+=a[i];
        pa[i]=c;
    }
    long long int ans=0;
    for(int i=0;i<n;i++)
    {
        long long int ff=(c-pa[i])%mod;
        long long int ss=(a[i]*ff)%mod;
        ans=(ans+ss)%mod;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 6724
#include <iostream>
using namespace std;
int main()
{
	char c;
	int v;

	while( true )
	{
		v = 0;

		while(true)
		{
			cin.get(c);
			if( !isdigit(c) )
				break;

			v += c - '0';
		}

		if( 0 == v)
			break;

		cout << v << "\n";	
	}

	return 0;
}

Measured memory_bytes: 1128
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,ans=0;
map<int,bool> visited;
map<int,bool>::iterator it;
inline void get(int x)
{
	if (x==1)  return;
	int m=n;
	while (m%x==0) m/=x;
	if (m%x==1 && !visited[x]) visited[x]=1;
}
signed main()
{
	cin>>n;
	for (int i=1;i*i<=n;i++) if (n%i==0)  get(i),get(n/i);
	for (int i=1;i*i<=n-1;i++) if ((n-1)%i==0)  get(i),get((n-1)/i);
	for (it=visited.begin();it!=visited.end();it++)  ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
  long n = 0, i, min = 1000000, max = -1000000, sum = 0;
  long a[10000];

  scanf("%ld", &n);
  for( i = 0; i < n; i++)
    {
      scanf("%ld", &a[i]);
      if(a[i] < min)min = a[i];
      if(a[i] > max)max = a[i];
      sum += a[i];
    }

  printf("%ld %ld %ld\n", min, max, sum);
  return 0;
}



Measured memory_bytes: 2112
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

int main() {
	/*string st; cin >> st;
	if (st.size()>=4&&st.substr(0,4) == "YAKI")cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;*/

	int N, M, K; cin >> N >> M >> K;
	bool ok = false;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j < M; ++j) {
			int a = i*M + j*N - 2 * i*j;
			if (a == K)ok = true;
		}
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdio.h>
#include<math.h>
#define F(i,n) for(int i=0; i<n; i++)

int compare(long *a,long *b){
    if(*a>*b) return 1;
    else if(*a<*b) return -1;
    else return 0;
}
long asum(long *a,int n){
    long sum=0;
    F(i,n){
        sum+=a[i];
    }
    return sum;
}

int main(){
    int n;
    scanf("%d",&n);
    long tmp;
    int p_sum=0,m_sum=0;
    int p_count=0,m_count=0,z_count=0;
    long plus[n];
    long minus[n];
    F(i,n){
        scanf("%ld",&tmp);
        tmp -= i+1;
        if(0<tmp){
            plus[p_count] = tmp;
            p_count++;
        } 
        else if(0>tmp){
            minus[m_count] = -tmp;
            m_count++;
        }
        else z_count++;
    }
    long sum=0;
    if(p_count>m_count+z_count){
        int m=ceil(((double)(p_count-(m_count+z_count)))/2.0);
        qsort(plus,p_count,sizeof(long),compare);
        sum+=(p_count-(z_count+m_count))*plus[0];
        if(m>1){
            for(int j=1;j<m;j++){
                sum+=(p_count-j*2-(z_count+m_count))*(plus[j]-plus[j-1]);
            }
        }
        printf("%ld\n",asum(plus,p_count)+asum(minus,m_count)-sum);
    }
    else if(m_count>z_count+p_count){
        int m=ceil(((double)(m_count-(p_count+z_count)))/2.0);
        qsort(minus,m_count,sizeof(long),compare);
        sum+=(m_count-(z_count+p_count))*minus[0];
        if(m>1){
            for(int j=1;j<m;j++){
                sum+=(m_count-j*2-(z_count+p_count))*(minus[j]-minus[j-1]);
            }
        }
        printf("%ld\n",asum(plus,p_count)+asum(minus,m_count)-sum);
    }
    else printf("%ld\n",asum(plus,p_count)+asum(minus,m_count));
    return 0;
}

Measured memory_bytes: 4092
#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 = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    if('A' <= S[0] && S[0] <= 'Z') cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;

int main() {
	vector<int> A = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int N;
	cin >> N;
	cout << A[N - 1] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 100000
#define BLACK 0
#define WHITE 1
#define N 101

int n, a[N][N];
int prim(void);
int main()
{
  int i, j;
  int total;

  scanf("%d", &n);
  
  for(i = 1; i <= n; i++)
    {
      for(j = 1; j <= n; j++)
	{
	  scanf("%d", &a[i][j]);
	  if(a[i][j] == -1) a[i][j] = INF;
	}
    }
  total = prim();
  printf("%d\n", total);
  
  return 0;
}

int prim(void)
{
  int u, v;
  int i;
  int mincost, d[N], pi[N], ans = 0, color[N];
  
  for(u = 1; u <= n; u++)
    {
      d[u] = INF;
      pi[u] = -1;
      color[u] = WHITE;
    }
  d[1] = 0;

  while( 1 )
    {
      mincost = INF;
      for(i = 1; i <= n; i++)
	{
	  if(color[i] != BLACK && d[i] < mincost)
	    {
	      mincost = d[i];
	      u = i;
	    }
	}
      if(mincost == INF) break;

      color[u] = BLACK;

      for(v = 1; v <= n; v++)
	{
	  if(color[v] != BLACK && a[u][v] < d[v])
	    {
	      pi[v] = u;
	      d[v]=  a[u][v];
	    }
	}
      color[v] = BLACK;
    }

  for(i = 1; i <= n; i++)
    {
      if(pi[i] != -1) ans+=a[i][pi[i]];
    }

  return ans;
}

Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;

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

	int a,b;
	cin >> a >> b;
    
    cout << (b-1+a-2)/(a-1);
	return 0;
}

Measured memory_bytes: 256
N,A,B,C=map(int,input().split())

l=[int(input()) for i in range(N)]

INF=3000

def mp(co,a,b,c):
    if co==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+l[co],b,c)+10
    ret2=mp(co+1,a,b+l[co],c)+10
    ret3=mp(co+1,a,b,c+l[co])+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,x,t;
    cin>>n>>x>>t;
    ll p=n/x;
    if(n%x==0)
    {
        cout<<p*t<<endl;
    }
    else
    {
        cout<<(p+1)*(t)<<endl;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
vector<int>par;
vector<int>num;
void init(int N) {
  for (int i = 0; i <= N; i ++) {
    par[i] = i;
    num[i] = 1;
  }
}
int root(int v) {
  if (par[v] == v) return v;
  return par[v] = root(par[v]);
}
bool same(int a, int b) {
  return root(a) == root(b);
}
void unit(int a, int b) {
  a = root(a);
  b = root(b);
  if (num[a] < num[b]) swap(a, b);
  par[b] = a;
  num[a] += num[b];
}
int group_Size(int v) {
  v = root(v);
  return num[v];
}
int main () {
  int N, M, K;
  cin >> N >> M >> K;
  par.resize(N + 1);
  num.resize(N + 1);
  vector<vector<int>>fri(N + 1);
  vector<vector<int>>blo(N + 1);
  init(N);
  for (int i = 0; i < M; i ++) {
    int a, b;
    cin >> a >> b;
    fri[a].push_back(b);
    fri[b].push_back(a);
    if (!same(a, b)) {
      //cout << 'u' << endl;
      unit(a, b);
    }
  }
  for (int i = 0; i < K; i ++) {
    int a, b;
    cin >> a >> b;
    blo[a].push_back(b);
    blo[b].push_back(a);
  }
  for (int i = 1; i <= N; i ++) {
    //cout << group_Size(i) << endl;
    int ans = group_Size(i) - (int)fri[i].size() - 1;
    for (int j = 0; j < (int)blo[i].size(); j ++) {
      if (same(i, blo[i][j])) ans --;
    }
    cout << ans;
    if (i < N) cout << ' ';
  }
  cout << endl;
}


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

typedef unsigned long long int ulint;
typedef long long int lint;

int main(){
  ulint N, K, S;
  cin >> N >> K >> S;

  //for (int i = 0; i < N; ++i) {
  //  if (i < K + 1) {
  //    cout << 1 + i * S << " ";
  //  } else {
  //    cout << 1 + K * S + (i - K) * (S - 1) << " ";
  //  }
  //}
  ulint v = S - 1;
  if (S == 1) {
    v = S + 1;
  }
  for (int i = 0; i < N; ++i) {
    if (i < K) {
      cout << S << " ";
    } else {
      cout << v << " ";
    }
  }

  cout << endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>

int main() {
    std::vector<int> a,b;
    int n, tmp = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> tmp;
        if ((n + i) % 2 != 0) {
            a.push_back(tmp);
        } else {
            b.push_back(tmp);
        }
    }
    for(int i= a.size()-1;i>=0;i--){
        std::cout << a[i] << " ";
    }
    for (int i = 0; i < b.size(); i++) {
        std::cout << b[i] << " ";
    }
    std::cout << "\n";
}

Measured memory_bytes: 3188
N = int(input())
S = [list(input()) for _ in range(N)]

def generate(A, B):
    T = [[""] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            ni = (i + A) % N
            nj = (j + B) % N
            T[ni][nj] = S[i][j]
    flag = True
    for i in range(N):
        for j in range(N):
            flag &= T[i][j] == T[j][i]
    return flag

ans = 0

for A in range(N):
    ans += N * generate(A, 0)

print(ans)

Measured memory_bytes: 87644
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{

    ll n,w;
    cin>>n>>w;
    vector<ll> a(n);
    vector<ll> b(n);
    for(ll i=0;i<n;i++)
    {
        cin>>b[i];
        cin>>a[i];
    }
    vector<vector<ll>> dp(w+1,vector<ll>(n+1,0));
    for(ll i=0;i<=w;i++)
    {
       for(ll j=0;j<=n;j++)
       {
         if(j==0 || i==0)
            {dp[i][j]=0;continue;}
         

         dp[i][j]=max(dp[i][j],dp[i][j-1]);
         if(i-b[j-1]>=0)
            dp[i][j]=max(dp[i-b[j-1]][j-1]+a[j-1],dp[i][j]);
       }
    }

    cout<<dp[w][n];
    
}

Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    string s;
    int a[26]={};
    while(getline(cin,s)){
        for(int i=0;i<s.size();++i){
            if('A'<=s[i]&&s[i]<='Z'){
             ++a[s[i]-'A'];
            }
            else if('a'<=s[i]&&s[i]<='z'){
                ++a[s[i]-'a'];
            }
        }
    }
    for(int i=0;i<26;++i){
        cout<<(char)(i+'a')<<" : "<<a[i]<<endl;
    }
}



Measured memory_bytes: 3152
#include <stdio.h>
#include <string.h>
#define N 1001

int main(void){
        char T[N],P[N];
        int i,j;
        scanf("%s",T);
        scanf("%s",P);

        for(i=0;i<(int)strlen(T)-(int)strlen(P)+1;i++){
                for(j=0;j<strlen(P);j++){
                        if(T[i+j]!=P[j]) break;
                }
                if(j==strlen(P)) printf("%d\n",i);
        }
        return 0;
}

Measured memory_bytes: 540
H,n = map(int,input().split())
ab = []
mb = 0 #max of b
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
    mb = max(mb,b)
inf = 10**9+7

dp = [inf]*(H+mb+1) #dp[h]は敵のhpをちょうどhだけ減らすのに必要な最小コスト
dp[0] = 0
for h in range(H+mb+1):
    for a,b in ab:#dp[h]を更新するときに最小となる魔法a,bを選ぶ
        if h >= a:
            dp[h] = min(dp[h-a]+b,dp[h])
        else:
            pass
ans = inf
for h in range(H,H+mb+1):
    ans = min(dp[h],ans)
print(ans)


Measured memory_bytes: 44124
#include<bits/stdc++.h>
using namespace std;
 int fun (int i, vector<int>&a, vector<int>&dp)
{
    
    if(dp[i]!=-1)
        return dp[i];
    else
    {
        dp[i]=min(fun(i-1,a,dp)+abs(a[i-1]-a[i]), fun(i-2,a,dp)+abs(a[i]-a[i-2]));
        return dp[i];
    }

}

int main()
{
    #ifndef ONLINE_JUDGE 
    freopen ("input1.txt", "r", stdin); 
   freopen ("output1.txt", "w", stdout); 
    #endif
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

   int n;
   cin>>n;
   vector<int> dp(n+1,-1),a(n+1,0);
   for(int i=0;i<n;i++)
    cin>>a[i+1];
   dp[0]=100005;
   dp[1]=0;
 int ans=fun(n,a,dp);
 cout<<ans<<"\n";
    return 0; 

} 

  
        
    

    

    

        

    

  
        
    

    

    

        

    

Measured memory_bytes: 7116
#include <iostream>
using namespace std;
int main(void){
  long long L,R;
  cin >> L >> R;

  if(R - L >= 2019)
    cout << 0 << endl;
  else{
    long long ans = 2019;
    for(long long i=L;i<R;i++){
      for(long long j=i+1;j<=R;j++){
        if((i * j) % 2019 < ans)
          ans = (i * j) % 2019;
      }
    }

    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;

int main(void) {
	int H,W;
	cin >> H >> W;
	vector< vector<int> > res(H, vector<int>(W,-1));
	char c;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> c;
			if (c == 'c') {
				for (int k = 0; (j+k) < W; ++k) {
					res[i][j+k] = k;
				}
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << res[i][j];
			if (j < W-1) {
				cout << " ";
			}
		}
		cout << endl;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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 pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

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

int main(){

  string s;cin>>s;
  bool e=false;
  rep(i,0,s.size()-1){
    if(s[i]=='A'&&s[i+1]=='C')e=true;
  }

  if(e)out("Yes");
  else out("No");

  return 0;
}


Measured memory_bytes: 256
import java.lang.StringBuilder
import java.util.*
import kotlin.collections.ArrayList

val sc = Scanner(System.`in`)
fun nextIntArray() = sc.nextLine().split(" ").map(String::toInt).toTypedArray()

const val INF = 10000000




fun main(args: Array<String>) {

    val N = sc.nextLine().toInt()
    val a = nextIntArray()
    val map = Array(N+1){ArrayList<Int>()}
    val dp = IntArray(N){INF}
    var cnt = 0
    val ans = IntArray(N){0}

    for(i in 0..N-2){
        val u = sc.nextInt()
        val v = sc.nextInt()
        map[u].add(v)
        map[v].add(u)
    }

    val back_idx = IntArray(N+1){-1}
    val back_val = IntArray(N+1){-1}

    val stack = LinkedList<Int>()
    stack.push(1)
    while(stack.isNotEmpty()){

        var i = stack.pop()

        if(i < 0){
            i = -i
            dp[back_idx[i]] = back_val[i]
            if(back_val[i] == INF) cnt--
            continue
        }

        val s = dp.binarySearch(a[i-1], 0, cnt)
        val idx = if(s < 0) -s-1 else s

        val pre = dp[idx]
        if(pre == INF) cnt++
        dp[idx] = a[i-1]
        ans[i-1] = cnt

        stack.push(-i)
        back_idx[i] = idx
        back_val[i] = pre

        for(j in map[i]){
            if(ans[j-1] == 0) {
                stack.push(j)
            }
        }
    }

    val sb = StringBuilder()
    for(t in ans) sb.appendln(t)
    println(sb.toString())
}

Measured memory_bytes: 112732
import sys
from collections import defaultdict
input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rank = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x_root = self.Find_Root(x)
        y_root = self.Find_Root(y)

        if(x_root == y_root):
            return
        # 違う木に属していた場合rankを見てくっつける方を決める
        if self.rank[x_root] >= self.rank[y_root]:
            self.rank[x_root] += self.rank[y_root]
            self.root[y_root] = x_root
        else:
            self.rank[y_root] += self.rank[x_root]
            self.root[x_root] = y_root

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

n, k, l = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(k)]
rs = [list(map(int, input().split())) for _ in range(l)]

uf1 = UnionFind(n)
uf2 = UnionFind(n)

for i in range(k):
    uf1.Unite(pq[i][0], pq[i][1])

for i in range(l):
    uf2.Unite(rs[i][0], rs[i][1])

pairs = []
d = defaultdict(int)

for i in range(1, n+1):
    name = "{} {}".format(uf1.Find_Root(i), uf2.Find_Root(i))
    pairs.append(name)
    d[name] += 1

ans = []
for i in range(n):
    ans.append(d[pairs[i]])

print(*ans)




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

int INF = 1e9;

vector<int>g[200005];//edgeの配列でmax_vに対応するindexは各頂点のindex　それぞれのg[v]に対して複数のedgeが入っている
ll d[200005];//距離
int n, m;
vector<int>ans;
void bfs(int u){
    queue<int>que;
    rep(i, n) ans[i] = INF;
    ans[0] = 0;
    que.push(0);
    while(!que.empty()){
        int u = que.front();
        que.pop();
        for(int v : g[u]){
            if(ans[v] == INF){
                ans[v] = u+1;
                que.push(v);
            }
        }
    }
}


int main(void){
    cin>>n>>m;
    ans.resize(n);
    rep(i, m){
        int a, b;
        cin>>a>>b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bfs(0);
    cout<<"Yes"<<endl;
    rep(i, n-1){
        cout<<ans[i+1]<<endl;
    }
    return 0;
}

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

#define int long long

const int INF = LLONG_MAX;

int n,a,b;
int ans=INF;

signed main()
{
	cin>>n>>a>>b;
	if(a>b)
		swap(a,b);
	if((b-a)%2==0)
		ans = min(ans,(b-a)/2);
	ans = min(ans,max(a-1,b-1));
	ans = min(ans,max(n-a,n-b));
	ans = min(ans,a+(b-a-1)/2);
	ans = min(ans,n-b+1+(b-a-1)/2);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2005;
int N, K, Q, A[MAX];

int main(){
	scanf("%d %d %d", &N, &K, &Q);
	for(int i = 1; i <= N; i++){
		scanf("%d", A + i);
	}
	int ans = 1e9;
	for(int i = 1; i <= N; i++){
		vector<int> vt;
		int bef = 0;
		for(int j = 1; j <= N; j++){
			if(A[j] < A[i]){
				if(bef == 0)	continue;
				vector<int> tvt;
				for(int k = bef; k < j; k++)
					tvt.push_back(A[k]);
				sort(tvt.begin(), tvt.end());
				for(int k = bef; k + K - 1 < j; k++)
					vt.push_back(tvt[k - bef]);
				bef = 0;
			}
			else if(bef == 0)	bef = j;
		}
		if(bef != 0){
			vector<int> tvt;
			for(int k = bef; k <= N; k++)
				tvt.push_back(A[k]);
			sort(tvt.begin(), tvt.end());
			for(int k = bef; k + K - 1 <= N; k++)
				vt.push_back(tvt[k - bef]);
		}
		sort(vt.begin(), vt.end());
		if(vt.size() < Q)	continue;
		else{
			ans = min(ans, vt[Q - 1] - A[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

a=['#'*(w+2)]
for i in range(h):
    b='#'+input()+'#'
    a.append(b)
a.append('#'*(w+2))
#print(a)

from collections import Counter

n=[(1,1)]
route={(1,1):0}
p=[[1,0],[0,1],[-1,0],[0,-1]]
count=1
while route.get((h,w),0)==0 and count != 10000:
    n2=[]
    #print(n,route)
    for i in n:
        for j in p:
            np=(i[0]+j[0],i[1]+j[1])
            if a[np[0]][np[1]]=='.' and route.get(np,-1)==-1:
                n2.append(np)
                if route.get(np,1000)>count:
                    route[np]=count
    n=n2
    #print(n,route)
    count+=1

    
a2=[]
for i in a:
    for j in range(len(i)):
        a2.append(i[j])
con=Counter(a2)


if count==10000:
    print('-1')
else:
    print(con['.']-route[(h,w)]-1)

Measured memory_bytes: 3700
def solve(N,M,S,C) -> int:
    for n in range(10**N):
        length = len(str(n))
        if(length == N):
            n = str(n)
            for s,c in zip(S,C):
                if(int(n[s-1]) != c):
                    break
            else:
                return n
    return -1


def main():
    N,M = map(int,input().split())
    S = []
    C = []
    for _ in range(M):
        s,c = map(int,input().split())
        S.append(s)
        C.append(c)
    # solve()
    print(solve(N,M,S,C))
if __name__ == "__main__":
    main()



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

int main() {
  int N;
  cin >>N;
  int a[N];
  vector<int> b(N+1);
	for(int i=0;i<N-1;i++){
    cin>>a[i];
  	b[a[i]]++;
	}
  	for(int i=0;i<N;i++){
      cout<<b[i+1]<<endl;
    }
}

Measured memory_bytes: 4844
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;


signed main(){

	string s;
	cin >> s;
	int N = s.length();
	int zero = 0;
	for (int i = 0; i < N; i++)
		if (s[i] == '0') zero++;

	int one = N - zero;

	cout << min(zero, one) * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
def doc_string():
	"""
	I can fly.
	"""

while True:
	num = int(raw_input())
	if num == 0:
		break
	
	list = []
	for i in xrange(num):
		list.append(int(raw_input()))
	
	list.sort()
	ans = []
	for i in xrange(num):
		ans.append(sum(list[:i]))
		
	print sum(ans)

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

using namespace std;
#define int long long 
#define N 666666
#define inf 9999999999999999
int dis[66][2666];
int n,m,s;
int C[N],D[N];
int cnt;
int head[N*10];
struct edge{
	int v,a,b,next;
}e[9*N];
void addegde(int u,int v,int a,int b){
	e[++cnt].v=v;
	e[cnt].a=a;
	e[cnt].b=b;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void init(){
	for(int i=0;i<=n;i++)
		for(int j=0;j<=2500;j++) 
			dis[i][j]=inf;
}
void dij(){
	queue<pair<int,int> > q;
	q.push(make_pair(1,s));
	dis[1][s]=0;
	while(!q.empty()){
		int u=q.front().first;
		int w=q.front().second;
		q.pop();
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].v;
			int a=e[i].a;
			int b=e[i].b;
			if(w-a>=0&&dis[v][w-a]>dis[u][w]+b){
				dis[v][w-a]=dis[u][w]+b;
				q.push(make_pair(v,w-a));
				
			}
		}
		if(dis[u][w]+D[u]<dis[u][min(2500*1ll,w+C[u])]){
			dis[u][min(2500*1ll,w+C[u])]=dis[u][w]+D[u];
			q.push(make_pair(u,min(2500*1ll,w+C[u])));
		}
	}
}
signed main(){
	cin>>n>>m>>s;
	s=min(s,2500*1ll);
	init();
	for(int i=1;i<=m;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		addegde(a,b,c,d);
		addegde(b,a,c,d);
	}
	for(int i=1;i<=n;i++) cin>>C[i]>>D[i];
	
	dij();
	//cout<<"==";
	for(int i=2;i<=n;i++){
		int res=inf;
		for(int j=0;j<2500;j++) res=min(res,dis[i][j]);
		cout<<res<<'\n';
	}
	return 0;
}

Measured memory_bytes: 5200
#include<stdio.h>
#include<string.h>

int main(void){
	int l;
	char s[131072];
	scanf("%s",s);
	l = strlen(s);
	if(s[0] == s[l-1]){l++;}
	if(l%2){printf("First\n");}else{printf("Second\n");}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> v={0,1,0,2,0,2,0,0,2,0,2,0};
  int a,b;
  cin >> a >> b;
  if(v[a-1]==v[b-1]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // AGC027A - Candy Distribution Again

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(); // 2 <= n <= 100
        int x = sc.nextInt(); // 1 <= x <= 10^9
        int[] a = new int[n]; // 1 <= a <= 10^9

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        //Arrays.sort(s, Collections.reverseOrder());
        Arrays.sort(a);

        int count = 0;
        for (int j = 0; j < n; j++) {
            if (x <= 0) break;
            if (x >= a[j]) {
                ++count;
            }
            x -= a[j];
        }
        if (count > 0 && x > 0) --count;

        System.out.println(count);
    }

}

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

using namespace std;

int N,K;
int G[2005][2005];
int m[2005][2005],M[2005][2005];

int mat(int x1,int y1,int x2,int y2){

  int p,q,r;

  if(x2<0||y2<0) return 0;
  if((x1>2*K-1)||(y1>2*K-1)) return 0;
  if(x1<0) x1=0; 
  if(y1<0) y1=0;
  if(x2>2*K-1) x2=2*K-1; 
  if(y2>2*K-1) y2=2*K-1;

  if(x1-1>=0){
    p=M[x1-1][y2];
  }
  else{
    p=0;
  }

  if(y1-1>=0){
    q=M[x2][y1-1];
  }
  else{
    q=0;
  }

  if((x1-1>=0)&&(y1-1>=0)){
    r=M[x1-1][y1-1];
  }else{
    r=0;
  }
  
  return M[x2][y2]-q-p+r;
  
}

int add(int i,int j){
  int a1,a2,a3;
  a1=mat(i-K,j+K,i-1,j+2*K-1);
  a2=mat(i-K,j-K,i-1,j-1);
  a3=mat(i+K,j-K,i+2*K-1,j-1);
  return a1+a2+a3;
}

int cnt(int i,int j){
  int c0,c1,c2,c3,c4;

  c0=mat(i,j,i+K-1,j+K-1);
  c1=mat(i-K,j+K,i-1,j+2*K-1);
  c2=mat(i-K,j-K,i-1,j-1);
  c3=mat(i+K,j+K,i+2*K-1,j+2*K-1);
  c4=mat(i+K,j-K,i+2*K-1,j-1);

  return c0+c1+c2+c3+c4+add(i-K,j-K);
}

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

for(int i=0; i<N; i++){
  int x,y;  char c;
  scanf("%d %d %c",&x,&y,&c);
  if(c=='W'){
    y=y+K; 
  }
  x=x%(2*K); y=y%(2*K); 
  G[x][y]++;
}

for(int j=0; j<2*K; j++){
  if(G[0][j]) m[0][j]=G[0][j];
}

for(int j=0; j<2*K; j++){
for(int i=1; i<2*K; i++){
  m[i][j]=m[i-1][j]+G[i][j];
}
}

for(int i=0; i<2*K; i++){
  M[i][0]=m[i][0];
}

for(int i=0; i<2*K; i++){
for(int j=1; j<2*K; j++){
  M[i][j]=M[i][j-1]+m[i][j];
}
}

int ans=0;

for(int j=0; j<2*K; j++){
for(int i=0; i<2*K; i++){
  ans=max(ans,cnt(i,j));
}
}

cout<<ans<<endl;

}

Measured memory_bytes: 47360
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x, a, b = LI()
    if b <= a:
        print("delicious")
    elif b <= a + x:
        print("safe")
    else:
        print("dangerous")

    return

#B
def B():
    n = II()
    a = IR(n)
    check = [False] * (n + 1)
    check[1] = True
    now = a[0]
    for i in range(1,n+1):
        if check[now]:
            break
        if now == 2:
            print(i)
            return
        check[now] = True
        now = a[now - 1]
    print(-1)
    return

#C
def C():
    return

#D
def D():
    def find(x):
        if x == par[x]:
            return x
        par[x] = find(par[x])
        return par[x]
    def unite(x, y):
        x = find(x)
        y = find(y)
        if x == y: return False
        if x < y: x, y = y, x
        par[y] = x
        return True
    n = II()
    par = [i for i in range(n)]
    xy = LIR(n)
    for i in range(n):
        xy[i].append(i)
    xy.sort(key=lambda x: x[0])
    edg = [None] * (2 * n - 2)
    a = 0
    for i in range(n-1):
        edg[i] = [xy[i + 1][0] - xy[i][0], xy[i][2], xy[i + 1][2]]
    xy.sort(key=lambda x: x[1])
    for i in range(n-1):
        edg[n + i - 1] = [xy[i + 1][1] - xy[i][1], xy[i][2], xy[i + 1][2]]
    ans = 0
    a = 0
    edg.sort(key=lambda x: x[0])
    for i in range(2 * n - 2):
        value, p0, p1 = edg[i]
        if a == n - 1:
            break
        if unite(p0, p1):
            a += 1
            ans += value
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 124708
h, w, k = list(map(int, input().split()))

choco = [list(map(int, list(input()))) for i in range(h)]

choco_cumsum = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    choco_cumsum[i][0] = choco[i][0]
    for j in range(1, w):
        choco_cumsum[i][j] = choco_cumsum[i][j-1] + choco[i][j]

ans = h + w + 1

for h_cut in range(2**(h-1)):
    # 上位ビットが上側。1が切る、0が切らない
    num_cut_init = bin(h_cut).count("1") # 立っているビットの個数
    num_cut = num_cut_init
    w_last_cut_pos = -1
    valid = True

    count_white = [0] * (num_cut_init + 1)
    temp_dict = {}
    idx = 0
    temp_dict[0] = idx
    for i in range(1, h):
        # print('idx', 2 ** (-i+h-1) )
        if h_cut & (2 ** (-i+h-1) ):
            idx += 1
        # idx += h_cut & (2 ** (h-1) - i)
        temp_dict[i] = idx
    # print(temp_dict)

    iw = 0
    while iw < w:

        for ih in range(h):
            count_white[temp_dict[ih]] += choco[ih][iw]
        # print(iw, count_white)

        condition = max(count_white) > k
        if condition:
            if w_last_cut_pos < iw-1:
                # もしそこで切ってkを超えるなら、その手前で切る
                num_cut += 1
                w_last_cut_pos = iw - 1
                count_white = [0] * (num_cut_init + 1)
                # print('iw: ', iw, 'last: ', w_last_cut_pos)

            else:
                # 1つしか動かしてないのに、Kマスを超えてしまった場合は、この横の切り方では達成不可能なので次のh_cutに
                valid = False
                break
        
        else:
            iw += 1
    
    if valid:
        ans = min(ans, num_cut)
    # print(num_cut)

print(ans)


Measured memory_bytes: 9436
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int main() {
    int N;
    cin >> N;
    vector<i64> H(N);
    int ans = 0;
    for(auto &x : H) cin >> x;
    int tmp = 0;
    for(int i = 0; i < N - 1; i++) {
        if(H[i] >= H[i + 1]) {
            tmp++;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }
    }
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int const MAXN = 1e5 + 5;
char T[MAXN];
int cs[MAXN], cr[MAXN], cp[MAXN];

signed main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  cin >> (T + 1);
  int ans = 0;
  for (RI i = 1; i <= n; ++i) {
    if (T[i] == 'r') {
      if (i <= k) ans += p, cr[i] = 1;
      else if (!cr[i - k]) ans += p, cr[i] = 1;
    }
    if (T[i] == 's') {
      if (i <= k) ans += r, cs[i] = 1;
      else if (!cs[i - k]) ans += r, cs[i] = 1;
    }
    if (T[i] == 'p') {
      if (i <= k) ans += s, cp[i] = 1;
      else if (!cp[i - k]) ans += s, cp[i] = 1;
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int Combination(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int n,k;
  int rr,ss,pp = 0;
  map<char,int> m;
  m['r']=0;
  m['s']=0;
  m['p']=0;
  int r,s,p;
  cin>>n>>k;
  cin>>r>>s>>p;
  vector<char> l,a;
  string st;
  cin>>st;
  for(int i=0;i<st.size();i++){
    char j = st[i];
    if(j=='r'){
      l.pb(j);
      a.pb('p');
      m['p']++;
    }
    else if(j=='s'){
      l.pb(j);
      a.pb('r');
      m['r']++;
    }
    else if(j=='p'){
      l.pb(j);
      a.pb('s');
      m['s']++;
    }
  }

  for(int i=k;i<n;i++){
    char j=a[i];
    if(a[i-k]==j){
      if(i+k<n){
        if(a[i+k]==j){
        a[i]='x';
        }
      }
      m[j]--;
    }
  }
  int result = m['r']*r+m['s']*s+m['p']*p;
  cout<<result;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffor(i,a,b) for(ll i=a;i<=b;i++)
#define rfor(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto start = high_resolution_clock::now()
#define etime auto stop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; while(testcases--)
#define ptime auto z1z = duration_cast<microseconds>(stop-start); cout<<"Time elapsed : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e6 + 6;
const ll maxN = 1e7 + 5;
const ll MAX_SIZE = 2e6 + 6;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

ll sieve[maxN] = {};

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input2.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	FIO
	ll n; cin >> n;
	for (ll i = 1; i <= n; i++) {
		for (ll j = i; j <= n; j += i) {
			sieve[j]++;
		}
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		ans += (i * sieve[i]);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 81768
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    if N < 5:
        print(N - 1)
        return
    i = 2
    ret = 2
    while i * i <= N:
        tmp = N
        while tmp % i == 0:
            tmp //= i
        tmp %= i
        if tmp == 1:
            ret += 1

        if N % i == 1 and i * i + 1 != N:
            ret += 1
        i += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63492
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    H,W,K = map(int, input().split())
    C = []
    for _ in range(H):
        S = input()
        cc = []
        for s in S:
            cc.append(1 if s == "#" else 0)
        C.append(cc)
    ans = 0
    for h in range(1<<H):
        for w in range(1<<W):
            tmp = 0
            for kh in range(H):
                if h>>kh & 1:
                    for kw in range(W):
                        if w>>kw & 1:
                            tmp += C[kh][kw]
            if tmp == K:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10488
/**Bismillahir Rahmanir Rahim**/


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

#define pb push_back
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define clr(v) v.clear()
vector<ll>v;
pair<ll,ll>p;
map<ll,ll>mp;
set<ll>st;
deque<ll>dq;
priority_queue<ll>pq;
#define f(i,b) for(i=0;i<b;i++)
#define f1(i,b) for(i=1;i<=b;i++)
#define fr(i,b)for(i=b-1;i>=0;i--)
ll mn=INT_MAX,mx=INT_MIN;
ll n,m,tc,i,j,tmp,sum,cn,ans,res,pos,flag,l,x,k,dif;

string s,str;


ll a[200007],b[200007];
int main()
{


   ll d,a,b,c;

cin>>a>>b>>c>>d;
if(abs(c-a)<=d)
    cout<<"Yes";
else
{
    ll dif=abs(a-b);
    ll dif1=abs(b-c);
    if(dif>d||dif1>d)
        cout<<"No";
    else cout<<"Yes";
}
return 0;
}





Measured memory_bytes: 3604
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<numeric>
#include<string>

int main() {
  int64_t N, K; std::cin >> N >> K;
  int64_t ans = N%K;
  if(ans+ans > K) ans = K - ans;
  std::cout << ans << std::endl;
  return 0;
}


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


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

    long ans = 0;
    // When N = a*b + r with 0 <= a <= N, reminder is
    // 0, 1, .., b-1, 0, 1, .., r for fixed b 
    for( int b = K+1; b <= N; ++b ){
            ans += N/b * (b-K) + max( 0, (N % b) - K + 1 );
    }

    // Subtracting a == 0 case
    if( K == 0 ) ans -= N - K;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc064A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int r = int.Parse(str[0]);
            int g = int.Parse(str[1]);
            int b = int.Parse(str[2]);
            if ((r * 100 + g * 10 + b) % 4 == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

int main() {
  int n;
  
  while(cin >> n && n) {
    string s;
    cin >> s;
    
    for(int i=0; i<n; i++) {
      int const N = s.size();
      int cnt = 1;
      string ns;
      for(int j=0; j<N; j++) {
	if(j<N-1 && s[j] == s[j+1]) cnt ++;
	else {
	  stringstream ss; ss << cnt; ns += ss.str();
	  ns += s[j];
	  cnt = 1;
	}
      }
      s = ns;
    }
    
    cout << s << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    ll ans = 0ll;

    vector<ll> b(n+1);
    for (int i = 1; i <= n; ++i) {
        b[i]++;
        for (int j = i+i; j <= n; j+=i) b[j]++;
    }

    for (ll i = 1; i <= n; ++i) ans += i*b[i];

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

Measured memory_bytes: 81328
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
  // int n, m;
  // cin >> n >> m;
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  fenwick_tree<long long> fw(N);

  for (int i = 0; i < N; ++i) {
    fw.add(i,A[i]);
  }

  vector<long long> ANS;
  
  for (int i = 0; i < Q; ++i) {
    int q;
    cin >> q;
    if (q == 0) {
      int p, x;
      cin >> p >> x;
      fw.add(p, x);
    }else{
      int l, r;
      cin >> l >> r;
      ANS.push_back( fw.sum(l,r));
    }
  }

  for (int i = 0; i < ANS.size(); ++i) {
    cout << ANS[i] << "\n";
  }

  return 0;
}



Measured memory_bytes: 12264
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nm = Input.ar;
        var adj = Enumerable.Repeat(0, nm[0]).Select(v => new List<int>()).ToArray();
        for(var i = 0; i < nm[1]; i++)
        {
            var inp = Input.ar;
            adj[inp[0] - 1].Add(inp[1] - 1);
            adj[inp[1] - 1].Add(inp[0] - 1);
        }
        var isWhite = new bool[nm[0]];
        if (IsBip(new bool[nm[0]], isWhite, true, 0, adj))
        {
            var ctw = isWhite.Count(v => v);
            WriteLine((long)ctw * (nm[0] - ctw) - nm[1]);
        }
        else
            WriteLine((long)nm[0] * (nm[0] - 1) / 2 - nm[1]);
    }
    private static bool IsBip(bool[] isTh,bool[] isWhite,bool white,int index,List<int>[] adj)
    {
        if (isTh[index])
            return white.Equals(isWhite[index]);
        isTh[index] = true;
        isWhite[index] = white;
        var isCl = true;
        foreach (var ad in adj[index])
            if (isCl)
                isCl = IsBip(isTh, isWhite, !white, ad, adj);
        return isCl;
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 30872