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

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


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
int a[35];
set<string> s1;
void print(set<string> S,int k)
{
     int i=1;	
	for(set<string>::iterator it = S.begin();it != S.end();it++)
	{
		//cout<<" "<<(*it);
		if(i==k) cout<<(*it)<<endl;	
		i++;
	}
}
void print(set<string> S)
{
	cout<<S.size()<<":";
	for(set<string>::iterator it = S.begin();it != S.end();it++)
	{
		cout<<" "<<(*it);
	}
	cout<<endl;
}
int main()
{
	string s;
	getline(cin,s);
	int len=s.length();
	//for(int i=0;i<len;i++)
	    //a[s[i]-'a']++;
	int k;
	cin>>k;
	int index=0;
    for(int i=1;i<=k;i++)
       for(int j=0;j+i<=len;j++)
          {
          		s1.insert(s.substr(j,i));
		  }
	//print(s1);
	print(s1,k);
	return 0;
 } 

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

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

    ll answer = 0;
    for(int j = 1; j <= n; j++)
    {
        ll termCount = n / j;
        answer += termCount * (termCount + 1) * j / 2;
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int lcs[3001][3001],i,j;
string s1,s2;
vector<char> v;
void func(int x,int y)
{
    if(x==0 || y==0) return ;
    if(lcs[x][y]==lcs[x-1][y])
    {
        func(x-1,y);
    }
    else if(lcs[x][y]==lcs[x][y-1])
    {
        func(x,y-1);
    }
    else if(lcs[x][y]==lcs[x-1][y-1]+1)
    {
        v.push_back(s1[x-1]);
        func(x-1,y-1);
    }
}
int main()
{
    cin>>s1;
    cin>>s2;
    for(i=0;i<s1.size();i++)
    {
        for(j=0;j<s2.size();j++)
        {
           if(s1[i]==s2[j]) lcs[i+1][j+1]=lcs[i][j]+1;
           else lcs[i+1][j+1]=max(lcs[i][j+1],lcs[i+1][j]);
        }
    }
    func(s1.size(),s2.size());
    for(i=v.size()-1;i>=0;i--)
    {
        printf("%c",v[i]);
    }
}


Measured memory_bytes: 35456
n = int(input())
A = list(map(int, input().split()))

if A.count(0) >= 1:
    ans = 0
    for i in range(n):
        ans += abs(A[i])
else:
    ans = 0
    parity = 0
    absmin = 10**10
    for i in range(n):
        if A[i] < 0:
            parity += 1
        absmin = min(absmin, abs(A[i]))
        ans += abs(A[i])
    if parity % 2 == 0:
        pass
    else:
        ans = ans - absmin * 2
print(ans)



Measured memory_bytes: 15020
import numpy as np

N=int(input())
S=input()

W=[0 for i in range(N)] # W[i]=(S[i]より西で西を向いている人の数)
E=[0 for i in range(N)] # E[i]=(S[i]より東で東を向いている人の数)

for i in range(1,N):
    if S[i-1]=='W':
        W[i]=W[i-1]+1
    else:
        W[i]=W[i-1]
for i in reversed(range(N-1)):
    if S[i+1]=='E':
        E[i]=E[i+1]+1
    else:
        E[i]=E[i+1]

print(min([x for x in np.array(W)+np.array(E)]))

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

int main()
{
  int a, b;
  cin >> a >> b;
  int count=0;
  for(int i = a; i <= b; i++)
  {
   	string str = to_string(i);
    if(str[0] == str[4] && str[1] == str[3]) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,a,b,n,i,j,k,sum=0;
    cin>>n;
    ll A[n];
    for(i=0;i<n;i++)
        cin>>A[i];
    sort(A,A+n);
    if(A[n/2]==A[(n/2)-1])
        cout<<0;
    else
        cout<<(A[n/2]-A[(n/2)-1]);
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<queue>
#include<map>

using namespace std;

int main(){
	long long a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='+')
	cout<<a+b<<endl;
	else
	cout<<a-b<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);//freopen("in.txt", "r", stdin);
#else 
#endif
}
void fast(){
	std::ios_base::sync_with_stdio(0); cin.tie(NULL);
}
int main()
{
	fast();
	unsigned long long q, h, s, d,mn1,num,ans;
	cin >> q >> h >> s >> d>>num;
	q *= 4;
	h *= 2;
	mn1 = min(q, min(h,s));
	if (num == 1){
		cout << mn1*num<< endl;
		return 0;
	}
	else
	if (num % 2 != 0){
		ans = mn1;
		num--;
		if (mn1 * 2 <= d){
			ans += num*mn1;
		}
		else {
			ans += (num / 2 * d);
		}
		cout << ans << endl;
	}
	else {
		 ans = 0;
		 if (mn1 * 2 <= d){
			 ans += num*mn1;
		 }
		 else {
			 ans += (num / 2 * d);
		 }
		 cout << ans << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;
using ld = long double;
class DisjointSets
{
public:
    DisjointSets(const int v)
    {
        m_parent.resize(v);
        m_rank.resize(v);
        m_size.resize(v);
        for (int i = 0; i < v; i++) {
            m_parent[i] = i;
            m_rank[i] = 0;
            m_size[i] = 1;
        }
    }

    bool same(const int a, const int b)
    {
        return find(a) == find(b);
    }


    int find(const int a)
    {
        if (m_parent[a] == a) {
            return a;
        } else {
            return m_parent[a] = find(m_parent[a]);
        }
    }

    void unite(const int a_, const int b_)
    {
        const int a = find(a_);
        const int b = find(b_);
        if (a == b) {
            return;
        }
        if (m_rank[a] > m_rank[b]) {
            m_parent[b] = a;
            m_size[a] += m_size[b];
        } else {
            m_parent[a] = b;
            m_size[b] += m_size[a];
        }
        if (m_rank[a] == m_rank[b]) {
            m_rank[b]++;
        }
    }

    int getSize(const int a)
    {
        return m_size[m_parent[a]];
    }

private:
    vector<int> m_parent;
    vector<int> m_rank;
    vector<int> m_size;
};

struct Edge {
    int from;
    int to;
    ld cost;
    bool operator<(const Edge& e) const
    {
        return cost < e.cost;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    using P = pair<ld, ld>;
    vector<P> pos(n);
    for (int i = 0; i < n; i++) {
        cin >> pos[i].first >> pos[i].second;
    }
    priority_queue<Edge> Q;
    DisjointSets uf(n);
    ld total = 0;
    for (int i = 0; i < m; i++) {
        int from;
        int to;
        cin >> from >> to;
        from--, to--;
        const ld l = hypot(pos[from].first - pos[to].first, pos[from].second - pos[to].second);
        total += l;
        Q.push(Edge{from, to, l});
    }

    ld rest = 0;
    for (int i = 0; i < m; i++) {
        const auto& e = Q.top();
        const int p = e.from;
        const int q = e.to;
        if (not uf.same(p, q)) {
            uf.unite(p, q);
            rest += e.cost;
        }
        Q.pop();
    }
    cout << fixed << setprecision(10) << total - rest << endl;

    return 0;
}

Measured memory_bytes: 4488
k=int(input())

from heapq import heappush, heappop,heappushpop,heapify
ans=[1,2,3,4,5,6,7,8,9]
heapify(ans)

a=0
for i in range(k):
    a=heappop(ans)
    md=a%10
    if md != 0:
        heappush(ans,10*a + md-1)
    if md != 9:
        heappush(ans,10*a + md+1)
    heappush(ans,10*a+md)
print(a)

Measured memory_bytes: 55604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int fact(int n); 
  
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
// Returns factorial of n 
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
int solve()
{
    string s;
    cin>>s;
    int ans  = 1;
    int n = s.length();
    rep(i,n)
    {
        if(s[i]!=s[n-i-1])
        {
            ans = 0;
            break;
        }
    }
    rep(i,(n-1)/2)
    {
        if(s[i]!=s[(n-1)/2-i-1])
        {
            ans = 0;
            break;
        }
    }
    rep_a(i,(n+3)/2 - 1,n)
    {
        if(s[i]!=s[n-i-1])
        {
            ans = 0;
            break;
        }
    }
    if (ans)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #endif */
    solve();
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif */
    return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <vector>


struct statement
{
    unsigned honest = 0;
    unsigned unkind = 0;
};

static bool check_consistency(
    std::vector<statement> const& statements, unsigned condition
);

static bool checkbit(unsigned bits, int i);
static int  popcount(unsigned bits);


int main()
{
    std::vector<statement> statements;

    int n_people;
    std::cin >> n_people;

    for (int i = 0; i < n_people; i++) {
        int n_statements;
        std::cin >> n_statements;

        statement stmt;

        for (int j = 0; j < n_statements; j++) {
            int person;
            int type;
            std::cin >> person >> type;

            // Input index is one-based. Our index is zero-based.
            assert(person >= 1);
            person -= 1;

            // Input coding is 0: unkind, 1: honest.
            if (type == 0) {
                stmt.unkind |= 1u << person;
            } else {
                stmt.honest |= 1u << person;
            }
        }

        statements.push_back(stmt);
    }

    int max_honests = 0;
    unsigned n_conditions = 1u << n_people;
    for (unsigned condition = 0; condition < n_conditions; condition++) {
        if (check_consistency(statements, condition)) {
            max_honests = std::max(max_honests, popcount(condition));
        }
    }

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


static bool check_consistency(
    std::vector<statement> const& statements, unsigned condition
)
{
    auto const n_people = statements.size();

    for (std::size_t i = 0; i < n_people; i++) {
        if (!checkbit(condition, i)) /* i is unkind; can't say anything */ {
            continue;
        }
        auto const& stmt = statements[i];

        // Now we assume i is honest.

        if (stmt.honest & ~condition) {
            return false;
        }
        if (stmt.unkind & condition) {
            return false;
        }
    }
    return true;
}


static bool checkbit(unsigned bits, int i)
{
    return (bits >> i) & 1;
}


static int popcount(unsigned bits)
{
    int n = 0;
    for (int i = 0; i < 32; i++) {
        n += checkbit(bits, i);
    }
    return n;
}


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

int main(void){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	if(a[1]>=0){
		int ans = -a[0];
		for(int i = 1; i < n; ++i){
			ans+=a[i];
		}
		cout << ans << endl;
		int before = a[0];
		for(int i = 1; i < n-1; ++i){
			cout << before << " "<< a[i] << endl;
			before -= a[i];
		}
		cout << a[n-1] << " " << before << endl;
		return 0;
	}
	if(a[n-2]<=0){
		sort(a.rbegin(), a.rend());
		int ans = a[0];
		for(int i = 1; i < n; ++i){
			ans -= a[i];
		}
		cout << ans << endl;
		int before = a[0];
		for(int i = 1; i < n-1; ++i){
			cout << before << " "<< a[i] << endl;
			before -= a[i];
		}
		cout << before << " " << a[n-1] << endl;
		return 0;
	}
	int m;
	int ans = 0;
	for(int i = 0; i < n; ++i){
		if(a[i]>=0){
			m=i;
			break;
		}
		ans -= a[i];
	}
	for(int i = m; i < n; ++i){
		ans += a[i];
	}
	cout << ans << endl;
	int before = a[m-1];
	for(int i = m; i < n-1; ++i){
		cout << before << " " << a[i] << endl;
		before -= a[i];
	}
	cout << a[n-1] <<  " " << before << endl;
	before = a[n-1] - before;
	for(int i = m-2; i >= 0; --i){
		cout << before << " " << a[i] << endl;
		before -= a[i];
	}
}

Measured memory_bytes: 2304
def main():
	N = int(input())
	dp = [1]*(N+1)
	ans = 0
	for i in range(2, N+1):
		div = 1
		while i * div <= N:
			dp[i*div] += 1
			div += 1
		if dp[i] == 8 and i%2==1:
			ans += 1
	print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a > b){
        int t = a;
        a = b;
        b = t;
    }

    if (a < c && c < b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b;

    scanf("%d %d",&a,&b);

  if(a>b){
      printf("a > b\n");
  }else if(a<b){
      printf("a < b\n");
  }else{
      printf("a == b\n");
  }
return 0;
}



Measured memory_bytes: 2100
from operator import itemgetter
n=int(input())
a=[]
for _ in range(n):
	x,y=map(int,input().split( ))
	a.append((x,y))
a.sort(key=itemgetter(1))
total=0
for b,c in a:
	total+=b
	if total>c:
		print("No")
		exit(0)
	
print("Yes")






Measured memory_bytes: 31932
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
size = a.size
a = a.sort 
i = 1
while true
    if a[i] == a[i-1]
        puts "NO"
        break
    else
        i += 1
    end
    if size  == i - 1
        puts "YES"
        break
    end
end

Measured memory_bytes: 33044
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define int long long
#define PI 3.14159265358979l
signed main() {
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
   
    int ans = 0;
    rep(i, n) {
        char s[3] = { a[i],b[i],c[i] };
        if (s[0] == s[1] && s[0] != s[2]) {
            ans++;
        }
        else if (s[0] == s[2] && s[0] != s[1]) {
            ans++;
        }
        else if (s[1] == s[2] && s[1] != s[0]) {
            ans++;
        }
        else if (s[1] != s[2] && s[1] != s[0]) {
            ans += 2;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
int h[100005], dp[100005], N;

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

    for(int i = 0; i < N; i++)
        cin >> h[i];
    dp[1] = abs(h[1] - h[0]);
    for(int lvl = 2; lvl < N; lvl++)
        dp[lvl] =  min(dp[lvl - 2] + abs(h[lvl] - h[lvl - 2]), dp[lvl - 1] + abs(h[lvl] - h[lvl - 1]));

    cout << dp[N - 1] << "\n";

    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < s.length(); ++i)
		if(s[i] == '2')
			++cnt;
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int H, W, i, j;
    
    while(1){
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) break;
        if(H > 300 || W > 300){printf("error\n");return 0;}
    
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                if(i % 2 == 0){
                    if(j % 2 == 0){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }else{
                    if(j % 2 == 0){
                        printf(".");
                    }else{
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
            
        printf("\n");
    }
        
    return 0;
}
    

Measured memory_bytes: 572
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define y1 wzpakking
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
int n,m;
priority_queue<int> Q;
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n){
		int x;
		scanf("%d",&x);
		Q.push(x);
	}
	while (m--){
		int x=Q.top();
		Q.pop();
		Q.push(x/2);
	}
	ll ans=0;
	for (;!Q.empty();ans+=Q.top(),Q.pop());
	printf("%lld\n",ans);
}

Measured memory_bytes: 892
#include<stdio.h>
#define ifmod(a,mod) ((a) >= (mod) ? (a) % (mod) : (a))
#define QUEUE_LEN 400
#define INF 1<<13
#define max(a,b) ((a)>(b)?(a):(b))

typedef struct{
    int i,j;
}index;

typedef struct{
    index data[QUEUE_LEN];
    int len,head;
}queue;

static inline void enqueue(queue *qu,index data){
    qu->data[ifmod(qu->head + qu->len,QUEUE_LEN)] = data;
    qu->len++;
}

static inline index dequeue(queue *qu){
    index res = qu->data[qu->head];
    qu->len--;
    qu->head++;
    qu->head = ifmod(qu->head,QUEUE_LEN);
    return res;
}

int main(void){
    int h,w,ansmax = 0;
    register int i,j,ii,jj;
    scanf("%d %d",&h,&w);
    getchar();//!'\n' befor grid input
    char grid[h][w];
    for(i = 0;i < h;i++,getchar())for(j = 0;j < w;j++)scanf("%c",&grid[i][j]);
    for(i = 0;i < h;i++)for(j = 0;j < w;j++){//! start
        if(grid[i][j] == '#')continue;
        int rmax = 0;
        int dist[h][w];
        for(ii = 0;ii < h;ii++)for(jj = 0;jj < w;jj++)dist[ii][jj] = INF;
        queue qu = (queue){.len = 0,.head = 0};
        dist[i][j] = 0;
        enqueue(&qu,(index){i,j});
        while(qu.len){
            index ver = dequeue(&qu);
            int ndist = dist[ver.i][ver.j];
            if(ver.i != 0 && grid[ver.i-1][ver.j] != '#' && dist[ver.i-1][ver.j] == INF){
                dist[ver.i-1][ver.j] = ndist + 1;
                enqueue(&qu,(index){ver.i-1,ver.j});
            }
            if(ver.j != 0 && grid[ver.i][ver.j-1] != '#' && dist[ver.i][ver.j-1] == INF){
                dist[ver.i][ver.j-1] = ndist + 1;
                enqueue(&qu,(index){ver.i,ver.j-1});
            }
            if(ver.i+1 != h && grid[ver.i+1][ver.j] != '#' && dist[ver.i+1][ver.j] == INF){
                dist[ver.i+1][ver.j] = ndist + 1;
                enqueue(&qu,(index){ver.i+1,ver.j});
            }
            if(ver.j+1 != w && grid[ver.i][ver.j+1] != '#' && dist[ver.i][ver.j+1] == INF){
                dist[ver.i][ver.j+1] = ndist + 1;
                enqueue(&qu,(index){ver.i,ver.j+1});
            }
        }//! while
        for(ii = 0;ii < h;ii++)for(jj = 0;jj < w;jj++)if(grid[ii][jj] != '#')rmax = max(rmax,dist[ii][jj]);
        ansmax = max(ansmax,rmax);
    }
    printf("%d",ansmax);
    return 0;
}

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

int main() {
    int x; cin >>x;
    bool ret = 0;

    for (int i = 1; i < 1000; i++) {
        if (i*100<=x && x<=105*i) {ret = 1; break;}
    }
    if (x==100000) ret = 1;

    cout << ret << endl;
    return 0;
}

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

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

    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}

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

int main() {
	int h, w;
	cin >> h >> w;
	string s[50];

	const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
	const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
	for (int i = 0; i < h; ++i) cin >> s[i];

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j)	{
			if (s[i][j] == '#') continue;
			int n = 0;

			for (int d = 0; d < 8 ; ++d) {
				int x = j + dx[d], y = i + dy[d];
				if (x < 0 || y < 0 || w <= x || h <= y) continue;
				if (s[y][x] == '#') ++n;
			}

			s[i][j] = char (n + '0');
		}
		cout << s[i] << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
     int n, num, digit, rev = 0;
     cin >> num;
     n = num;
     do{
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     }
     while (num != 0);

     if (n == rev)
         cout << "Yes"<<endl;
     else
         cout << "No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string,int> table;
int main(){
    string str;
    string maxLen, maxT;
    while(cin >> str)
	{
        (table[str])++;
        if(table[maxT] < table[str])
		{
            maxT = str;
		}
        if(maxLen.size() < str.size())
		{
            maxLen = str;
		}
    }
    cout << maxT << ' ' << maxLen << endl;    
}

Measured memory_bytes: 3220
# coding: utf-8
# Your code here!

N = int(input())

for i in range(N):
    a,b,c = map(int,input().split())
    a = a*a
    b = b*b
    c = c*c
    if a==b+c or b==a+c or c==a+b:
        print('YES')
    else:
        print('NO')



Measured memory_bytes: 5596
import heapq

n,m,K=map(int,raw_input().split())
g=[[] for _ in xrange(n)]
cost=[[10**5]*n for _ in xrange(n)]

for i in xrange(m):
    a,b,l=map(int,raw_input().split())
    a-=1;b-=1
    g[a].append(b)
    g[b].append(a)
    cost[a][b]=l
    cost[b][a]=l

pq=[]
d=[float('inf')]*n
for i in xrange(K):
    c=int(raw_input())-1
    heapq.heappush(pq,[0,c])
    d[c]=0
while len(pq)!=0:
    t,u=heapq.heappop(pq)
    if d[u]<t:
        continue
    for v in g[u]:
        if d[u]+cost[u][v]<d[v]:
            d[v]=d[u]+cost[u][v]
            heapq.heappush(pq,[d[v],v])

ans=0
for i in xrange(n):
    for j in g[i]:
        ans=max(ans,(1+d[i]+d[j]+cost[i][j])/2)
print(ans)

Measured memory_bytes: 87308
package main

import (
	"fmt"
	"strings"
)

func main() {

	var S string

	fmt.Scan(&S)

	Acount := strings.Count(S,"A") 
	
	if Acount ==0 || Acount ==3{

		fmt.Println("No")

	}else{

		fmt.Println("Yes")
	}

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>

#include<iostream>
using namespace std;

int main() {
    int W, H,x,y;
	cin >> W >> H>>x>>y;
	double sq = (double)W * H/2;
	printf("%.10f ",sq);
    
	
	if (2*x == W  && 2*y == H ) cout << 1 << endl;
	else cout << 0 << endl;
	
}




Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/02/20 20:07:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int INF = 1e9+1;

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

  int n; cin>>n;
  vector<int> A(n); for(auto& a:A) cin>>a;
  vector<int> graph[n];
  for (int i = 0; i < n-1; i++) {
    int u,v; cin>>u>>v; u--; v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<int> dp(n,INF);
  vector<int> ans(n);
  auto dfs = [&graph,&dp,&A,&ans](auto& f, int s, int p) -> void {
    auto bound = lower_bound(dp.begin(), dp.end(), A[s]);
    bool changed = false;
    int prev = *bound;
    if (*bound > A[s]) {
      changed = true;
      *bound = A[s];
    }
    ans[s] = lower_bound(dp.begin(), dp.end(), INF)-dp.begin();
    for (auto t:graph[s]) {
      if (t == p) continue;
      f(f, t, s);
    }
    if (changed)
      *bound = prev;
  };
  dfs(dfs, 0, -1);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 30752
import math
X = int(input())

flug=0
while(flug == 0):
  flug2=1
  for i in range(2,round(math.sqrt(X))+1):
    if X%i==0:
      flug2=0
      
  if flug2==1:
    flug=1
    
  else:
    X+=1
    
print(X)

Measured memory_bytes: 9204
integer mi,ma,md
integer N
integer cnt
integer,allocatable,dimension(:)::mins
integer A
read*,N
read*,A
allocate(mins(N))
cnt=1
mins(1)=A
do i=2,N
  read*,A
  if(A>mins(cnt))then
    mi=0
    ma=cnt 
    do while(mi+1<ma)
      md=(mi+ma-1)/2+1
      if(mins(md)<A)then
        ma=md
      else
        mi=md
      endif
    end do
    mins(ma)=A
  else
    cnt=cnt+1
    mins(cnt)=A
  end if
end do
print"(I0)",cnt
end

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

typedef long long ll;

int main(){
  int N;
  cin >> N;
  map<int,int> m;
  
  for(int i = 1; i <= N; i++){
    m[i] = 0;
  }
  for(int i = 1; i <= N; i++){
    int tmp;
    cin >> tmp;
    m[tmp] = m[tmp] + 1;
    if(tmp > 1) m[tmp-1]++;
    if(tmp < N) m[tmp+1]++;
  }
  
  int tmpmax = 0;
  int tmpindex;
  for(auto x : m){
    if(x.second > tmpmax){
      tmpmax = x.second;
      tmpindex = x.first;
    }
  }
  
  cout << m[tmpindex] << endl;

}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	vi h(n, 0); zip(i, 0, n)  cin >> h[i];
	int ans = 0;
	//better O(n) approach for this problem previos approach is brute force very bad.....

	ans += h[0];
	zip(i, 1, n)
	{
		int x = h[i] - h[i - 1];

		if (x > 0) //because agar element pichle wale sae choa hai to pichla wala sambhaal lega varna apan ko eventually difference to add karna hoga
		{
			ans += x;
		}
	}

	// zip(i, 0, n)
	// {
	// 	int j = i;
	// 	int x = inf;

	// 	while (h[j] > 0 && j < n)
	// 	{
	// 		x = min(x, h[j]);
	// 		j++;
	// 	}
	// 	rep(k, i, j - 1)
	// 	{
	// 		if (x != inf)
	// 		{
	// 			h[k] -= x;
	// 		}
	// 	}
	// 	if (x != inf)
	// 	{
	// 		ans += x;
	// 		i = -1;
	// 	}
	// }
	cout << ans << en;
	// zip(i, 0, n)
	// {
	// 	zip(j, i, n)
	// 	{
	// 		int x = 1e9;
	// 		int y = 0;
	// 		zip(k, i, j + 1)
	// 		{
	// 			x = min(h[k], x);
	// 			y = max(h[k], y);
	// 		}
	// 		if ((i == 0 || h[i - 1] == 0) && (j == n - 1 || h[j + 1] == 0) && y > 0)
	// 		{
	// 			zip(k, i, j + 1)
	// 			{
	// 				h[k] -= x;
	// 			}
	// 			ans += x;
	// 			i = -1;
	// 			//j = 0;

	// 		}
	// 	}
	// }




	return 0;
}



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


using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	
	vector<long long>h(n,0);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}
	
	if(n <= k){
		cout << 0 << endl;
		return 0;
	}
	//全部必殺技で終わる
	
	
	std::sort(h.begin(), h.end());
	long long ans = 0;
	for(int i = 0; i < n - k; i ++) {
		ans += h.at(i);
	}
	
	cout << ans << endl;

	return 0;
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vector<string> v(h, string(w, '0'));
  for (int i = 0; i < b; ++i) {
    for (int j = 0; j < a; ++j) {
      v[i][j] = '1';
    }
  }
  for (int i = b; i < h; ++i) {
    for (int j = a; j < w; ++j) {
      v[i][j] = '1';
    }
  }
  for (string s : v) {
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
// Seiranchan!
    int N,sum=0,ans=0;
    cin >> N;
    char a;

    REP(i,N){
        cin >> a;
        if(a=='I'){
            sum ++;
        }else{
            sum --;
        }
        ans =max(ans,sum); 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=3e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n;
ll A,B,K;
void input()
{
	n=read<int>();
	A=read<ll>(),B=read<ll>(),K=read<ll>();
}
const int mo=998244353;
int mc[N],inv[N];
ll power(ll x,int y)
{
	ll res=1;
	for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
	return res;
}
int C(int x,int y){return (ll)mc[x]*inv[y]%mo*inv[x-y]%mo;}
int sum[N],ans;
int cal(int i)
{
	ll res=K-A*i;
	if(res<0)return 0;
	else 
	{
		if(res%B)return 0;
		if(res/B>n)return 0;
		return C(n,res/B);
	}
}
void work()
{
	mc[0]=inv[0]=1;
	For(i,1,n)mc[i]=(ll)mc[i-1]*i%mo;
	inv[n]=power(mc[n],mo-2);
	Fordown(i,n-1,1)inv[i]=(ll)inv[i+1]*(i+1)%mo;
	Fordown(i,n,0)sum[i]=(sum[i+1]+C(n,i))%mo;
	For(i,0,n)
	{
		ans=(ans+1ll*C(n,i)*cal(i)%mo)%mo;
		//cout<<i<<' '<<cal(i)<<' '<<C(n,i)<<' '<<sum[cal(i)]<<endl;
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 3712
# coding: utf-8
N = gets.to_i
s = []
N.times do |_|
  s << gets.chomp
end

M = gets.to_i
t = []
M.times do |_|
  t << gets.chomp
end

# 青のカードに書かれた文字を一つずつ検査する
# ansは最大点を保存する
ans = 0
s.each do |word|
  cp = 0
  # 青カード検索（point up）
  cp += (s.select {|w| w == word}).size
  # 赤カード検索（point down)
  cp -= (t.select {|w| w == word}).size
  # ループの終わりで最大点を比較して、より高得点だったら更新する
  ans = cp if cp > ans
end

puts ans


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

#define maxn 2500
#define INF 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
using namespace std;



void slove()
{
	int n, tmp, flag = 0;
	cin >> n;
	while (n)
	{
		tmp = n % 10;
		n /= 10;
		if (tmp == 7)
		{
			flag = 1;
			break;
		}
	}
	if (flag) cout << "Yes\n";
	else cout << "No\n";
}

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

	slove();

	return 0;
}

Measured memory_bytes: 3584
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	int n = read.to!int;
	int m = read.to!int;
	
	bool[int] isUsed;
	for(int i = 1; i <= n; i ++) isUsed[i] = 0;
	
	debug isUsed.writeln;
	
	int a, b;
	bool[int][int] adjset;
	for(int i = 0; i < m; i ++){
		a = read.to!int;
		b = read.to!int;
		adjset[a][b] = 1;
		adjset[b][a] = 1;
		}
	
	int a0 = a;
	isUsed[a] = 1;
	
	int[] ans1 = [];
	while(1){
		int[] bs = adjset[a].keys;
		debug writeln(a, " ", bs, " ", isUsed);
		bool foundflag = 0;
		foreach(b1; bs){
			if(!isUsed[b1]){
				b = b1;
				debug writeln(b);
				foundflag = 1;
				break;
				}
			}
		if(!foundflag) break;
		else{
			isUsed[b] = 1;
			ans1 ~= b;
			a = b;
			}
		}
	
	debug writeln("-");
	
	a = a0;
	int[] ans2 = [];
	while(1){
		int[] bs = adjset[a].keys;
		debug writeln(a, " ", bs, " ", isUsed);
		bool foundflag = 0;
		foreach(b1; bs){
			if(!isUsed[b1]){
				b = b1;
				debug writeln(b);
				foundflag = 1;
				break;
				}
			}
		if(!foundflag) break;
		else{
			isUsed[b] = 1;
			ans2~= b;
			a = b;
			}
		}
	
	int[] ans1reverse;
	for(int i = cast(int)(ans1.length - 1); i >= 0; i --) ans1reverse ~= ans1[i];
	int[] ans = ans1reverse ~ [a0] ~ ans2;
	
	ans.length.writeln;
	ans.map!(to!string).join(" ").writeln;
	} 

Measured memory_bytes: 43644
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
struct S{
  mint sum,nb;
};
struct F{
  mint b,c;
};
S op(S a, S b){
  return S{a.sum+b.sum, a.nb+b.nb};
}
S e(){
  return S{0, 0};
}
S mapping(F f, S x){
  return S{f.b*x.sum+f.c*x.nb, x.nb};
}
F composition(F f2, F f1){
  return F{f2.b*f1.b, f2.b*f1.c+f2.c};
}
F id(){
  return F{1, 0};
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,q,x,type,b,c,l,r;
  cin >> n >> q;
  vector<S> a(n);
  for(int i = 0; i < n; ++i){
    cin >> x;
    mint x2 = x;
    a[i] = S{x2,1};
  }
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
  while(q--){
    cin >> type >> l >> r;
    if(type == 0){
      cin >> b >> c;
      mint b2 = b, c2 = c;
      seg.apply(l,r,F{b,c});
    }
    else{
      cout << seg.prod(l,r).sum.val() << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 19448
from itertools import product

n = int(input())
n_len = len(str(n))
ans = 0
for i in range(3,n_len):
    ite = product(range(3),repeat=i)
    for it in ite:
        if 0 in it and 1 in it and 2 in it:
            ans += 1


num_d = {0:7,1:5,2:3}
ite = product(range(3),repeat=n_len)
for it in ite:
    if 0 in it and 1 in it and 2 in it:
        curr_num = 0
        for i,j in enumerate(it):
            curr_num += num_d[j]*(10**(n_len-1-i))
        if curr_num <= n: 
            ans+=1

print(ans)

Measured memory_bytes: 42588
fn main() {
    let (a, b) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let mut ws = s.trim_right().split_whitespace();
        let a: usize = ws.next().unwrap().parse().unwrap();
        let b: usize = ws.next().unwrap().parse().unwrap();
        (a, b)
    };
    let s: Vec<char> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().chars().collect()
    };

    let mut ans = true;
    for (i, c) in s.iter().enumerate() {
        if i < a || a+1 <= i {
            if (*c as u32) < 48+0 || 48+9 < (*c as u32) {
                ans = false;
                break;
            }
        } else if i == a {
            if *c != '-' {
                ans = false;
                break;
            }
        }
    }

    println!("{}", if ans {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h> 
using namespace std;
using ll = long long int;
ll A,B;
vector<ll> s(100005);
vector<ll> t(100005);
int binary_search_s(ll key){
    int left = -1;
    int right = A;
    while(right - left > 1){
        int mid = (left + right) / 2;
        
        if(s.at(mid) >= key){
            right = mid;
        }
        else{
            left = mid;
        }
    }
    return  left;
}

int binary_search_t(ll key){
    int left = -1;
    int right = B;
    while(right - left > 1){
        int mid = (left + right) / 2;
        
        if(t.at(mid) >= key){
            right = mid;
        }
        else{
            left = mid;
        }
    }
    return  left;
}


int main(void){

ll Q;
cin >> A >> B >> Q;
A += 2;
B += 2;
vector<ll> x(Q);
s.at(0) = -100000000000 ;
s.at(A-1) =100000000000 ;
t.at(0) = -100000000000 ;
t.at(B-1) =100000000000 ;

for(int i = 0; i < A-2; i++) cin >> s.at(i+1);
for(int i = 0; i < B-2; i++) cin >> t.at(i+1);
for(int i = 0; i < Q; i++) cin >> x.at(i); 

for(int i = 0; i < Q; i++){
      ll ans;
      ll a,b,c,d;
      a = abs(x.at(i)-s.at(binary_search_s(x.at(i))));
      b = abs(x.at(i)-s.at(1 + binary_search_s(x.at(i))));
      c = abs(x.at(i)-t.at(binary_search_t(x.at(i))));
      d = abs(x.at(i)-t.at(1 + binary_search_t(x.at(i))));
      
      ans = (2*a+d);
      ans = min(ans, a+2*d);
      ans = min(ans, max(a,c));
      ans = min(ans, 2*b+c);
      ans = min(ans,b+2*c);
      ans = min(ans,max(b,d));
      cout << ans << endl;
      
  }
}


Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

struct Dice
{
	vi d;
	static const int top = 0, frt = 1, rit = 2, lft = 3, bck = 4, btm = 5;
	Dice(){
		rep(i, 6) d.pb(i + 1);
	}
	Dice(vi d):d(d){}
	Dice(int _d[]){
		rep(i, 6) d.pb(_d[i]);
	}
	void spin(int f1, int f2, int f3, int f4){
		int tmp = d[f1];
		d[f1] = d[f2];
		d[f2] = d[f3];
		d[f3] = d[f4];
		d[f4] = tmp;
	}
	void spinN(){
		spin(top, frt, btm, bck);
	}
	void spinS(){
		spin(top, bck, btm, frt);
	}
	void spinE(){
		spin(top, lft, btm, rit);
	}
	void spinW(){
		spin(top, rit, btm, lft);
	}
	void spinCW(){
		spin(frt, rit, bck, lft);
	}
	void spinCCW(){
		spin(frt, lft, bck, rit);
	}

	void spin(char c){	
		if(c == 'N') spinN();
		else if(c == 'S') spinS();
		else if(c == 'E') spinE();
		else if(c == 'W') spinW();	
	}
	void spin(string s){
		for(char c : s){
			spin(c);
		}
	}
	void spin(int t, int f){
		rep(i, 4){
			if(d[top] == t) break;
			spinN();
		}
		rep(i, 4){
			if(d[top] == t) break;
			spinE();
		}
		rep(i, 4){
			if(d[frt] == f) break;
			spinCW();
		}
	}
};


int main(){
	vi v(6);
	rep(i, 6) cin>>v[i];
	Dice dice(v);
	int q; 
	cin>>q;
	int t, f;
	rep(i, q){
		cin>>t>>f;
		dice.spin(t, f);
		cout<<dice.d[2]<<endl;
	}
}

Measured memory_bytes: 3136
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction


def main():
    num, k = map(int, input().split())
    R, S, P = map(int, input().split())
    data = list(input())

    ans = 0
    ans_dic = {"r":P, "s":R, "p":S}

    for i in range(num):
        hand = data[i]
        if i < k:
            ans += ans_dic[hand]
        else:
            if data[i - k] == hand:
                data[i] = -1
            else:
                ans += ans_dic[hand]
    print(ans)



if __name__ == '__main__':
    main()



Measured memory_bytes: 78316
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int S=sc.nextInt();
    BigDecimal bd = new BigDecimal((double)S/3);
    bd = bd.setScale(8, RoundingMode.HALF_UP);
    BigDecimal s = bd.multiply(bd);
    BigDecimal v = s.multiply(bd);
    v = v.setScale(8, RoundingMode.HALF_UP);
    System.out.println(v);
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll N; cin >> N;
  ll X[N], Y[N], P[N]; rep(i,N) cin >> X[i] >> Y[i] >> P[i];
  ll xmin[N][1<<N], ymin[N][1<<N];
  rep(i,1<<N) rep(j,N) {
    xmin[j][i] = abs(X[j]); rep(k,N) if (i&1<<k) xmin[j][i] = min(xmin[j][i], abs(X[k]-X[j]));
    ymin[j][i] = abs(Y[j]); rep(k,N) if (i&1<<k) ymin[j][i] = min(ymin[j][i], abs(Y[k]-Y[j]));
  }
  // rep(i,N) debug(xmin[i],xmin[i]+(1<<N));

  ll result[N+1]; rep(i,N+1) result[i] = LLINF;
  rep(i,pow(3,N)) {
    ll ti = i, dx = 0, dy = 0, count = 0;
    rep(j,N) {
      if (ti%3==1) { dx += 1<<j; count++; }
      else if (ti%3==2) { dy += 1<<j; count++; }
      ti /= 3;
    }
    ll sum = 0; rep(j,N) sum += min(xmin[j][dx], ymin[j][dy]) * P[j];
    result[count] = min(result[count], sum);
  }
  rep(i,N+1) cout << result[i] << endl;
  return 0;
}

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

int n;
long double d,x;
long double ans;

int main()
{
	double _d,_x;
	scanf("%d%lf%lf",&n,&_d,&_x);
	d=_d,x=_x;
	for (int i=n;i>0;i--)
	{
		ans+=d+(i*2-1)*x/2;
		d=(d*(i*2+2)+x*5)/(i*2);
		x=(i*2+4)*x/(i*2);
	}
	printf("%.10lf\n",(double)ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using ll=long long;
int main(){ _;
  int n;cin>>n;
  ll sm=0;
  ll a,aprev=0;
  REP(i,n){
    cin>>a;
    if(aprev==1LL){
      if(a>0){
	sm++;
	a--;
      }
    }
    sm+=a/2;
    aprev=a-(a/2)*2;
  }
  cout<<sm<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main() {
	int n, a, b;


	cin >> n >> a >> b;


	int pat1 = n * a;
	int pat2 = b;


	cout << min({ pat1,pat2 }) << endl;

	return 0;
}

Measured memory_bytes: 256
def insertionSort(A,N):
    print (" ".join(map(str,A)))
    for i in range(1,N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print (" ".join(map(str,A)))

N = int(input())
A = list(map(int,input().split()))
insertionSort(A,N)

Measured memory_bytes: 7760
#include <bits/stdc++.h>
using namespace std;
int n;
map<vector<int>,int> bfs(vector<int> A){
  map<vector<int>,int> D;
  queue<vector<int> > Q;
  Q.push(A);
  D[A] = 0;
  while(!Q.empty()){
    vector<int> t = Q.front();Q.pop();
    int cost = D[t];
    if(cost == 4) continue;
    
    for(int i=0;i<n;i++)
      for(int j=i+2;j<=n;j++){
	vector<int> nt = t;
	reverse(nt.begin()+i,nt.begin()+j);
	if(D.count(nt)) continue;
	Q.push(nt);
	D[nt]=cost+1;
    }
  }
  return D;
}


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

  
  map<vector<int>,int> X = bfs(A);
  map<vector<int>,int> Y = bfs(B);

  map<vector<int>,int>::iterator it = X.begin();
  int ans = 9;
  
  for(;it!=X.end();it++)
    if(Y.count(it->first))ans = min(ans,it->second+Y[it->first]);
  
  cout<<ans<<endl;
  


  return 0;
}

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

using namespace std;

int gcd(int p,int q)
{
    if(p%q==0)return q;
    return gcd(q,p%q);
}

int main()
{
    int K;
    scanf("%d",&K);
    long long ans = 0;
    for(int a=1;a<=K;a++){
        for(int b=1;b<=K;b++){
            for(int c=1;c<=K;c++){
                ans+=gcd(gcd(a,b),c);
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	rep(i, a) {
		cin >> p[i];
	}
	rep(i, b) {
		cin >> q[i];
	}
	rep(i, c) {
		cin >> r[i];
	}
	ll ans = 0;
	sort(all(p)); reverse(all(p));
	sort(all(q)); reverse(all(q));
	sort(all(r)); reverse(all(r));
	vector<ll> aka(x), midori(y);
	priority_queue<ll, vector<ll>, greater<ll>> que;
	rep(i, x) {
		aka[i] = p[i];
		que.push(aka[i]);
		ans += aka[i];
	}
	rep(i, y) {
		midori[i] = q[i];
		que.push(midori[i]);
		ans += midori[i];
	}
	int rp = 0;
	while(!que.empty() && que.top() < r[rp]) {
		ans -= que.top();
		que.pop();
		ans += r[rp];
		rp++;
		if(rp >= c) break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6132
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    i64 i = f.size();
    if (x >= i) {
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 comb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}
int main() {
    i64 n, k;
    cin >> n >> k;
    cout << (n <= k) << endl;
    return 0;
}


Measured memory_bytes: 3112