akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

bool ispa(string s)
{
    ll n = s.length();
    bool pos = 1;
    rep(n)
        if(s[i]!=s[n-1-i])
            pos = 0;
    return pos;        
}

int main()
{
   FAST/**/
   
   ll powa[64];
   powa[0] = 1;
   for(ll i=1;i<64;i++)
        powa[i] = powa[i-1]*2;
   
   ll n,m,k;
   cin>>n>>m>>k;
   
   string arr1[n];
   rep(n)
        cin>>arr1[i];
   ll arr[n][m];
   rep(n)
        repi(j,m)
            arr[i][j] = (arr1[i][j] - '0');
   ll lim = (1ll<<n);
   ll ans = inf;
   for(ll mask = 0;mask<lim;mask++)
   {
       vector<ll> hold;
       ll cnt = 0;
       repi(j,n)
       {
           if(j == 0)
           {
               cnt++;
               continue;
           }
           
           ll p1 = ((powa[j]&mask)>0);
           ll p2 = ((powa[j-1]&mask)>0);
           if(p1 == p2)
                cnt++;
           else 
           {
               hold.pb(cnt);
               cnt = 1;
           }
       }
       
       hold.pb(cnt);
       ll l = hold.size();
       ll tot = 0;
       bool pos = 1;
       vector<ll> store(l);
       for(ll j=0;j<m;j++)
       {
           bool mnew = 0;
           vector<ll> v1(l,0);
           ll sub = 0;
           repi(i1,l)
           {
               for(ll pt = sub;pt<=sub+hold[i1]-1;pt++)
                   v1[i1]+=arr[pt][j];
               sub+=hold[i1];
           }
           
           repi(i1,l)
           {
               if(v1[i1]>k)
                    pos = 0;
           }
           if(pos == 0)
                break;
           repi(i1,l)
           {
               if(v1[i1]+store[i1]>k)
                    mnew = 1;
           }
           if(mnew == 1)
           {
               tot++;
               store = v1;
           }
           else
           {
               repi(i1,l)
                   store[i1]+=v1[i1];
           }
       }
       if(pos == 0)
            continue;
       ans = min(ans,tot + l-1);
       
   }
   cout<<ans;
   
   
   return 0;        
}  
   

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

void input(vector<vector<int>>& rvvnNum)
{
  for (int i = 0; i < rvvnNum.size(); i++)
    for (int j = 0; j < rvvnNum[i].size(); j++)
      cin >> rvvnNum[i][j];
}

int isRight(const vector<vector<int>>& cnrvvnNum)
{
  vector<int> vnDx(2);

  for (int j = 0; j < cnrvvnNum[0].size() - 1; j++)
    vnDx[j] = cnrvvnNum[0][j + 1] - cnrvvnNum[0][j];

  for (int i = 1; i < cnrvvnNum.size(); i++)
    for (int j = 0; j < cnrvvnNum[i].size() - 1; j++)
      if (cnrvvnNum[i][j + 1] == cnrvvnNum[i][j] + vnDx[j]);
      else
        return 0;

  return 1;
}

int main()
{
  vector<vector<int>> vvnNum(3, vector<int>(3));

  input(vvnNum);
  if (isRight(vvnNum)) cout << "Yes" << endl;
  else                 cout << "No"  << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a,b,c;
    cin>>a>>b>>c;
    ll res=0LL;
    ll t=min(b,c);
    b-=t;
    c-=t;
    res+=2*t;
    t=min(a,c);
    res+=t;
    a-=t;
    c-=t;
    if(c>=1) res++;
    res+=b;
    cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int a,b,c,mn,mx,a2;

int main()
{
	cin>>a>>b>>c;
	int sum=a+b+c;
	mn=min(a,min(b,c));
	mx=max(a,max(b,c));
	a2=sum-mn-mx;
	int ans=mn*a2;
	if(ans%2==0) cout<<ans/2<<endl;
	else cout<<ans/2<<".5"<<endl;
	rt0;
}

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::string s;
	std::cin >> s;
	s[0] = '2', s[1] = '0', s[2] = '1', s[3] = '8';
	pnl(s);
}



Measured memory_bytes: 256
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N+1):
        z = N - (x + y)
        if (z >= 0) & (10000*x + 5000*y + 1000*z == Y):
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8]={+1, +1, +1, 0, 0, -1, -1, -1};
int YY[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int dx[4]={-1,1,0,0};
int dy[4]={0,0,1,-1};


signed main() {

	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	string s;
	cin>>s;

	int maxi=0,cnt=0,n=s.size();

	for(int i=0;i<n;i++){
		if(s[i]=='R'){
			cnt+=1;
		}else{
			cnt=0;
		}

		maxi=max(maxi,cnt);
	}

	cout<<maxi<<endl;

	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int compress(vector<ll> &x)
{
    vector<ll> tmp = x;
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());

    rep(i, x.size()) {
        x[i] = lower_bound(tmp.begin(), tmp.end(), x[i]) - tmp.begin() + 1;
    }

    return tmp.size();
}

template<class T>
class BIT {
    int n;
    vector<T> dat;

public:
    BIT(int _n) : n(_n), dat(vector<T>(_n+1)) {}

    void add(int i, T x)
    {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }

    T sum(int i)
    {
        T res = 0;
        while (i > 0) {
            res += dat[i];
            i -= i & -i;
        }
        return res;
    }

    // [l, r]
    T sum(int l, int r)
    {
        return sum(r) - sum(l-1);
    }
};

int main()
{
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<int> A(N);
    vector<ll> sum(N+1);
    ll ans = 0LL;
    rep(i, N) {
        cin >> A[i];
        A[i] -= K;
        sum[i+1] = sum[i] + A[i];
    }

    int NN = compress(sum);
    BIT<ll> bit(NN+1);
    REP(i, 0, N+1) {
        int now = sum[i];
        // DUMP2(i, sum[i]);
        ans += bit.sum(now);
        // DUMP(ans);
        bit.add(now, 1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4224
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl;
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl;

void putStar( int n )
{
	REP( i, 0, n )
	{
		cout << '*';
	}

	return;
}

int main()
{
	VI v( 6 );

	int n;
	cin >> n;

	REP( i, 0, n )
	{
		double in;
		cin >> in;

		if ( in < 165 )
		{
			v[0]++;
		}
		else if ( in < 170 )
		{
			v[1]++;
		}
		else if ( in < 175 )
		{
			v[2]++;
		}
		else if ( in < 180 )
		{
			v[3]++;
		}
		else if ( in < 185 )
		{
			v[4]++;
		}
		else
		{
			v[5]++;
		}
	}

	REP( i, 0, 6 )
	{
		cout << i + 1 << ':';
		putStar( v[i] );
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import itertools,math
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
seq=[]
for i in range(N):
    seq.append(i)
    
l=list(itertools.permutations(seq))

num=0
for i in l:
    for u in range(1,len(i)):
        num+=math.sqrt((x[i[u-1]]-x[i[u]])**2+(y[i[u-1]]-y[i[u]])**2)
print(num/len(l))    

Measured memory_bytes: 72024
n = int(input())
c = input()


r = 0
w = 0
for x in c:
    if x == 'R':
        r += 1
    else:
        w += 1

if r == 0:
    print(0)
    exit()

ans = 0
for x in c:
    r -= 1
    if x =='W':
        ans += 1
    if r == 0:
        break    

print(ans)


Measured memory_bytes: 9448
#include<stdio.h>
int main(){
int a,b,c,x,y,i,ans=10000000;
scanf("%d %d %d",&a,&b,&c);
if(c%1000==0){
x=c/1000;
}
else{
x=c/1000+1;
}
for(i=0;i<=x;i++){
y=(c-1000*i)/500;
if(c%500!=0){
y++;
}
if(1000*i>c){
y=0;
}
if(ans>a*i+b*y){
ans=a*i+b*y;
}
}
printf("%d\n",ans);
return 0;
}



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

unsigned long long a, b, n;

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

  cin >> a >> b >> n;
  unsigned long long x = min(n, b-1);
  cout << a*x/b << endl;
}

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

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

using namespace std;

int main(){
	int n; cin>>n;
	vector<int> p(n);
	rep(i,n) cin>>p[i];

	rep(j,n) rep(i,j+1) {
		swap(p[i],p[j]);
		bool ok=true;
		rep(k,n-1) if(p[k]>p[k+1]) ok=false;
		if(ok){ cout<<"YES"<<endl; return 0; }
		swap(p[i],p[j]);
	}
	cout<<"NO"<<endl;

	return 0;
}


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

int a[101],n,p,q;

bool cmp(int x,int y)
{
	return x>y;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		q+=a[i];
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i+=2)
		p+=a[i];
	cout<<p-q+p<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input().strip())
P_list = list(map(int, input().rstrip().split()))
#-----
min_P = float("inf")
cnt = 0

for p in P_list:
    if min_P >= p:
        cnt += 1
        min_P = min(min_P, p)

print(cnt)


Measured memory_bytes: 24744
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b) printf("a < b\n");
    if(a>b) printf("a > b\n");
    if(a==b) printf("a == b\n");
    return 0;
    
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 

#define MAX 3000
#define mod 1000000007

ll add(ll a,ll b)
{
	return (mod+(a+b)%mod)%mod;
}


int main()
{
	
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	
	ll n;
	cin>>n;
	
	ll k = n;
	string ans;
	
	while(k>0)
	{
		//cout<<k<<" "<<(k/26)<<" "<<(k%26)<<endl;
		if((k%26)==0)
		{
			ans += 'z';
			k = k-26;
		}
		else{
			ans += char('a'+(k%26)-1);
		}
		k = k/26;
	}
	
	reverse(ans.begin(), ans.end());
	
	cout<<ans<<endl;
	
}















Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	sort(a.begin(),a.end());
	if( a[n-1] - a[0] > 1){
		cout<<"No"<<endl;
		return 0;
	}
	else if(a[n-1]-a[0]==1){ 
		ll sma = 0, lar = 0;
		ll x = a[0]+1;
		for(int i=0;i<n;i++){
			if(a[i] == a[0]){
				sma++;
			}
			else{
				lar++;
			}
		}
		if( x < sma+1 || (sma+lar/2)<x ){
			cout<<"No"<<endl;
			return 0;
		}
		if( lar == 1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	else{
		if(a[0] != n-1 && a[0] > n/2){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1400
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, c,i, j, k, p, q, r, x, y, u, v, n, m;
	cin>>n>>m;
	for(int i=0;i<=n;i++)
	{
		t=i;
		c=n-i;
		x=t*4+c*2;
		if(x==m)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

int main()
{
	int n,i,minn=1000000,x,y;
	cin>>n;
	for(i=0;i<n;i++)
	{
		y=0;
	cin>>x;
	while(x%2==0)
	{
		x/=2;
		y++;
	}
	if(y<minn) minn=y;
	}
	cout<<minn;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <cstdio>
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
 /////////////////////////////////////////////////////
int main(){
	int A,B,K;
	scanf("%d%d%d",&A,&B,&K);
	
	if ((B-A)>=2*K) {
		FOR(i,A,A+K){PRINTD(i);}
		for(int i = B-K+1 ; i <=B ; i++){PRINTD(i);}
	}else{
		FOR(i,A,B+1){PRINTD(i);}
	
	}
	return 0;
}




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

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vii vector<vi>

#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>

const ll INF = 1e18;

int h = 19, w = 15;
vector<map<pii, int> > dp;
vi dx = {0, 1, 1, 1, 0, -1, -1, -1}, dy = {-1, -1, 0, 1, 1, 1, 0, -1};

bool in(int x, int a, int b) {
	return a <= x and x < b;
}

int main() {
	int n = 0;
	vii a(h, vi(w, -1));
	pii start;
	rep (i, h) {
		rep (j, w) {
			char c;
			cin >> c;
			if (c == 'O') {
				start = pii(i, j);
			}
			if (c == 'X') {
				a[i][j] = n;
				n++;
			}
		}
	}
	int m = 1 << n;
	dp.resize(m);
	dp[m - 1][start] = 0;

	int ans = 1e9;
	for (int i = m - 1; i >= 0; i--) {
		for (auto itr = dp[i].begin(); itr != dp[i].end(); itr++) {
			int y = itr->first.first, x = itr->first.second;
			int cost = itr->second;
			rep (k, 8) {
				int ny = y + dy[k], nx = x + dx[k];
				vi use;
				bool is_black = false;
				while (in(ny, 0, h) and in(nx, 0, w)) {
					if (a[ny][nx] == -1) break;
					if ((i & (1 << a[ny][nx])) == 0) break;
					is_black = true;
					use.push_back(a[ny][nx]);
					ny += dy[k];
					nx += dx[k];
				}
				if (not is_black) continue;
				if (ny == h or (ny == h - 1 and in(nx, 0, w))) {
					ans = min(ans, cost + 1);
				}
				else if (ny == -1 or not in(nx, 0, w)) {
					continue;
				}
				else {
					int ni = i;
					rep (k, use.size()) {
						ni -= (1 << use[k]);
					}
					if (dp[ni][pii(ny, nx)] == 0) {
						dp[ni][pii(ny, nx)] = cost + 1;
					}
					else {
						dp[ni][pii(ny, nx)] = min(dp[ni][pii(ny, nx)], cost + 1);
					}
				}
			}
		}
	}
	if (ans >= 1e8) {
		cout << -1 << endl;
	}
	else{
		cout << ans << endl;
	}
}


Measured memory_bytes: 57296
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	vector<int> p(1,0),q(1,0);
	int N; scanf ("%d",&N); while (N--){
		int l,r; scanf ("%d %d",&l,&r);
		p.push_back(r);
		q.push_back(l);
	}
	sort(p.begin(),p.end());
	sort(q.rbegin(),q.rend());

	long long ans = 0;
	for (int i=0;i<p.size()/2;i++){
		if (q[i] - p[i] > 0) ans += q[i] - p[i];
	}
	printf ("%lld\n",ans*2);

	return 0;
}


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

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int V_MAX = 1e5+10;
const int E_MAX = 1e5+10;
struct edge{
  int to;
  ll cost;
};

int V,E;
vector<edge> G[V_MAX];
vector<ll> dist(V_MAX,0);

void dfs(int cur, int pare, ll d){
  dist[cur] = d;
  for(auto &e: G[cur]){
    if(e.to == pare) continue;
    dfs(e.to, cur, d+e.cost);
  }
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V;
  E = V-1;
  rep(i,E){
    int f,t,c;cin >> f >> t >> c;
    --f;--t;
    G[f].push_back({t,c});
    G[t].push_back({f,c});
  }
  int Q, K;cin >> Q >> K;
  --K;
  dfs(K,-1,0);
  while(Q--){
    int x,y; cin >> x >> y;
    --x;--y;
    cout << dist[x] + dist[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)
#define srd(i,x) for(int i=x-1;i<=x+1;i++)

int main(){
  ll h,w,n,a[100010],b[100010],c,ans[10]={};
  map<P,bool> m,vis;
  cin>>h>>w>>n;
  fr(i,n){
    cin>>a[i]>>b[i];
    m[mp(--a[i],--b[i])]=1;
  }
  fr(k,n){
    srd(i,a[k]){srd(j,b[k]){if(0<i&&i<h-1&&0<j&&j<w-1){
      if(!vis[mp(i,j)]){
        vis[mp(i,j)]=1;
        c=0;
        srd(I,i) srd(J,j) c+=m[mp(I,J)];
        ans[c]++;
      }
    }}}
  }
  ans[0]=(h-2)*(w-2);
  Fr(i,9) ans[0]-=ans[i];
  fr(i,10) cout<<ans[i]<<endl;
}

Measured memory_bytes: 214272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> A(N);
	vector<P> CB(M);
	FOR(i,0,N)cin>>A[i];
	for(auto &x:CB){
		cin>>x.second;
		cin>>x.first;
	}
	int cnt = N;
	sort(CB.rbegin(),CB.rend());
	for(auto x:CB){
		while(x.second && cnt){
			A.push_back(x.first);
			cnt--;x.second--;
		}
	}
	sort(A.rbegin(),A.rend());
	ll ans = 0;
	FOR(i,0,N) ans += A[i];
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
    long long x;
    while(cin>>x)
    {
        long long y=x/11;
        long long z=x%11;
        long long ans=2*y;
        if(z==0)
        ans+=0;
        else if(z<7)
        ans+=1;
        else  
        ans+=2;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 200000
#define RT 1000000000

int main()
{
  int i,n,R[N],max=-RT,mi,d;
  scanf("%d",&n);
  if( n > N  || n < 2 )
    exit(1);
  for( i = 0; i <n ; i++ )
    {
      scanf("%d",&R[i]);
      if( R[i] > RT || R[i] < 1 )
	exit(1);
    }
  
  mi=R[0];
  for( i = 1; i < n; i++ )
    {
      d = R[i]-mi;
      if( d>max )
	max = d;
      if( R[i]<mi )
	mi = R[i];
    }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2516
#include <iostream>

// nyu-syutu-ryoku no settei wo suru
#include <iomanip>

// pi wo tukau ze
#include <math.h>

int main()
{
    double r, s, l, pi;

    // M_PI no yuko-suji ha 16-keta
    pi = M_PI;

    std::cin >> r;

    s = r * r * pi;
    l = r * 2 * pi;

    std::cout << std::fixed << std::setprecision(5)
      << s << " " << l << std::endl;

    return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  REP(i, n) { cin >> p[i]; }

  int left = 0;
  int right = k;
  ll ans = 0;
  REP(i, k) { ans += p[i]; }
  ll tmp = ans;
  while (right < n) {
    tmp = tmp - p[left] + p[right];
    ans = max(ans, tmp);
    left++;
    right++;
  }
  coutd(10) << (double)ans / 2 + (double)k / 2 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
constexpr int INF = 1<<30;
constexpr ll LINF = 1LL<<60;
constexpr ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }


int n, m, q, a[50], b[50], c[50], d[50];
int ans = 0;
vector<int> v;

void dfs(int i, int x) {
  if(i == n) {
    int res = 0;
    rep(j, q) {
      if(c[j]==v[b[j]]-v[a[j]]) res+=d[j];
    }
    chmax(ans,res);
    return;
  }
  REP(j, x, m+1) {
    v.push_back(j);
    dfs(i+1, j);
    v.pop_back();
  }
}


int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i], a[i]--, b[i]--;
  dfs(0, 1);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3668
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/*
.-.. . -. -.- .- / .. ... / .-.. --- ...- . -.-.--
 */
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    string s, t;
    cin >> s >> t;
    ll cnt = 0;
    for(ll i=0; i<(ll)s.size(); i++)
        cnt += (s[i] != t[i]);
    cout << cnt << endl;
    return 0;
}


signed main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}

/*******************************************************************************/
// Remeber - In a custom comparator cmp(a, b) a==b must always return to false.



Measured memory_bytes: 3740
//package atcoder.beginner179;

import java.io.*;
import java.util.*;

public class Main {
    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args) {
        //initReaderPrinter(true);
        initReaderPrinter(false);
        //solve(in.nextInt());
        solve(1);        
    }

    static void solve(int testCnt) {
        for (int testNumber = 0; testNumber < testCnt; testNumber++) {
            int n = in.nextInt();
            int[] d1 = new int[n], d2 = new int[n];
            for(int i = 0; i < n; i++) {
                d1[i] = in.nextInt();
                d2[i] = in.nextInt();
            }
            int cnt = 0;
            boolean found = false;
            for(int i = 0; i < n; i++) {
                if(d1[i] == d2[i]) {
                    cnt++;
                    if(cnt == 3) {
                        found = true;
                        break;
                    }
                }
                else {
                    cnt = 0;
                }
            }
            out.print(found ? "Yes" : "No");
        }   
        out.close();
    }

    static void initReaderPrinter(boolean test) {
        if (test) {
            try {
                in = new InputReader(new FileInputStream("src/input.in"));
                out = new PrintWriter(new FileOutputStream("src/output.out"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            in = new InputReader(System.in);
            out = new PrintWriter(System.out);
        }
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        InputReader(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream), 32768);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        Integer[] nextIntArray(int n) {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        Long[] nextLongArray(int n) {
            Long[] a = new Long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }
    }
}




Measured memory_bytes: 25612
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
a = na()
ans = sum(a)

import heapq
b = []

for i in a:
    heapq.heappush(b, -i)

for i in range(m):
    k = -(heapq.heappop(b))
    p = k//2
    ans -= (k-p)
    heapq.heappush(b, -p)

print(ans)

Measured memory_bytes: 14372
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CAntiDivision {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            long a = s.nextLong(), b = s.nextLong(), c = s.nextLong(), d = s.nextLong(), lcm = (c * d) / func.gcd(c, d);
            w.println(b - a + 1 - (b / c - (a - 1) / c + b / d - (a - 1) / d - (b / lcm - (a - 1) / lcm)));
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public long nextLong() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }

            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class func {
        public static long gcd(long a, long b) {
            return (b == 0) ? a : gcd(b, a % b);
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
using namespace std;
int main() {
  double N,K,sum=0.0;
  int n,i,j;
  cin>>N>>K;
  for(i=1;i<=N;i++){
    n=i;
    double p=1;
    for(j=1;n<K;j++){
      n*=2;
      p/=2;
    }
    sum+=(double)p/N;
  }
  printf("%.14f\n",sum);
}


Measured memory_bytes: 256
i = int(input())
l = list(map(int,input().split()))

while len(l)!=1:
	l.sort()
	#print(l)
	x = (l[1] + l[0])/2
	if len(l)==2:
		print(x)
		exit()
	l.pop(1)
	l.pop(0)
	l.append(x)

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

int A, B, K;

void print(set<int> S) {
  for(set<int>::iterator it = S.begin(); it != S.end(); it++){
    cout << *it << endl;
  }
}

int main(){
	set<int> S;
	cin >> A >> B >> K;
	for (int i=0;i<K && i + A <= B;i++){
		S.insert(A + i);
	}
	for (int i=K-1;0<=i && B - i >= A;i--){
		S.insert(B - i);
	}
	print(S);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string t;
    cin>>t;
    for(ll i=0;i<t.size();++i){
        if(t[i] == '?'){
            cout<<'D';
        }else{
            cout<<t[i];
        }
    }
    cout<<endl;
}

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

ll ze(ll x,ll y){
    return max(x,y)-min(x,y);
};

int main(){
    int n,l;
    cin >> n >> l;
    int mn=1e9,mn2=1e9;
    int sum=0;
    for(int i=0; i<n; i++){
        if(mn>ze(l+i,0)){
            mn2=l+i;
            mn=ze(l+i,0);
        };
        sum+=l+i;
    }
    cout << sum - mn2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int m,y,n,i,t,u;
double s,r;
double a(){return (double)(1+y*r/100);}
double b(){return pow((double)(1+r/100),y);}

int main()
{
	double(*f[3])();
	f[1]=a;f[2]=b;
	for(;~scanf("%d%d",&n,&y),n;)
	{
		for(i=0,s=0;i<n;i++)
		{
			scanf("%d%lf%d",&m,&r,&t);
			if(s<f[t]())
				s=f[t](),u=m;
		}
		printf("%d\n",u);
	}
	return 0;
}

Measured memory_bytes: 720
// A - AtCoDeerくんとペンキ

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int ans;

	if (a == b && b == c) ans = 1;
	else if (a != b && b != c && c != a) ans = 3;
	else ans = 2;

	cout << ans << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    mat G(N*3);
    REP(i,0,M) {
        ll v, w;
        cin >> v >> w;
        --v; --w;
        G[v*3].eb(w*3+1);
        G[v*3+1].eb(w*3+2);
        G[v*3+2].eb(w*3);
    }
    ll S, T;
    cin >> S >> T;
    S = (S-1)*3; T = (T-1)*3;

    vec D(N*3, -1);
    queue<ll> Q;

    D[S] = 0;
    Q.push(S);
    while(!Q.empty() && D[T] == -1) {
        ll v = Q.front(); Q.pop();
        FORR(nv,G[v]) {
            if(D[nv] == -1) {
                D[nv] = D[v] + 1;
                Q.push(nv);
            }
        }
    }
    PR(D[T]==-1?-1:D[T]/3);


    
    return 0;
}

/*



*/

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)(n); i++)
#define reps(i,s,e) for(int i=s; i<(int)(e); i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int N;
    cin >> N;
    vector<bool> sq(2*N+1, false);
    vector<int> sqn;
    reps(i, 2, std::sqrt(2*N)+0.01+1) {
        sq[i*i] = true;
        sqn.push_back(i*i);
    }
    int sqnlen = sqn.size();
    reps(n, 1, N+1) {
        int count = 0;
        rep(i, sqnlen) {
            reps(j, i, sqnlen) {
                int xy = sqn[i];
                int yz = sqn[j];
                int zx = 2*n - xy - yz;
                
                if (zx >= 2 && zx <= 2*N+1 && sq[zx]) {
                    int xysq = std::floor(std::sqrt(xy) + 0.1);
                    int yzsq = std::floor(std::sqrt(yz) + 0.1);
                    int zxsq = std::floor(std::sqrt(zx) + 0.1);
                    int sum2 = xysq + yzsq + zxsq;
                    // cout << zx << "sum" << sum2 << endl;
                    if (sum2%2 == 0 && sum2/2 - xysq >= 1 && sum2/2 - yzsq >= 1 && sum2/2 - zxsq >= 1) {
                        // cout << n << "ans:" << xy << " " << yz << " " << zx << endl;
                        if (xy != yz) {
                            count += 2;
                        } else {
                            count++;
                        }
                    }
                }
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 3612
def resolve():
    # nCk = n! / n!(n-k)! のテーブル作成
    def COMinit(n, MOD):
        fact = [1, 1]
        fact_inv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
        return fact, fact_inv

    # 二項係数計算
    def Combination(n, k, MOD=998244353):
        # fac, finv = COMinit(n, MOD)
        if n < k: return 0
        if n < 0 or k < 0: return 0
        ret = fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
        return ret

    MOD = 998244353
    N, M, K = map(int, input().split())

    # テーブルを作成し、K回使いまわす
    fac, finv = COMinit(N-1, MOD)

    ans = 0
    for k in range(K+1):
        cmb = Combination(N-1, k)
        m_pow = pow(M-1, (N-k-1), MOD)
        ans += M * m_pow * cmb
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 32940
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=998244353
 

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	if al[0] != 0:
		return 0
	if al.count(0) != 1:
		return 0
	
	alc = collections.Counter(al)
	mm = max(alc.keys())
	
	b = alc.keys()
	b=list(b)
	b.sort()
	if list(range(mm+1)) != b:
		#pa('rrrr')
		return 0
		
	v = 1
	p=1
	for k in range(1, mm+1):
		num = alc[k]
		add = pow(p, num, mod)
		v *= add
		v %= mod
		p = num
	return v
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(){
    int ans=0,ans1=0;
    string s,s1;
    cin >> s;
    s1 = s;
    for(int i = 1;i < s.size();i ++){
        if(s[i]==s[i-1]){
            ans ++;
            s[i] = s[i]=='0'?'1':'0';
        }
    }
    for (int i = s1.size()-2;i >= 0;i --){
        if(s1[i]==s1[i+1]){
            ans1 ++;
            s1[i] = s1[i]=='0'?'1':'0';
        }
    }
    cout << min(ans,ans1) << endl;
    return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

ll solve2(string a) {
  set<string>s;
  int n = size(a);
  rep(i, n + 1)rep(j, i, n + 1) {
    reverse(a.begin() + i, a.begin() + j);
    s.insert(a);
    reverse(a.begin() + i, a.begin() + j);
  }
  return size(s);
}

void Calc() {
  string s = in;
  int n = size(s);
  //cerr << (solve2(s)) << endl;
  ll ans = 1;
  std::array<vector<int>, 26> t{};
  rep(i, 26) {
    t[i].resize(n + 1);
    char c = i + 'a';
    rep(j, n)if (s[j] != c)t[i][j]++;
  }
  rep(i, 26)rep(j, n)t[i][j + 1] += t[i][j];
  rep(i, n) {
    ans += t[s[i] - 'a'][n] - t[s[i] - 'a'][i];
  }
  cout << (ans) << endl;
}


Measured memory_bytes: 21012
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;



int main(){
    Init();
    // 入力(0-Based)
    ll h, w, k;
    cin >> h >> w >> k; k--;

    if(w == 1){
        cout << 1 << endl;
        return 0;
    }

    // 2^wroot[i][j]; i列目からj列目に行ける本数
    vvi root(w+1, vi(w+1, 0));
    for(ll i=0; i<(1LL<<w-1); i++){
        vi line(w-1, 0);
        for(ll m=0; m<w-1; m++){
            if(i&(1LL<<m)){
                if(m == 0) line[m] = 1;
                else if(line[m-1] == 0) line[m] = 1;
                else{
                    line[0] = INFLL;
                    break;
                }
            }
        }
        if(line[0] == INFLL) continue;
        for(ll m=0; m<w-1; m++){
            if(line[m] == 1){
                root[m][m+1]++;
                root[m+1][m]++;
            }
            else{
                if(m == 0) root[m][m]++;
                else{
                    if(m == w-2) root[w-1][w-1]++;
                    if(line[m-1] == 0) root[m][m]++;
                }
            }
        }
    }

    // dp[i][j]; i行j列にいる場合の数
    vvi dp(h+2, vi(w+2, 0)); dp[0][0]++;
    for(ll i=0; i<=h; i++){
        for(ll j=0; j<=w; j++){
            dp[i+1][j] += (dp[i][j]*root[j][j])%MODV;
            dp[i+1][j+1] += (dp[i][j]*root[j][j+1])%MODV;;
            if(j != 0) dp[i+1][j-1] += (dp[i][j]*root[j][j-1])%MODV;
        }
    }
    cout << dp[h][k]%MODV << endl;
}

Measured memory_bytes: 3668
#include<stdio.h>
a,b,c,r,l;int main(){
	for(;scanf("%d,%d,%d",&a,&b,&c)!=EOF;){
		if(a*a+b*b==c*c)r++;else if(a==b)l++;
	}
	printf("%d\n%d\n",r,l);exit(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
bool chk(char x) {
    return x=='A' || x=='T' || x=='G' || x=='C';
}
int main()
{
    char in[200];
    while (~scanf("%s", in+1)) {
        int n = strlen(in+1);
        int ans = 0;
        REP(i,1,n) if(chk(in[i])) {
            int j = i;
            while (j+1<=n && chk(in[j+1])) j++;
            ans = max(ans, j-i+1);
        }
        printf("%d\n", ans);
    }
    
    return 0;
}




Measured memory_bytes: 256