akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 2101;
ld solve(ll n, ld d, ld x)
{
	if(n==1) return d*0.5;
	ld sum = d*0.5 + ld(n-1)*0.25*x;
	sum+=solve(n-1,d+((2*d+3*x)/ld(n*2)), x+(ld(4*x)/ld(2*n)));
	return sum;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n,d,x; cin>>n>>d>>x;
	cout<<fixed<<setprecision(20)<<solve(n,d+d+x,4*x)<<'\n';
}


Measured memory_bytes: 15872
n = $stdin.gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
mon = 1000;kab = 0

(n-1).times do |k|
  if arr[k] < arr[k+1] && kab == 0
    kab += mon / arr[k]
    mon -= arr[k] * kab
  end
  if arr[k] > arr[k+1]
    mon += arr[k] * kab
    kab = 0
  end
end

if kab != 0
  mon += arr[n-1] * kab
  kab = 0
end
puts mon  

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

using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector< vector<int> > board(n + 1, vector<int>(n + 1));
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        ++board.at(l).at(r);
    }
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) board.at(i).at(j) += board.at(i - 1).at(j);
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) board.at(i).at(j) += board.at(i).at(j - 1);
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        --l;
        cout << board.at(r).at(r) - board.at(l).at(r) - board.at(r).at(l) + board.at(l).at(l) << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(1,n):
  for j in range(i+1,n+1):
    d_o=j-i
    if i<=x and i<=y and j<=x and j<=y:
      d_d=10**4
    elif i>=x and i>=y and j>=x and j>=y:
      d_d=10**4
    elif i<=x and i<=y and j>=x and j>=y:
      d_d=x-i+1+j-y
    elif i<=x and i<=y and x<=j<=y:
      d_d=x-i+1+(y-j)
    elif x<=i<=y and j>=x and j>=y:
      d_d=i-x+1+j-y
    elif x<=i<=y and x<=j<=y:
      d_d=i-x+1+y-j
    else:
      print("###")
    tmp=min(d_o,d_d)
    ans[tmp-1]+=1

for i in ans:
  print(i)

Measured memory_bytes: 49372
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+9;
int a[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) 
		cin>>a[i];
    while(k--)
    {
        int b[maxn];
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
        {
            int l = max(1,i-a[i]);
            int r = min(n,i+a[i]);
            b[l]++;
            b[r+1]--;
        }
        int flag = 1;
        for(int i=1;i<=n;i++)
        {
            a[i] = a[i-1] + b[i];
            if(a[i]!=n) 
				flag = 0;
        }
        if(flag) 
			break;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 5048
#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);
    long long int A = 0;
    int max = 0;
    int min = 1000000001;
    for(int i=0;i<N;i++){
        scanf("%d",&A);
        if(A<min){
            min = A;
        }
        if(A>max){
            max = A;
        }
    }
    printf("%d",max-min);
    return 0;
}

Measured memory_bytes: 128
# coding=utf-8

class Tree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        node = Node(key)
        flag = False

        if self.root == None:
            self.root = node
        else:
            search_node = self.root
            while search_node:
                final_node = search_node
                if final_node.key < key:
                    search_node = final_node.right
                    flag = 'right'
                else:
                    search_node = final_node.left
                    flag = 'left'
            node.parent = final_node
            if flag == 'right':
                final_node.right = node
            elif flag == 'left':
                final_node.left = node

    def print_tree(self):
        prewalked = self.root.prewalk()
        inwalked = self.root.inwalk()
        print(' ', end = '')
        print(*inwalked)
        print(' ', end = '')
        print(*prewalked)


class Node():
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

    def prewalk(self):
        result = []
        result += [self.key] # ??¢?´¢????????? #
        if self.left:
            result += self.left.prewalk()
        if self.right:
            result += self.right.prewalk()
        #print("self.key:", self.key, result) #debugger
        return result



    def inwalk(self):
        result = []
        if self.left:
            result += self.left.inwalk()
        result += [self.key] # ??¢?´¢????????? #
        if self.right:
            result += self.right.inwalk()
        #print("self.key:", self.key, result) #debugger
        return result


n = int(input())
tree = Tree()
for _ in range(n):
    order, *key = input().split()
    if order == 'insert':
        tree.insert(int(key[0]))
    else:
        tree.print_tree()

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

#define PI 3.14159265358979323846264338327950L
#define ll long long
#define lli long long int

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 1; i <= 5; i++) {
        int temp;
        cin >> temp;
        if (temp == 0) {
            cout << i << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
int n;
int x;
 
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
  	cin>>n;
  	int cnt=0;
  	 for(int i=1;i<=n;++i){
  	 	cin>>x;
  	 	if(i&1 && x&1) cnt++;
  	 }

  	 cout<<cnt<<endl;


    return 0;
}

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

int64_t dp[1000][1000], mod = 1000'000'007;
char b[1000][1000];
vector<pair<int, int>> dd = {{0, -1}, {-1, 0}};

int64_t recurse(int i, int j) {
	auto& state = dp[i][j];
  	if(state != -1) return state;
  	if(b[i][j] == '#') return state = 0;
  	if(i == 0 and j == 0) return state = 1;
  	state = 0;
  	for(auto& d: dd) {
    	int x, y; tie(x, y) = d;
      	if(i + x >= 0 and y + j >= 0) {
        	state = (state % mod + recurse(i + x, j + y) % mod) % mod;
        }
    }
  	return state;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  memset(dp, -1, sizeof dp);
  int h, w; cin >> h >> w;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      cin >> b[i][j];
  cout << recurse(h - 1, w - 1);
  return 0;
} //farewell, until we meet again..

Measured memory_bytes: 9216
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List (length, sort, group)
import Data.Array.Unboxed
import Prelude hiding ((!!))

solve :: [Int] -> Int
solve xs = foldr f 0 xs
  where
    (b, e) = (head xs, last xs)
    gs = group xs
    zs = zip (map head gs) (map length gs) ++ [(e+1,0), (e+2,0)]
    aa = accumArray (+) 0 (b, e+2) zs :: UArray Int Int
    f x a = let a' = aa!x + aa!(x+1) + aa!(x+2) in max a a'

main :: IO ()
main = do
    _ <- getLine
    a <- sort . map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    print $ solve a


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

int main() {
    string b;
    string ans;
    cin >> b;
    if (b == "A") {
        ans = "T";
    } else if (b == "T") {
        ans = "A";
    } else if (b == "G") {
        ans = "C";
    } else {
        ans = "G";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main ()
{
    char a,b,c,d,e,f;
    scanf("%c %c %c %c %c %c", &a,&b,&c,&d,&e,&f);
    if(c==d){
        if(e==f)printf("Yes\n");
        else printf("No\n");
    }
    else printf("No\n");
}


Measured memory_bytes: 128
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

struct UnionFind {
    vector<int> par, rank, _size;
    
    UnionFind(int n) : par(n), rank(n, 1), _size(n, 1) {
        for (int i=0; i<n; i++) par[i] = i;
    }
    
    int find(int x) {
        if (par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;

        _size[x] = _size[y] = _size[x] + _size[y];
        if(rank[x] == rank[y]) rank[y]++;

        if(rank[x] > rank[y]) par[y] = x;
        else par[x] = y;
    }

    int size(int x) {
        return _size[find(x)];
    }
};


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

    ll a[m], b[m];
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    ll ans[m];
    UnionFind island(n);
    ans[m-1] = n*(n-1)/2;

    for (int i=m-1; i>=0; i--) {
        ll size_a = island.size(a[i]);
        ll size_b = island.size(b[i]);
        if (island.same(a[i], b[i])) ans[i-1] = ans[i];
        else ans[i-1] = ans[i] - size_a*size_b;
        island.unite(a[i], b[i]);
    }

    rep(i, m) cout << ans[i] << endl;

    return 0;
}

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

int main(){
  int a,b,c,d,e,f,g,h,i;
  cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
  if(d-a == e-b && e-b == f-c && g-d == h-e && h-e == i-f && g-a == h-b && h-b == i-c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  int sum = 0;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    sum += (a - 1);
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct point { int x, y,ind; };
int r, c;
bool onside(point t) {
	if (t.x == 0 || t.x == r || t.y == 0 || t.y == c)return true;
	return false;
}
int dim(point t) {
	if (t.x == 0)return 0;
	if (t.y == c)return 1;
	if (t.x == r)return 2;
	return 3;
}
bool comp(point a, point b) {
	int s = dim(a);
	if (s != dim(b))return s < dim(b);
	if (s == 0)return a.y < b.y;
	if (s == 1)return a.x < b.x;
	if (s == 2)return a.y > b.y;
	return a.x > b.x;
}
point x[1 << 18];
bool used[1 << 17];
int deq[1 << 18];
int main() {
	int n; cin >> r >> c >> n;
	int numofside = 0;
	rep(i, n) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		point z1 = { x1,y1,i };
		point z2 = { x2,y2,i };
		if (onside(z1) && onside(z2)) {
			x[numofside] = z1;
			x[numofside+1] = z2;
			numofside += 2;
		}
	}
	sort(x, x + numofside, comp);
	fill(used, used + n, false);
	int siz = 0;
	bool out = true;
	rep(i, numofside) {
		if (siz == 0) {
			siz++; deq[0] = x[i].ind; used[x[i].ind] = true;
		}
		else {
			if (used[x[i].ind]&&deq[siz - 1] != x[i].ind) {
				out = false; break;
			}
			else if (!used[x[i].ind] && deq[siz - 1] != x[i].ind) {
				used[x[i].ind] = true;
				deq[siz] = x[i].ind; siz++;
			}
			else {
				siz--;
			}
		}
	}
	if (out)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define db long double
#define all(a) a.begin(),a.end()
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
#define pb push_back

int main() {

ll n;
cin>>n;
ll val[n+1]={0};
f(i,1,101)
{
    f(j,1,101)
    {
        f(k,1,101)
        {
                       ll v1=(i+j)*(i+j);
            ll v2=(k+j)*(k+j);
            ll v3=(i+k)*(i+k);
            ll sum=(v1+v2+v3)/2;
            if(sum<=n)
            val[sum]++;
           
            
        }
    }
}
f(i,1,n+1)
cout<<val[i]<<endl;
    
    return 0;
}

Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 16 20:59:51 2020

@author: H_Hoshigi
"""

N = int(input())
A_list = list(map(int, input().split()))
answer = "APPROVED"

for i in A_list:
    if i%2==1:
        pass
    else:
        if i%3==0 or i%5==0:
            pass
        else:
            answer = "DENIED"
            break
print(answer)


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

int main(){
    int N;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    cin >> N;
    for(int i = 0;i < N;i++){
        string S;
        cin >> S;
        if(S == "AC"){
            ac++;
        }else if(S == "WA"){
            wa++;
        }else if(S == "TLE"){
            tle++;
        }else{
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;    
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int count = 0;
  while(a >= b){
    b *= 2;
    count++;
  }
  while(b >= c){
    c *= 2;
    count++;
  }

  if(count <= k) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

const int INF = INT_MAX;


struct lst
{
private:
    int n;
    vector<int> node;
    vector<int> lazy;
    vector<int> lflg;
    void lazy2node(int k, int l, int r)
    {
        if(lflg[k])
        {
            node[k]=lazy[k];
            lflg[k]=false;
            prop(k, l, r);
        }
    }
    void prop(int k, int l, int r)
    {
        if(r-l>0)
        {
            lazy[2*k+1]=lazy[2*k+2]=node[k];
            lflg[2*k+1]=lflg[2*k+2]=true;
        }
    }
public:
    lst(int sz)
    {
        n=1; while (n<sz) n*=2;
        node.resize(2*n-1, INF);
        lazy.resize(2*n-1, 0);
        lflg.resize(2*n-1, false);
    }

    void update(int qa, int qb, int v, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return;
        if(qa<=l && r<=qb)
        {
            node[k]=v;
            prop(k,l,r);
        }
        else
        {
            int m = (l+r)/2;
            update(qa, qb, v, 2*k+1, l, m);
            update(qa, qb, v, 2*k+2, m+1, r);
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }

    int get(int qa, int qb, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        if(qb<l || qa>r) return INF;
        lazy2node(k,l,r);
        if(qa<=l && r<=qb) return node[k];
        else
        {  
            int m = (l+r)/2;
            int la = get(qa, qb, 2*k+1, l, m);
            int lb = get(qa, qb, 2*k+2, m+1, r);
            return min(la, lb);
        } 
    }
};


int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    lst tree = lst(n);
    for(int i=0;i<q; i++)
    {
        int type;
        scanf("%d", &type);
        if(!type)
        {
            int s, t, x;
            scanf("%d %d %d", &s, &t, &x);
            tree.update(s, t, x);
        }
        else
        {
            int s, t;
            scanf("%d %d", &s, &t);
            printf("%lld\n", tree.get(s,t));
        }
        
    }
}


Measured memory_bytes: 5980
#include<bits/stdc++.h>
using namespace std;
#define INF (1e9)
int main(){
  while(1){
    int N;
    int x[100],y[100];
    vector<int> X,Y;
    int ax=INF,bx=-INF;
    int ay=INF,by=-INF;
    
    scanf("%d",&N);
    if(N==0)break;
    for(int i=0;i<N;i++){
      scanf("%d %d",&x[i],&y[i]);
      X.push_back(x[i]);
      Y.push_back(y[i]);
    }
    for(int i=0;i<4;i++){
      int px,py;
      cin>>px>>py;
      ax=min(ax,px);
      ay=min(ay,py);
      bx=max(bx,px);
      by=max(by,py);
    }
    X.push_back(ax);
    Y.push_back(ay);
    X.push_back(bx);
    Y.push_back(by);
    
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    X.erase( unique( X.begin(), X.end() ), X.end() );
    Y.erase( unique( Y.begin(), Y.end() ), Y.end() );
    
    for(int i=0;i<N;i++){
      x[i]=lower_bound(X.begin(),X.end(),x[i])-X.begin();
      y[i]=lower_bound(Y.begin(),Y.end(),y[i])-Y.begin();
    }
    ax=lower_bound(X.begin(),X.end(),ax)-X.begin();
    ay=lower_bound(Y.begin(),Y.end(),ay)-Y.begin();
    bx=lower_bound(X.begin(),X.end(),bx)-X.begin();
    by=lower_bound(Y.begin(),Y.end(),by)-Y.begin();
    vector<int> G[300];
    for(int i=0;i<N;i++){
      int px=x[i],py=y[i];
      int qx=x[ (i+1)%N ];
      int qy=y[ (i+1)%N ];
      if(qy!=py)continue;
      G[py].push_back( min(px,qx) );
      G[py].push_back( max(px,qx) );
    }

    int t[300]={};
    
    long long ans=0;
    for(int py=0;py+1<(int)Y.size();py++){
      for(int i=0;i<(int)G[py].size();i+=2){
        int ax=G[py][i];
        int bx=G[py][i+1];
        for(int px=ax;px<bx;px++){
          t[px]=1-t[px];
        }
      }
      for(int px=0;px+1<(int)X.size();px++){
        if(t[px]==0)continue;
        if(ax<=px&&px<bx&&ay<=py&&py<by)continue;
        long long dy=Y[py+1]-Y[py];
        long long dx=X[px+1]-X[px];
        ans+=dy*dx;
      }
    }
    printf("%lld\n",ans);
  }
  
  return 0;
}

Measured memory_bytes: 3260
#include "bits/stdc++.h" // {{{
#define ALL(x)  x.begin(), x.end()
#define fin '\n'
#ifdef DEBUG
#define debug(...)  fprintf(stderr,__VA_ARGS__)
#define FAST()      ios::sync_with_stdio(false), cin.tie(nullptr)
#else
#define debug(...)
#define FAST()
#endif
using namespace std;

namespace
{ // }}}

map<int,int> cnt;

int _$_$_()
{
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    cnt[a] += 1;
  }

  priority_queue<int> pq;

  for (auto e: cnt) {
    pq.emplace(e.second);
  }
  pq.emplace(0);

  while(pq.top() > 1) {
    int a = pq.top(); pq.pop();
    int b = pq.top(); pq.pop();

    --a;
    --b;
    pq.push(a); pq.push(b);
  }

  int ans = 0;
  while( !pq.empty() )
  {
    int v = pq.top(); pq.pop();
    if (v > 0) {
      ++ans;
    }
  }

  cout << ans << fin;
}

} // {{{
int main() {
  FAST(); return _$_$_();
} // }}}



Measured memory_bytes: 5628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] c = sc.next().toCharArray();
        int res=0;
        int count=0;
        for(int i=0; i<N; i++){
            if(c[i]=='R'){
                count++;
            }
        }
        int red=0;
        for(int i=0; i<count; i++){
            if(c[i]=='R'){
                red++;
            }
        }
        System.out.println(count-red);
        
        
        
        
        
        }
    }

Measured memory_bytes: 41064
module Main where
-- B

main :: IO ()
main = do
    s <- getLine
    putStrLn . sayYes . checkEzStep .reverse $ s

sayYes True = "Yes"
sayYes _ = "No"

checkEzStep :: String -> Bool
checkEzStep = fst . foldr f (True,True)
    where
        f x (isEz,isOdd) = if isOdd
            then
                (isEz && isin "RUD" x, False)
            else
                (isEz && isin "LUD" x, True)
        isin w x = foldr (\y acc -> acc || x==y) False w



Measured memory_bytes: 508
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int high = 0;
		for(int n=1;n<b-a;n++){
			high += n;
		}
		System.out.println(high-a);

	}
}


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

int main() {
	int i, j, n, m, c[21], dp[50002] = {};

	cin >> n >> m;
	for (i = 0; i < m; i++) {
		cin >> c[i];
	}

	for (i = 0; i < m; i++) {
		j = 0;
		while (j + c[i] <= n) {
			if(dp[j + c[i]])dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
			else dp[j + c[i]] = dp[j] + 1;
			j++;
		}
	}

	cout << dp[n] << endl;



	return 0;
}

Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
#define testcases ll t; cin>>t; while(t--)

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

    int n,k;
    cin>>n>>k;
    vector<int> v(n+1),dp(n+1,INT_MAX);
    for(int i=1;i<=n;i++) cin>>v[i];
    dp[1]=0;
    dp[0]=0;
    dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++)
    {
        for(int j=max(1,i-k);j<i;j++)
        {
            dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
        }
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
n,q=map(int,input().split())

class RMQ:
    def __init__(self, N,INF=2**31-1):
        self.N0 = 2**(N-1).bit_length()
        self.INF=INF
        self.data = [INF]*(2*self.N0)

    def update(self, k, x):
        k += self.N0-1
        self.data[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])

    def query(self, l, r):
        L = l + self.N0; R = r + self.N0
        s = self.INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])

            if L & 1:
                s = min(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

rmq = RMQ(n+1)

for i in range(q):
   com,x,y=map(int,input().split())
   if com==0:
      rmq.update(x,y)
   else:
      ans = rmq.query(x,y+1)
      print(ans)


Measured memory_bytes: 8696
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s,w = LI()
if s <= w:
    print('unsafe')
else:
    print('safe')

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

int main()
{
    int n,arr[200005],mn,i,j;
    
    long long int sum;

    sum=0LL;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }

    sort(arr,arr+n);

    sum+=arr[n-1];
    j=2;
    for(i=n-2;i>=0 && j<n ;i--)
    {
        j++;
        sum+=arr[i];
        if(j<n)
        {
            j++;
            sum+=arr[i];
        }
    }

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4404
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;

ll bin_exp_mod(ll a, ll b,ll m)
{
	a%=m;
	ll ans=1;
	if(a==0) ans=0;

	while(b>0)
	{
		if(b&1) ans=(ans*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}

int main()
{ 

fast;

ll n;
cin>>n;

if(n<2)
	cout<<0;
else
{
	ll ans=(bin_exp_mod(10,n,mod)-2*bin_exp_mod(9,n,mod)%mod +mod +bin_exp_mod(8,n,mod) )%mod;
	cout<<ans; 
}

}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, q;
    char s[200020], t[200020], d[200020];
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < q; i++) cin >> t[i] >> d[i];
    
    vector<int> a(n, 0), b(n, 0);
    int x = 0, y = n - 1, xt = 0, yt = 0;
    for (int i = q - 1; i >= 0; i--) {
        if (d[i] == 'L' && s[x] == t[i]) x++;
        if (d[i] == 'R' && x != 0 && s[x - 1] == t[i]) x--;
    }
    for (int i = q - 1; i >= 0; i--) {
        if (d[i] == 'R' && s[y] == t[i]) y--;
        if (d[i] == 'L' && y + 1 != n && s[y + 1] == t[i]) y++;
    }
    
    cout << n - x - (n - 1 - y) << endl;
    
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int k;
	cin >> k;
	string s;
	cin >> s;
	for (int i = 0; i < min(sz(s), k); ++i) {
		cout << s[i];
	}
	int rem = sz(s) - k;
	if (rem > 0) {
		cout << "...";
	}
}

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


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

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define all(v) (v.begin(), v.end())
#define pi acos(-1.0)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define bug(a) cerr << #a << " : " << a << endl
#define pq dp
using namespace std;
const ll mx = 4444444444;

ll posx[] = {1,-1, 0, 0};
ll posy[] = {0, 0, 1,-1};

int main()
{
    FastRead

#ifdef Mfc_Tanzim
    freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
#endif /// Mfc_Tanzim

    ll t=1, n, k, m, a, b, c, d;
    //cin >> t;

    while(t--){
              cin >> n;
              k = 0;
              for(ll i=1; i<1000000; i++){
                              k = (k*10+7)%n;
                              if(k){
                                       continue;
                              }
                              else{
                                       cout << i << endl;
                                       return 0;
                              }
              }
              cout << "-1" << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int c = 0, cc = 0, ccc = 0;

    ci >> n >> a >> b;
    rep(i, n) {
	ci >> p;
	if(p <= a) c++;
	else if(p <= b) cc++;
	else ccc++;
    }

    co << min(c, min(cc, ccc)) << en;
  
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int t[30];
pair<int,int> d[101];
int kisyou[101];
int dp[101][30];//i日目でサイクルt[j]になるには何個必要か
int main()
{
	int m,n;
	int ans=0;
	while(1)
	{
		cin>>m;
		if(m==0)
			break;
		for(int i=0;i<m;i++)
			cin>>t[i];
		t[0]=1;
		cin>>n;
		d[0]=make_pair(1,1);
		for(int i=1;i<n+1;i++)
		{
			int x,y;
			cin>>x>>y;
			d[i]=make_pair(x,y);
		}
		sort(d,d+n);
		int now=0;
		fill(kisyou,kisyou+101,23);
		for(int i=1;i<n+1;i++)
			kisyou[d[i].first]=min(kisyou[d[i].first],d[i].second);
		fill(dp[0],dp[101],1e8-1);
		dp[1][0]=0;
		for(int i=2;i<101;i++)
		{
			for(int j=0;j<m;j++)
				dp[i][0]=min(dp[i-1][j]+1,dp[i][0]);
			//m日さかのぼる
			//dp[i][j]が可能か調べる（j==mのときj=0）
			for(int j=1;j<m+1;j++)
			{
				if(i-j==0)
					break;
				bool f=true;
				for(int k=0;k<m;k++)
				{
					if(j==k)
						break;
					if(dp[i-j+k][k]==1e8-1)
					{
						f=false;
						break;
					}
				}
				if(f && t[j%m]<=kisyou[i])
					dp[i][j%m]=dp[i-j][0];
			}
			//cerr<<dp[i][0]<<endl;
		}
		ans=1e8-1;
		for(int i=0;i<m;i++)
			ans=min(ans,dp[100][i]);
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> rui(n);
    rep(i, n) {
        cin >> a[i];
        if(i > 0) {
            rui[i] += rui[i - 1] + a[i];
        }
        else rui[0] = a[0];
    }
    int key = 0;
    ll mi = 100000000000;
    rep(i, n) {
        if(abs(rui[i] * 2 - rui[n - 1]) < mi) {
            mi = abs(rui[i] * 2 - rui[n - 1]);
            key = i;
        }
    }
    ll cost = abs(rui[key] * 2 - rui[n - 1]);
    cout << cost << endl;
    
    
}

Measured memory_bytes: 6416
#include <stdio.h>
#define N 100

void insertionSort(int*, int);

int main(){
  int i,A[N],n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  insertionSort(A,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i==n-1)break;
    printf(" ");
  }
  printf("\n");
  return 0;
}

void insertionSort(int* A, int n){
  int i,j,v,k;
  for(i=1;i<n;i++){
    v=A[i];
    j=i-1;
    for(k=0;k<n;k++){
      printf("%d",A[k]);
      if(k==n-1)break;
      printf(" ");
    }
    printf("\n");
  
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
  }
}



Measured memory_bytes: 2732
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    REP(i,n)cin >> a[i];
    ll answer = 0;
    REP(i,n){
        while(a[i]%2==0){
            a[i]/=2;
            answer++;
        }
    }
    cout << answer << endl;
    return 0;
}

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

class Dice {
public:
    int face[6];
    Dice() {}
    void dir(char ch) {
        if (ch == 'E') rot(0, 2, 5, 3);
        if (ch == 'W') rot(0, 3, 5, 2);
        if (ch == 'S') rot(0, 1, 5, 4);
        if (ch == 'N') rot(0, 4, 5, 1);
    }
    void rot(int a, int b, int c, int d) {
        int t[4] = {};
        t[0] = face[a];
        t[1] = face[b];
        t[2] = face[c];
        t[3] = face[d];
        face[a] = t[3];
        face[b] = t[0];
        face[c] = t[1];
        face[d] = t[2];
    }
    int side(int f) {
        if (f == 0 || f == 1 || f == 5) { return 0; }
        if (f == 3) rot(1, 2, 4, 3);
        if (f == 2) {
            for (int i = 0; i < 3; i++) {
                rot(1, 2, 4, 3);
            }
        }
        if (f == 4) {
            for (int i = 0; i < 2; i++) {
                rot(1, 2, 4, 3);
            }
        }
    }
};
int main() {
    Dice dice1;
    int n, top, front,tnum=0,fnum = 0;
    for (int i = 0; i < 6; i++) {
        cin >> dice1.face[i];
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> top >> front;
        for (tnum = 0; tnum < 6; tnum++) {
            if (dice1.face[tnum] == top) break;
        }
        switch (tnum) {
        case 0:break;
        case 1:
            dice1.dir('N');
            break;
        case 4:
            dice1.dir('S');
            break;
        case 5:
            dice1.dir('N');
            dice1.dir('N');
            break;
        case 2:
            dice1.dir('W');
            break;
        case 3:
            dice1.dir('E');
            break;
        default: break;
        }
        for (fnum = 0; fnum < 6; fnum++) {
            if (dice1.face[fnum] == front) break;
        }
        dice1.side(fnum);
        cout << dice1.face[2] << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
a = int(input())
s = list(input())

n_s_1 = []
n_s_2 = []

if a%2 :
    print("No")
    exit()

for i in range(int(a/2)):
    n_s_1 += s[i]
    n_s_2 += s[i + int(a/2)]

if n_s_1 == n_s_2:
    print("Yes")
else :
    print("No")

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
using namespace std;
int X, Y, Z, n;
int D[51][51][51][51], LCP[51], oto[51];
char p[60], q[110];
bool Pos(int pv){
    int i, j, k, l;
    for(i=1;i<=pv;i++){
        for(j=0;j<=pv-i;j++){
            if(p[j]!=p[i+j]){
                if(p[j] > p[i+j])return false;
                else break;
            }
        }
    }
    oto[0] = -1;
    for(i=0;i<=pv;i++){
        int t = oto[i];
        while(t!=-1 && p[i]!=p[t])t=oto[t];
        oto[i+1] = t+1;
    }
    int tt = oto[pv+1];
    for(i=pv+1;i<n;i++){
        p[i] = p[tt];
        tt++;
        oto[i+1]=oto[i]+1;
    }
    LCP[0] = 0;
    for(i=1;i<=pv;i++){
        if(p[LCP[i-1]] > p[i])return false;
        int t = LCP[i-1];
        while(t!=-1 && p[t]!=p[i])t = oto[t];
        LCP[i] = t+1;
    }
    int c1 = 0, c2 = 0, c3 = 0;
    for(i=0;i<=pv;i++){
        if(p[i]=='a')c1++;
        if(p[i]=='b')c2++;
        if(p[i]=='c')c3++;
    }
    for(i=0;i<=X;i++)for(j=0;j<=Y;j++)for(k=0;k<=Z;k++)for(l=0;l<=n;l++)D[i][j][k][l]=0;
    D[c1][c2][c3][pv+1] = 1;
    //printf("%s\n",p);
    for(i=c1;i<=X;i++){
        for(j=c2;j<=Y;j++){
            for(k=c3;k<=Z;k++){
                for(l=0;l<=n;l++){
                    if(!D[i][j][k][l])continue;
                    //printf("%d %d %d %d\n",i,j,k,l);
                    int tp = l;
                    if(i!=X && p[tp] <= 'a'){
                        int t = tp;
                        while(t!=-1 && p[t]!='a')t = oto[t];
                        D[i+1][j][k][t+1] = 1;
                    }
                    if(j!=Y && p[tp] <= 'b'){
                        int t = tp;
                        while(t!=-1 && p[t]!='b')t = oto[t];
                        D[i][j+1][k][t+1] = 1;
                    }
                    if(k!=Z && p[tp] <= 'c'){
                        int t = tp;
                        while(t!=-1 && p[t]!='c')t = oto[t];
                        D[i][j][k+1][t+1] = 1;
                    }
                }
            }
        }
    }
    for(i=0;i<=n;i++){
        if(!D[X][Y][Z][i])continue;
        //printf("%d\n",i);
        for(j=0;j<i;j++)q[j] = p[j];
        for(j=0;j<n;j++)q[i+j] = p[j];
        int ck = 0;
        for(j=0;j<=i;j++){
            for(k=0;k<n;k++){
                if(p[k]!=q[j+k]){
                    if(p[k] > q[j+k])ck = 1;
                    else break;
                }
            }
        }
        if(!ck){
            return true;
        }
    }
    return false;
}
int main(){
    int i, j, c1 = 0, c2 = 0, c3 = 0;
    scanf("%d%d%d",&X,&Y,&Z);
    n = X+Y+Z;
    for(i=0;i<n;i++){
        p[i] = 'c';
        c3++;
        if(c3 <= Z && Pos(i)){
            if(i!=0 || (!X&&!Y))continue;
        }
        c3--,c2++;
        p[i] = 'b';
        if(c2 <= Y && Pos(i)){
            if(i!=0 || !X)continue;
        }
        c2--,c1++;
        p[i] = 'a';
    }
    printf("%s\n",p);
}

Measured memory_bytes: 20736
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int d[105][105];
	MS(d, 0);
	int n; cin >> n;
	REP(i, n)
	{
		int a, b; cin >> a >> b;
		a--;
		int to;
		REP(j, b)
		{
			cin >> to;
			to--;
			d[a][to] = 1;
		}
	}
	REP(i, n)
	{
		REP(j, n-1)
		{
			cout << d[i][j] << " ";
		}
		cout << d[i][n - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <cstdio>
#include <cstdlib>

int main() {
  int n;
  scanf("%d", &n);

  int X=0, Y=0, T=0;
  for (int i=0; i<n; ++i) {
    int t, x, y;
    scanf("%d %d %d", &t, &x, &y);
    int dx=std::abs(X-x), dy=std::abs(Y-y);
    int dt=t-T;
    if ((dx+dy+dt) & 1 || (dx+dy) > dt)
      return !printf("No\n");

    X = x;
    Y = y;
    T = t;
  }
  puts("Yes");
}
// Sent from my iPhone

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N, X, m, sum = 0, vmin = 1e9, cnt = 0;
    cin >> N >> X;
    rep(i, N) {
        cin >> m;
        vmin = min(vmin, m);
        sum += m;
    }
    if (X == sum) {
        cout << N << endl;
    } else {
        cout << N + (X - sum) / vmin << endl;
    }
}

Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()

    fun sieve(n: Int): List<Int> {
        val xs = BooleanArray(n + 1) { true }
        var i = 2
        while (i * i <= n) {
            if (xs[i]) {
                for (j in i + i..n step i) {
                    xs[j] = false
                }
            }
            i++
        }
        return (2..n).filter { xs[it] }
    }

    val primes = sieve(55555)
    println(primes.filter { it % 10 == 1 }.take(n).joinToString(" "))
}


Measured memory_bytes: 38428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest.cs
{
	class Program
	{


		static void Main(string[] args)
		{
			int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                     int A = input[0];
                     int B = input[1];
                     string ans;
                     if(A <= 8 && B <= 8)
                     {
                           ans = "Yay!";
                     }
                     else
                     {
                           ans = ":(";
                     }
                     Console.WriteLine(ans);
		}

		static string[] readStr()
		{
			return Console.ReadLine().Split(' ').ToArray();

		}

		static int[] readInt()
		{
			return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		}
	}
}


Measured memory_bytes: 13268
N = int(input())
A = list(map(int, input().split()))

dp = [[0 for i in range(N)] for i in range(N)]
res = 0

def f(l, r):
  if 0 < dp[l][r]:
    return dp[l][r]
  if l == r:
    return 0
  fans = float('inf')
  for m in range(r)[l:]:
    fans = min(fans, f(l, m)+f(m+1, r))
  dp[l][r] = fans + sum(A[l:r+1])
  return dp[l][r]
  
print(f(0,N-1))


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


int dp[3005][3005];
int lcs(string x,string y){
	int m=x.length();
	int n=y.length();

	for (int i = 0; i < m; ++i) dp[i][0]=0;
	for(int i=0;i<n;i++) dp[0][i]=0;

	for (int i = 1; i <=m; ++i)
	{
		for (int j = 1; j <=n; ++j)
		{	int q=0;
			if(x[i-1]==y[j-1]){
				q=1+dp[i-1][j-1];
			}
			else {
				q=max(dp[i-1][j],dp[i][j-1]);
			}
			dp[i][j]=q;
		}
	}
	return dp[m][n];
}

int main(){

	string str1,str2;
	cin>>str1>>str2;

	int index=lcs(str1,str2);
	int m=str1.length();
	int n=str2.length();/*
	char ans[index+1];
	ans[index]='\0';*/
	string ans="";
	int i=m;int j=n;

	while(i> 0 and j>0){
		if(dp[i][j] > dp[i][j-1] and dp[i][j]>dp[i-1][j]){ ans=str1[i-1]+ans; i--;j--; }

		else if(dp[i][j]==dp[i][j-1]) j--;
		else {i--;}
	}
	cout<<ans;
}

Measured memory_bytes: 35456
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	a,b = map(int,input().split())
	print((a-1)*(b-1))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 63340
class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

n,m = map(int,input().split())

u = Unionfind(n+1)
for i in range(m):
    a,b = map(int,input().split())
    u.union(a,b)
ans = 1
for i in range(n+1):
    ans = max(ans,u.size(i))
print(ans)

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

template<typename T> struct FordFulkerson{
	struct edge{
		int to,rev;
		T cap;
	};
	int n;
	vector< vector<edge> > G;
	deque<bool> vis;
	void init(int n){
		this->n = n;
		G.assign(n,vector<edge>());
		vis.assign(n,false);
	}
	void add_edge(int from,int to,T cap){
		G [from].push_back(edge{to,int(G [to].size()),cap});
		G [to].push_back(edge{from,int(G [from].size()) - 1,0});
	}
	T dfs(int curr,int t,T f){
		if(curr == t) return f;
		vis [curr] = true;
		for(int i = 0;i < G [curr].size();i++){
			edge& e = G [curr] [i];
			if(e.cap > 0 && vis [e.to] == false){
				T d = dfs(e.to,t,min<T>(f,e.cap));
				if(d == 0) continue;
				e.cap -= d;
				G [e.to] [e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}
	T max_flow(int s,int t){
		T flow = 0;
		while(true){
			vis.assign(n,false);
			T d = dfs(s,t,numeric_limits<T>::max());
			if(d == 0) break;
			flow += d;
		}
		return flow;
	}
};

int N,M;

int main()
{
	scanf("%d%d",&N,&M);
	FordFulkerson<int> ff;
	ff.init(N);
	FOR(i,0,M){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		ff.add_edge(u,v,c);
	}

	printf("%d\n",ff.max_flow(0,N - 1));

	return 0;
}

Measured memory_bytes: 3324
#include <stdio.h>
#include <string.h>

int main( void ) {
	char s[1001];
	scanf("%s", s);
	
	int al[26] = {0};
	
	int n = strlen(s);
	for( int i = 0; i < n; i++ ) {
		al[s[i]-'a']++;
	}
	
	for( int i = 0; i < 26; i++ ) {
		if( al[i] % 2 ) {
			puts("No");
			return 0;
		}
	}
	
	puts("Yes");
	
	return 0;
}

Measured memory_bytes: 128
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100
struct node{
	int x,y;
}a[MAXN+5],b[MAXN+5];
bool vis[MAXN+5];
int cnt[MAXN+5],n;
int Find(int x){
    for(int i=1;i<=n;i++){
        if((a[x].x<b[i].x)&&(a[x].y<b[i].y)&&!vis[i]){
            vis[i]=1;
            if(cnt[i]==0||Find(cnt[i])){
                cnt[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&a[i].x,&a[i].y);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&b[i].x,&b[i].y);
	int ans=0;
	for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        if(Find(i)){
            ans++;
        }
    }
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128