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

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i < (int)vec.size(); ++i) {
        os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
void dump_func() {
    cerr << "\n";
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) == 0) {
        cerr << " ";
    } else {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" << to_string(__LINE__) << "]"        \
                       << "    " << string(#__VA_ARGS__) << " = ", \
                  dump_func(__VA_ARGS__)

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()
#define CAUTO const auto&

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI p(n);
    REP(i, n)
    cin >> p[i];
    int ans = 0;
    FOR(i, 1, n - 2) {
        if ((p[i - 1] < p[i] && p[i] <= p[i + 1]) || (p[i + 1] < p[i] && p[i] <= p[i - 1])) {
            ans++;
        }
    }
    cout << ans << ln;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c; cin >> a >> b >> c;
  if(c-a-b < 0) cout << "No" << endk;
  else cout << (4*a*b < (c-a-b)*(c-a-b) ? "Yes" : "No") << endk;
  return 0;
}


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


int main()
{
	int n,r,i;

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

	if(n<10)
	{
		i = r + 100*(10-n);
	}else{
		i = r;
	}

printf("%d",i);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	int k, s;
	int xmin, xmax, x;
	int ymin, ymax;
	int res = 0;
	scanf("%d %d", &k, &s);
	xmin = s - 2 * k;
	if(xmin < 0) xmin = 0;
	xmax = k;
	if(s < xmax) xmax = s;
	for(x = xmin; x <= xmax; x++){
		ymin = s - x - k;
		if(ymin < 0) ymin = 0;
		ymax = k;
		if(s - x < k) ymax = s - x;
		res += ymax - ymin + 1;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
    int k,n;
    int a[200000];
    
    cin >> k >> n;
    for (int i = 0;i < n;i++){
        cin >> a[i];
    }
    int ans = a[n-1]-a[0];
    for (int i = 1;i < n;i++){
        if (k-a[i]+a[i-1] < ans){
            ans = k-a[i]+a[i-1];
        }
    }
    cout << ans << endl;
}


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

#define int long long

using namespace std;



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

    int X, K, D;
    cin >> X >> K >> D;

    X = abs(X);

    int cont = X/D;

    if(cont >= K)
    {
    	cout << X - K*D << '\n';
    }
    else
    {
    	X = X%D;
    	K -= cont;

    	if(K%2 == 0)
    	{
    		cout << X << '\n';
    	}
    	else
    	{
    		cout << abs(X-D) << '\n';
    	}
    }

    return 0;
}

Measured memory_bytes: 3608
import codecs
n = int(input())
s = input()

def caesar(s, n):
    ns = []
    for ch in s:
        # A - Z
        if ('A' <= ch and ch <= 'Z'):
            ns.append(chr((ord(ch) - ord('A') - n) % 26 + ord('A')))
        # a - z
        elif ('a' <= ch and ch <= 'z'):
            ns.append(chr((ord(ch) - ord('a') - n) % 26 + ord('a')))
        # 0 - 9
        elif ('0' <= ch and ch <= '9'):
            ns.append(chr((ord(ch) - ord('0') - n) % 10 + ord('0')))
        # no change for other characters
        else:
            ns.append(ch)
    return "".join(ns)

result = caesar(s, -n)
print(result)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return f?-x:x;
}
inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);
	putchar(x%10+48);
}
ll n,a[100001],max1=0,max2=0;
int main(void){
	n=read();
	for(ll i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+1+n);
	for(int i=n;i>=1;i--){
		if(max1>0){if(a[i]==a[i-1]&&max2<a[i])max2=a[i];}
		else if((a[i]==a[i-1])&&max1<a[i]){
			max1=a[i];
			if(a[i]==a[i-1])a[i]=0;a[i-1]=0;
		}
	}
	write(max1*max2);
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_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())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;
  vll a(n), b(n);
  REP(i, n)
    cin >> a[i];
  REP(i, n)
    cin >> b[i];

  ll as, bs;
  as = bs = 0;
  REP(i, n){
    as += max(a[i]-b[i], 0LL);
    bs += max((b[i]-a[i])/2, 0LL);
  }

  if(as<=bs)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 384
N,K=map(int,input().split())
S=[0]*N
d=0
count=0
for i in range(K):
    d=int(input())
    L=list(map(int,input().split()))
    for j in range(d):
        S[L[j]-1]=1
    
for i in range(len(S)):
    if S[i]==0:
        count+=1
print(count)

Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 77,mo=1e9+7;const ll MOD=7LL*mo*mo;
int res,mx,n,k,C[N*2][N*2],sz[N],cnt[N],f[N];char S[N];
void dfs(int dep, int least){
	if(dep>mx){
		static int r[N],b[N];int extra=0;
		rep(i,1,mx)r[i]=cnt[i],b[i]=0;
		rep(t,1,k)
			if(S[t]=='r'){
				bool find=0;
				per(i,mx,1)if(r[i]){
					find=1;r[i]--;b[i-1]++;break;
				}
				if(!find&&extra)extra--;
			}
			else{
				bool find=0;
				per(i,mx,1)if(b[i]){
					find=1;b[i]--;extra+=i-1;break;
				}
				if(!find&&extra)extra--;
			}
		rep(i,1,mx)if(r[i]||b[i])return;if(extra)return;
		memset(f,0,sizeof(f));int tot=0,cur=0,ans=1;f[0]=1;
		static int hz[N];per(i,mx,1)hz[i]=hz[i+1]+cnt[i]*sz[i];
		rep(y,1,mx)if(cnt[y]){
			ans=1LL*ans*C[cur+cnt[y]][cur]%mo;
			cur+=cnt[y];
		}
		int A=cur-1,B=2;if(!cur)A=0,B=1;
		rep(y,1,mx)if(cnt[y]){A+=cnt[y]*sz[y];if(y>1)B+=2*cnt[y];}
		res=(res+1LL*ans*C[n+B-1][A+B-1])%mo;
	//	rep(i,1,mx)printf("%d ",cnt[i]);printf("-->%d\n",res);
		return;
	}
	for(int x=0;least+x*(1+sz[dep])<=n;x++)
		cnt[dep]=x,dfs(dep+1,least+x*(1+sz[dep]));
}
int main() {
	read(n);read(k);scanf("%s",S+1);
	rep(i,0,(n+3)*2){
		C[i][0]=C[i][i]=1;
		rep(j,1,i-1)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
	}
	mx=(n+3)/2;
	sz[1]=1;rep(i,2,mx)sz[i]=2*i-3;
	dfs(1,-1);cout<<res;
	return 0;
}


Measured memory_bytes: 384
n,k = input().split()
n=int(n)
k=int(k)
h = [int(input()) for i in range(n)]
h.sort()
#print(h)
ans=10000000000

for i in range(n-k+1):
#  list1 = [h[j] for j in range(i,i+k)]
#  print(list1)
  if h[i+k-1]-h[i] < ans:
      ans = h[i+k-1]-h[i]
print(ans)

Measured memory_bytes: 7384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int get_digits(long val) {
    int i = 0;
    for (; val != 0; val /= 10) {
        i++;
    }

    return i;
}

int main(void) {
    long N;
    std::cin >> N;

    long sqrt = static_cast<long>(std::sqrt(N));

    int min = 0x7fffffff;
    for (int i = 1; i <= sqrt; i++) {
        if (N % i == 0) {
            long val = N / i;

            min = std::min(min, get_digits(val));
        }
    }

    std::cout << min << std::endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = input[0];
            var B = input[1];
            var T = input[2];

            Console.WriteLine(T / A * B);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int a, b;
  cin >> a >> b;
  
  int ok = 0, t;
  for (int i = 1; i < 100001; i++){
    if ((int)(1.0*i * 0.08) == a && (int)(1.0*i * 0.10) == b){
      ok = 1;
      t = i;
      break;
    }
  }

  if (ok){
    cout << t << endl;
  }
  else
    cout << -1 << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 5010
using namespace std;
typedef long long ll;
int n,K,a[N],s[N],ans;
bool f[N][N],g[N][N];
int main(){
	cin>>n>>K;
	f[0][0]=g[n+1][0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		for(int j=0;j<=K;j++)if(f[i-1][j]){
			f[i][j]=1;
			if(j<=K-a[i])f[i][j+a[i]]=1;
		}
	}
	for(int i=n;i;i--)
		for(int j=0;j<=K;j++)if(g[i+1][j]){
			g[i][j]=1;
			if(j<=K-a[i])g[i][j+a[i]]=1;
		}
	for(int i=1;i<=n;i++){
		s[0]=g[i+1][0];
		for(int j=1;j<=K;j++)s[j]=s[j-1]+g[i+1][j];
		for(int j=0;j<K;j++)if(f[i-1][j])if(s[K-j-1]-(K-j-a[i]<=0?0:s[K-j-a[i]-1])){ans++;break;}
	}
	printf("%d",n-ans);
	return 0;
}

Measured memory_bytes: 49280
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> b(n);
  vector<int64_t> numcnt(n);
  rep(i,n){
    cin >> b[i];
    numcnt[b[i]-1]++;
  }
  int64_t idtotal = 0;
  rep(i,n){
    idtotal += (numcnt[i]*(numcnt[i]-1))/2;
  }
  rep(i,n){
    int64_t kk = 0;
    int64_t hoge = numcnt[b[i]-1];
    kk = idtotal - (hoge*(hoge-1))/2 + ((hoge-1)*(hoge-2))/2;
    cout << kk << endl;
  }
    
 
}


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

int main(){
    long long int a, b, n;
    cin >> a >> b >> n;
    long long int x = b - 1;
    if(x > n){
        x = n;
    }
        cout << floor(a * x / b) - a * floor(x / b) << endl;
}

Measured memory_bytes: 3788
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........

//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
	string s;
	cin>>s;
	if(s.SZ>=4&&s.substr(0,4)=="YAKI")cout<<"Yes";
	else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
/**
 * @author      : omgursocute
 * @created     : 21/02/2020
 * @task        : A
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
	// freopen("A.inp", "r", stdin);
	// freopen("A.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && a != c) cout << "Yes";
	else if(a == c && a != b) cout << "Yes";
	else if(b == c && a != b) cout << "Yes";
	else cout << "No";

	return 0;
}



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

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

    ll a, b;
    cin >> a >> b;
    for(int i = 1; i <= b; i++) {
        if((a * i) % b == 0) {
            cout << a * i << "\n";
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[4010][4010] = {};

ll v1[4010] = {};
ll v3[4010][4010] = {};
ll mp_b[4010] = {}, mp_w[4010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    char c[4010];
    ll a[4010];
    rep(i,0,2*N) cin >> c[i] >> a[i];
    // map< pair<char, ll>, ll > mp;

    rep(i,0,2*N){
        if(c[i] == 'B'){
            mp_b[a[i]] = i;
        }else{
            mp_w[a[i]] = i;
        }
    }


    rep(i,0,2*N+1){
        rep(j,0,2*N+1){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;


    rep(i,0,2*N){
        if(c[i] == 'B'){
            rep(j,1,a[i]){
                if(mp_b[j]> i){
                    v1[i]++;
                }
            }
        }else{
            rep(j,1,a[i]){
                if(mp_w[j] > i){
                    v1[i]++;
                }
            }  
        }
    }
    rep(i,0,2*N){
        if(c[i] == 'B'){
            rep(k,1,2*N){
                if(mp_w[k] > i){
                    v3[i][k]++;
                    v3[i][2*N]--;
                }
            }
        }else{
            rep(k,1,2*N){
                if(mp_b[k] > i){
                    v3[i][k]++;
                    v3[i][2*N]--;
                }
            }  
        }
    }
    
    rep(i,0,2*N){
        rep(k,0,2*N+1){
            v3[i][k+1] += v3[i][k]; 
        }
    }


    rep(i,0,2*N){
        rep(j,0,i+1){
            // Bが来る
            pair<char, ll> nxt = {'B', j+1};
            ll pos = mp_b[j+1];
            pos += v1[pos];
            ll n_white = i-j;
            pos += v3[mp_b[j+1]][n_white];

            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + abs(pos - i));

            // Wが来る
            pair<char, ll> nxt2 = {'W', i-j+1};
            ll pos2 = mp_w[i-j+1];
            pos2 += v1[pos2];
            pos2 += v3[mp_w[i-j+1]][j];
            dp[i+1][j] = min(dp[i+1][j], dp[i][j] + abs(pos2 - i));
        }
    }
    print(dp[2*N][N]);

    

}

Measured memory_bytes: 251392
n=gets.to_i
h=gets.split.map(&:to_i)
m=0
i=0
while i<n-1
  c=0
  while i+c+1 <= n-1 and h[i+c]>=h[i+c+1]
    c+=1
  end
  m=(m<c)?c:m
  i+=1+c
end
puts m

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

using namespace std;

int mat[107][107];
int L, C, n, x, y, a;

int main() {
    cin >> L >> C >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> x >> y >> a;
        if(a == 1) {
            for(int p = 1; p <= x; ++p) {
                for(int l = 1; l <= C; ++l) {
                    mat[p][l] = 1;
                }
            }
        }
        if(a == 2) {
            for(int p = x + 1; p <= L; ++p) {
                for(int l = 1; l <= C; ++l) {
                    mat[p][l] = 1;
                }
            }
        }
        if(a == 3) {
            for(int l = 1; l <= y; ++l) {
                for(int p = 1; p <= L; ++p) {
                    mat[p][l] = 1;
                }
            }
        }
        if(a == 4) {
            for(int p = 1; p <= L; ++p) {
                for(int l = y + 1; l <= C; ++l) {
                    mat[p][l] = 1;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= L; ++i) {
        for(int j = 1; j <= C; ++j) {
            ans += mat[i][j];
        }
    }
    cout << L * C - ans;
    return 0;
}


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

int main(){
  int64_t n; cin >> n;
  int64_t a, b;
  int flag = 0;
  
  for(int64_t i = sqrt(n); i > 0; i--){
    if(n % i == 0){
      a = i;
      b = n / i;
      flag = 1;
      break;
    }
  }
  
  cout << a + b - 2 << endl;
}





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

cnt = 0
for i in range(N-1):
    if p[i] == i+1:
        v = p[i]
        p[i] = p[i+1]
        p[i+1] = v
        cnt += 1
    
if p[-1] == N:
    cnt += 1
    
print(cnt)

Measured memory_bytes: 52908
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum = 0;
    REP(i,3){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum>=22){
        puts("bust");
    }else{
        puts("win");
    }

    return 0;
}

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

using namespace std;


int main()
{


/*#ifndef	ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

  int a,b,c,d;

  cin>>a>>b>>c>>d;

  while(true)
  {
  	 c -= b;
  	 a -= d;

  	 if(c<=0)
  	 {
  	 	cout<<"Yes";
  	 	break;
  	 }

  	 if(a<=0)
  	 {
  	 	cout<<"No";
  	 	break;
  	 }

  }
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言

//グローバル変数
//const int INF = ;
//const int MAX_N = ;
//const int MAX_M = ;
//vvec dp(MAX_N, vec(MAX_M));

//関数：
/* メイン・プログラム */
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, m; cin >> n >> m;
	if(n == m) cout << "Yes" << endl;
	else  cout << "No" << endl;
	return 0;
}

/*	(n * m) % dvs = ((n%dvs) * (m%dvs)) % dvs
*/

//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';
//int id = lower_bound(all(arr), x) - arr.begin();
//cout << fixed << setprecision(10) << tld << endl;
//vector<int> sub(itr,itr+d); //イテレーターで部分数列(i=0...d)を指定

/*	struct data {
	char *name;
	int age;
	int height;
	double weight;
};*/

/*	string ans(lgd, '0');
	string &refer = ans;
	for(int i=0; i<lgd; i++) refer[i] = (char)vd[i] + '0';*/

/*	map<int,int> mp;
for(auto p : mp) {
	ct += p.second*(p.second-1); }

map<int,int>::iterator itr;
for(itr = mp.begin(); itr != mp.end(); itr++) {
	ans += itr->second * (itr->second-1);
}*/


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean tt = false;
		for(int i=0;i<3;i++) {
			int t = n % 10;
			 n = n / 10;
			 if(t == 7) {
				 tt = true;
			 }
		}
		if(tt) {
		    System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	
	}
}


Measured memory_bytes: 35776
#!/usr/bin/env python

N = int(raw_input())
Array3 = [[] for i in range(9)]
Array5 = [[] for i in range(9)]
Array7 = [[] for i in range(9)]
Array53 = [[] for i in range(9)]
Array75 = [[] for i in range(9)]
Array73 = [[] for i in range(9)]
Array753 = [[] for i in range(9)]
Array3[0].append(3)
Array5[0].append(5)
Array7[0].append(7)
Arraytot = []

for i in range(8):
    Array753[i+1].extend(map(lambda x: x*10+7, Array753[i]))
    Array753[i+1].extend(map(lambda x: x*10+5, Array753[i]))
    Array753[i+1].extend(map(lambda x: x*10+3, Array753[i]))
    Array753[i+1].extend(map(lambda x: x*10+3, Array75[i]))
    Array753[i+1].extend(map(lambda x: x*10+5, Array73[i]))
    Array753[i+1].extend(map(lambda x: x*10+7, Array53[i]))
    Array75[i+1].extend(map(lambda x: x*10+5, Array75[i]))
    Array75[i+1].extend(map(lambda x: x*10+7, Array75[i]))
    Array75[i+1].extend(map(lambda x: x*10+7, Array5[i]))
    Array75[i+1].extend(map(lambda x: x*10+5, Array7[i]))
    Array73[i+1].extend(map(lambda x: x*10+3, Array73[i]))
    Array73[i+1].extend(map(lambda x: x*10+7, Array73[i]))
    Array73[i+1].extend(map(lambda x: x*10+7, Array3[i]))
    Array73[i+1].extend(map(lambda x: x*10+3, Array7[i]))
    Array53[i+1].extend(map(lambda x: x*10+3, Array53[i]))
    Array53[i+1].extend(map(lambda x: x*10+5, Array53[i]))
    Array53[i+1].extend(map(lambda x: x*10+5, Array3[i]))
    Array53[i+1].extend(map(lambda x: x*10+3, Array5[i]))
    Array3[i+1].extend(map(lambda x:x*10+3, Array3[i]))
    Array5[i+1].extend(map(lambda x:x*10+5, Array5[i]))
    Array7[i+1].extend(map(lambda x:x*10+7, Array7[i]))
    Arraytot.extend(Array753[i+1])

Arraytot.sort()
ans = 0
for i in Arraytot:
    if i <= N:
        ans+=1
    else:
        break
print ans

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

int main () {
	long long N;
	cin >> N;
	long long min = N-1;
	for (long long i=2; i*i<=N; i++) {
		if (N%i==0) {
			long long j = N/i;
			min = i+j-2;
		}
	}
	printf ("%lld\n", min);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979323846;

int main() {
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i=0; i<N; i++) {
    cin >> b[i];
    b[i]--;
  }
  vector<int> res;
  for (int i=0; i<N; i++) {
    int pivot = -1;
    for (int j=b.size()-1; j>=0; j--) {
      if (b[j]==j) {
        pivot = j;
        break;
      }
    }
    if (pivot==-1) {
      cout << -1 << endl;
      return 0;
    }
    res.push_back(pivot+1);
    b.erase(b.begin()+pivot);
  }
  reverse(res.begin(), res.end());
  for (auto v: res) cout << v << endl;
  return 0;
}

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

using namespace std;

int main(void){
	int n, c, s, f, t;
	scanf("%d", &n);

	vector<int> cs, ss, fs;

	for(int i = 0;i < n-1;++i){
		scanf("%d %d %d", &c, &s, &f);
		cs.push_back(c);
		ss.push_back(s);
		fs.push_back(f);
	}

	for(int j = 0;j < n-1;++j){
		t = 0;
		for(int i = j;i < n-1;++i){
			if(t < ss[i]){
				t = ss[i];
				t += cs[i];
			}else{
				if(t%fs[i] == 0){
					t += cs[i];
				}else{
					t += fs[i] - (t%fs[i]) + cs[i];
				}
			}
		}

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long answer = 0;
        for (int i = 1; i <= n; i++)
        {
            answer += i * (n + 1 - i);
        }

        for (int i = 0; i < n - 1; i++)
        {
            long e1 = sc.NextLong();
            long e2 = sc.NextLong();
            answer -= Math.Min(e1, e2) * (n - Math.Max(e1, e2) + 1);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 46064
#include <iostream>
#include <cmath>

using namespace std;

void solve() 
{
	int n; cin >> n;

	int ans = 0;
	int e = sqrt(n);
	for(int i = 1; i <= e; ++i) 
	{
		int j = i;
		while(i * j < n)
			++j;

		ans += 2 * (j - i);
		if(i != j)
			--ans;
	}
	cout << ans << '\n';
}

int main()
{
#ifndef ONLINE_JUDGE
   freopen("input.txt", "rt", stdin);
   freopen("output.txt", "wt", stdout);
#endif

   	ios_base::sync_with_stdio(false);
	cin.tie(0);

	solve();
	return 0;
}



Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n;cin>>n;
  ll ans = 1;
  for(int i = 1;i <= n;++i){
    ans *= i;
    ans %= INF;
  }
  print(ans);
  return 0;
}



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

using namespace std;
using ll = long long;

int main() {
    ll h, n; cin >> h >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        sum += x;
    }

    if (sum >= h) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define int ll
const ll mod=998244353;
ll dp[333][99999]={0};
ll dp2[333][99999]={0};
ll ar[305]={0};
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1){
    res*=x;
    res%=mod;
  }
  return res;
}
signed main(){
  ll n,sum=0;
  cin>>n;
  dp[0][0]=1;
  dp2[0][0]=1;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    ar[i]=a;
    sum+=a;
  }
  for(int i=0;i<n;i++){
    ll a=ar[i];
    for(int j=0;j<98999;j++){
      dp[i+1][j]+=(dp[i][j]*2)%mod;
      dp[i+1][j+a]+=dp[i][j];
      dp[i+1][j]%=mod;
      dp[i+1][j+a]%=mod;

      dp2[i+1][j]+=dp2[i][j];
      dp2[i+1][j+a]+=dp2[i][j];
      dp2[i+1][j]%=mod;
      dp2[i+1][j+a]%=mod;
    }
  }

  ll ans=pow(3,n);
  for(ll i=(sum+1)/2;i<=sum;i++){
    ans+=mod-((dp[n][i]*3)%mod);
    ans%=mod;
  }
  if(sum%2==0) {
    ans+=(dp2[n][sum/2]*3)%mod;
    ans%=mod;
  }
  ans%=mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 470528
while True:
    try:
        S = input()
        for i, j in enumerate(S):
            if i % 2 == 1:
                if j != 'L' and j != 'U' and j != 'D':
                    print("No")
                    break
            else:
                if j != 'R' and j != 'U' and j != 'D':
                    print("No")
                    break
        else:
            print("Yes")
    except EOFError:
        break

Measured memory_bytes: 3060
from collections import Counter

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

def root(n, u):
    if u[n] == n:
        return n
    u[n] = root(u[n], u)
    return u[n]

union1 = {x:x for x in range(1, n+1)}
for p, q in ps:
    union1[root(p, union1)] = root(q, union1)

union2 = {x:x for x in range(1, n+1)}
for r, s in rs:
    union2[root(r, union2)] = root(s, union2)

gs = {x:(root(x, union1), root(x, union2)) for x in range(1, n+1)}
c = Counter(gs.values())
print(' '.join(str(c[gs[x]]) for x in range(1, n+1)))


Measured memory_bytes: 119608
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const long long INF = 1LL << 60;
long long h[100010];
long long dp[100010];

int main()
{
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }
    for (int i = 0; i < 100010; i++)
    {
        dp[i] = INF;
    }
    dp[0] = 0;

    for (int i = 0; i < N; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    cout << dp[N - 1] << endl;
}

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

using namespace std;

void display(int array[], int N);
int bubbleSort(int array[],int N);

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int n = bubbleSort(A,N);
  display(A,N);
  cout << n << endl;
  return 0;
}

int bubbleSort(int array[],int N){
  bool flag = true;
  int i = 0;
  while(flag){
    flag = false;
    for(int j=N-1;j>0;j--){
      if(array[j] < array[j-1]){
        int t = array[j];
        array[j] = array[j-1];
        array[j-1] = t;
        flag = true;
        i++;
      }
    }
  }
  return i;
}

void display(int array[], int N){
  for(int i=0;i<N;i++){
    if(i>0) cout << " ";
    cout << array[i];
  }
  cout << endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000000+7
using namespace std;
typedef long long ll;

int main(){
  int N;  cin >> N;
  vector<int> vec(N);
  rep(i, 0, N){
    cin >> vec[i];
  }
  int ans = INF;
  rep(i, -100, 100+1){
    int tmp = 0;
    rep(j, 0, N){
      tmp += pow(vec[j]-i, 2);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}
int main() {
  int N;
  cin >> N;
  vector<ll> X(N);
  rep(i, N) cin >> X[i];
  ll p=0, sum=0, fac=1;
  rep(i, N-1) (fac *= (i+1)) %= mod;
  rep(i, N-1) {
    (p += fac * modinv(i+1) % mod) %= mod;
    (sum += (X[i+1]-X[i]) * p % mod) %= mod;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        int x[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        x[0]=0;
        for(int i=0;i<n;i++){
            x[0]+=((i%2==0)?a[i]:-a[i]);
        }
        for(int i=1;i<n;i++){
            x[i]=2*a[i-1]-x[i-1];
        }
        
        for(int i=0;i<n;i++){
        System.out.print(x[i]+((i==n-1)?"":" "));}
    }
}


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

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

    vector<int> mochi;
    for (int i = 0; i < n; i++){
        int x; cin >> x;
        mochi.push_back(x);
    }
    sort(mochi.begin(), mochi.end());

    int stages = 0, cx = 0;
    for (int i = 0; i < n; i++){
        if (cx < mochi[i]){
            cx = mochi[i];
            stages++;
        }
    }
    cout << stages << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int w, h;
string m[60];
int vis[60][60];

int d[4][2]={{0, 1},{1,0},{-1,0},{0, -1}};

pii dfs(int x, int y){
	if(x<0||y<0||w<=x||h<=y) return pii(0, 0);
	if(m[y][x] == 'B') return pii(2, 0);
	if(m[y][x] == 'W') return pii(1, 0);
	if(vis[y][x]) return pii(0, 0);
	vis[y][x] = 1;
	pii ret(0, 1);
	REP(i, 4){
		pii res = dfs(x+d[i][0], y+d[i][1]);
		ret.first |= res.first;
		ret.second += res.second;
	}
	return ret;
}

main(){
	while(cin >> w >> h, w){
		memset(vis, 0, sizeof(vis));
		REP(i, h) cin >> m[i];
		int b=0,s=0;
		REP(i, h)REP(j, w){
			if(!vis[i][j]){
				pii ret=dfs(j, i);
				if(ret.first == 1) s += ret.second;
				if(ret.first == 2) b += ret.second;
			}
		}
		cout << b << " " << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1344
#include <iostream>
using namespace std;
int main(void){
    int n;
    int pm[10100], pe[10100], pj[10100];
 
    while(true){
        cin >> n;
        if(n == 0) {
            break;
        }
 
        for(int i = 0; i < n; i++){
            cin >> pm[i] >> pe[i] >> pj[i];
        }
         
        int mean_me[10100]; 
        int c[10100]; 
 
        for(int i = 0; i < n; i++){
            if(pm[i] == 100 || pe[i] == 100 || pj[i] == 100) 
                c[i] = 1;
 
            else if((pm[i] + pe[i]) / 2 >= 90)
                c[i] = 1;
 
            else if((pm[i] + pe[i] + pj[i]) / 3 >= 80)
                c[i] = 1;
 
            else if((pm[i] + pe[i] + pj[i]) / 3 >= 70)
                c[i] = 2;
 
            else if((pm[i] + pe[i] + pj[i]) / 3 >= 50 && (pm[i] >= 80 || pe[i] >= 80))
                c[i] = 2;
             
            else
                c[i] = 3;
 
            if(c[i] == 1) cout << "A" << endl;
            else if(c[i] == 2) cout << "B" << endl;
            else cout << "C" << endl;
        }
    }
}


Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
char Color[3] = {'R', 'G', 'B'};

int main(){

    int n; cin >> n;
    vector<int> h(n);
    vector<int> w(n);
    for(int i = 0; i < n; i++) cin >> h[i] >> w[i];
    string C;
    for(int i = 0; i < 4; i++){
        string tmp; cin >> tmp;
        C = C + tmp;
    }

    queue<pair<int, int> > que;                  //cost bit(一致していたら1そうでなければ0)
    
    vector<bool> used((1 << 16), false);
    used[0] = true;
    que.push({0, 0});

    while(!que.empty()){

        int bit = que.front().second;
        int cost = que.front().first;
        //cout << cost << " " << str << endl;
        que.pop();

        if(bit == (1 << 16) - 1){
            cout << cost << endl;
            break;
        }

        for(int ii = 0; ii < n; ii++){

            for(char color : Color){

                //cout << i << " " << color << endl;
                for(int si = -3; si <= 3; si++){
                    for(int sj = -3; sj <= 3; sj++){
                        int gi = si + h[ii] - 1;
                        int gj = sj + w[ii] - 1;

                        int next;
                        next = bit;
                        //cout << i << " " << si << " " << gi << " " << sj << " " << gj << " " << endl;
                        for(int i = max(si, 0); i <= min(gi, 3); i++){
                            for(int j = max(sj, 0); j <= min(gj, 3); j++){            
                                int idx = i * 4 + j;
                                if(C[idx] == color) next = next | (1 << idx);
                                else next = next & ~(1 << idx);
                            }
                        }

                        if(!used[next]){
                            //cout << "ok" << endl;
                            used[next] = true;
                            que.push({cost + 1, next});
                        }

                    }
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3348
#include <iostream>
#include <utility>
#include <algorithm>
int main(){
  int n,m;
  long long a,b,c=0;
  std::pair<long long,long long> p[100001];
  std::cin>>n>>m;
  for(int i=0;i<n;++i){std::cin>>a>>b;p[i]={a,b};}
  std::sort(p,p+n);
  for(int i=0;i<n;++i){
    if(p[i].second<m){
      c+=p[i].first*p[i].second;
      m-=p[i].second;
    }
    else{
      c+=p[i].first*m;
      break;
    }
  }
  std::cout<<c<<"\n";
}
  
  

Measured memory_bytes: 1920
#include <stdio.h>

int K=0;
int ans=0;

void f(int a,int b,int c,int k){
  if(k>K || ans==1) return;
  if(a < b && b < c){
    ans=1;
    return;
  }
  f(a*2,b,c,k+1);
  f(a,b*2,c,k+1);
  f(a,b,c*2,k+1);
  return;
}

int main(){
  int A,B,C;
  scanf("%d %d %d\n%d",&A,&B,&C,&K);
  f(A,B,C,0);
  if(ans==0) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main(){
	ios;
	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y;
	return 0;
}

Measured memory_bytes: 256
import math
import copy

inputa = input().split()
inputb = input().split()
inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# a = inputa[0]
# inputList = list(a)

# x = int(inputb[0])
# y = int(inputb[1])

# inputList=[]
# for i in range(a):
#     inputNum = input()
#     inputList.append(inputNum)

b = [int(n) for n in inputb]
c = [int(n) for n in inputc]

sum = 0
for i in range(len(b)):
    if b[i] > c[i]:
       sum += b[i] - c[i]

print(sum)




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

using namespace std;

long long ans = 1;
//vector<int> nxt[303];
int am[303];

int main() {

    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i++) {
        //nxt[s[i]].push_back(i);
        am[s[i]]++;
    }

    for(int i = 0; i < s.size(); i++) {
        //cout << "TEST " << s.size() << '\n';
        ans += 1LL*(1LL*s.size()-i-am[s[i]]);
        am[s[i]]--;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int n,cnt;
priority_queue <pair <int,int> > que;
bool used[100005];
int main(){
	cin>>n;
	que.push(mp(-1,1));
	while (!que.empty()) {
		int c=-que.top().first;
		int v=que.top().second;
		que.pop();
		if (v==0){
			cout<<c;
			return 0;
		}
		if (used[v]) continue;
		used[v]=true;
		que.push(mp(-c-1,(v+1)%n));
		que.push(mp(-c,(v*10)%n));  
	}
}

Measured memory_bytes: 1528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

void print(int A[], int N){
	rep(i, N){
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void selectionSort(int A[], int N){
	int count = 0;
	rep(i, N){
		int minj = i;
		FOR(j, i, N){
			if (A[j] < A[minj])
				minj = j;
		}
		if (i != minj){
			swap(A[i], A[minj]);
			count++;
		}
	}
	print(A, N);
	cout << count << endl;
}

int main() {

	int N;
	cin >> N;

	const int MAX_N = 10000;
	int A[MAX_N];
	rep(i, N){ cin >> A[i]; }

	selectionSort(A, N);

}

Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define ll long long

const int maxn = 1e5 + 7;


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

	int a, b;
	cin >> a >> b;
	int Max = -0xffffff;
	Max = max(Max, max(a + b, max(a - b, a*b)));
	cout << Max << endl;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << P+Q+R-max(max(P,Q),R) << endl;
}

Measured memory_bytes: 256