akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int change[26][26];

int main()
{
    string s, t;

    map<char, int> rep1, rep2;
    cin >> s >> t;
    for (auto &c : s)
    {
        rep1[c]++;
    }
    vector<int> mapOfS;
    for (auto &a : rep1)
    {
        mapOfS.push_back(a.second);
    }
    sort(mapOfS.begin(), mapOfS.end());

    for (auto &c : t)
    {
        rep2[c]++;
    }
    vector<int> mapOfT;
    for (auto &a : rep2)
    {
        mapOfT.push_back(a.second);
    }
    sort(mapOfT.begin(), mapOfT.end());

    if (mapOfS == mapOfT)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li l[1010];

int main(){
	li n;
	cin>>n;
	n*=2;
	rin{cin>>l[i];}
	sort(l,l+n);
	li res=0;
	rep(i,n/2){
		res+=min(l[2*i], l[2*i+1]);
	}
	cout<<res<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=998244353;
const ll ms=1e6+5;
const ll inf=1e17;

ll ar[ms]={0};
int qr[20][2];
ll ss[ms]={0};
ll gets(int i)
{
    if(i>=0)return ss[i];
    return 0;
}
int main(){
    idfc;

    int n;
    cin>>n;
    int k;
    cin>>k;
    int i;
    int x,y;
    int j;
    for(i=1;i<=k;i++)
    {
        cin>>qr[i][0]>>qr[i][1];
    }
    ss[1]=1;
    for(i=2;i<=n;i++)
    {
        for(j=1;j<=k;j++)
        {
            x=i-qr[j][0];
            y=i-qr[j][1]-1;
            ar[i]+=(gets(x)+modo-gets(y));
           // cout<<x<<" "<<y<<"\n";
            ar[i]%=modo;
        }
     //   cout<<ar[i]<<"\n";
        ss[i]=(ss[i-1]+ar[i])%modo;
    }
    cout<<ar[n];


    return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<int> il(n + 1);
    int odp = 0;
    for (int i = n; i >= 1; --i)
    {
        int ile = 0;
        for (int j = 2 * i; j <= n; j += i)
            ile += il[j];
        if (ile % 2 == 0)
        {
            if (a[i - 1] == 0)
                il[i] = 0;
            else
            {
                il[i] = 1;
                ++odp;
            }
        }
        else
        {
            if (a[i - 1] == 1)
                il[i] = 0;
            else
            {
                il[i] = 1;
                ++odp;
            }
        }
    }
    cout << odp << endl;
    for (int i = 1; i <= n; ++i)
        if (il[i] == 1)
            cout << i << " ";
    return 0;
}


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

const int mod = 1000000007;

struct mint
{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint &operator+=(const mint m)
    {
        if((x += m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint m)
    {
        if((x += mod - m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint m)
    {
        (x *= m.x) %= mod;
        return *this;
    }
    mint operator+(const mint m) const
    {
        return mint(*this) += m;
    }
    mint operator-(const mint m) const
    {
        return mint(*this) -= m;
    }
    mint operator*(const mint m) const
    {
        return mint(*this) *= m;
    }
    mint pow(ll n) const
    {
        if(!n) return 1;
        mint m = pow(n>>1);
        m *= m;
        if(n & 1) m *= *this;
        return m;
    }
    mint inv() const { return pow(mod-2);}
    mint &operator/=(const mint m) { return *this *= m.inv();}
    mint operator/(const mint m) const { return mint(*this) /= m;}
};
istream &operator>>(istream &is, const mint &m) { return is >> m.x;}
ostream &operator<<(ostream &os, const mint &m) { return os << m.x;}

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1)
    {
        assert(n < mod);
        fact.at(0) = 1;
        for(int i=1; i<=n; i++)
        {
            fact.at(i) = fact.at(i-1) * i;
        }
        ifact.at(n) = fact.at(n).inv();
        for(int i=n; i>=1; i--)
        {
            ifact.at(i-1) = ifact.at(i) * i;
        }
    }
    mint operator()(int n, int k)
    {
        if(k < 0 || k > n) return 0;
        return fact.at(n) * ifact.at(k) * ifact.at(n-k);
    }
};

mint comb(ll a, ll n)
{
    mint ma = 1;
    mint X = 1, Y = 1;
    for(int i=n; i>=n-a+1; i--) X *= i;
    for(int i=1; i<=a; i++) Y *= i;
    ma = X/Y;
    return ma;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;

    mint ans = 2;
    ans = ans.pow(n);
    ans -= 1;
    ans -= comb(a, n);
    ans -= comb(b, n);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define LL long long
#define R register
int n,m,fa[100005],val[100005],x,y,z;
int find(int x)
{
	if(x==fa[x])return x;
	int par=fa[x];
	fa[x]=find(fa[x]);
	val[x]+=val[par];
	return fa[x];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		int xx=find(x),yy=find(y);
		if(xx==yy)
		{
			if(val[x]-val[y]!=z)
			{
				puts("No");
				return 0;
			}
		}
		else
		{
			fa[xx]=yy;
			val[xx]=val[y]+z-val[x];
		}
	}
	puts("Yes");
	return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int memo[100];
int N;

void init2(int x)
{
	int n = 2;
	while (true) {
		if (x == 1) return;
		while (x % n) {
			if (x < n * n) {
				memo[x]++;
				return;
			}
			n++;
		}
		while (x % n == 0) {
			x /= n;
			memo[n]++;
		}
	}
}

void init()
{
	cin >> N;
	reps(i, 1, N+1) {
		init2(i);
	}
}

int a4, a2, a24, a14, a74;

int calc()
{
	rep(i, 100) {
		if (memo[i] >= 74) a74++;
		if (memo[i] >= 24) a24++;
		if (memo[i] >= 14) a14++;
		if (memo[i] >= 4) a4++;
		if (memo[i] >= 2) a2++;
	}
	if (a4 < 2) return 0;
	if (a2 < 3) return 0;
	int res = 0;
	if (a4 >= 2 && a2 >= 3) {
		res += a4 * (a4 - 1) / 2 * (a2 - 2);
	}
	if (a24 >= 1 && a2 >= 2) {
		res += a24 * (a2 - 1);
	}
	if (a14 >= 1 && a4 >= 2) {
		res += a14 * (a4 - 1);
	}
	if (a74 >= 1) {
		res += 1;
	}
	return res;
}

void solve()
{
	cout << calc() << endl;
}






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

int main(){
int a,b,c;
  cin >> a;
  int count=0;
  if((a%10)==1){
  count++;
  }
  a=a/10;
    if((a%10)==1){
  count++;
  }
  a=a/10;
      if(a==1){
  count++;
  }
  cout <<count;
return 0;
}

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

int main() {
	// your code goes here
	int a,b,c,k;
	cin>>a>>b>>c>>k;
    if(a>=k)
      cout<<k<<endl;
    else if(a+b>=k)
      cout<<a<<endl;
    else cout<<a-(k-(a+b))<<endl;
	return 0;
}


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

typedef pair<int,int> PII;
typedef long long int ll;
typedef pair< ll,ll> PLL;
typedef unsigned long long int ULL;
typedef pair<ULL,int> PUI;
#define S second
#define F first
typedef tree<
PLL,
null_type,
less<PLL>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


PLL operator+(PLL a,PLL b){ return {a.first + b.first, a.second + b.second}; }
PLL operator-(PLL a,PLL b){ return {a.first - b.first, a.second - b.second}; }
PLL operator*(PLL a,PLL b){ return {a.first * b.first, a.second * b.second}; }
PLL operator/(PLL a,PLL b){ return {a.first / b.first, a.second / b.second}; }
PLL operator%(PLL a,PLL b){ return {( b.first + a.first) % b.first, (b.second + a.second) % b.second}; }
PLL operator%(PLL a,ll b){ return {a.first % b, a.second % b} ;}
PLL operator+(PLL a,ll b){ return {a.first + b, a.second + b} ;}
PLL operator-(PLL a,ll b){ return {a.first - b, a.second - b} ;}
PLL operator*(PLL a,ll b){ return {a.first * b, a.second * b} ;}

ostream& operator<<(ostream &out,PLL a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}

ostream& operator<<(ostream &out,PUI a)
{
    out << "( " << a.first << ", " << a.second << " )" ;
    return out;
}
/*
	Order Statistics Tree ( OST )

	find_by_order()
		takes an integer k and returns an iterator to the k'th largest element counting from zero
	order_of_key()
		takes an element, here an integer and returns the number of elements strictly smaller than input
*/


int const MOD = 1e9 + 7;

int const N = 1e5 + 10;
bool mark[N] ;

void sieve()
{
    for(int i = 2; i < N; i++){
        if(!mark[i]){
            for(int j = 2 * i ; j < N; j += i) 
                mark[j] = 1;
        }
    }
}
int n,k;
vector < int > g[N], g1[N];
ll ans;
int lvl[N] ;

void dfs1(int u, int p)
{
    for(auto x : g1[u]){
        if(x != p) {
            g[u].push_back(x);
            dfs1(x,u);
        }
    }
}

void dfs(int u,int p,int l = 0)
{
    ll cnt;
    lvl[u] = l;

    for(int i = 0; i < g[u].size(); i++){
        int v = g[u][i] ;
        cnt = k;
        if(v != p){
            dfs(v,u,l+1);
            
            cnt -= i;
           // cout << v << " " << cnt << endl;

            if(lvl[v] > 0 ) cnt--;
            if(lvl[v] > 1 ) cnt--;
            if(cnt < 0 ) cnt = 0;
          //  cout << v << " " << lvl[v] << " " << cnt << endl;
            ans = (ans * cnt) % MOD;        
        }
        
    }
    //cout << u << " " << cnt << endl;
    
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    ans = 1;
    cin >> n >> k;

    for(int i = 0; i < n - 1; i++){
        int a,b;
        cin >> a >> b;
        g1[a].push_back(b);
        g1[b].push_back(a);
    }
    dfs1(1,-1);
    dfs(1,-1);
    cout << (ans*k) % MOD << endl;

    return 0;

}

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

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

	long N;
	cin >> N;

	long long A, P;
	cin >> A;

	long c[N] = {};
	long cc = 1;
	c[0] = A;
	P = A;

	bool f = false;
	for (long i = 1; i < N; i++) {
		cin >> A;

		if (P >= A && f == false) {
			c[cc] = A;
			cc++;
			P = A;
			continue;
		}

		f = false;

		for (long x = 0; x < cc; x++) {
			if (c[x] < A) {
				c[x] = A;
				f = true;
				break;
			}
		}

		if (f == false) {
			c[cc] = A;
			cc++;
		}
		P = A;
	}

	cout << cc << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, a; cin >> n >> a;
    if (n % 500 <= a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = abs(x[k-1]) + 2*abs(x[0])
for i in range (n-k+1):
  if x[i+k-1] <= 0:
    ans = min(ans, -x[i])
  elif x[i] >= 0:
    ans = min(ans, x[i+k-1])
  else:
    ans = min(ans, -2*x[i] + x[i+k-1], 2*x[i+k-1] - x[i])
print(ans)

Measured memory_bytes: 20372
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
using namespace std;


#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

vector<long long int> vec;

int main() {
	long long int n, a,s,y;
	cin >> n;

	for (int i = 0; i < 5; i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());
	if ( n%vec[0] == 0) {
		y = n/vec[0];
	}
	else {
		y = n/vec[0] + 1;
	}
	cout << y+4 << endl;
}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int e = -(d-b) + c;
    int f = c-a + d;
    int g = -(d-b) + a;
    int h = c-a + b;
    cout << e << " " << f << " " << g << " " << h << endl;
    return 0;
}

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

int main() {
    int n,k; cin >> n >> k;
    vector<int> A(n);
    int m;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        if (A[i] == 1) m = i;
    }

    int ans = 100000;
    for (int i = -k + 1; i <= k - 1; i++) {
        int j = m + i;
        int cnt = 0;
        while (0 < j && j < n) {
            j -= k - 1;
            cnt++;
        }
        j = m + i;
        while(0 <= j && j < n-1) {
            j += k - 1;
            cnt++;
        }
        if (cnt > 0) ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double EPS = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp);
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "(" << p.first << ":" << p.second << ")";
    return os;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", ";
        a = 1; os << tp;
    }
    return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, M, Q; cin >> N >> M >> Q;
    vi a(Q), b(Q), c(Q), d(Q);
    REP(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    function<ll(int,vi&)> dfs = [&](int i, vi& A) {
        if (i == N+1) {
            ll score = 0;
            REP(t, Q) {
                if (A[b[t]] - A[a[t]] == c[t]) score += d[t];
            }
            return score;
        }
        ll ret = 0;
        FOR(nxt, A[i-1], M+1) {
            A[i] = nxt;
            chmax(ret, dfs(i+1, A));
        }
        return ret;
    };

    vi A(N+1, 1);
    ll ans = dfs(1, A);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3660
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        char[] s=fsc.next().toCharArray();
        fsc.close();
        int ans=0;
        for(int i=0;i<n-2;i++){
            if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
                ans++;
            }
        }
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string t;
	cin>>t;
	reverse(t.begin(),t.end());
	t+='0';
	ll ch[1000010][2];
	for(ll i=0;i<1000010;i++){
		for(ll j=0;j<2;j++){
			ch[i][j]=INF;
		}
	}
	ch[0][0]=0;
	for(ll i=0;i<t.size();i++){
		ll now=t[i]-'0';
		for(ll a=0;a<=9;a++){
			ll num=now;
			if(a>=now){
				ch[i+1][0]=min(ch[i+1][0],ch[i][0]+2*a-num);
			}
			if(a<now){
				ch[i+1][1]=min(ch[i+1][1],ch[i][0]+a+10-num);
			}
			if(a>=now+1){
				ch[i+1][0]=min(ch[i+1][0],ch[i][1]+2*a-(num+1));
			}
			if(a<now+1){
				ch[i+1][1]=min(ch[i+1][1],ch[i][1]+2*a+10-(num+1));
			}
		}
	}
	cout << ch[t.size()][0];
	// your code goes here
	return 0;
}


Measured memory_bytes: 20048
def updiv(a,b):

    if a % b == 0:

        return a // b

    else:

        return a // b + 1


N,K = map(int,input().split())
ans = 0

if K == 0:
    print (N ** 2)

else:

    for i in range(N):

        i += 1

        if i < K:
            continue;

        ans += (i - K) * (N // i)

        nk = N - (N // i) * i

        ans += max(0 , nk - (K-1))

    print (ans)


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define random_shuffle asdasdd

int n;
int p[10], q[10];
int pn, qn;
int a[10];
int num;

int main() { 

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

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

  num = 1;
  do {
    bool okP = true, okQ = true;
    for (int i = 0; i < n; i++) {
      if (a[i] != p[i]) {
        okP = false;
      }
      if (a[i] != q[i]) {
        okQ = false;
      }
    }
    if (okP) {
      pn = num;
    }
    if (okQ) {
      qn = num;
    }
    num++;
  } while (next_permutation(a, a + n));

  cout << abs(pn - qn) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <queue>
#include <iostream>

using namespace std;

#define MAXN 510
#define INF 0x3f3f3f3f
typedef long long LL;

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%s\n", (b * 10 + c) % 4 ? "NO" : "YES");
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



ab = [[] for i in range(n)]

ki = UnionFind(n)

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ki.union(a,b)
    #ab[a-1].append(b-1)
    
print(ki.group_count() - 1)

Measured memory_bytes: 18988
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  int n;
  cin >> n;
  int prev = 0, prevx = 0, prevy = 0;
  bool flag = true;
  REP(i, n) {
    int t, x, y;
    cin >> t >> x >> y;
    int dif = t-prev;
    int dist = abs(x-prevx) + abs(y-prevy);
    if(dist > dif) {
      flag = false;
    }
    if((dif-dist)%2) {
      flag = false;
    }
    prevx = x, prevy = y;
    prev = t;
  }

  if(flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 1e5+5;
const ll M = (1ll << 63)-1;
const int INF = 0x3f3f3f3f;

inline ll cal(ll x){
	return x*x*x*x*x;
}

int main() {
	ll x;
	scanf("%lld",&x);
	
	for(ll i = 0;i <= 6208;++i){
		for(ll j = 0;j <= 6208;++j){
			if(cal(i) - cal(j) == x){
				printf("%lld %lld\n",i,j);
				return 0;
			}
			if(x - cal(j) == cal(i)){
				printf("%lld %lld\n",i,-j);
				return 0;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 3748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int N = int.Parse(strs[0]);
            int X = int.Parse(strs[1]) - 1;
            int Y = int.Parse(strs[2]) - 1;
            if (X > Y)
            {
                var tmp = X;
                X = Y;
                Y = tmp;
            }
            int[] distance = new int[N];
            for(int i = 0; i < N; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    //最短距離を出す
                   distance[A(i,j,X,Y)]++;
                }
            }
            for(int i = 1; i < N; i++)
            {
                Console.WriteLine(distance[i]);
            }
        }

        static int A(int i, int j, int x, int y)
        {
            int a = Math.Abs(j - i);
            int b = Math.Abs(x-i) + 1 + Math.Abs(y - j);
            int c = Math.Abs(y - i) + 1 + Math.Abs(x - j); ;
            if (a < b && a < c) return a;
            if (b < c) return b;
            return c;
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	for(int i=1;i<=a.size();i++)
	{
		a=a.substr(a.size()-1,1)+a.substr(0,a.size()-1);
		if(a==b)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct P{
    int a, b;
    P(int a, int b) : a(a), b(b){}
    bool operator<(const P &p)const{
        if(a != p.a)return a < p.a;
        return b < p.b;
    }
};
int main(void){
    int n, t, ans = 0;
    vector< vector<int> > dp;
    vector<P> p;
    cin >> n >> t;
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        p.push_back(P(a, b));
    }
    sort(p.begin(), p.end());

    dp.assign(2, vector<int>(t+3001, 0));
    for(int i=0;i<n;i++){
        int ni = i%2, bi = 1-i%2;
        int a = p[i].a;
        int b = p[i].b;
        for(int j=0;j<t+a;j++){
            dp[ni][j] = dp[bi][j];
            if(j >= a){
                dp[ni][j] = max(dp[ni][j], dp[bi][j-a] + b);
            }
            ans = max(ans, dp[ni][j]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    int a,b;
    int m,n;
    scanf("%d %d",&a,&b);
    if(a<1)
       exit(0);
    if(b>100)
        exit(0);
    else{
        m=a*b;
        n=2*a+2*b;
        printf("%d %d\n",m,n);
    }
    return 0;
}

Measured memory_bytes: 596
use std::io::*;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut ans = 100u32;
    for a in v {
        ans = cmp::min(ans,a.trailing_zeros())
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void) {
  int i, j;
  int n, m;
  int a[101][101], b[101], c[101] = { 0 };

  scanf("%d %d\n", &n, &m);


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

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

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      c[i] += a[i][j] * b[j];
    }
    printf("%d\n", c[i]);
  }

  return 0;
}



Measured memory_bytes: 2136
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<59;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	vi used(n);
	int num=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(!used[a[i]]){
			num++;
			used[a[i]]=1;
		}
	}
	if(num>2){
		cout<<"No"<<endl;
		return 0;
	}
	sort(a.begin(),a.end());
	if(num==1){
		if(n>=2*a[0]||a[0]+1==n) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}
	if(a[0]+1!=a[n-1]){
		cout<<"No"<<endl;
		return 0;
	}
	int c=a[0],m=0,M=0;
	for(int i=0;i<n;i++){
		if(a[i]==c) m++;
		else M++;
	}
	if(m>c||M<2*(c+1-m)) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
# jsc2019-qualA - Takahashi Calendar
# exhaustive search
def main():
    M, D = tuple(map(int, input().split()))
    ans = 0
    for m in range(1, M + 1):
        for d in range(1, D + 1):
            if len(str(d)) != 1:
                d1, d10 = int(str(d)[1]), int(str(d)[0])
                if d1 >= 2 and d10 >= 2:
                    ans += 1 if d1 * d10 == m else 0
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

#define D_MAX 100
#define DIGITS_MAX 10000
#define BUF_SIZE (DIGITS_MAX+50)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

#define DIVISOR 1000000007

int main(void) {
    static uint64_t dp[DIGITS_MAX+1][D_MAX];
    int i, j;
    static char dstr[BUF_SIZE];
    get_str(dstr, BUF_SIZE);
    int len = strlen(dstr)-1;
    int num = get_int();
    // i = 1
    for(i = 0; i < 10; i++) {
        dp[1][i%num]++;
    }
#ifdef DEBUG
        for(i = 0; i < num; i++) {
            printf("%d ", (int)dp[1][i]);
        }
        putchar('\n');
#endif

    int digit;
    for(digit = 2; digit <= len; digit++) {
        for(i = 0; i < num; i++) {
            for(j = 0; j <= 9; j++) {
                int mod = (i+j)%num;
                dp[digit][mod] = (dp[digit][mod] + dp[digit-1][i]*dp[1][j])%DIVISOR;
            }
        }
#ifdef DEBUG
        for(i = 0; i < num; i++) {
            printf("%d ", (int)dp[digit][i]);
        }
        putchar('\n');
#endif
    }
    // exclude 0
    uint64_t res = -1;
    int mod = 0;
    for(i = len; i >= 2; i--) {
        int d = dstr[len-i] - '0';
        for(j = 0; j < d; j++) {
            res = (res + dp[i-1][(mod+10*num-j)%num])%DIVISOR;
        }
        mod = (mod + 10*num - d)%num;
#ifdef DEBUG
        printf("mod: %d, res: %d\n", mod, (int)res);
#endif
    }

    for(i = 0; i <= dstr[len-1]-'0'; i++) {
        if(i%num==mod) res++;
    }
    res = res%DIVISOR;
    printf("%d\n", (int)res);
    return 0;
}

Measured memory_bytes: 7936
#include <stdio.h>
#include <string.h>
 
int xmove[8001];
int ymove[8001];
int xmove_len=0, ymove_len=0;
 
char S[8001];
int goalx,goaly;
 
char dp[10000][20000];
 
//#define DEBUG
int abs(int a){ return (a < 0)? -a : a;}
char possible(int goal, int * move, int move_len){
#ifdef DEBUG
    puts("move:");
    for(int i = 0; i < move_len; i++) printf("%d,", move[i]);
    puts(""); printf("movelen=%d\n",move_len);
#endif
    if(move_len == 0){
        if(goal == 0) return 1;
        else          return 0;
    }
    
    int sum = 0;
    for(int i = 0; i < move_len ; i++) sum += move[i];
      
    if((sum+goal) % 2 == 1) return 0;

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    dp[0][move[0]]=1;
    for(int i = 1; i < move_len; i++){
        for(int j = 0; j <= (sum+goal)/2 ; j++){
            dp[i][j] |= dp[i-1][j];
            if(j-move[i] >= 0) dp[i][j] |= dp[i-1][j-move[i]];    
        }
    }
#ifdef DEBUG
    for(int i = 0; i < move_len; i++){
        for(int j = 0; j <= (sum+goal)/2 && j <= 8000; j++){
           printf("%d,",dp[i][j]);
        }
       puts("");
    }
#endif
    return dp[move_len-1][(sum+goal)/2];
}
 
int main(void){
    scanf("%s",S);
    scanf("%d %d",&goalx,&goaly);
    /*
    goalx=-8000; goaly=0;
    for(int i = 0; i < 8000 ; i++){
        S[i]='F';
    }S[8000]=0;*/
 
    int xmove_ind = 0, ymove_ind = 0;
    char dir_x = 1;
    int count = 0;
    for(int i = 0; i <= strlen(S); i++){
        if(i == strlen(S) || S[i] == 'T' ){
            if(dir_x) xmove[xmove_ind++] = count;
            else      ymove[ymove_ind++] = count;
            
            dir_x = !dir_x;
            count = 0;
        }else{
            count++;
        }
    }
    xmove_len = xmove_ind;
    ymove_len = ymove_ind;
#ifdef DEBUG
    puts("xmove:");
    for(int i = 0; i < xmove_len; i++){
        printf("%d,",xmove[i]);
    }printf("xmovelen=%d\n",xmove_len);
    
    puts("ymove:");
    for(int i = 0; i < ymove_len; i++){
        printf("%d,",ymove[i]);
    }printf("ymovelen=%d\n",ymove_len);
#endif
    if(possible(abs(goaly),ymove,ymove_len)){
        if(xmove_len==1){
            if(goalx == xmove[0]) puts("Yes");
            else                  puts("No");
        }else{
            if(possible(abs(goalx-xmove[0]), &(xmove[1]), xmove_len-1)) puts("Yes");
            else                                                        puts("No");
        }
    }else{
        puts("No");
    }
    
    return 0;
}

Measured memory_bytes: 195456
#include <stdio.h>
#include <string.h>
int main(){
	int n;
	char s[4];
	int a[4] = {0};
	scanf("%d", &n);
	while(n--){
		scanf("%s", s);
		if(!strcmp(s, "AC"))
			a[0]++;
		if(!strcmp(s, "WA"))
			a[1]++;
		if(!strcmp(s, "TLE"))
			a[2]++;
		if(!strcmp(s, "RE"))
			a[3]++;

	}
	printf("AC x %d\n", a[0]);
	printf("WA x %d\n", a[1]);
	printf("TLE x %d\n", a[2]);
	printf("RE x %d\n", a[3]);
	return 0;
}

Measured memory_bytes: 1736
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [1 << 62] * N
dp[0] = 0
for i in range(1, N):
    for j in range(i, min(i + K, N)):
        cost = abs(H[i - 1] - H[j])
        dp[j] = min(dp[j], dp[i - 1] + cost)
print(dp[-1])


Measured memory_bytes: 52448
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool is_possible(int arr[],int k,int n,int len)
{
	int cuts = 0;
	for(int i = 0; i < n;++i){
		cuts += ((arr[i]+len-1)/len) - 1;
	}
	return cuts <= k;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i = 0;i < n;++i){
		cin >> arr[i];
	}
	int l = 1;
	int r = 1e9+1;
	int ans = INT_MAX;
	while(l < r){
		int mid = (l+r)/2;
		if(is_possible(arr,k,n,mid)){
			r = mid;
			ans = min(ans,mid);
		}
		else
			l = mid+1;
	}
	cout << ans << "\n";
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    vector<int> tem(D);
    rep(i, D) cin >> tem[i];

    vector<vector<int>> cloth(N, vector<int>(3));
    rep(i, N) cin >> cloth[i][0] >> cloth[i][1] >> cloth[i][2];

    vector<vector<int>> dp(D, vector<int>(N, -1));

    rep(i, N) {
        if (cloth[i][0] <= tem[0] && cloth[i][1] >= tem[0]) {
            dp[0][i] = 0;
        }
    }

    repd(i, 1, D) {
        rep(j, N) {
            if (cloth[j][0] <= tem[i] && cloth[j][1] >= tem[i]) {
                rep(k, N) {
                    if (dp[i-1][k] != -1) {
                        chmax(dp[i][j], dp[i-1][k] + abs(cloth[j][2] - cloth[k][2]));
                    }
                }
            }
        }
    }

    int ans = 0;
    rep(i, N) {
        ans = max(ans, dp[D-1][i]);
    }

    cout << ans << endl;

    return 0;
}


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

// グラフ
using Graph = vector<vector<int> >;

int main() {
    int N, M; cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
    }

    int shortest = N+1;
    vector<int> res;
    for (int s = 0; s < N; ++s) {
        vector<int> dist(N, -1);
        vector<int> prev(N, -1);
        queue<int> que;
        que.push(s); dist[s] = 0;
        while (!que.empty()) {
            auto v = que.front(); que.pop();
            for (auto nv : G[v]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[v] + 1;
                    prev[nv] = v;
                    que.push(nv);
                }
            }
        }
        for (int t = 0; t < N; ++t) {
            if (t == s || dist[t] == -1) continue;
            for (auto nt : G[t]) {
                if (nt == s) {
                    vector<int> tmp({s});
                    int cur = t;
                    while (cur != s) tmp.push_back(cur), cur = prev[cur];
                    if (shortest > tmp.size()) {
                        shortest = tmp.size();
                        res = tmp;
                    }
                }
            }
        }
    }

    if (shortest == N+1) cout << -1 << endl;
    else {
        cout << res.size() << endl;
        for (auto v : res) cout << v+1 << endl;
    }
}

Measured memory_bytes: 384
x, y = map(int, input().split())

A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]

if x in A:
    x = "A"
elif x in B:
    x = "B"
else:
    x = "C"

if y in A:
    y = "A"
elif y in B:
    y = "B"
else:
    y = "C"

if x == y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
H,W=map(int,input().split())
S=[[i=="." for i in input()+"#"] for _ in range(H)]+[[False]*(W+1)]

map_=[[0]*W for _ in range(H)]
for i in range(H):
    cnt=0
    q=[]
    for j in range(W+1):
        if S[i][j]==False and cnt!=0:
            for Q in q:
                map_[Q[0]][Q[1]]=cnt
            cnt=0
            q=[]
        elif S[i][j]:
            cnt+=1
            q.append([i,j])
for j in range(W):
    cnt=0
    q=[]
    for i in range(H+1):
        if S[i][j]==False and cnt!=0:
            for Q in q:
                map_[Q[0]][Q[1]]+=cnt
            cnt=0
            q=[]
        elif S[i][j]:
            cnt+=1
            q.append([i,j])
print(max([max(i) for i in map_])-1)

Measured memory_bytes: 119644
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    num = 0
    while num <= n:
        if (n - num) % 7 == 0:
            print('Yes')
            sys.exit()
        num += 4
    print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int n, a, ans = 0;
	cin >> n;
	FOR(i, n) {
		cin >> a;
		while (a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var N, A, B, C int

func main() {
	fmt.Scan(&N, &A, &B, &C)
	arr := make([]int, N)
	for i := 0; i < N; i++ {
		var tmp int
		fmt.Scan(&tmp)
		arr[i] = tmp
	}
	fmt.Println(rec1(0, 0, 0, 0, arr))
}

func rec1(depth, a, b, c int, arr []int) int {
	if depth >= N {
		if a > 0 && b > 0 && c > 0 {
			return abs(A - a) + abs(B - b) + abs(C - c) - 30
		} else {
			return math.MaxInt32
		}
	}
	w := rec1(depth + 1, a, b, c, arr)
	x := rec1(depth + 1, a + arr[depth], b, c, arr) + 10
	y := rec1(depth + 1, a, b + arr[depth], c, arr) + 10
	z := rec1(depth + 1, a, b, c + arr[depth], arr) + 10
	return min1([]int{w, x, y, z})
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min1(arr []int) int{
	a := arr[0]
	for i := 1; i < len(arr); i++ {
		if arr[i] < a {
			a = arr[i]
		}
	}
	return a
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

class UF{
public:
  vector<int> u;
  vector<int> r;

  void init(int n){
    u.resize(n, 0);
    r.resize(n, 0);
    for(int i=0; i<n; i++) u[i] = i;
  }
  int root(int x){
    // if( u[x] == x ) return x;
    // else return root(u[x]);
    return u[x] == x ? x : u[x] = root(u[x]);
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if( x == y ) return;

    if( r[x] < r[y] ){
      u[x] = y;
    }else{
      u[y] = x;
      if( r[x] == r[y] ) r[x]++;
    }
  }
};
class Graph{
public:
  int from, to, cost;
  bool operator<(const Graph &g1)const{
    return g1.cost < cost;
  };
};

int main(void) {

  int n;
  cin >> n;
  UF uf;
  uf.init(n);
  priority_queue<Graph> g;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      int a;
      cin >> a;
      if( a == -1 ) continue;
      Graph tg;
      tg.to = i;
      tg.from = j;
      tg.cost = a;
      g.push(tg);
    }
  }

  int sum = 0;
  while( !g.empty() ){
    Graph p = g.top();
    g.pop();

    if( uf.same(p.to, p.from) ) continue;

    sum += p.cost;
    uf.unite(p.to, p.from);

  }
  cout << sum << endl;

  return 0;
}

// EOF

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;

#define INF (i32)1e9
#define INF_LL (i64)1e18
#define REP(i, n) for(i64 i = 0; i < n; i++)
#define RANGE(i, a, b) for(i64 i = a; i < b; i++)

int main() {
  i64 n;
  cin >> n;
  i64 ans = 0;
  RANGE(i, 1, n + 1) {
    i64 m = n / i;
    ans += i * m * (m + 1) / 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=2e5+5;

int bit[MAXN];
vector<int> v[30];
char s[MAXN];
int cnt[30];
bool used[MAXN];
int n;

int lowbit(int x) {return x&(-x);}

int sum(int i)
{
    int s=0;
    while(i>0)
    {
        s+=bit[i];
        i-=lowbit(i);
    }
    return s;
}

void add(int i,int val)
{
    while(i<=n)
    {
        bit[i]+=val;
        i+=lowbit(i);
    }
}

void init()
{
    for(int i=0;i<26;i++)
        v[i].clear();
    memset(cnt,0,sizeof(cnt));
    memset(bit,0,sizeof(bit));
    memset(used,false,sizeof(used));
}

void solve()
{
    for(int i=1;i<=n;i++)
    {
        add(i,1);
    }
    LL ans=0;
    for(int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            int sz=v[s[i]-'a'].size();
            int pr=v[s[i]-'a'][sz-1];
            //cout<<"pr: "<<pr<<endl;
            if(i==pr)
            {
                //cout<<"sum(pr)1 "<<sum(pr)<<endl;
                ans+=(sum(n)-sum(pr))/2;
            }else
            {
                //cout<<"sum(pr)2 "<<sum(pr)<<endl;
                ans+=(sum(n)-sum(pr));
            }
            used[i]=true;used[pr]=true;
            add(i,-1);add(pr,-1);
            v[s[i]-'a'].pop_back();
        }
    }
    printf("%lld\n",ans);
}

int main()
{
    while(scanf("%s",s+1)!=EOF)
    {
        init();
        n=strlen(s+1);
        int odd=0;
        for(int i=1;i<=n;i++)
        {
            cnt[s[i]-'a']++;
            v[s[i]-'a'].push_back(i);
        }
        for(int i=0;i<26;i++)
        {
            if(cnt[i]&1) odd++;
        }
        if(odd>1)
        {
            printf("-1\n");
        }else
        {
            solve();
        }
    }
    return 0;
}


Measured memory_bytes: 2808