akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int h,w,k; cin >> h >> w >> k;
    vector<string> s(h); rep(i,h) cin >> s[i];

    vector<vector<int>> a(h,vector<int>(w,-1));
    int num = 0;
    rep(i,h){
        int cnt = 0;
        rep(j,w) if(s[i][j]=='#') cnt++;

        if(cnt==0){
            if(i==0) rep(j,w) a[i][j] = -1;
            else rep(j,w) a[i][j] = a[i-1][j];
        }else{
            rep(j,w){
                if(s[i][j]=='#') num++;
                a[i][j] = num;
            }
            rep(j,w){
                if(s[i][j]=='#') break;
                a[i][j]++;
            }
        }
    }

    rrep(i,h) rep(j,w){
        if(a[i][j]==-1) a[i][j] = a[i+1][j];
    }

    rep(i,h){
        rep(j,w){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()
S = sum(A)
if (S % 10 != 0):
  print(S)
else:
  flag = False
  for j in range(N):
    if ((S-A[j]) % 10 != 0):
      flag = True
      break
  if flag:
    print(S-A[j])
  else:
    print(0)

Measured memory_bytes: 3060
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, mid, sub[MAXN];

ll sol;

vector <pii> v[MAXN];

void dfs(int cvor, int p) {
  sub[cvor]++;

  for (auto N : v[cvor]) {
    int ncvor = N.fi;
    int x = N.sec;
    if (ncvor == p) continue;
    dfs(ncvor, cvor);
    sub[cvor] += sub[ncvor];
    if (sub[ncvor] == n / 2 && n % 2 == 0) {
      mid = x;
    }
    sol += (ll)min(sub[ncvor],n - sub[ncvor]) * 2 * x;
  }
}

int main() {
  scanf("%d",&n);
  REP(i, n - 1) {
    int a, b, c;
    scanf("%d %d %d",&a,&b,&c);
    v[a].push_back({b, c});
    v[b].push_back({a, c});
  }

  dfs(1, -1);
  if (mid) {
    cout << sol - mid << endl;
    return 0;
  }

  FOR(cvor, 1, n + 1) {
    if (n - sub[cvor] > n / 2) continue;
    int x = - 1;
    for (auto t : v[cvor]) {
      if (sub[t.fi] > sub[cvor]) {
        if (x == -1) x = t.sec;
        else x = min(x, t.sec);
        continue;
      }
      else if (sub[t.fi] > n / 2) {
        x = -1;
        break;
      }
      if (x == -1) x = t.sec;
      else x = min(x, t.sec);
    }
    if (x != -1) {
      cout << sol - x << endl;
      return 0;
    }
  }
  assert(0);
  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0;
  string a,b,c;
  cin >> n >> a >> b >> c;
  for(int i=0;i<n;i++){
    map<char, int> mp;
    mp[a[i]]++;
    mp[b[i]]++;
    mp[c[i]]++;
    ans+=3-max(mp[a[i]], max(mp[b[i]], mp[c[i]]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()

int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.len;
    int m=t.len;
    int dp[n][m];
    forl(i,0,n) forl(j,0,m) dp[i][j]=0;

    int maxn=n+1;
    int maxm=m+1;
    forl(i,0,n){
        if(s[i]==t[0])
        {
            maxn=i;
            break;
        }
    }

    forl(i,0,m){
        if(t[i]==s[0])
        {
            maxm=i;
            break;
        }
    }


    forl(i,maxn,n)
    {
        dp[i][0]=1;
    }

    forl(i,maxm,m)
    {
        dp[0][i]=1;
    }
    forl(i,1,n)
    {
        forl(j,1,m) 
        {
            if(s[i]==t[j]) dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
         }
    }
    //cout<<dp[n-1][m-1]<<endl;
    int i=n-1,j=m-1;
    vector<char>v;
    while(i>=0 && j>=0)
    {
        if(i==0){
            if(dp[i][j])v.pb(s[i]);
            break;
        }
        if(j==0)
        {
            if(dp[i][j])v.pb(t[j]);
            break;
        }
        if(s[i]==t[j])
        {
            if(dp[i-1][j-1]+1==max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]))) 
            {
                v.pb(s[i]);
                i--;
                j--;

            }else if(dp[i-1][j]==max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1])))
            {
                i--;
            }else j--;
        }
        else 
        {
            if(dp[i-1][j]==max(dp[i-1][j],dp[i][j-1])) 
            {
                i--;
            }else j--;
        }
    }

    rfor(i,v.si-1,0) cout<<v[i];
    cout<<endl;
}


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

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

  vector<int> p(N);

  for (int i = 0; i < N; i++)
  {
    cin >> p.at(i);
  }

  int ans = 0;

  for (int i = 1; i < N - 1; i++)
  {
    if (p.at(i) != max({p.at(i - 1), p.at(i), p.at(i + 1)}) && p.at(i) != min({p.at(i - 1), p.at(i), p.at(i + 1)}))
    {
      ans++;
    }
  }

  cout << ans << endl;
}


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

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<llint> v;

int calc_digits(llint x){
	llint ret=0;
	while(x){
		ret++;
		x/=10;
	}
	return ret;
}

void solve(){
	llint n;
	cin >> n;
	int ans=(1<<29);
	for(llint i=1;i*i<=n;i++){
		if(n%i==0){
			llint B=n/i;
			int F=max(calc_digits(i),calc_digits(B));
			ans=min(ans,F);
		}
	}
	cout << ans << endl;
}

int main() {
  solve();
  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 repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout<<s<<endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}


int main()
{
    string s;
    int cnt0=0,cnt1=0;
    cin>>s;
    rep(i,s.size()){
        if(s[i]=='0')cnt0++;
        else cnt1++;
    }
    if(cnt0>=cnt1){
        cout<<cnt1*2<<endl;
    }else{
        cout<<cnt0*2<<endl;
    }
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  
  int n;
  cin>>n;
  int rem =0;
  rem = n%10;
  if (rem==3){
    cout<<"bon";
  }
  else if (rem==0||rem==1||rem==6||rem==8){
    cout<<"pon";
  }
  else {
    cout<<"hon";
  }
}

Measured memory_bytes: 3608
#include <stdio.h>

int main() {
    long long num;
    long long count = 1;
    unsigned long long a = 0;
	scanf("%lld", &num);
	while (num) {
		a += count;
		count <<= 1;
		num >>= 1;
	}
	printf("%lld", a);
    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict

N, M = map(int, input().split())

ac = set()
wa = defaultdict(int)
ttl_wa = 0

for _ in range(M):
    pi, st = input().split()
    pi = int(pi)

    if st == 'AC':
        if pi not in ac:
            ac.add(pi)
            ttl_wa += wa[pi]
    else: # st == 'WA'
        wa[pi] += 1

print(len(ac), ttl_wa)


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

using namespace std;

#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

int main(){
  int a, b, h, m;

  cin >> a >> b >> h >> m;
  cin.ignore();

  long double theta_m, theta_h;
  theta_m = m / (long double)60 * M_PI * 2;
  theta_h = (h / (long double)12 + m / (long double) 12 / 60) * M_PI * 2;
  long double result = sqrtl((b * sin(theta_m) - a * sin(theta_h)) * (b * sin(theta_m) - a * sin(theta_h)) + (b * cos(theta_m) - a * cos(theta_h)) * (b * cos(theta_m) - a * cos(theta_h)));
  std::printf("%.100Lf\n", result);

  return 0;
}
    
  


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

int main()
{
int n,i,j,k;
ll ans=0;
cin>>n;
int a[n+1],b[n];
for(i=0;i<=n;i++)
    cin>>a[i];
for(i=0;i<n;i++)
    cin>>b[i];
int crry=0;
if(b[0]>a[0])
    crry=b[0]-a[0];
ans=min(a[0],b[0]);

    //cout<<ans<<endl;
for(i=1;i<n;i++)
{

    ans+=min(a[i],crry+b[i]);
//cout<<ans<<endl;
  crry=b[i]-max(0,(a[i]-crry));
  crry=max(0,crry);
}

    ans+=min(a[n],crry);
cout<<ans<<endl;

return 0; }


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

using namespace std;

int main ()
{
	int N;
	while( cin >> N )
	{
		int count = 0;
		bool f = true;
		while( N )
		{
			if( N % 2 )
			{
				if( f )
				{
					f = false;
				} else
				{
					cout << " ";
				}
				cout << (int) pow ( 2 , count );
			}
			N >>= 1;
			count++;
		}
		cout << endl;
	}
}

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

long long calc(const vector<long long>& v)
{
  long long res = 0;
  for (auto it = v.rbegin(); it != v.rend(); it++) {
    res = 10 * res + *it;
  }
  return res;
}

bool is_valid_number(const vector<long long>& v)
{
  for (auto x : v) {
    if (10 <= x) {
      return false;
    }
  }
  return true;
}

int main()
{
  long long k;
  cin >> k;
  long long ndigit = 1;
  vector<long long> v(10);
  v.at(0) = 1;
  for (int times = 2; times <= k; times++) {
    int d = 0;
    while (d+1 < ndigit) {
      if (v.at(d) == 9) {
        d++;
        continue;
      }
      if (abs(v.at(d)+1 - v.at(d+1)) <= 1) {
        break;
      }
      d++;
    }
    if (v.at(d) == 9) {
      v.at(ndigit) = 1;
      for (int i = 0; i < ndigit; i++) {
        v.at(i) = 0;
      }
      ndigit++;
    } else {
      v.at(d)++;
      for (int i = d-1; 0 <= i; i--) {
        v.at(i) = max(0LL, v.at(i+1) - 1);
      }
    }
    //cout << calc(v) << '\n';
    //assert(is_valid_number(v));
  }

  cout << calc(v) << '\n';

  return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	if(n%2){
		co(0);
		return 0;
	}

	n /= 2;
	ll ans = 0;
	while(n){
		n /= 5;
		ans += n;
	}
	co(ans);

	return 0;
}


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

using namespace std;

int n,a[101][101],sum[101][101];

int main(void){
	
	cin >> n;

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)cin >> a[i][j];

	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			sum[i][j]=a[i][j]+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];

	int ans=-10000000;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=i;k++)
				for(int l=1;l<=j;l++)
					ans=max(ans,sum[i][j]-sum[k-1][j]-sum[i][l-1]+sum[k-1][l-1]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1240
/*input
3 3 3
###
#S#
###
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=805;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

string s[maxn];
int sx,sy;
vector<pii> q;
int pt=0;
int d[maxn][maxn];


int main()
{
	IOS;
	int n,m,k;
	cin>>n>>m>>k;
	REP(i,n) cin>>s[i];
	REP(i,n) REP(j,m) if(s[i][j]=='S') sx=i,sy=j;
	REP(i,n) REP(j,m) d[i][j]=-1;
	q.pb(MP(sx,sy));
	d[sx][sy]=0;
	while(pt<SZ(q)){
		pii cur=q[pt++];
		int meow=d[cur.F][cur.S];
		if(cur.F+1<n){
			cur.F++;
			if(d[cur.F][cur.S]==-1&&s[cur.F][cur.S]=='.'){
				d[cur.F][cur.S]=meow+1;
				q.pb(cur);
			}
			cur.F--;
		}
		if(cur.S+1<m){
			cur.S++;
			if(d[cur.F][cur.S]==-1&&s[cur.F][cur.S]=='.'){
				d[cur.F][cur.S]=meow+1;
				q.pb(cur);
			}
			cur.S--;
		}
		if(cur.F>0){
			cur.F--;
			if(d[cur.F][cur.S]==-1&&s[cur.F][cur.S]=='.'){
				d[cur.F][cur.S]=meow+1;
				q.pb(cur);
			}
			cur.F++;
		}
		if(cur.S>0){
			cur.S--;
			if(d[cur.F][cur.S]==-1&&s[cur.F][cur.S]=='.'){
				d[cur.F][cur.S]=meow+1;
				q.pb(cur);
			}
			cur.S++;
		}
	}
	int ans=INF;
	REP(i,n) REP(j,m){
		if(d[i][j]==-1||d[i][j]>k) continue;
		ans=min(ans,1+(min({i,j,n-1-i,m-1-j})+k-1)/k);
	}
	cout<<ans<<'\n';
	return 0;
}


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

P = list(map(int, input().split()))
P_sort = sorted(P)
cnt = 0

for i in range(len(P)):
    if P[i] != P_sort[i]:
        cnt += 1

if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d){
    cout << "Left" << endl;
  }
  else if (a + b == c + d){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#define ENABLE_DEBUG 0
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmn=[](auto&x,auto y){if(x>y){x=y;return true;}return false;};
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u64 inf = numr<u64>::max();

    usize T;
    std::cin >> T;
    while (T--) {
        u64 n, a, b, c, d;
        std::cin >> n >> a >> b >> c >> d;

        vec<std::pair<u64, u64>> data {
            {2, a},
            {3, b},
            {5, c},
        };

        std::map<u64, u64> map;
        auto cal = [&](auto&& f, u64 x) -> u64 {
            if (x==0) return 0;
            if (auto it=map.find(x); it!=map.end()) {
                return it->second;
            }
            DEBUG(x);
            u64 ans = inf;
            if (x <= inf/d) cmn(ans, x*d);

            for (auto[p, cost]: data) {
                u64 q = x / p;
                u64 r = x % p;
                cmn(ans, r*d + cost + f(f,q));
                if(x!=q+1) cmn(ans, (p-r)*d + cost + f(f,(q+1)));
            }
            return map[x] = ans;
        };

        u64 ans = cal(cal, n);
        DEBUG(map);

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


Measured memory_bytes: 4860
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if i == 0 or j == 0 or i == H-1 or j == W-1:
                    print('#', end='')
                else:
                    print('.', end='')
            print()
    print()


Measured memory_bytes: 7000
import itertools
x=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
s=list(itertools.permutations(list(range(1,x+1,1))))
for i in range(len(s)):
    if s[i]==p:
        pp=i
    if s[i]==q:
        qi=i
print(abs(pp-qi))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000007
#define F first
#define S second
typedef pair<int,int> P;
int main()
{
	int n,m,s;
	int a,b,c;
	int i,j,k,mn,pp;
	
	cin>>n>>m>>s;
	int d[n];
	vector<P> v[n];
	
	for(i=0;i<m;i++){
		cin>>a>>b>>c;
		v[a].push_back(P(b,c));
	}

	priority_queue<P, vector<P>, greater<P> >que;
	fill(d,d+n,mx);
	d[s]=0;
	que.push(P(0,s));
	
	while(!que.empty()){
	
		P p=que.top(); que.pop();
		int x=p.S;
		if(d[x]<p.F) continue;
		for(i=0;i<v[x].size();i++){
			P z=v[x][i];
			if(d[z.F]>d[x]+z.S){
				d[z.F]=d[x]+z.S;
				que.push(P(d[z.F],z.F));
			}
		}
	}	

	for(i=0;i<n;i++){
		if(d[i]==mx) cout<<"INF"<<endl;
		else cout<<d[i]<<endl;
	}
	return 0;
}	


Measured memory_bytes: 13012
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  //input
  int N, T;
  cin >> N >> T;
  /*
  vector <int> c(N);
  vector <int> t(N);
  rep(i,N) cin >> c[i] >> t[i];
  */

  //solve
  int MAX = 1 << 30;  //2の30乗
  int ans = MAX;  //コスト

  rep(i,N){
    int c, t;
    cin >> c >> t;
    if (t <= T) ans = min(ans, c);
  }
  if (ans < MAX) cout << ans << endl;
  else cout << "TLE" << endl;
}


Measured memory_bytes: 3632
import sys
N=int(input())

if N==2:
  print(1)
  sys.exit(0)

answer_set=set()
for i in range(2,int(N**0.5)+1):
  N2=N
  while N2%i==0:
    N2//=i
  if N2%i==1:
    answer_set.add(i)
#print(answer_set)

for i in range(1,int(N**0.5)+1):
  if (N-1)%i==0:
    answer_set.add((N-1)//i)    
#print(answer_set)

answer_set.add(N)
print(len(answer_set))

Measured memory_bytes: 64372
n = int(input())
s = [int(input()) for i in range(n)]
ans=0
m = sum(s)
if m%10==0:
    f = True
    s.sort()
    for si in s:
        if si%10!=0:
            print(m-si)
            f = False
            break
    if f:
        print(0)
else:
    print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }
ll INF = 1e15;
struct SegmentTree {
private:
    ll n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v) {
        ll sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(ll i=0; i<sz; i++) node[i+n-1] = v[i];
        for(ll i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(ll x, ll val) {
        x += (n - 1);
        node[x] = val;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    ll getmin(ll a, ll b, ll k=0, ll l=0, ll r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];

        ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main(){
    ll n, x; cin>>n>>x;
    vector<ll> a(n);
    rep(i, n) cin>>a[i];
    SegmentTree seg(a);
    ll res=1e15;
    for(ll i=0; i<n; i++){
        ll tmp = x*i;
        rep(j, n){
            if(j<i){
                tmp += min(seg.getmin(0, j+1), seg.getmin(n+j-i, n));
            }else{
                tmp += seg.getmin(j-i, j+1);
            }
        }
        chmin(res, tmp);
    }
    cout<<res<<endl;
    return 0;
}

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

if n == 2:
    b, c = map(int, input().split())
    print((b + c) / 2)
else:
    s = list(map(int, input().split()))
    s.sort()
    k = s[0] / 2 ** (n - 1)
    for i in range (1, n):
        k = k + s[i] / 2 ** (n - i)
    
    print(k)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2e5 + 5;
const int oo = 1e9 + 5;

int a[N];

void solve() {
	ll x;
	cin >> x;
	cout << ((x / 500) * 1000) + ((x % 500) / 5) * 5;	
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way.” Naruto
*/

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,n,d=0;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]!=i+1){
      d++;
    }
  }
  if(d==0||d==2){
    printf("YES");
  }
  else{
    printf("NO");
  }
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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 int ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    ll ga,sa,ba;
    cin >> ga >> sa >> ba;
    ll gb,sb,bb;
    cin >> gb >> sb >> bb;

    vector<ll> dp(N+1,0);

    // A → B
    REP(x,N+1){
        dp[x] = x;
        if(x-ga >= 0) chmax(dp[x],dp[x-ga]+gb);
        if(x-sa >= 0) chmax(dp[x],dp[x-sa]+sb);
        if(x-ba >= 0) chmax(dp[x],dp[x-ba]+bb);
    }

    // B → A
    ll M_N = dp[N];
    vector<ll> dp2(M_N+1,0);
    REP(x,M_N+1){
        dp2[x] = x;
        if(x-gb >= 0) chmax(dp2[x],dp2[x-gb]+ga);
        if(x-sb >= 0) chmax(dp2[x],dp2[x-sb]+sa);
        if(x-bb >= 0) chmax(dp2[x],dp2[x-bb]+ba);
    }

    pl(dp2[M_N])

    return 0;
}

Measured memory_bytes: 195584
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int main(){
    ll N;
    vector<ll> hito;
    cin >> N;
    rep(i, 0, N){
        ll tempa, tempb;
        cin >> tempa >> tempb;
        hito.push_back(tempb - tempa + 1);
    }

    cout << accumulate(begin(hito), end(hito), 0) << endl;;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>    
#include <cmath>
#include <map>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <set>
#include <functional>
#define int long long
#define mod(int)(1000000007)
using namespace std;
const int INF = 1000000000000000;
int cnt[345678], test[345678];
signed main() {
	int n, a, sum = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; cnt[a]++; test[h] = a;
	}
	for (int h = 0; h <= n; h++) {
		if (cnt[h] != 0) {
			sum += cnt[h] * (cnt[h] - 1) / 2;
		}
	}
	for (int h = 0; h < n; h++) {
		cout << sum - (cnt[test[h]] * (cnt[test[h]] - 1) / 2) + ((cnt[test[h]] - 1) * (cnt[test[h]] - 2) / 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
int main(){
  string s,t; cin >> s >> t;
  ll ans=0;
  rep(i,3){
    if(s[i]==t[i]) ans++;
  }
  cout << ans;
  return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

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

  int a, b, c, x; cin >> a >> b >> c >> x;
  int cnt = 0;
  for(int i=0;i<=a;++i) {
    for(int j=0;j<=b;++j) {
      for(int k=0;k<=c;++k) {
        cnt += x == i * 500 + j * 100 + k * 50;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
D, X = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

et = 0
for a in A:
    et += (D-1)//a[0] + 1
print(et+X)


Measured memory_bytes: 38256
N=int(input())
Ax = map(int,input().split())
Q=int(input())

t=[0]*(10**5+1)
s = 0
for a in Ax:
    t[a] += 1
    s += a

for _ in range(Q):
    b,c=map(int,input().split())
    s += t[b]*c
    s -= t[b]*b
    t[c] += t[b]
    t[b] = 0
    print(s)

Measured memory_bytes: 17356
#include <bits/stdc++.h>
using namespace std;
static const int INF = 2000000000;
static const int NIL = -1;

static const int MAX = 50000;


int main(){
    int n,m;
    int C[21];
    int T[MAX+1];

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

    for(int i=0;i<m;i++) scanf("%d",&C[i]);

    for(int i=0;i<=MAX+1;i++) T[i] = INF;

    //printf("%d\n",T[n]);

    T[0] = 0;

    for(int i=0;i<m;i++){
        for(int k=0;k+C[i]<=n;k++){
            T[k+C[i]] = min(T[k+C[i]],T[k]+1);
        }
    }

    printf("%d\n",T[n]);

    return 0;
}

Measured memory_bytes: 3400
#include <iostream>
#include <string>

using namespace std;

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

	int digits = 0;

	for (int i = 1; i <= n; i++)
	{
		if (i >= 1 && i <= 9)
			digits += 1;

		if (i >= 100 && i <= 999)
			digits += 1;

		if (i >= 10000 && i <= 99999)
			digits += 1;

		if (i >= 1000000 && i <= 9999999)
			digits += 1;
	}

	cout << digits;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt();
			String s = scanner.next();
			System.out.println(s.matches("[0-9]{" + a + "}-[0-9]{" + b + "}") ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 39112
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Job[] jobs = new Job[n];
        PriorityQueue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());
        for(int i = 0; i<n; i++) jobs[i] = new Job(sc.nextInt(), sc.nextInt());

        Arrays.sort(jobs, (ac, bc)->(ac.a - bc.a));
        long cnt = 1;
        long ans = 0;
        for(int i = 0; i<n; i++) {
            if(jobs[i].a == cnt) queue.add(jobs[i].b);
            else {
                while(jobs[i].a != cnt && cnt<=m) {
                    if (queue.size() != 0) ans += (long)queue.poll();
                    System.err.println("ans = " +cnt+" "+ ans);
                    cnt++;
                }
                queue.add(jobs[i].b);
            }
        }
        //System.err.println("day = " + cnt);
        while(cnt<=m && queue.size()!=0) {
            ans+= (long)queue.poll();
            System.err.println("ans = " + ans);
            cnt++;
        }

        System.out.println(ans);

    }
}
class Job {
    int a,b;
    public Job(int a, int b) {
        this.a = a;
        this.b = b;
    }
}

Measured memory_bytes: 96600
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

from collections import deque

h,w = ip()
ax,ay = ip()
bx,by = ip()
ax -= 1; ay -= 1; bx -= 1; by -= 1
mat = [input().strip() for i in range(h)]
dist = [[float('inf')]*w for i in range(h)]
dist[ax][ay] = 0
dx,dy = [1,-1,0,0],[0,0,-1,1]
dq = deque()
dq.append([ax,ay])
while dq:
    cx,cy = dq.popleft()
    for i in range(4):
        nx,ny = cx+dx[i], cy+dy[i]
        if 0 <= nx < h and 0 <= ny < w and mat[nx][ny] == '.':
            if dist[nx][ny] > dist[cx][cy]:
                dist[nx][ny] = dist[cx][cy]
                dq.appendleft([nx,ny])
    for i in range(cx-2,cx+3):
        for j in range(cy-2,cy+3):
            if 0 <= i < h and 0 <= j < w and mat[i][j] == '.':
                if dist[i][j] > dist[cx][cy]+1:
                    dist[i][j] = dist[cx][cy]+1
                    dq.append([i,j])
if dist[bx][by] == float('inf'): dist[bx][by] = -1
print(dist[bx][by])


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;
bool used[333333];

int main(){

	ll n,l;cin >> n >> l;
	ll ans = 0;
	bool is10 = false;
	vector<ll> x(n);REP(i,n)cin >> x[i];
	vector<pair<ll,ll>> t;
	REP(i,n){
		ll tmp;
		cin >> tmp;
		ans +=  tmp - (tmp % (2*l));
		tmp %= 2 * l;
		if(tmp == 0){
			t.PB(MP(1,1));
			used[i] = true;
			is10 = false;
		}
		else{
			int a,b;
			if(2 * (l - x[i]) >= tmp)a = 0;
			else a = 1;
			if(2 * x[i] >= tmp)b = 0;
			else b = 1;
			t.PB(MP(a,b));
			ans += l;
			if(a == 0 && b == 1)is10 = true;
			else is10 = false;
		}
	}

	DBG(
	cout << "first " << ans << endl;
	REP(i,n)cout << t[i].FI << " " << t[i].SE << endl;
	)

	int pla = -1;
	queue<int> q;
	REP(i,n){
		if(t[i] == pair<ll,ll>(0,0)){
			q.push(i);
		}
		if(t[i] == pair<ll,ll>(0,1)){
			if(q.size()){
				used[q.front()] = true;
				used[i] = true;
				q.pop();
				pla = i;
			}
		}
	}

	if(pla != -1 && is10)REP(i,n){
		if(used[i] == false && pla > i && t[i] == pair<ll,ll>(0,0)){
			used[i] = true;
			used[pla] = false;
			break;
		}
	}

	while (q.size())q.pop();
	REP(i,n){
		if(used[i])continue;
		if(t[i] == pair<ll,ll>(1,0)){
			q.push(i);
		}
		if(t[i] == pair<ll,ll>(0,0)){
			if(q.size()){
				used[q.front()] = true;
				used[i] = true;
				q.pop();
			}
		}
	}

	while (q.size())q.pop();
	REP(i,n){
		if(used[i])continue;
		if(t[i] == pair<ll,ll>(0,0)){
			if(q.size()){
				used[q.front()] = true;
				used[i] = true;
				q.pop();
			}
			else{
				q.push(i);
			}
		}
	}

	DBG(
	cout << "second " << ans << endl;
	REP(i,n)if(!used[i])cout << t[i].FI << " " << t[i].SE << endl;
	)

	bool flag = false;
	REP(i,n){
		if(!used[i]){
			ans += l;
		}
		if(!used[i] && t[i].FI == 0 && t[i].SE <= 1)flag = false;
		else flag = true;
	}

	if(flag)ans += l;
	else ans -= l;
	if(ans % (2*l))ans += l;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 13164
def hamming_dist(str1,str2):
    count = 0
    if len(str1) > len(str2):
        str_data1 = str1[:]
        str_data2 = str2[:]
    elif len(str1) < len(str2):
        str_data1 = str2[:]
        str_data2 = str1[:]
    else:
        str_data1 = str1[:]
        str_data2 = str2[:]
    for i in range(len(str_data2)):
        if str_data1[i] != str_data2[i]:
            count += 1
    for i in range(len(str_data1)-len(str_data2)):
        count += 1

    return count
p = input()
q = input()
print(hamming_dist(p, q))

Measured memory_bytes: 9532
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

  struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[], int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }else{
      A[k]=R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t=A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit) stable=0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 2952
#include<iostream>
using namespace std;
int n,h[100000],k[100000]={0},a=1;
int ans=-1,m=0;
int main(void){
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];
	for(int i=0;i<n-1;i++)if(h[i]>=h[i+1])k[i]=1;
//	for(int i=0;i<n;i++)cout<<k[i]<<' ';
//	cout<<endl;
	for(int i=0;i<n;i++){
		if(a){
			if(!k[i]){a=0;ans=max(ans,m);continue;}
			m++;
		}
		else if(k[i]){a=1;m=1;}
	}
	cout<<ans;
	return 0;
} 

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


int main(){
    int n;
    cin>>n;
    long long x,a[n];
    cin>>x;
    long long ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>x) ans+=a[i]-x,a[i]=x;
        if(i && a[i]+a[i-1]>x){
            long long t=a[i]+a[i-1]-x;
            ans+=t;
            if(t<a[i]) a[i]-=t;
            else a[i]=0;
        }
    }

    cout<<ans;



}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;
const double PI=acos(-1);

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

typedef complex<double> Point;

int main()
{
	for(int n;cin>>n && n;){
		double r,t; cin>>r>>t; t=t*PI/180;
		vector<Point> ps(n);
		rep(i,n){
			int x,y; cin>>x>>y;
			ps[i]=Point(x,y);
		}
		
		vvd d(n,vd(n));
		rep(i,n) rep(j,n)
			d[i][j]=abs(ps[j]-ps[i]);
		vvvi g(n,vvi(n));
		rep(i,n) rep(j,n) if(j!=i) rep(k,n) if(k!=j){
			Point d1=ps[j]-ps[i],d2=ps[k]-ps[j];
			if(abs(arg(d2/d1))<t)
				g[i][j].push_back(k);
		}
		
		queue<tuple<int,int,double>> q; // (prev,cur,len)
		repi(i,1,n) if(d[0][i]<r) q.emplace(0,i,d[0][i]);
		for(int c=0;;c++){
			if(q.empty()){
				cout<<c<<endl;
				break;
			}
			vvd cand(n,vd(n,INF));
			while(q.size()){
				int prev,cur; double len;
				tie(prev,cur,len)=q.front(); q.pop();
				if(len>r) continue;
				for(int next:g[prev][cur])
					cand[cur][next]=min(cand[cur][next],len+d[cur][next]);
			}
			rep(i,n) rep(j,n) if(cand[i][j]<r)
				q.emplace(i,j,cand[i][j]);
		}
	}
}

Measured memory_bytes: 1440
#include <iostream>
#include <unordered_map>
#include <algorithm>

#define ll long long

using namespace std;
int n, t, ans;
bool flag = true;

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> t;
        if (t == i) ans += flag, flag = !flag; else flag = true;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
cnt = 0

for i in range(N//2):
    if S[i] != S[-1-i]:
        cnt += 1

print(cnt)

Measured memory_bytes: 61932
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N;	cin>>N;
	int ans;
	string s;
	rep(i,N,1000){
		s=to_string(i);
		if(s[0]==s[1]&&s[1]==s[2]) break;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,l,m,n;
    cin>>n;
    m=0;
    while(n--)
    {
        cin>>i>>j>>k;
        l=j+k;

        if(l<=i)
        {
            if((l%2==1&&i%2==0)||(l%2==0&&i%2==1))
            {
                m=1;
            }

        }
        else
            m=1;
    }
    if(m==1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


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

int main(void){
    int prcSum=0, numSum=0;
    int times=0;
    int prc,num;
    int numAv;
    
    while (scanf("%d,%d", &prc, &num)!=EOF){
        prcSum += prc*num;
        numSum += num;
        times++;
    }
    numAv = floor((double)numSum/times + 0.5);
    printf("%d\n%d\n", prcSum, numAv);
    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int e = 0;
	for(char i:s) {
		if(i == 'o') e++;
	}
	cout << 700 + 100 * e << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, m, a[2000], b[2000], c[2000];
double sum[2010], e[3][2010], dp[4][2010];

void calc(double *e, int *v, int bonus){
	rep(i, m + 1){
		double dp[4] = {}, p = 1;
		dp[0] = 1;
		for(int j = 1; j < n; j++){
			int need = (v[0] * i + v[j] - 1) / v[j] - 1;
			double w = need < 0 ? 0 : sum[min(m, need)];
			
			p *= 1 - w;
			for(int k = 2; k >= 0; k--){
				dp[k + 1] += dp[k] * (1 - w);
				dp[k] *= w;
			}
		}
		e[i] = (dp[0] + dp[1] + dp[2]) * bonus - p;
	}
}

int main(){
	cin >> n >> m;
	sum[0] = 1;
	rep(i, m) for(int j = i; j >= 0; j--){
		sum[j + 1] += sum[j] / 3;
		sum[j] *= 2 / 3.0;
	}
	rep(i, m) sum[i + 1] += sum[i];
	
	rep(i, n) cin >> a[i] >> b[i] >> c[i];
	calc(e[0], a, 5);
	calc(e[1], b, 3);
	calc(e[2], c, 2);
	
	rep(i, 4) rep(j, m + 1) dp[i][j] = -INF;
	dp[0][0] = 0;
	rep(i, 3) rep(j, m + 1) if(dp[i][j] > -INF){
		rep(k, m - j + 1) dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + e[i][k]);
	}
	printf("%.9f\n", dp[3][m]);
	
	return 0;
}

Measured memory_bytes: 1328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        for(int i = 0; i <= 1250; i++){
            if((int) (i * 0.08) == a && (int) (i * 0.1) == b){
                System.out.println(i);
                System.exit(0);
            }
        }
        System.out.println(-1);
    }
}

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

int main() {
  string S;
  cin >> S;
  int N;
  if (S == "SSS")
    N = 0;
  if (S == "RSS")
    N = 1;
  if (S == "SRS")
    N = 1;
  if (S == "SSR")
    N = 1;
  if (S == "RRS")
    N = 2;
  if (S == "SRR")
    N = 2;
  if (S == "RSR")
    N = 1;
  if (S == "RRR")
    N = 3;
  cout << N << endl;
}


Measured memory_bytes: 3620