akhauriyash/Code-Regression huggingface dataset:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

s = STR()
t = STR()
ans = inf
lt = len(t)
for strt in range(len(s) - len(t) + 1):
    a = s[strt:strt + lt]
    cnt = 0
    for i in range(lt):
        if a[i] != t[i]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 73168
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX)
{return uniform_int_distribution<int>(l,r)(rng);}

template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.x<<", "<<a.y<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}

template<typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
ostream&>::type operator<<(ostream& out, T(&a)[N])
{out<<"[ ";for(size_t i=0;i<N;++i)out<<a[i]<<", ";out <<"]"<<endl;return out;}

void debug_out(){cerr<<endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr<<(H)<<" ";debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr<<"#"<<#__VA_ARGS__<<":\n",debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

const int mod = 1000000007;
int md(int x,int mdo=mod){
	while(x<0)
		x+=mdo;
	return x%mdo;
}
int ge(int a, int b, int *x, int *y){
	if (a == 0){
		*x = 0, *y = 1;
		return b;
	}
	int x1, y1;
	int gcd = ge(b%a, a, &x1, &y1);
	*x = y1 - (b/a) * x1;
	*y = x1;
	return gcd;
}
int  modinv(int a, int m=mod){
	int x, y;
	int g = ge(a, m, &x, &y);
	int p = (x%m + m) % m;
	return p;
}

vector<int> fct(MAX),ifct(MAX);

void pre(){
	fct[0]=1;
	for(int i=1;i<MAX;i++){
		fct[i]=md(fct[i-1]*i);
	}
	ifct[MAX-1]=modinv(fct[MAX-1]);
	for(int i=MAX-2;i>=0;i--){
		ifct[i]=md(ifct[i+1]*(i+1));		
	}
}

int ncr(int n, int r){
	if(n<r)
		return 0;
	return md(ifct[r]*md(fct[n]*ifct[n-r]));
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	pre();
	int n,k,i;
	cin>>n>>k;
	vector<int> a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=0;
	sort(a.begin(), a.end());
	for(i=k-1;i<n;i++){
		ans=md(ans+md(md(a[i])*ncr(i,k-1)));
	}
	for(i=0;i<n-k+1;i++){
		ans=md(ans-md(md(a[i])*ncr(n-i-1,k-1)));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2560
import math
a,b,x=map(int,input().split())
if a*a*b==x:
    ans=90
elif x>((a**2)*b)/2:
    ans=math.degrees(math.atan(a/(2*(b-(x/(a**2))))))
else:
    ans=math.degrees(math.atan((2*x)/(a*(b**2))))
print(90-ans)


Measured memory_bytes: 3060
H,W=map(int,input().split())
while(H,W)!=(0,0):
    
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()
    H,W=map(int,input().split())


Measured memory_bytes: 7004
#include <iostream>
#include <string>
#include <vector>

bool IsWhiteLine(const std::string s);
std::vector<std::string> RemoveWhiteLine(std::vector<std::string> v);
std::vector<std::string> FindWhiteVertical(std::vector<std::string> v, int H, int W);
std::vector<std::string> RemoveWhiteVertical(std::vector<std::string> v);

int main() {
  int H, W;  // H is row, W is column 
  std::cin >> H >> W;

  std::vector<std::string> v;
  v.reserve(H);

  std::string line;
  while (v.size() < H) {
    std::cin >> line;
    v.push_back(line);
  }

  v = RemoveWhiteLine(v);
  H = v.size();
  v = FindWhiteVertical(v, H, W);
  v = RemoveWhiteVertical(v);

  for (auto s : v) {
    std::cout << s << std::endl;
  }

  return 0;
}

bool IsWhiteLine(const std::string s) {
  // '.' == white, '#' == black
  // return true if All char in line is while
  for (auto c : s)
    if (c == '#') return false;

  return true;
}

std::vector<std::string> RemoveWhiteLine(std::vector<std::string> v) {
  std::vector<std::string> new_v;
  for (auto s : v)
    if (!IsWhiteLine(s)) new_v.push_back(s);

  return new_v;
}

std::vector<std::string> FindWhiteVertical(std::vector<std::string> v, int H, int W) {
  bool flag = false;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      flag = false;
      if (v[i][j] == '.') {
        flag = true;
        for (int k = 0; k < H; ++k)
          if (v[i][j] != v[k][j]) flag = false;
      }
      if (flag)
        for (int k = 0; k < H; ++k) v[k][j] = 'w';
    }
  }
  return v;
}

std::vector<std::string> RemoveWhiteVertical(std::vector<std::string> v) {
  std::vector<std::string> new_v;
  std::string line = "";
  for (auto s : v) {
    line = "";
    for (auto c : s)
      if (c != 'w') line += c;
    new_v.push_back(line);
  }
  return new_v;
}


Measured memory_bytes: 3668
#include <stdio.h>

using namespace std;

int main() {

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

    int x = 10 * (a + b) / 2;
    if (x % 10 >= 5) x = x / 10 + 1;
    else x = x / 10;

    printf("%d\n", x);

    return 0;
}


Measured memory_bytes: 128
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

int solve() {
	ll n, k;
	cin >> n >> k;

	vector<ll> as(n);
	REPD(i, 0, n) cin >> as[i];

	REPD(i, k, n) {
		bool is_good = as[i] > as[i - k];
		cout << (is_good ? "Yes" : "No") << endl;
	}


	return 0;
}

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

	solve();

	return 0;
}


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

void solve(istream& cin, ostream& cout) {
  int n;
  int p;
  cin >> n;
  vector<int> idx(n + 1);

  for (int i = 1; i <= n; i++) {
    cin >> p;
    idx[p] = i;
  }

  multiset<int> upper{0, 0, n + 1, n + 1};

  long long ans = 0;
  for (int v = n; v >= 1; v--) {
    int i = idx[v];
    long long w, x, y, z;
    upper.insert(i);
    auto itr = upper.find(i);
    x = *(--itr);
    w = *(--itr);
    itr = upper.find(i);
    y = *(++itr);
    z = *(++itr);

    ans += ((x - w) * (y - i) + (i - x) * (z - y)) * v;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 5376
#include <stdio.h>
#define MAX 500000
#define INFTY 2000000000

int L[MAX/2+2], R[MAX/2+2];
int count, n;

void merge(int A[],int left,int mid,int right)
{

  int n1, n2, i, j, k;
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  
  for(k=left;k<right;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{ 
      A[k] = R[j];
      j = j + 1;
    }
  }
  
}

void mergeSort(int A[],int left,int right)
{

  int mid;
  
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }

}

int main()
{

  int A[MAX];
  int i;

  count = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    if(i != n-1) printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }

  printf("%d\n",count);

  return 0;

}




Measured memory_bytes: 5636
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 300005
using namespace std;
typedef long long ll;
ll a[N],L[N],R[N],tot[N],sum[N];
int n,m,s[N],top;
int D=0;
ll f[N],h[N],ans[N];
ll calc(int x,int i){
	return h[x]+tot[i-x]+sum[x]-sum[i];
}
ll suan(int p,int j){
	return 2*(h[p]-h[j]-sum[j]+sum[p])-1LL*j*j+1LL*p*p+j-p;
}
void push(int x){
	while(top>1&&suan(s[top-1],s[top])*2*(s[top]-x)<=suan(s[top],x)*2*(s[top-1]-s[top])) top--;
	s[++top]=x;
}
void solve(int l,int r){
	if(l==r){
		//f[l]=max(f[l],L[l-1]+R[r+1]+1-a[l]);
		return;
	}
	int mid=l+r+D>>1;
	top=0;
	for(int i=l-1;i<=mid;i++){
		h[i]=L[i];
		push(i);
	}
	for(int i=mid+1;i<=r;i++){
		while(top>1&&calc(s[top],i)<=calc(s[top-1],i)) top--;
		h[i]=calc(s[top],i)+R[i+1];
	}
	for(int i=r-1;i>mid;i--) h[i]=max(h[i],h[i+1]);
	for(int i=mid+1;i<=r;i++) f[i]=max(f[i],h[i]);
	solve(l,mid);
	solve(mid+1,r);
}
void dp(){
	top=1;
	s[1]=0;
	for(int i=1;i<=n;i++){
		while(top>1&&calc(s[top],i)<=calc(s[top-1],i)) top--;
		h[i]=max(h[i-1],calc(s[top],i));
		push(i);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
		tot[i]=tot[i-1]+i;
	}
	dp();
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[n-i+1],L[i]=h[i];
	dp();
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i],R[i]=h[n-i+1];
	for(int i=1;i<=n;i++) f[i]=-1e15;
	solve(1,n);
	for(int i=1;i<=n;i++) ans[i]=f[i];
	for(int i=1;i+i<=n;i++) swap(a[i],a[n-i+1]);
	for(int i=1;i<=n;i++) swap(L[i],R[n-i+1]),sum[i]=sum[i-1]+a[i];
	memset(f,0,sizeof(f));
	D=-1;
	for(int i=1;i<=n;i++) f[i]=-1e15;
	solve(1,n);
	for(int i=1;i<=n;i++) ans[i]=max(ans[i],f[n-i+1]);
	scanf("%d",&m);
	for(int i=1;i+i<=n;i++) swap(a[i],a[n-i+1]);
	for(int i=1;i<=n;i++) swap(L[i],R[n-i+1]);
	for(int i=1,x,w;i<=m;i++){
		scanf("%d%d",&x,&w);
		ll ret=max(ans[x]+a[x]-w,L[x-1]+R[x+1]);
		printf("%lld\n",ret);
	}
	return 0;
}

Measured memory_bytes: 22656
use proconio::*;

fn main() {
    input! {
        n: usize,
        s: String,
    };

    let x = s
        .chars()
        .map(|c| c.to_digit(2).unwrap() as i64)
        .collect::<Vec<_>>();
    let pc: i64 = x.iter().sum();
    let mut ans = vec![0; n];

    for b in 0..=1 {
        let mut pc = pc;

        if b == 0 {
            pc += 1;
        } else {
            if pc == 1 {
                continue;
            }
            pc -= 1;
        }

        let mut r0 = 0;
        for &v in &x {
            r0 = ((r0 << 1) + v).rem_euclid(pc);
        }

        let mut k = 1;
        for (i, &v) in x.iter().enumerate().rev() {
            if v == b {
                if v == 0 {
                    ans[i] = f((r0 + k).rem_euclid(pc)) + 1;
                } else {
                    ans[i] = f((r0 - k).rem_euclid(pc)) + 1;
                }
            }

            k = (k << 1).rem_euclid(pc);
        }
    }

    for a in &ans {
        println!("{}", a);
    }
}

fn f(n: i64) -> i64 {
    if n == 0 {
        return 0;
    }

    f(n.rem_euclid(n.count_ones() as i64)) + 1
}


Measured memory_bytes: 5524
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ans = [0] * (N+1)
    ans[N] = N
    ans[N-1] = N*N
    S = 0
    for i in range(N-2, 0, -1):
        ans[i] = (ans[i+1] + S + N*(i+1) + (N-1) * (N-i-2))%mod
        S = (S + ans[i+2])%mod
    print(ans[1])
    #print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
    int n, q, ac = 0;
    string s;
    cin >> n >> q >> s;
    vector<int> l(q), r(q), sac(n,0);
    for(int i = 0;i < q;i++){
        cin >> l[i] >> r[i];
    }

    for(int i = 0;i < n;i++){
        if(s[i] == 'A' && s[i + 1] == 'C'){
            ac++;
        }
        sac[i + 1] = ac;
    }

    for(int i = 0;i < q;i++){
        cout << sac[r[i] - 1] - sac[l[i] - 1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 2176
x,try_k = map(int,input().split())

input_x = input().split()

list_a = [0]*x
list_b = [[] for i in range(x)]
for i in range(len(list_a)):
  list_a[i] = int(input_x[i])

for i in range(try_k):
  a,b = map(int,input().split())
  
  list_b[b-1].append(list_a[a-1])
  list_b[a-1].append(list_a[b-1])
  
#print(list_b)
count = 0
for i in range(x):
  if(len(list_b[i]) == 0):
     count += 1
     continue
  if(list_a[i] > max(list_b[i]) ):
    count += 1
print(count)

Measured memory_bytes: 30184
#include <bits/stdc++.h>
using namespace std;
void File()
{
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
}
int countDivisors(long long  n){
int cnt = 0;
for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
        // If divisors are equal,
        // count only one
        if (n / i == i)
            cnt++;

        else // Otherwise count both
           cnt+=2;
    }
}
return cnt;
}

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pair<int,int> > vii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<long, long> mll;
typedef set<int> si;
typedef set<string> sst;
typedef set<long> sl;
typedef long long ll;
typedef pair<int, int> pii;
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n-1);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define setzero(a)	memset(a,0,sizeof(a))
#define bits(a) 	__builtin_popcountll(a)
#define fr first
#define sc second
#define el      	 "\n"
#define pii pair<int, int>
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sfs1(v) cin>>v;
#define ndl puts("")
#define SS stringstream
#define rep(i, a, n)	for(int i = a; i<=n; i++)
int const N = 3e3 + 9, MOD = 1e9+7 , oo = 1e9+7;
vector<vector<int>>adj(N);
vi start(N),finish(N);
int visited[N];


int arr[N];
int n;


string str;
int main()
{
    cin>>str;
    loop(i,str.size())if (str[i]!=',')cout<< str[i];else cout<< ' ';



















/*
*/













return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str0,str1;
    int N,ans = 0;
    cin >> str0 >> N;
    for(int i = 0;i<N;i++){
        cin >> str1;
        str1 += str1;
        int a = str1.find(str0);
        if(a>=0)ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    string s;
    int a = 0, b = 0;
    while(getline(cin,s)){
        int p1, p2, p3;
        sscanf(s.c_str(), "%d,%d,%d", &p1, &p2, &p3);
        if(p1*p1+p2*p2 == p3*p3){
            a++;
        } else 
        if(p1 == p2){
            b++;
        }
    }
    cout << a << endl << b << endl;
    return 0;
}

Measured memory_bytes: 1232
using System;

namespace C
{
    public struct Node
    {
        public int left;
        public int right;
        public Tree tree;
    }

    public class Tree
    {
        internal Node[] nodes;
        bool[] isRoot;

        public Tree(int nodes)
        {
            this.nodes = new Node[nodes];
            isRoot = new bool[nodes];
            for (int i = 0; i < nodes; i++)
            {
                this.nodes[i].left = -1;
                this.nodes[i].right = -1;
                this.nodes[i].tree = this;
                isRoot[i] = true;
            }
        }

        public void AddChilden(int id, int left, int right)
        {
            nodes[id].left = left;
            nodes[id].right = right;
            if (left != -1) isRoot[left] = false;
            if (right != -1) isRoot[right] = false;
        }

        public int GetRoot()
        {
            for (int i = 0; i < isRoot.Length; i++)
            {
                if (isRoot[i]) return i;
            }
            return -1;
        }

        public void Preorder(int node)
        {
            Console.Write(" " + node);
            if (nodes[node].left != -1) Preorder(nodes[node].left);
            if (nodes[node].right != -1) Preorder(nodes[node].right);
        }
        public void Inorder(int node)
        {
            if (nodes[node].left != -1) Inorder(nodes[node].left);
            Console.Write(" " + node);
            if (nodes[node].right != -1) Inorder(nodes[node].right);
        }
        public void Postorder(int node)
        {
            if (nodes[node].left != -1) Postorder(nodes[node].left);
            if (nodes[node].right != -1) Postorder(nodes[node].right);
            Console.Write(" " + node);
        }
    }


    class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var tree = new Tree(n);
            for (int i = 0; i < n; i++)
            {
                var strs = Console.ReadLine().Split(' ');
                var id = int.Parse(strs[0]);
                tree.AddChilden(id, int.Parse(strs[1]), int.Parse(strs[2]));
            }
            var root = tree.GetRoot();
            Console.WriteLine("Preorder");
            tree.Preorder(root);
            Console.WriteLine();
            Console.WriteLine("Inorder");
            tree.Inorder(root);
            Console.WriteLine();
            Console.WriteLine("Postorder");
            tree.Postorder(root);
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx_4[]={1,0,-1,0}, dy_4[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, m, k;
	string ans = "No";
	cin >> n >> m >> k;

	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= m;j++){
			int black = i*(m-j) + j*(n-i);
			if(black == k) ans = "Yes";
		}
	}

	cout << ans << endl;
	rtn 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void replace(string &s){
	int a,b;
	string t;
	cin>>a>>b>>t;
	for(int j=a;j<=b;j++)
		s[j]=t[j-a];
}
void reverse(string &s){
	string t;
	int c,d,cnt;
	cin>>c>>d;
	t=s;
	cnt=c;
	for (int j=d;j>c-1;j--){
		s[cnt]=t[j];
		cnt++;
	}
}

int main(){
	int n,c,d;
	string s, op;
	cin >> s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> op;
		if (op == "replace")
			replace(s);
		else if (op == "reverse")
			reverse(s);
		else if (op == "print"){
			cin>>c>>d;	
			for(int j=c;j<=d;j++){
				cout<<s[j];	
			}
			cout<<'\n';
		}
	}
}


Measured memory_bytes: 3208
def lcs(x, y):
    m = len(x)
    n = len(y)
    c = [0] * (n + 1)
    for i in range(m):
        tmp = x[i]
        c_ = c[:]
        for j in range(n):
            if tmp == y[j]:
                c[j + 1] = c_[j] + 1
            elif c[j + 1] < c[j]:
                c[j + 1] = c[j]
    return c[-1]


q = int(input())
ans = []
for _ in range(q):
    x = input()
    y = input()
    ans.append(lcs(x, y))

print(*ans, sep="\n")


Measured memory_bytes: 5628
#include <cstdio>

using namespace std;

int main() {
    int t, i;
    
    scanf("%d", &t);
    
    for (i = 0; i < t; i++) {
        int n, d;
        
        scanf("%d %d", &n, &d);
        
        if (n % 2 == 1) {
            printf("%d\n", (n - 1) * 127 + d);
        } else {
            printf("%d\n", (n - 1) * 127 + (d ^ 127));
        }
    }
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
int p[1100],m[1100];
int main(){
	ll n,x=0;
	cin>>n;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			p[++x]=i;
			while(n%i==0){
				n/=i;
				m[x]++;
			}
		}
	}
	if(n>1){
		p[++x]=n;
		m[x]=1; 
	}
	ll cnt=0;
//	for(int i=1;i<=x;i++) cout<<m[i]<<' '<<p[i]<<endl;
	for(ll i=1;i<=x;i++){
		int j=1;
		while(1){
			if(m[i]-j>=0){
				m[i]-=j;
				j++;
				cnt++;
			}else{
				break;
			}
		}
	}
	cout<<cnt<<endl;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 200010;
const ll INF = TEN(18);

ll dp[2][maxn][16];

int main() {
	int N; cin >> N;
	V<int> A(N);
	rep(i, N) cin >> A[i];

	rep(t, 2) {
		rep(i, maxn) {
			rep(j, 16) {
				dp[t][i][j] = INF;
			}
		}

		rep(j, 16) dp[t][N-1][j] = j;

		for (int i = N-2; i >= 0; --i) {
			int c = 0;
			ll x = A[i], y = A[i+1];

			rep(j, 16) {
				while (x > y) {
					y *= 4;
					++c;
				}
				chmin(dp[t][i][j], (c >= 16 ? dp[t][i+1][15] + (c-15) * (N-1-i) : dp[t][i+1][c]) + j);

				x *= 4;
			}
		}

		reverse(ALL(A));
	}

	ll ans = INF;
	for (int i = 0; i <= N; ++i) {
		ll t = 0;
		if (i < N) {
			t += dp[0][i][0];
		}
		if (i > 0) {
			t += dp[1][N-i][0];
		}
		chmin(ans, t * 2 + i);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 51072
#! /usr/bin/env python
# coding: utf-8

import math

def slove(n, a):
    dict = {}
    for i in range(n):
        if a[i] in dict:
            dict[a[i]] += 1
        else:
            dict[a[i]] = 1

    count = 0
    for k,v in dict.items():
        if int(k) < v:
            count += (v - int(k))
        elif int(k) != v:
            count += v
    return count

if __name__ == "__main__":
    n = int(input())
    a = input().split()

    print(slove(n, a))

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

class C
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int n = h[0], k = h[1];
		var a = Read();

		var next = true;
		for (int c = 0; c < k && next; c++)
		{
			next = false;

			var d = new int[n + 1];
			for (int i = 0; i < n; i++)
			{
				d[Math.Max(0, i - a[i])]++;
				d[Math.Min(n, i + a[i] + 1)]--;
			}

			var t = 0;
			for (int i = 0; i < n; i++)
			{
				t += d[i];
				if (a[i] != t)
				{
					a[i] = t;
					next = true;
				}
			}
		}
		Console.WriteLine(string.Join(" ", a));
	}
}


Measured memory_bytes: 63020
from collections import Counter

n = int(input())
s = Counter([str(input()) for _ in range(n)])
l = []
c = 1

for stri, count in s.items():
    if count == c:
        c = count
        l.append(stri)
    elif count > c:
        c = count
        l.clear()
        l.append(stri)


sort_l = sorted(l)

for i in sort_l:
    print(i)


Measured memory_bytes: 156068
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int n;
	while(~scanf("%d", &n)) {
		const int K = 3;
		vector<int> v[K];
		rep(i, n) {
			int a;
			scanf("%d", &a);
			v[a % 3].push_back(a);
		}
		rep(k, 3)
			sort(v[k].begin(), v[k].end());
		int ans = 0;
		rer(first, 1, 2) if(!v[first].empty()) {
			vector<int> rem[3];
			rer(k, 1, 2) rem[k] = v[k];
			int sum = 1;
			rem[first].pop_back();
			sum += v[0].size();
			int r = first;
			while(!rem[r].empty()) {
				++ sum;
				rem[r].pop_back();
				(r += r) %= K;
			}
			if(!rem[3 - r].empty())
				++ sum;
			amax(ans, sum);
		}
		if(!v[0].empty())
			amax(ans, 1);
		printf("%d\n", ans);
	}
	return 0;
}

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

int main()
{
    char a, b;
    cin >> b;
    if (b == 'A')
        a = 'T';
    else if (b == 'T')
        a = 'A';
    else if (b == 'C')
        a = 'G';
    else if (b == 'G')
        a = 'C';
    cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int get_abs(int x);

int main(){
    string ans = "";
    for(int i = 0; i < 3; i++){
        string s;
        cin >> s;
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}

int get_abs(int x){
    return (x > 0)? x : -x;
}

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

int main()
{
    std::string a, b, c;
    std::cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front())
    {
        std::cout << "YES";
    }
    else
    {
        std::cout << "NO";
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
typedef std::pair<int,int> P;


	ll ans=0;
	ll N,M,K,G,A,B;
	ll id=0;
	ll sum;bool F=true;

int main(){
	ios_base::sync_with_stdio(false);
	cin>>N>>K;
	EREP(i,N){
		if(i%K==K/2)A++;
		if(i%K==0)B++;
	}
	DEB(A)DEB(B)END
	if(K%2==0||K==1)ans=A*A*A;
	if(K!=1)ans+=B*B*B;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
a = int(input()) #500
b = int(input()) #100
c = int(input()) #50
x = int(input()) 

cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if(500 * i + 100 * j + 50 * k == x):
                cnt += 1
            elif(500 * i + 100 * j + 50 * k > x):
                break
            # print("500:%d 100:%d 50:%d [%d]" %(i,j,k,cnt))
print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> v1,v2,v3;
    rep (i,0,n)
    {
        ll x,y;
        cin>>x>>y;
        v1.pb(x+y);
        v2.pb(x-y);
        v3.pb(y-x);
    }
    ll ans=0;
    ans=abs(mxe(v1)-mne(v1));
    ans=max({ans,abs(mxe(v2)+mxe(v3)),abs(mne(v2)+mne(v3))});

    cout<<ans<<"\n";
}


Measured memory_bytes: 8172
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("sumsqr.in");ofstream out("sumsqr.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int a;
vec<vec<int>> l;
vec<int> m, o, cur;

int predessesor(int X){
    int l = -1, r = a+2;
    for(; l+1<r;){
        int md = (l+r)/2;
        if(cur[md]<X) l = md;
        else r = md;
    }
    return l;
}

void dfs(int v, int p){
    int ps = predessesor(m[v]);
    o[v] = p==-1 ? ps+1 : max(o[p], ps+1);
    int was = cur[ps+1];
    cur[ps+1] = min(cur[ps+1], m[v]);
    for(int h : l[v]){
        if(h==p) continue;
        dfs(h, v);
    }
    cur[ps+1] = was;
}

int main() {
    fast;
    cin>>a;
    m = vec<int>(a);
    o = vec<int>(a);
    cur = vec<int>(a+5, 2e9);
    l = vec<vec<int>>(a, vec<int>());
    cur[0] = 0;
    for(int q=0; q<a; q++) cin>>m[q];
    for(int q=0; q<a-1; q++){
        int x,y; cin>>x>>y; x--, y--;
        l[x].pb(y);
        l[y].pb(x);
    }
    dfs(0, -1);
    for(int i : o) cout<<i<<"\n";
}

Measured memory_bytes: 30804
data class PC(val p: Int, val c: Int) {
    constructor(pc: List<Int>): this(pc[0], pc[1])
}
fun main(args: Array<String>) {
    var (D, G) = listOfInt()
    val pc = Array(D) { PC(listOfInt()) }
    var ans = Int.MAX_VALUE
    var mask = 0
    for (mask in 0 until 1.shl(D)) {
        var s = 0
        var num = 0
        var rest_max = -1
        for (d in 0 until D) {
            if (mask.ushr(d) and 1 != 0) {
                s += 100 * (d + 1) * pc[d].p + pc[d].c
                num += pc[d].p
            } else rest_max = d
        }
        if (s < G) {
            val s1 = 100 * (rest_max + 1)
            val need = (G - s + (s1 - 1)) / s1
            if (need >= pc[rest_max].p) continue
            num += need
        }
        ans = Math.min(ans, num)
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 36132
using System;

namespace Structured_Program_I
{
    class Structured_Programming
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            int i = 0;
            while (++i <= n)
            {
                if (i % 3 == 0)
                {
                    Console.Write(" " + i);
                    continue;
                }
                int x = i;
                while (true)
                {
                    if(x%10 == 3)
                    {
                        Console.Write(" " + i);
                        break;
                    }
                    if ((x /= 10) == 0) break; ;
                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9372
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i in input().split()]
a.sort()
f.sort(reverse=True)
w=[0,0]
for i in range(n):
    w[1]=max(w[1],a[i]*f[i])
x=50
while x>0:
    x-=1
    ws=(w[0]+w[1])//2
    p=k
    for i in range(n):
        if a[i]*f[i]>ws and p<a[i]-ws//f[i]:
            p=-1
            break
        elif a[i]*f[i]>ws:
            p-=a[i]-ws//f[i]
    if p>=0:
        w[1]=ws
    else:
        w[0]=ws
print(w[1])

Measured memory_bytes: 119500
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();

    vector<ll> a(n);
    for(int i=0;i<n;++i) a[n-1-i] = s[i] - '0';

    ll b = 1;
    vector<vector<ll>> dp(n+1, vector<ll>(13, 0));
    dp[0][0] = 1;
    for(int i=0;i<n;++i) {
        for(int j=0;j<13;++j) {
            if(!dp[i][j]) continue;
            if(a[i] < 10) {
                dp[i+1][(j+a[i]*b)%13] += dp[i][j];
                dp[i+1][(j+a[i]*b)%13] %= MOD;
            } else {
                for(int k=0;k<10;++k) {
                    dp[i+1][(j+k*b)%13] += dp[i][j];
                    dp[i+1][(j+k*b)%13] %= MOD;
                }
            }
            
        }
        b *= 10;
        b %= 13;
    }

    cout << dp[n][5] << endl;
}

/*
0 1
1 10
2 9
3 12
4 3
5 4
6 1
7 10
8 9
9 12
10 3
11 4
12 1
13 10
14 9
15 12
 */

Measured memory_bytes: 14416
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

int main() {
    int N,X,T;
    cin >> N >> X >> T;
    cout << (N/X)*T + (N%X != 0)*T << endl;
}

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

int main() {
    string s;
    cin >> s;

    int ans = 0, r_count = 0, s_count = 0;

    for (auto c : s) {
        if (c == 'R')
            r_count++;
        else
            s_count++;
    }

    if (s[1] == 'R')
        cout << r_count << endl;
    else
        cout << min(r_count, 1) << endl;
}

Measured memory_bytes: 3576
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    cout << n/m + (n%m ? 1 : 0) << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


ll N,K;
vector<ll> V;

int main(){

	scanf("%lld %lld",&N,&K);

	ll tmp;
	for(ll i = 0; i < N; i++){

		scanf("%lld",&tmp);
		V.push_back(tmp);
	}

	if(K >= N){

		printf("0\n");
		return 0;
	}

	sort(V.rbegin(),V.rend());

	ll ans = 0;

	for(ll i = K; i < V.size(); i++){

		ans += V[i];
	}

	printf("%lld\n",ans);

	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll res = 0;
    REP(i, N) res += A[i];

    vector<ll> cnt(101010, 0);
    REP(i, N) cnt[A[i]]++;

    ll Q;
    cin >> Q;
    REP(i, Q){
        ll B, C;
        cin >> B >> C;

        ll ko = cnt[B];
        cnt[B] = 0;
        cnt[C] += ko;
        res -= ko*B;
        res += ko*C;
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int N = (int)(2e5) + 7;

char s[10];

int main() {

    scanf("%s", s + 1);
    int cnt = 0;
    if (s[1] == 'R') ++cnt;
    if (s[2] == 'R') ++cnt;
    if (s[3] == 'R') ++cnt;
    if (!cnt) puts("0");
    else if (cnt == 1) {
        puts("1");
    } else if (cnt == 2) {
        if (s[2] == 'S') puts("1");
        else puts("2");
    } else puts("3");

    return 0;
}

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

using namespace std;

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

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

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

// Bit Matrix
const int MAX_ROW = 110000; // to be set appropriately
const int MAX_COL = 60; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};
 
// 掃き出し法
void GaussJordan(BitMatrix &A, bool is_extended = false) {
    vector<bool> used(A.H, 0);
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = 0; row < A.H; ++row) {
            if (used[row]) continue;
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        for (int row = 0; row < A.H; ++row) {
            if (row != pivot && A[row][col]) A[row] ^= A[pivot];
        }
        used[pivot] = true;
    }
}

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

  int n; cin >> n;
  vll a(n);
  ll x = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    x ^= a[i];
  }

  for(int i=0;i<n;++i) {
    for(int j=0;j<60;++j) {
      a[i] &= (((1ll<<60)-1) ^ x);
    }
  }

  BitMatrix A(n, 60);
  for(int i=0;i<n;++i) {
    ll tmp = 0;
    for(int j=0;j<60;++j) {
      tmp += ((a[i]>>j)&1)<<(59-j);
    }
    A[i] = bitset<MAX_COL>(tmp);
  }

  GaussJordan(A);
  ll add = 0;
  for(int i=0;i<n;++i) {
    ll tmp = 0;
    //cout << A[i] << endl;
    for(int j=0;j<60;++j) {
      tmp *= 2;
      tmp += A[i][j];
    }
    //cout << tmp << endl;
    add ^= tmp;
  }
  cout << x + add * 2 << endl;


}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define LOOP(i,o) for(i=0;i<o;i++)
#define ALL(a)  (a).begin(),(a).end()            
int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  int i;
  LOOP(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=n-1;i>=2;i--){
    for(int j=i-1;j>=1;j--){
      for(int k=j-1;k>=0;k--){
if(a[i]<a[j]+a[k]){
ans++;
}
      }
    }
  }
   
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    map<ll, ll> mp;
    ll a;
    REP(i, n){
        cin >> a;
        mp[a]++;
    }
    ll res = 0;
    for(auto v : mp){
        ll f = v.first, s = v.second;
        if(s < f) res += s;
        else res += s - f;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6272
n, *a = map(int, open(0).read().split())
minus_cnt = len([1 for A in a if A < 0])
ans = sum([abs(A) for A in a])
if (0 not in a) and (minus_cnt %2 != 0):
    ans -= 2 * min([abs(A) for A in a])
print(ans)

Measured memory_bytes: 20060
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
  //cin>>t;
  int tt=1;
  while(t--){
        int n,i;
        cin>>n;
        int arr[n],ans=0;
        fr(i,0,n)
        cin>>arr[i];
        int mx=arr[0];
        ans=1;
        fr(i,1,n)
        {
          if(arr[i]>=mx)
            ans++;
          mx=max(mx,arr[i]);
        }
        cout<<ans;
       //cout<<"Case #"<<tt<<": ";
       //tt++;
    }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int i,j;
    int h[N];
    for(i=0;i<N;i++)
    {
        cin >> h[i];
        if(i>0&&h[i] == h[i+1])
        {
            i++;
        }
        
    }
    
   
    sort(h,h+N);
    
    int temp;
    while(h[0] < h[1])
    {
        
        while(1)
        {
        h[1] = h[1] - h[0];
        if(h[1] <= h[0])
        {
            temp = h[1];
            h[1] = h[0];
            h[0] = temp;
            break;
        }
        }
    }
    int min = h[0];
    for(i=2;i<N;i++)
    {
        if(h[i] %h[0] < min && h[i] %h[0] > 0)
        {
            min = h[i] %h[0];
        }
    }
    cout << min << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    string n;
    cin>>n;
    if(n[1]=='B'){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3572