akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp  make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 4e5 + 5;
const int mod = 1e9 + 7;
int n , k;
ll Pow(ll a , ll b){
    if(b == 0)return 1;
    ll r = Pow(a,b/2);
    if(b&1)return (ll)r * r % mod * a  % mod;
    return r * r%mod;
}
int fac[maxn] , rfac[maxn];

int nck(int n , int k){
    if(k < 0 || k > n)return 0;
    return 1ll * fac[n] * rfac[k] % mod * rfac[n - k] % mod;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    cin >> n >> k;
    fac[0] = 1;rfac[0] = 1;
    for(int i = 1 ; i <= 2 * n ; ++i){
        fac[i] = (ll)fac[i - 1] * i % mod;
        rfac[i] = (ll)rfac[i - 1] * Pow(i,mod-2)%mod;
    }
    int res = 0;
    k = min(n-1,k);
    for(int i = min(n-1,k) ; i >= (k == 1 ? 1 : 0) ; --i){
//        cout << i <<  " " << nck(n,i)*nck(n-1,n-i-1) << endl;
        res = (res + (ll)   nck(n,i)*nck(n-1,n-i-1)) % mod;
    }
    cout << res << endl;
}



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

int main(){
	int n;
	double a[1005];
	cin>>n;
	for(int i= 0;i<n;i++) cin>>a[i];
	
	sort(a,a+n);
	
	for(int i =0; i<n-1 ;i++){
		a[i]=a[i+1]=(a[i]+a[i+1])/2;
	}
	cout<<a[n-1]<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
    int N,M;
    scanf("%d",&N);
    scanf("%d",&M);
    int num[N];
    for(int j=0; j<N; j++){
        num[j] = 10;
    }
    int s,c;
    for(int i=0;i<M;i++){
        scanf("%d",&s);
        scanf("%d",&c);
        if(s>N){
            printf("-1");
            return 0;    
        }
        if(num[s-1]!=10 && num[s-1]!=c){
            printf("-1");
            return 0;
        }else{
            num[s-1]=c;
        }
    }
    if((num[0]==0||num[0]==10 )&& N==1){printf("0");return 0;}
    if(num[0]==10){num[0]=1;}
    for(int p=1;p<N;++p){
        if(num[p]==10){num[p]=0;}
        
    }
    if(N==1&&num[0]==0){printf("0");return 0;}
    if(num[0]==0){printf("-1");
        return 0;
        }
    for(int q=0;q<N;++q){
        printf("%d",num[q]);
    }
    return 0;
}

Measured memory_bytes: 128
n = int(input())
s = input()
west = [0 for _ in range(n+1)]
east = [0 for _ in range(n+1)]

for i in range(n):
    west[i+1] += west[i] + 1 if s[i] == 'W' else west[i]
    east[i+1] += east[i] + 1 if s[i] == 'E' else east[i]
    
ans = n+1
for i in range(n+1):
    ans = min(ans,(west[i] + (east[n] - east[i])))

print(ans)


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

int n,ans,a[100005];

void work(int n)
{
	int num;
	for(int i = 1;i <= n;i++)
	{
		num = 0;
		int t = i;
		while(t)
		{
			t /= 10;
			num++;
		}
		if(num % 2 == 1)
			ans++;
		a[ans] = i;
	}	
} 

int main()
{
	scanf("%d",&n);
	work(n);
	printf("%d",ans); 
} 

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		int num = 0;
		if(H > W)
			num = H;
		else
			num = W;

		int sum = 0;
		int cnt = 0;
		while(sum < N) {
			sum +=num;
			cnt++;			
		}

		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  string ans="";
  rep(i,s.size()){
    if(s[i]=='B'){
      if(ans.size())ans.pop_back();
    }
    else ans+=s[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto wh = readln.split.to!(int[]);
    auto W = wh[0];
    auto H = wh[1];
    auto ps = new long[](W);
    foreach (i; 0..W) ps[i] = readln.chomp.to!long;
    auto qs = new long[](H);
    foreach (i; 0..H) qs[i] = readln.chomp.to!long;
    sort(ps);
    sort(qs);
    auto w = W+1, h = H+1;
    long r;
    size_t i, j;
    while (i < W || j < H) {
        if (j >= H || i < W && ps[i] < qs[j]) {
            r += h * ps[i++];
            if (w > 1) --w;
        } else {
            r += w * qs[j++];
            if (h > 1) --h;
        }
    }
    writeln(r);
}

Measured memory_bytes: 4860
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n ,n){
        vector<vector<char>> v(n+5, vector<char>(2000, '?'));
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            int ok = 0;
            for (int j = (int)s.size()-1; j >= 0; --j) {
                v[i+1][j] = s[j];
                if(v[i+1][j] == '.' && !ok){
                    ok = 1;
                    v[i+1][j] = '+';
                }
            }
        }

        for (int i = 1; i <= n; ++i) {
            for (int j = 0; j < 2000; ++j) {
                if(v[i][j] == '+'){
                    int cur = i+1;
                    while(v[cur][j] == '.') cur++;
                    if(v[cur][j] == '+'){
                        for (int k = i+1; k < cur; ++k) {
                            v[k][j] = '|';
                        }
                    }
                }
            }
        }
        for (int i = 1; i <= n; ++i) {
            int cur = 0;
            while(v[i][cur] != '?') {
                if(v[i][cur] == '.') printf(" ");
                else printf("%c", v[i][cur]);
                cur++;
            }
            puts("");
        }
        
    }
    return 0;
}


Measured memory_bytes: 4908
h,w=map(int,input().split())
s = []
wl = [0]*w
hl = [0]*h
for _ in range(h):
  s.append(input())
for i in range(h):
  if s[i].count("#") == 0:
    hl[i] = 1
for j in range(w):
  cnt = 0
  for i in range(h):
    if s[i][j] == "#":
      break
    cnt += 1
  if cnt == h:
    wl[j] = 1
ans=[]
for i in range(h):
  tmp =""
  if hl[i] == 0:
    for j in range(w):
      if wl[j] == 0:
        tmp += s[i][j]
    ans.append(tmp)
for x in ans:
  print(x)

Measured memory_bytes: 3064
#include <cstdio>

int n;

bool solve(int *balls, int i, int depth, int left, int right) {
    if (i == depth)
        return true;
    if (left < balls[i] 
            && solve(balls, i+1, depth, balls[i], right))
        return true;
    if (right < balls[i]
            && solve(balls, i+1, depth, left, balls[i]))
        return true;
    return false;
}

int main() {
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        puts(solve(balls, 0, 10, 0, 0) ? "YES" : "NO");
    }
}



Measured memory_bytes: 2656
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const int inf = 101;

int main() {
    int n; cin >> n;
    map<int, int> m;
    repf(i,1,inf) repf(j,1,inf) repf(k,1,inf) {
        ll tmp = i*i+j*j+k*k+i*j+j*k+k*i;
        if(tmp > n) continue;
        m[tmp]++;
    }
    repf(i,1,n+1) {
        cout << m[i] << endl;
    }
    return 0;
}

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

void read( string s[], int n )
{
	for( int i = 0; i < n; i++ ) {
		cin >> s[ i ];
	}
}

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

	string a[ n ], b[ m ];

	read( a, n );
	read( b, m );

	bool issame = false;
	for( int i = 0; i <= n - m and !issame; i++ ) {
		for( int j = 0; j <= n - m and !issame; j++ ) {
			
			issame = true;
			for( int x = 0; x < m; x++ ) {
				for( int y = 0; y < m; y++ ) {
					if( a[ i + x ][ j + y ] != b[ x ][ y ] ) {
						issame = false;
						break;
					}
				}
				if( !issame ) {
					break;
				}
			}
		}
	}

	cout << ( issame ? "Yes" : "No" ) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> as(n);
  int xs[20][20];
  int ys[20][20];
  for(int i=0;i<n;i++){
    cin>>as[i];
    for(int j=0;j<as[i];j++)
      cin>>xs[i][j]>>ys[i][j],xs[i][j]--;
  }
  int sz=1<<n;
  int ans=0;
  for(int bit=0;bit<sz;bit++){
    int cnt=0,flg=1;
    for(int i=0;i<n;i++){
      if((~bit>>i)&1) continue;
      cnt++;
      for(int j=0;j<as[i];j++)
        flg&=((bit>>xs[i][j])&1)==ys[i][j];
    }
    if(flg) chmax(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    ll k;
    cin >> k;
    ll testcase = 7;
    ll ans = 1;
    if (k % 2 == 0 || k % 5 == 0) {
        cout << "-1";
    }
    else {
        while (testcase % k) {
            testcase = testcase * 10 % k + 7;
            ans++;
        }
        cout << ans;
    }
    return 0;
}



Measured memory_bytes: 3636
/*
 * Write a program that reads one integer x, computes the cube of x, and outputs the result.
 */

using System;

namespace XCubic
{
    class XCubic
    {
        public void Run()
        {
            ReadX();
            Calc();
            ShowCubic();
        }

        protected void ReadX()
        {
            string s = string.Empty;

            s = System.Console.ReadLine();

            x = int.Parse(s);
        }

        protected void Calc()
        {
            cubic =  x * x * x;
        }

        protected void ShowCubic()
        {
            System.Console.WriteLine(cubic);
        }

        // field
        private int x;
        private int cubic;
    }

    class Program
    {
        static void Main(string[] args)
        {
            new XCubic().Run();
        }
    }
}

Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int n,k;
  cin>>n>>k;
  vl x(n);
  cin>>x;
  ll ans = LINF;
  rep(i,n-k+1){
    ans = min(ans,min(abs(x[i])+x[i+k-1]-x[i],abs(x[i+k-1])+x[i+k-1]-x[i]));
  }
  cout<<ans<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
using namespace std;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
template<class T> void print(const T& x){cout << x << endl;}
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;

int main(){
    string S;
    cin >> S;
    int year = stoi(S.substr(0, 4));
    int month = stoi(S.substr(5, 2));
    int day = stoi(S.substr(8, 2));
    ll num = 365*year + 31 * month + day;
    ll heisei = 365*2019 + 31 * 4 + 30;
    if(num - heisei> 0){
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
    return 0;
}




Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
int a[5], b[5];
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	bool turn = 1;
	while(a > 0 && c > 0)
	{
		if (turn) c -= b;
		else a -= d;
		turn = !turn;
	}
	if (turn) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n,t;
    scanf(" %d %d", &n, &t);
    vector<int> a(n);
    rep(i,n) scanf(" %d", &a[i]);

    int B=0;
    int max_a = a[n-1];
    int ans=1;
    for(int i=n-2; i>=0; --i)
    {
        if(B < max_a-a[i])
        {
            B = max_a-a[i];
            ans=1;
        }
        else if(B == max_a-a[i]) ++ans;

        max_a = max(max_a,a[i]);
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll W;
ll w[201],v[201];
vector<ll> vec[5];
ll sum[4];

int main(void){
	scanf("%d%lld",&n,&W);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&w[i],&v[i]);
		vec[w[i]-w[0]].push_back(v[i]);
	}
	for(int i=0;i<=3;i++){
		sort(vec[i].begin(),vec[i].end());
		reverse(vec[i].begin(),vec[i].end());
	}
	ll res=0;
	for(int i=0;i<=vec[0].size();i++){
		if(i==0)sum[0]=0;
		else sum[0]+=vec[0][i-1];
		for(int j=0;j<=vec[1].size();j++){
			if(j==0)sum[1]=0;
			else sum[1]+=vec[1][j-1];
			for(int k=0;k<=vec[2].size();k++){
				if(k==0)sum[2]=0;
				else sum[2]+=vec[2][k-1];
				for(int l=0;l<=vec[3].size();l++){
					if(l==0)sum[3]=0;
					else sum[3]+=vec[3][l-1];
					if((ll)i*w[0]+(ll)j*(w[0]+1LL)+(ll)k*(w[0]+2LL)+(ll)+l*(w[0]+3LL)<=W){
						res=max(res,sum[0]+sum[1]+sum[2]+sum[3]);
					}
				}
			}

		}
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 256
// ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//


#include <iostream>
#include <string>
using namespace std;
int main(){
   int x=0,n,m=0;
   cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
       if(s[i]=='D'){
           x--;
       } 
       else
       x++;
       m=max(m,x);
    }
    cout<<m;
    return 0;
}




Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();

    let mut ans = 0;

    for (i, x) in a.iter().enumerate() {
        let mut sum = 0;
        let mut front = 0;
        for (j, y) in a.iter().enumerate() {
            if y > x {
                sum += 1;
                if i > j {
                    front += 1;
                }
            }
        }
        ans += (front * k) % 1_000_000_007
            + sum * ((((k - 1) * k) / 2) % 1_000_000_007) % 1_000_000_007;
        ans %= 1_000_000_007;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  k--;
  for (int i = 0; i < n; ++i) {
    if (i == k) {
      cout << (char)(s[i] - 'A' + 'a');
    } else {
      cout << s[i];
    }
  }
  cout << "\n";
  return 0;
}

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

int main(void){
  ll n; cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  ll p[n+1];
  rep(i,n+1) p[i] = 0;
  rep(i,n){
    p[a[i]]++;
  }
  ll ans = 0;
  rep(i,n+1){
    ans += p[i]*(p[i]-1)/2;
  }
  rep(i,n){
    if(a[i] != 0 || a[i] != 1){
      ans = ans - p[a[i]]*(p[a[i]] - 1)/2 + (p[a[i]]-1)*(p[a[i]] - 2)/2;
      cout << ans << endl;
      ans = ans + p[a[i]]*(p[a[i]] - 1)/2 - (p[a[i]]-1)*(p[a[i]] - 2)/2;
    }
    else cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <algorithm>
long long p = 1000000000;
long long l, r, m, t, k;
long long n, x, y, z, w;
long long a[200000];
int main() {
	l = p * p * (-1);
	r = p * p + 1;
	scanf("%lld%lld", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
		if (a[i] < 0)x++;
		if (a[i] == 0)y++;
		if (a[i] > 0)z++;
	}
	std::sort(a, a + n);
	while (r - l > 1) {
		m = (r + l) / 2;
		t = 0;
		if (m == 0) {
			t = x * z;
		}
		if (m > 0) {
			t = x * z + (x + z) * y + y * (y - 1) / 2;
			w = n - 1;
			for (long long i = x + y; i < n; i++) {
				while (a[w] * a[i] >= m)w--;
				if (w > i)t += w - i;
				else break;
			}
			w = 0;
			for (long long i = x - 1; i >= 0; i--) {
				while (a[w] * a[i] >= m)w++;
				if (w < i)t += i - w;
				else break;
			}
		}
		if (m < 0) {
			w = x - 1;
			for (long long i = n - 1; i >= x + y; i--) {
				while (w >= 0 && a[w] * a[i] >= m)w--;
				if (w >= 0)t += w + 1;
			}
		}
		if (t < k)l = m;
		else r = m;
	}
	printf("%lld\n", l);
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
  string s;
  cin>>s;
  ll ok=0;
  ll ng=101010;
  ll l=s.size();
  while(ng-ok>1){
    ll m=(ok+ng)/2;
    char f='2';
    bool o=1;
    for(ll i=max(0ll,l-m);i<min(m,l);i++){
      if(f=='2') f=s[i];
      else if(f!=s[i]) o=0;
    }
    if(o) ok=m;
    else ng=m;
  }

  cout<<min(l,ok)<<endl;

  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main()
{
  int n;
  cin >> n;
  int A[n+1], B[n+1], C[n+1];
  long long ans = 0;
  for (int i = 1; i <= n; i++)
  {
    cin >> A[i];
  }
  for (int i = 1; i <= n; i++)
  {
    cin >> B[i];
  }
  for (int i = 1; i <=n-1; i++)
  {
    cin >> C[i] ;
  }
  //cout << C[1] <<" "<< C[2] << endl;

  for (int i = 1; i <= n;i++){
    ans += B[A[i]];
    if(i<=n)
      if(A[i-1]+1==A[i])
        ans += C[A[i]-1];
  }

  cout << ans << endl;


}


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

fact = {}
for i in range(2, int(n**.5)+1):
  cnt = 0
  if n % i == 0: fact.setdefault(i, 0)
  while n % i == 0:
    fact[i] += 1
    n //= i
    
if n != 1: fact[n] = 1

res = 0
for p, cnt in fact.items():
  i = j = 1
  while j <= cnt:
    res += 1
    i += 1
    j += i

print(res)

Measured memory_bytes: 9464
#include<iostream>
#include<vector>
typedef long long ll;
using namespace std;

int main(){

    ll n; cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }

    if(sum % (n * (n + 1) / 2) != 0){
        cout << "NO" << endl;
        return 0;
    }

    ll k = sum / (n * (n + 1) / 2);
    vector<ll> d(n);
    for(int i = 0; i < n; i++){
        d[i] = -(a[i] - a[(i - 1 + n) % n] - k);
    }

    for(int i = 0; i < n; i++){
        
        if((d[i] % n != 0) || d[i] < 0){
            cout << "NO" << endl;
            return 0;
        }
        k -= (d[i] / n);
    }

    if(k) cout << "NO" << endl;
    else cout << "YES" << endl;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll x=5;
	vector<ll> a(x);
	
	for(int i=0;i<x;i++)
		cin>>a[i];
	ll k;
  	cin>>k;
  	if(a[4]-a[0]>k)
      	cout<<":(";
  	else
      	cout<<"Yay!";
  
	return 0;
}


Measured memory_bytes: 3664
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
input = []
lc = 0
ll = 1
rr = nil
while l = $stdin.gets do
  input = l.chomp.split(" ").map(&:to_i)
  if lc == 0
    rr = input[0]
  else
    ll = input[0] if input[0] > ll
    rr = input[1] if input[1] < rr
  end
  lc += 1
end

if  rr >= ll
  puts rr - ll + 1
else
  puts 0
end


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

using namespace std;

int main(){
int N,M;
string tmp_s;
cin>>N;
map<string,int> profit;
for(int i=0;i<N;i++){
    cin>>tmp_s;
    profit[tmp_s]+=1;
}
cin>>M;
for(int i=0;i<M;i++){
    cin>>tmp_s;
    profit[tmp_s]-=1;
}

int max_val=0;

for(auto x:profit){
    if(x.second>max_val &&x.second>=0){
        max_val=x.second;
    }
}
cout<<max_val<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
from copy import deepcopy

def solve(bit1):
    L1 = deepcopy(grid)
    ret = 0
    for i in range(h):
        if bit1[i]:
            L1[i] = ['x'] * w
    for i in range(1 << w):
        bit2 = [0] * w
        for j in range(w):
            if i >> j & 1:
                bit2[j] = 1
        cnt = 0
        L2 = deepcopy(L1)
        for l in range(w):
            if bit2[l]:
                for m in range(h):
                    L2[m][l] = 'x'
        for i in range(h):
            for j in range(w):
                if L2[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ret += 1
    return ret

h, w, k = map(int, input().split())
grid = list(list(input()) for _ in range(h))
ans = 0
for i in range(1 << h):
    bit1 = [0] * h
    for j in range(h):
        if i >> j & 1:
            bit1[j] = 1
    ans += solve(bit1)
print(ans)


Measured memory_bytes: 9300
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int64_t INF=1e18+1;
const int mod = 1000000007;

int main() {
  int N;
  cin>>N;
  vector<int64_t>A(N);
  vector<int64_t>sum(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());
  sum=A;
  for(int i=0;i<N-1;i++){
    sum[i+1]+=sum[i];
  }
  for(int i=N-2;i>=0;i--){
    if(sum[i]*2<A[i+1]){cout<<N-1-i<<endl;return 0;}
  }
  cout<<N<<endl;
  return 0;
}

Measured memory_bytes: 4748
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n;
LL d;
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>d;
  d*=d;int ans=0;
  for(int i=1;i<=n;i++){
    LL x,y;
    cin>>x>>y;
    LL c=x*x+y*y;
    if(c<=d)ans++;
  }
  cout<<ans<<'\n';
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s; cin>>s;
    int cnt=0,ans=0;
    rep(i,s.size()){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') cnt++;
        else{
            ans=max(ans,cnt);
            cnt=0;
        }
        if(i==s.size()-1) ans=max(ans,cnt);
    }
    cout<<ans; 
}

Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<cmath>
#include<climits>
using namespace std;

int func(vector<int> &v,int i,int n,vector<int> &memo)
{
    if(i>=n)
        return 0;

    if(i==n-1)
        return 0;

    if(memo[i] == -1)
    {
        int n1 = INT_MAX,n2 = INT_MAX;
        if(i+1 < n)
            n1 = abs(v[i] - v[i+1]) + func(v,i+1,n,memo);
        if(i+2 < n)    
            n2 = abs(v[i] - v[i+2]) + func(v,i+2,n,memo);
        memo[i] = min(n1,n2);
    }
    return memo[i];
    
}

int main()
{
    int n{};
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    
    vector<int> memo(n,-1);
    cout<<func(v,0,n,memo);
    return 0;
}

Measured memory_bytes: 8832
#include<stdio.h>
int main()
{
    long long int a,b,t;
    scanf("%lld%lld",&a,&b);
    if(a==0)
        printf("%lld\n",a);
    if(b==0)
        printf("%lld\n",b);
    else{
        while(b!=0)
        {
           t=b;
           b=a%b;
            a=t;
        }
        printf("%d\n",a);
    }
}



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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
ans = float('inf')
# 縦
for i in range(1, W):
  a = H*i
  bc = H*(W-i)
  b = (H//2) * (W-i)
  c = bc-b
  mx = max([a, b, c])
  mn = min([a, b, c])
  ans = min(ans, (mx-mn))

  bb = H * ((W-i)//2)
  cc = bc-bb
  mx = max([a, bb, cc])
  mn = min([a, bb, cc])
  ans = min(ans, (mx-mn))

# 横
for i in range(1, H):
  a = i*W
  bc = (H-i)*W
  b = (H-i) * (W//2)
  c = bc-b
  mx = max([a, b, c])
  mn = min([a, b, c])
  ans = min(ans, (mx-mn))

  bb = ((H-i)//2) * (W)
  cc = bc-bb
  mx = max([a, bb, cc])
  mn = min([a, bb, cc])
  ans = min(ans, (mx-mn))

print(ans)

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

string calc(string str){
  string tmp;
  tmp+=str[0];
  for(int i=0;i<str.size();i++)
    if(str[i]=='a'||str[i]=='i'||str[i]=='u'||str[i]=='e'||str[i]=='o')
      tmp+=str[i+1];
  return tmp;
}

int main(){
  while(1){
    int n,ma=0,cnt=0,f=0;
    string str,code[51];
    cin>>n;
    if(n==0) break;
    
    for(int i=0;i<n;i++){
      cin>>str;
      code[i]=calc(str);
      ma=max(ma,(int)code[i].size());
    }
     while(cnt!=ma+1){
      f=0;
      for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++)
	  if(code[i].substr(0,cnt)==code[j].substr(0,cnt))f=1;
      if(f==0)break;
      cnt++;
    }
     
    if(f==0) cout<<cnt<<endl;
        else cout<<"-1"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=a[n-1]-a[0];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
h = int(input())
w = int(input())
n = int(input())

h_count = 0
w_count = 0

for h_i in range(h):
	h_count += 1
	if n <= (h_i + 1) * w:
		break

for w_i in range(w):
	w_count += 1
	if n <= (w_i + 1) * h:
		break


if w_count > h_count:
	print(h_count)
else:
	print(w_count)

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int k, x;
	cin >> k >> x;
	for (int i = max(-1000000, x - k + 1); i < min(1000001, x + k); ++i)
		cout << i << " ";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
vector<int> v;
int main()
{
  int a,b,k;
  cin>>a>>b>>k;
  for(int i=1;i<=110;i++) if(a%i==0 && b%i==0) v.push_back(i);
  // for(int i=0;i<v.size();i++) cout<<v[i]<<endl;
  cout<<v[v.size()-k]<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int sq = (int)Math.sqrt((double)N);
		if((A+B>N+1) || (A<sq && B<sq)) System.out.println(-1);
		//(単調増加列)+(単調減少列)で表現できる
		else if(A+B==N+1){
			for(int i=B;i<=N;++i) System.out.print(i+" ");
			for(int i=B-1;i>=1;--i) System.out.print(i+" ");
			System.out.println();
		}else{
			//長さBの単調減少列のブロックを作れるだけ作る。その時最長増加部分列は
			//tempAで表されるので、Aとの差分を左端に単調増加列として追加する
			int tempA = (N/B)+(N%B!=0? 1:0);
			int hidari = 0;
			while(tempA+hidari!=A){
				hidari++;
				if(hidari>N){ //条件を満たす数列を作るのは無理くぼ
					System.out.println(-1);
					return;
				}
				if((N-hidari)%B==0) tempA--;
			}
			
			int nowN = N-hidari;
			for(int i=1;i<=hidari;++i) System.out.print(i+" "); //左端の単調増加列
			for(int i=1;i<=nowN/B;i++){
				for(int j=i*B;j>(i-1)*B;j--){
					System.out.print((j+hidari)+" "); //単調減少列のブロック
				}
			}
			for(int j=nowN;j>B*(nowN/B);--j) System.out.print((j+hidari)+" "); //あまった奴
			System.out.println();
		}
		return;
	}
}

Measured memory_bytes: 48464
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
	double x,q;
	while(cin>>q){
		if(q==-1) break;
		x = q/2;
		while(1){
			x=x-(x*x*x-q)/3/x/x;
			if(x*x*x-q < q*0.00001 && x*x*x-q > -q*0.00001) break;
		}
		printf("%.6lf\n",x);
	}
	return 0;
}

Measured memory_bytes: 1236
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
a = input()
if ord(a) < ord('a'):
        print('A')
else:
        print('a')


Measured memory_bytes: 61872
O = list(str(input()))
E = list(str(input()))
count = len(O) - len(E)
ans = ''

if count == 0:
  for i in range(len(O)):
    ans += O[i]
    ans += E[i]
else:
  for i in range(len(E)):
    ans += O[i]
    ans += E[i]
  ans += O[-1]
  
print(ans)
  

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int a[200005];
const int mid=100002;
int main()
{
	int n;
	cin>>n;
	int front=0,back=1;
	for(int i=0;i<200005;i++)
	    a[i]=-1;
	for(int i=0;i<n;i++)
	{
		if(i%2==0)
		{
			cin>>a[mid+front];
		    front++;
		}
		else
		{
			cin>>a[mid-back];
			back++;
		}    
	}
	int mark;
	for(int i=0;i<200005;i++)
	    if(a[i]!=-1)
	    {
	    	mark=i;
	    	break;
		}
	int c[n];
	int count=0;
	for(int i=mark;a[i]!=-1;i++)
	{
		c[count]=a[i];
		count++;
	}
	if(n%2==1)
	    reverse(c,c+n);
	for(int i=0;i<n;i++)
	    cout<<c[i]<<' ';
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
const ll mx = 1e18;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  REP(i,N){
    if(mx/A[i]<ans){
      cout << -1 << endl;
      return 0;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4028
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] w = new int[n];
		for (int i = 0; i < n; i++)
			w[i] = in.nextInt();
		System.out.println(solve(w));
		in.close();
	}

	private static int solve(int[] w) {
		for (int i = 1; i < w.length; i++)
			w[i] = w[i - 1] + w[i];
		int r = 999;
		for (int i = 0; i < w.length; i++) {
			int t = Math.abs(w[w.length - 1] - 2 * w[i]);
			if (r > t)
				r = t;
		}
		return r;
	}
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        // 宣言・値の格納
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] W = new String[N];
        char wLast;
        char wFirst;
        
        W[0] = sc.next();
        
        // 頭と末尾の一致判定
        for(int i = 0; i < N-1; i++){
            W[i+1] = sc.next();
            wFirst = W[i].charAt(W[i].length()-1);
            wLast = W[i+1].charAt(0);
            
                // 一致しない場合
                if(!(wFirst == wLast)){
                    System.out.println("No");
                    return;
                }
        }
        
        // 新規の単語かの判定
        for(int i = 0; i < N; i++){
            for(int j = 0; j < i; j++){
                
                //新規でない場合 
                if(W[i].equals(W[j])){
                    System.out.println("No");
                    return;
                }
            }
        }

        // 規則を順守している場合
        System.out.println("Yes");

    }
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin>>N;
    vector<ll> a(N);
    REP(i,N) cin>>a[i];
    ll sum = 0;
    REP(i,N) sum += a[i];
    ll ans = INF;
    ll sunuke = 0;
    REP(i,N-1) {
        sunuke += a[i];
        sum -= a[i];
        ans = min(ans,abs(sunuke-sum));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (D, N) = Read2Longs();
            var ans = N == 100 ? Math.Pow(100, D) * (N + 1) : Math.Pow(100, D) * N;
            return ans;
        }
        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll n; cin >> n;
  ll ans = 0;

  rep2(k, 1, n+1) {
    ll m = n / k;
    ans += m*(m+1)/2 * k;
  }

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


Measured memory_bytes: 3664
n = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(n)]

dp[1] = abs(h[1] - h[0])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[n-1])
  
  

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n;
        cin>>n;
        vector<int>v(n);
        for(int i=0;i<n;i++)
        {
                cin>>v[i];
        }
        sort(v.begin(),v.end());
        int a=v.back();
        int b=0;
        for(int i=0;i+1<n;i++)
        {
                b+=v[i];
        }
        if(a<b)
        {
                cout<<"Yes\n";
        }
        else
        {
                cout<<"No\n";
        }
        return 0;
}
/**

**/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
const int maxn = 105 + 5;
ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n ; cin >> n;
    for (int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    sort(a + 1 , a + 1 + n);
    ll ans = 1e18;
    for (int i = a[1] ; i <= a[n] ; i++){
        ll res = 0;
        for (int j = 1 ; j <= n ; j++){
            res += (a[j] - i) * (a[j] - i);
        }
        ans = min (ans , res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
from collections import deque


def main():
    while que:
        v, d = que.popleft()
        for nv in G[v]:
            nv -= 1
            if D[nv] == -1:
                D[nv] = D[v] + 1
                que.append((nv, D[nv]))
    for i in range(N):
        print(i+1, D[i])


if __name__ == "__main__":
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N):
        ipts = [int(ipt) for ipt in input().split()]
        G[ipts[0]-1] = ipts[2:]
    D = [-1]*N
    D[0] = 0
    que = deque()
    que.append((0, 0))
    main()


Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

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

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

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("O3")
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin() , v.end()
#define pb push_back
#define eb emplace_back
#define MAX 1000006
#define MIN -100006
typedef long long  ll;
const ll MOD = 1e9 + 7;
using namespace std;
ll n_bits(ll n ) { ll x= __builtin_popcount(n) ;return x ;}
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";

ll a[3][3];


bool setX(ll x){
	for(int i =0 ; i <3;i++)
		for(int j = 0;j<3;j++)
			if(a[i][j] ==x) 
				a[i][j] =0;

	bool ok = false;
	
	ll ct =0 ;
	for(int i =0 ; i <3;i++){
		for(int j = 0;j<3;j++){
			if(a[i][j] == 0) 
				ct++;
		}
		if(ct ==3) ok = true;
		ct =0 ;
	}

	ct = 0;
	for(int i =0 ; i <3;i++){
		for(int j = 0;j<3;j++){
			if(a[j][i] == 0) 
				ct++;
		}
		if(ct ==3) ok = true;
		ct =0 ;
	}


	if(a[0][0] == a[1][1]  && a[1][1] == a[2][2] && a[1][1] ==0) ok = true;

	if(a[2][0] == a[1][1]  && a[1][1] == a[0][2] && a[1][1] ==0) ok = true;

	return ok;

}

int main(int argc, char const *argv[])
{
	fast
	cout.precision(0);
	cout<<fixed;
	ll n , m,k ,pt(0),ct(0) ,x,y; 
	
	
	

	for(int i=0;i<3;i++)for(int j =0 ; j<3;j++) cin>>a[i][j];

	cin>>n;
	bool ok= false;
	REP(i,n) {
		cin>>x;
		if(setX(x)){
			ok =true;
		}
	}
	cout<<(ok?"Yes" : "No")<<endl;

	
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;





int main()
{
	//ifstream cin("input.txt");
	
	int n, m,si,ci;
	cin>>n>>m;
	unordered_map <int,int> num;
	rep(i,0,m-1)
	{
		cin>>si>>ci;
		if(num.find(si) != num.end() && num[si] != ci)
		{
			cout<<-1;
			return 0;
		}
		else
			num[si] = ci;
	}
	int d1,d2,d3;
	if(n == 3)
	{
		if(num.find(1) == num.end())
			cout<<1;
		else if(num[1] == 0){
				cout<<-1;
				return 0;
			}
			else
			{
				cout<<num[1];
			}

		if(num.find(2) == num.end())
			cout<<0;
		else
			cout<<num[2];

		if(num.find(3) == num.end())
			cout<<0;
		else
			cout<<num[3];


	}else if(n == 2)
	{

			if(num.find(1) == num.end())
				cout<<1;
			else if(num[1] == 0)
			{
				cout<<-1;
				return 0;
			}
			else
				cout<<num[1];

			if(num.find(2) == num.end())
				cout<<0;
			else
				cout<<num[2];
	}
	else
	{

			if(num.find(1) == num.end())
				cout<<0;
			else
				cout<<num[1];
	}
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long int
using namespace std;

const ll mod = 1e9 + 7;

void dfs(vector<vector<ll>> &adj, vector<bool> &visited, ll i) {
	visited[i] = true;
	ll j, n = adj[i].size();
	for (j=0; j<n; ++j) {
		if (!visited[adj[i][j]]) {
			dfs(adj, visited, adj[i][j]);
		}
	}
}

ll dfs_main(vector<vector<ll>> &adj, vector<bool> &visited) {
	ll ans = 0, i, n=adj.size();
	for (i=1; i<n; ++i) {
		if (!visited[i]) {
			ans++;
			dfs(adj, visited, i);
		}
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, m, i, l, r;
	cin >> n >> m;
	vector<vector<ll>> adj(n+1);
	vector<bool> visited(n+1, false);
	for (i=0; i<m; ++i) {
		cin >> l >> r;
		adj[l].push_back(r);
		adj[r].push_back(l);
	}
	cout << max(0LL, dfs_main(adj, visited)-1);
	return 0;
}


Measured memory_bytes: 10856
#include <iostream>
#include <stdio.h>
using namespace std;

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


Measured memory_bytes: 3128