akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<queue>
#define MAXN 806
using namespace std;
int n,m,k,step[MAXN*MAXN],way[4][2]={{-1,0},{1,0},{0,1},{0,-1}},s,ans;
char a[MAXN][MAXN];
queue<int> q;
int main()
{
	//freopen("room.in","r",stdin);
	//freopen("room.out","w",stdout);
	scanf("%d%d%d",&n,&m,&k);
	ans=n*m*666;
	for(int i=1;i<=n;i++)
		scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(a[i][j]=='S')
			{
				if(i==1||i==n||j==1||j==m)
				{
					printf("0");
					return 0;
				}
				s=(i-1)*m+j;
				break;
			}
	step[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int now=q.front();
		q.pop();
		if(step[now]==k+1) continue;
		int nowx=(now-1)/m+1;
		int nowy=now-(nowx-1)*m;
		for(int i=0;i<4;i++)
		{
			int nex=nowx+way[i][0];
			int ney=nowy+way[i][1];
			int ne=(nex-1)*m+ney;
			if(step[ne]||a[nex][ney]!='.') continue;
			step[ne]=step[now]+1;
			q.push(ne);
		}
	}
	for(int i=1;i<=n*m;i++)
	{
		if(step[i])
		{
			int x=(i-1)/m+1;
			int y=i-(x-1)*m;
			int p=min(min(x-1,n-x),min(y-1,m-y));
			int q=p/k;
			if(p%k) q++;
			ans=min(ans,q+1);
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 3328
def main():
    s = input().rstrip()
    t = "AKIHABARA"
    i = 0
    while i < len(t) and i < len(s):
        if s[i] != t[i]:
            if t[i] != "A":
                break
            t = t[:i] + t[i+1:]
            i -= 1
        i += 1
    if s == t or s+"A" == t:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	n := nextInts(4)
	sort.Ints(n)
	if n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func intPow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func intMax(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func intMin(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func intSum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func intAbs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = newScanner()
}

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
#include <stdio.h>
int dp[1001][1001];
int exist[1001][1001];
int max(int a, int b) {
	if(a > b) return a;
	return b;
}
int main() {
	int n;
	int i, j, k;
	while(1) {
		scanf("%d", &n);
		if(n == 0) break;
		for(i = 0; i < 1001; ++ i) for(j = 0; j < 1001; ++ j) dp[i][j] = 0;
		for(i = 0; i < 1001; ++ i) for(j = 0; j < 1001; ++ j) exist[i][j] = 0;
		for(i = 0; i < n; ++ i) {
			scanf("%d %d", &j, &k);
			exist[j][k] = 1;
		}
		scanf("%d", &n);
		for(i = 0; i < n; ++ i) {
			scanf("%d %d", &j, &k);
			exist[j][k] = 1;
		}
		for(i = 0; i < 1000; ++ i) {
			for(j = 0; j < 1000; ++ j) {
				if(exist[i][j]) {
					dp[i + 1][j + 1] = max(max(dp[i + 1][j], dp[i][j + 1]), dp[i][j] + 1);
				} else {
					dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				}
			}
		}
		printf("%d\n", dp[1000][1000]);
	}
	return 0;
}

Measured memory_bytes: 8428
x = int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
a = num2alpha(x)
print(a.lower())

Measured memory_bytes: 9092
S = input()
T = input()

answer = 'Yes'

for c in 'abcdefghijklmnopqrstuvwxyz':
    found = ' '
    for i, s in enumerate(S):
        if s == c:
            if found == ' ':
                found = T[i]
            elif found == T[i]:
                found = T[i]
            else:
                answer = 'No'

    found = ' '
    for i, t in enumerate(T):
        if t == c:
            if found == ' ':
                found = S[i]
            elif found == S[i]:
                found = S[i]
            else:
                answer = 'No'


print(answer)

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

int main() {
  int n, k, cnt = 0, ans = 0;

  cin >> n >> k;

  vector<int> a(n), typ(n + 1);

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

  sort(typ.begin(), typ.end());

  for (int i = n; i >= 0; i--) {
    if (typ[i] == 0)
      break;
    else
      cnt++;
  }

  for (int i = 0; i < n && cnt > k; i++) {
    if (typ[i] != 0) {
      ans += typ[i];
      cnt--;
    }
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int n, m, i, sum = 0, count = 0;
  scanf("%d %d", &n, &m);
  int a[n - 1];
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }

  double vote = (double)sum/(4*(double)m);
  
  for(i = 0; i < n; i++) {
  	if ((double)a[i] >= vote)
      count++;
  }
  
  if (count >= m)
    printf("Yes");
  else
    printf("No");
  
  return(0);
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n)cin>>a[i];

	ll ans = 0;
	rep(i,n){
		if(i % 2 == 0){
			if(a[i] % 2) ans ++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

char color[] = {'W','B','R'};

int main()
{
  int H, W;
  cin >> H >> W;
  char mas[55][55];
  int cnt[3][55] = {0};
  int minv = INF;
  Rep(i,H)Rep(j,W) {
    cin >> mas[i][j];
    Rep(k,3) {
      cnt[k][i] += mas[i][j] != color[k];
    }
  }
  
  for(int i = 1; i <= H - 2; i++) {
    for(int j = i + 1; j <= H - 1; j++) {
      int c = 0, p = 0;
      for(;p < i;p++)c += cnt[0][p];
      for(;p < j;p++)c += cnt[1][p];
      for(;p < H;p++)c += cnt[2][p];
      chmin(minv,c);
    }
  }

  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const long long INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int n, m;
int dp[maxn], in[maxn];

vector<int> G[maxn];
queue<int> q;

int main(){
	int u, v, ans = 0;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		cin >> u >> v;
		G[u].push_back(v);
		in[v]++;
	}
	for(int i = 1; i <= n; i++){
		if(!in[i])
			q.push(i);
	}
	while(!q.empty()){
		int cur = q.front();
		q.pop();
		for(int i = 0; i < G[cur].size(); i++){
			dp[G[cur][i]] = max(dp[G[cur][i]], dp[cur] + 1);
			ans = max(ans, dp[G[cur][i]]);
			in[G[cur][i]]--;
			if(!in[G[cur][i]])
				q.push(G[cur][i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9800
#include <bits/stdc++.h>
using namespace std;
/* Written by Nishant Mittal aka nishantwrp */
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define modnum 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define rrep(n) for(int i = n-1;i>=0;i--)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a)-1]
#define INF 1000000000000000000

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};

//primes for hashing 937,991,1013,1409,1741

//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
/* Long Long Int */
#define int long long int
/*

███╗   ██╗██╗███████╗██╗  ██╗ █████╗ ███╗   ██╗████████╗██╗    ██╗██████╗ ██████╗ 
████╗  ██║██║██╔════╝██║  ██║██╔══██╗████╗  ██║╚══██╔══╝██║    ██║██╔══██╗██╔══██╗
██╔██╗ ██║██║███████╗███████║███████║██╔██╗ ██║   ██║   ██║ █╗ ██║██████╔╝██████╔╝
██║╚██╗██║██║╚════██║██╔══██║██╔══██║██║╚██╗██║   ██║   ██║███╗██║██╔══██╗██╔═══╝ 
██║ ╚████║██║███████║██║  ██║██║  ██║██║ ╚████║   ██║   ╚███╔███╔╝██║  ██║██║     
╚═╝  ╚═══╝╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝    ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝     
                                                                                                       
*/
int ans = 0;

void nishantwrp(int cas) {
	int a,b;
	cin>>a>>b;
	cout<<max((a-2*b),0ll);
}

signed main()
{
FAST
int t = 1;
// cin>>t;
int cas = 1;
while(cas <= t) {
	nishantwrp(cas);
	ans = 0;
	cas++;
}
return 0;
}

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

typedef long long				ll;
typedef unsigned long long		ull;

const int N = 2 * 100 * 1000 + 20;

ll a[N], dp[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll n, ans = 1;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int maxx = a[1];
	for (int i = 2; i <= n; i++)
		if (maxx > a[i])
			ans++, maxx = a[i];
	cout << ans << endl;
	return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 200000000000000000;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  vector<intll> d(n) ;
  intll total = 0;
  rep(i,n){
    cin >> d.at(i) ;
    total += d.at(i) ;
  }
  
  intll ans = INF ;
  intll now = 0 ; 
  rep(i,n){
    now += d.at(i) ;
    intll a = max(total-now,now) ;
    intll b = min(total-now,now) ;
    ans = min(ans,a-b);
  }
  
  cout << ans ;
}


Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define MAXX 200
#define ll long long
using namespace std;

int N;
string S;


string dp[333][333];

string Min(const string& A, const string& B) {
    if (A.back() == 'E' && B.back() == 'E')
        return "NONE";
    if (B.back() == 'E')
        return A;
    if (A.back() == 'E')
        return B;
    
    if (A.size() < B.size())
        return A;
    if (A.size() > B.size())
        return B;
    
    if (A.compare(B) < 0)
        return A;
    else
        return B;
    
}

string CreateClose(int x) {
    string cur;
    for(int j=0;j<x;j++)
        cur.push_back(')');
    return cur;
}

string Solve(int pos, int len, int num_open) {
    
    if (num_open<0 || num_open > MAXX || len > MAXX)
        return "NONE";
    if (pos == N) {
        if (num_open < 0)
            return "NONE";
        return CreateClose(num_open);
    }
    
    if (dp[pos][num_open] != "")
        return dp[pos][num_open];
    
    
    
    // insert (
    string cur1 = "(" + Solve(pos, len+1, num_open+1);
    
    // insert )
    string cur2 = ")" + Solve(pos, len+1, num_open-1);
    
    // move on
    string cur3 = (S[pos]==')' ? ")" : "(")+Solve(pos+1, 0, num_open+(S[pos]==')'?-1:1));
    
    
    string ret = "NONE";
    
    ret = Min(ret, cur1);
    ret = Min(ret, cur2);
    ret = Min(ret, cur3);
   
    
    return dp[pos][num_open]=ret;
}

int main() {
    cin>>N;
    cin>>S;
    
    cout << Solve(0, 0, 0) << endl;
    
}


Measured memory_bytes: 14464
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n;
	cin >> n;
	ll h[N];
	rep(i, n) cin >> h[i];
	bool ans = true;
	ll min_h = INFL;
	for(int i = n - 1; i >= 0; i--) {
		if(h[i] < min_h) {
			min_h = h[i];
		}
		else if(h[i] > min_h + 1) {
			ans = false;
		}
	}
	if(ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
    int ans = 1;
    int n, a;
    int i;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%d", &a);
        if (a % 2 == 0)
            if (a % 3 == 0 || a % 5 == 0)
                ans = 1;
            else
            {
                ans = 0;
                break;
            }
    }

    if (ans == 1)
        puts("APPROVED");
    else
        puts("DENIED");

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	int n = 0;
	cin >> n;
	while(n--){
		int m = 0;
		cin >> m;
		vector<int> data(m, 0);
		int max = 0, min = 0;
		for(int i = 0; i < m; i++){
			cin >> data[i];
			if(i){
				if(min > data[i]-data[i-1]) min = data[i]-data[i-1];
				if(max < data[i]-data[i-1]) max = data[i]-data[i-1];
			}
		}

		if(min < 0) min *= -1;

		cout << max << " " << min << endl;
	}

	return 0;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
const ll MOD = (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

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

void solve()
{
    ll n;
    cin >> n;
    vll z(60,0), o(60,0), a(n);
    for(ll i=0;i<n;i++) {
        cin >> a[i];
    }
    for(ll i=0;i<n;i++) {
        for(ll j=0;j<60;j++) {
            if(a[i]%2 == 0) {
                z[j]++;
            } else {
                o[j]++;
            }
            a[i]>>=1;
        }
    }
    ll ans = 0;
    for(ll i=0;i<60;i++) {
        ll temp = (z[i]*o[i])%MOD;
        temp = (temp * powmod(2,i))%MOD;
        ans = (ans + temp) % MOD;
    }
    cout << ans << "\n";
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
      // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 2560
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
'''
rsp -> 012
'''
dp = [[0] * 3 for i in range(N)]
for i in range(0, K):
    for j in range(i, N, K):
        if j == i:
            if T[j] == 'r':
                dp[j][0] += 0
                dp[j][1] += 0
                dp[j][2] += P
            if T[j] == 's':
                dp[j][0] += R
                dp[j][1] += 0
                dp[j][2] += 0
            if T[j] == 'p':
                dp[j][0] += 0
                dp[j][1] += S
                dp[j][2] += 0
        else:
            dp[j][0] = max(dp[j - K][1], dp[j - K][2])
            dp[j][1] = max(dp[j - K][0], dp[j - K][2])
            dp[j][2] = max(dp[j - K][0], dp[j - K][1])
            if T[j] == 'r':
                dp[j][0] += 0
                dp[j][1] += 0
                dp[j][2] += P
            if T[j] == 's':
                dp[j][0] += R
                dp[j][1] += 0
                dp[j][2] += 0
            if T[j] == 'p':
                dp[j][0] += 0
                dp[j][1] += S
                dp[j][2] += 0

#print(dp)
ans = 0
for i in range(N-K,N):
    ans += max(dp[i])
print(ans)


Measured memory_bytes: 28880
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	vector<string>s(n);
	vector<ll>ans(4);
	vector<string>res(4);
	res[0] = "AC";
	res[1] = "WA";
	res[2] = "TLE";
	res[3] = "RE";
	rep(i, n) {
		cin >> s[i];
		if (s[i] == "AC")ans[0]++;
		else if (s[i] == "WA")ans[1]++;
		else if (s[i] == "TLE")ans[2]++;
		else {
			ans[3]++;
		}
	}

	rep(i, 4) {
		cout << res[i] << " " << "x" << " " << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 6420
import copy
def selection_sort(A):
    global c
    c=0 
    for i in range(0,len(A)-1):
        selection(A,i)
        
        
    return A

def selection(A,i):
    global c
    min=i
    for j in range(i+1,len(A)):
        if A[min][1]>A[j][1]:
            min=j
            
            
    A[i],A[min]=A[min],A[i]
    if not A[i]==A[min]:
        c+=1
    
def bubble_sort(A):
    for i in range(0,len(A)-1):
        bubble(A,i)
        
    return A

def bubble(A,i):
    for j in range(0,len(A)-1-i):
        if A[j][1]>A[j+1][1]:
            A[j],A[j+1]=A[j+1],A[j]
            
            
def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return 'Not stable'
    return 'Stable'



n=int(input())
A=input().split()
A_t=[(i[0],int(i[1])) for i in A]
A_t2=copy.copy(A_t)
B_t=bubble_sort(A_t)
B=[i[0]+str(i[1]) for i in B_t]
print(' '.join(B))
print(is_stable(A_t,B_t))

S_t=selection_sort(A_t2)
S=[i[0]+str(i[1]) for i in S_t]

print(' '.join(S))
print(is_stable(A_t,S_t))


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
using namespace std;

signed main() {
	int n,m,cnt=0,ans=0;
	cin>>n>>m;
	map<int,int> mp;
	mp[0]=1;
	rep(i,n){
		int a;
		cin>>a;
		cnt+=a;
		ans+=mp[cnt%m];
		mp[cnt%m]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4224
n, k = map(int, input().split())
s = input()
d = 0
for c1, c2 in zip(s, s[1:]):
    if c1 == 'R' and c2 == 'L':
        d += 1
e = 0
if s[0] == 'L':
    e += 1
if s[-1] == 'R':
    e += 1
k, d = max(k - d, 0), max(0, d - k)
if k > 0:
    e = 1
ans = max(0, n - d * 2 - e)
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
    g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }


std::vector<int> tsort(const Graph &g) {
    int n = g.size();
    enum State { NEW, ACTIVE, FINISHED };
    std::vector<int> res;
    vector <State> state(n, NEW);
    static const std::function<bool(int)> dfs = [&](int v) {
        state[v] = ACTIVE;
        for (auto &e : g[v]) {
            int w = e.dst;
            if (state[w] == ACTIVE) return false;
            else if (state[w] == NEW) if (!dfs(w)) return false;
        }
        state[v] = FINISHED;
        res.push_back(v);
        return true;
    };
    for (int i = 0; i < n; ++i)
        if (state[i] == NEW && !dfs(i)) return {-1};
    std::reverse(res.begin(), res.end());
    return res;
}

using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,m;
    cin >> n >> m;
    Graph g(n);
    for(int i = 0; i < m; i++){
        int s,t;
        cin >> s >> t;
        g[s].emplace_back(s,t,0);
    }
    vector<int> ord = tsort(g);
    for(int i = 0; i < n; ++i){
        cout << ord[i] << '\n';
    }
}


Measured memory_bytes: 4444
/*input
73
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n;
	cin>>n;
	cout<<setprecision(10)<<n*2.0*3.141592653589793<<endl;
	return 0;
}




Measured memory_bytes: 3800
import math
a,b,x = map(int,input().split())
if a**2*b>x> (a**2)*b/2:
  tan=2*((a**2)*b-x)/(a**3)
elif x<=a*a*b/2:
  tan=a*b*b/(2*x)
elif x==a*a*b:
  tan=0
  

print(math.degrees(math.atan(tan)))

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===



int bsearch(const Vi& vec, const int& a)
{
	int left = 0, right = (int)vec.size();
	while (right - left > 0) {
		int mid = (right + left) / 2;
		if (vec[mid] > a) right = mid;
		else left = mid;
	}
	return left;
}


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

	int N;
	cin >> N;

	Vi L(N);
	for (int i = 0; i < N; ++i) {
		cin >> L[i];
	}

	sort(L.begin(), L.end());

	int ans = 0;
	for (int i = 1; i < N - 1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			int b = L[i], c = L[j];

			int num = upper_bound(L.begin(), L.end(), c - b) - L.begin();

			ans += max(i - num, 0);
		}
	}

	cout << ans << endl;

	return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
int N;
cin >> N;
cout << "ABC" << N << endl;
 }

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

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt");
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var a    = int.Parse(spl[0]);
        var b    = int.Parse(spl[1]);

        var k = a - 2 * b;
        if (k < 0) k = 0;
        return k;
    }
}


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

signed main() {
  int k, n;
  cin >> k >> n;
  bool distances[1000000];
  for(int i = 0; i < k; i++){
    distances[i] = false;
  }
  for(int i = 0; i < n; i++){
    int dist;
    cin >> dist;
    distances[dist] = true;
  }

  int firstDist = -1;
  int lastDist = -1;
  int maxDist = 0;
  for(int i = 0; i < k; i++){
    if(distances[i]){
      if(firstDist == -1){
        firstDist = i;
      }else if(maxDist < i - lastDist){
        maxDist = i - lastDist;
      }
      lastDist = i;
    }
  };
  int lastPart = k - lastDist + firstDist;
  if(lastPart > maxDist){
    maxDist = lastPart;
  }
  cout << k - maxDist << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define PI 3.14159265358979323846264338327950L
using namespace std;
int main()
{
    int a,b,h,m;
    long double rad1,rad2,rad,d;
    cin>>a>>b>>h>>m;
    rad2 = 2.0*PI*(long double)m * 6.0/360.0;
    rad1 = 2.0*PI*((long double)h * 30.0 + 0.5*(long double)m)/360.0;
    
    if(rad2>rad1)
    {
        if(rad2 - rad1 > PI)
        {
            rad = PI*2.0 - (rad2 - rad1);
        }else{
            rad = rad2 - rad1;
        }
    }else{
        if(rad1 - rad2 > PI)
        {
            rad = PI*2.0 - (rad1 - rad2);
        }else{
            rad = rad1 - rad2;
        }
    }
    if(rad == 0.0)
    {
        if(a>b)
        {
            d = (long double)(a-b);
        }else{
            d = (long double)(b-a);
        }
    }else if(rad == PI)
    {
        d = (long double)(a+b);
    }else{
        d = sqrt((long double)(a*a)+(long double)(b*b)-2.0*(long double)(a)*(long double)(b)*cosl(rad));
    }
    
    rad = rad1 - rad2;
    // long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
    // b) * cosl(rad);

    d = (long double)(a*a+b*b)-(long double)(2*a*b*cosl(rad));
    printf("%20.20Lf\n", sqrtl(d));
    // cout<<sqrt(d)<<endl;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n;
    cin>>n;
    vector<long long> a;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
            a.push_back(i+n/i-2);
        }
    }
    sort(a.begin(),a.end());
    cout<<a[0]<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2]) {
    cout << "No\n";
  }else {
    cout << "Yes\n";
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n, number[200], tmp, sum=0;
    scanf("%d", &n);
    for(int i=0; i<2*n; i++){
        scanf("%d", &number[i]);
    }
    for (int i=0; i<2*n; ++i) {
        for (int j=i+1; j<2*n; ++j) {
            if (number[i] > number[j]) {
                tmp =  number[i];
                number[i] = number[j];
                number[j] = tmp;
            }
        }
    }
    for (int i=0; i<2*n; i+=2){
        sum+=number[i];
    }
    printf("%d\n", sum);
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		double n = in.nextInt();
		int cnt = 0;
		while (n > 1) {
			n = (int)Math.ceil(n/3);
			cnt++;
		}
		out.println(cnt);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

int main(){
	int N,d;
	cin >> N;
	map<int,int> mp;
	for(int i=0; i<N; ++i){
		cin >> d;
		mp[d]++;
	}
	cin >> N;
	for(int i=0; i<N; ++i){
		cin >> d;
		if(--mp[d]<0){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    if (k == 1)
        cout << "Hello World";
    else
    {
        int a, b;
        cin >> a >> b;
        cout << a + b;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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 gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll a,b;
cin>>a>>b;
cout<<max({a+b,a-b,a*b})<<endl;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
int n , m ;
const int nmax = 1005 ;
string a[nmax];
int dist[nmax][nmax]={-1};
void solve(){
    cin >> n >> m ;
    for( int  i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    queue < pair < int , int > > q ;
    for( int i = 0 ; i < n ; i++){
        for( int j = 0 ; j < m ; j++){
                dist[i][j]=-1;
            if(a[i][j]=='#'){
                q.push({i,j});
                dist[i][j]=0;
            }
        }
    }
    int c=0;
    while(!q.empty()){
        c++;
        int row = q.front().ff;
        int col = q.front().ss;
        q.pop();
        for( int i = 0 ; i < 4 ; i++){
            int r = row + dx[i];
            int c = col + dy[i];
            if(r>=0 & r<n && c >=0 && c<m && dist[r][c] == -1){
                q.push({r,c});
                dist[r][c] = dist[row][col]+1;
            }
        }
    }
    int maxm = -1 ;
    for( int i = 0 ; i< n ; i++){
        for( int j = 0 ; j < m ; j++){
            maxm = max(maxm,dist[i][j]);
        }
    }
    cout << maxm ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

/*const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}*/

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int i = 0, j = n - 1, ans = 0, fl = true;
    while (i < j) {
        if (s[i] == 'W') {
            while (s[j] != 'R') {
                j--;
                if (j == i) {fl = false; break;}
            }
            if (!fl) {
                break;
            }
            if (s[j] == 'R') {
                ans++;
                s[i] = 'R', s[j] = 'W', i++;
            }
        } else {
            i++;
        }
    }

    cout << ans << endl;

}

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

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3760
yukichi_num = 0
ichiyou_num = 0
d,e,f = -1,-1,-1
a,b = map(int,input().split())
for i in range(a+1):
    for  n in range(a+1-i):
        if i*10000+n*5000+1000*(a-i-n) == b:
            d = i
            e = n
            f = a-i-n
print('{0} {1} {2}'.format(d,e,f))

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

using namespace std;

int main()
{
  int n, tmp;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    cin >> tmp;
    a.push_back(tmp);
  }

  int flag = 1;
  int swapCount = 0;
  int sortedIndex = 0;

  while (flag == 1)
  {
    flag = 0;
    for (int i = n - 1; i > sortedIndex; --i)
      if (a[i] < a[i - 1])
      {
        swap(a[i], a[i - 1]);
        swapCount++;
        flag = 1;
      }
    sortedIndex++;
  }

  for (int i = 0; i < n - 1; ++i)
    printf("%d ", a[i]);
  printf("%d\n", a[n - 1]);
  printf("%d\n", swapCount);
  return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
	READARR(x, n);
	int fac[n + 1], dp[n + 1]= {};
	fac[0] = 1;
	FOR (i, 1, n) fac[i] = fac[i - 1] * i % mod, dp[i] = (i*dp[i - 1] + fac[i - 1]) % mod;
	
	int sum = 0;
	FOR (i, 1, n - 1)
	    sum = (sum + dp[i] * (x[i + 1] - x[i]) % mod * power(fac[i]) % mod * fac[n - 1] % mod) % mod;
	
	cout << sum;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string s;
  cin >> s;
  int g = 0;
  int p = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'g') {
      g++;
    } else {
      p++;
    }
  }
  cout << ((p+g)/2) - p << endl;
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using std::vector;
    
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  std::cin >> n;
  
  int pow_of_2 = 1;

  while (2 * pow_of_2 <= n) {
    pow_of_2 *= 2;
  }

  std::cout << pow_of_2;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  int n,w; cin >>n >>w;
  vector<ll> weight(n),value(n);
  rep(i,n) cin >>weight.at(i) >>value.at(i);
  vector<vector<ll>> dp(n+1, vector<ll>(w+1, 0));
  for (int i=0; i<n; i++){
    for (int j=0; j<=w; j++){
      chmax(dp.at(i+1).at(j), dp.at(i).at(j));
      if (j+weight.at(i) <= w) chmax(dp.at(i+1).at(j+weight.at(i)), dp.at(i).at(j) + value.at(i));
    }
  }
  cout <<dp.at(n).at(w) <<endl;
}

Measured memory_bytes: 80256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
ll dp[305][305],dp2[305][305];
int main(){
	ll n,m,k;
    cin>>n>>m>>k;
      for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(i!=j)dp[i][j]=dp2[i][j]=inf;
      for(int i=0;i<m;i++){
          ll a,b,c;
          cin>>a>>b>>c;
          a--;b--;
          dp[a][b]=c;
          dp[b][a]=c;
      }
      for(int r=0;r<n;r++)
                for(int i=0;i<n;i++)
                   for(int j=0;j<n;j++)
                         dp[i][j]=min(dp[i][j],dp[i][r]+dp[r][j]);

          for(int i=0;i<n;i++)
               for(int j=0;j<n;j++)
                    if(dp[i][j]<=k)dp2[i][j]=min(dp2[i][j],1ll);
     for(int r=0;r<n;r++)
                for(int i=0;i<n;i++)
                   for(int j=0;j<n;j++)
                      dp2[i][j]=min(dp2[i][j],dp2[i][r]+dp2[r][j]);
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        a--;b--;
       if(dp2[a][b]>=inf)cout<<-1<<"\n";
       else cout<<dp2[a][b]-1<<"\n";
    }
}

Measured memory_bytes: 2048
#include <stdio.h>

int main() {
	int f_hill = 0, s_hill = 0, t_hill = 0;
	int i;

	int height[10];
	
	for(i = 0; i < 10; i++)
		scanf("%d", &height[i]);
	
	for(i = 0; i < 10; i++) {
		if(height[i] > f_hill) {
			t_hill = s_hill;
			s_hill = f_hill;
			f_hill = height[i];
		}
		else if(height[i] > s_hill) {
			t_hill = s_hill;
			s_hill = height[i];
		}
		else if(height[i] > t_hill)
			t_hill = height[i];
	}

	printf("%d\n", f_hill);
	printf("%d\n", s_hill);
	printf("%d\n", t_hill);

	return 0;
}

Measured memory_bytes: 600
#include <queue>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef pair<int, int> pii;

#define fi first
#define se second

namespace io
{
	const int maxb = 1 << 15;
	char b[maxb], *s = b, *t = b;
	bool getchar(char &ch)
	{
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++;
	}
	int getint()
	{
		char ch;
		while (getchar(ch) && (ch < '0' || ch > '9'));
		int s = ch - '0';
		while (getchar(ch) && ch >= '0' && ch <= '9')
			s = s * 10 + ch - '0';
		return s;
	}
}

using io::getint;

template<typename ty> bool Chkmax(ty &x, const ty &y) { return x < y ? x = y, 1 : 0; }
template<typename ty> bool Chkmin(ty &x, const ty &y) { return x > y ? x = y, 1 : 0; }

const int maxn = 5e5 + 10;

int n, k, a[maxn];

struct segment_tree
{
	int M;
	pii T[maxn * 4];
	
	void init()
	{
		for (M = 1; M < n + 2; M <<= 1);
		for (int i = 1; i <= n; ++ i)
			T[i + M] = pii(a[i], i);
		for (int i = M - 1; i; -- i)
			T[i] = max(T[i << 1], T[i << 1 | 1]);
	}
	
	void erase(int x)
	{
		for (T[x += M] = pii(0, 0); x > 1; x >>= 1)
			T[x >> 1] = max(T[x], T[x ^ 1]);
	}
	
	pii query(int s, int t)
	{
		pii res(0, 0);
		for (s += M - 1, t += M + 1; s ^ t ^ 1; s >>= 1, t >>= 1)
		{
			if (~ s & 1) Chkmax(res, T[s ^ 1]);
			if (  t & 1) Chkmax(res, T[t ^ 1]);
		}
		return res;
	}
	
} T;

priority_queue<int> Q;
bool inq[maxn];

void insert(int id)
{
	if (!id) return;
	int l = (id - 1) * k + 1, r = min(id * k, n);
	if (l > r) return;
	int pos = T.query(l, r).se;
	if (pos && !inq[pos] && T.query(max(1, pos - k + 1), min(n, pos + k - 1)).se == pos)
	{
		Q.push(pos);
		inq[pos] = true;
	}
}

int ans[maxn];

int main()
{
	n = getint(), k = getint();
	for (int i = 1; i <= n; ++ i) a[i] = getint();
	T.init();
	int tot = (n + k - 1) / k;
	for (int i = 1; i <= tot; ++ i) insert(i);
	for (int i = n; i; -- i)
	{
		int cur = Q.top(); Q.pop();
		ans[cur] = i;
		T.erase(cur);
		cur = (cur + k - 1) / k;
		insert(cur - 1);
		insert(cur);
		insert(cur + 1);
	}
	for (int i = 1; i <= n; ++ i) printf("%d\n", ans[i]);
	return 0;
}


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

Measured memory_bytes: 3648