akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 1010;

int d[d5][d5];
bool done[d5][d5];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;
    string s[d5];
    for(int i=0;i<h;i++)cin>>s[i];    
    queue<pair<int,int>> Q;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                Q.push(make_pair(i,j));
                d[i][j]=0;
                done[i][j]=true;
            }
        }
    }
    while(!Q.empty()){
        auto now=Q.front();
        Q.pop();
        int y=now.first;
        int x=now.second;
        for(int i=0;i<4;i++){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny<0||nx<0||ny>=h||nx>=w||done[ny][nx])continue;
            done[ny][nx]=true;
            d[ny][nx]=d[y][x]+1;
            Q.push(make_pair(ny,nx));
        }
    }
    int res=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            res=max(res,d[i][j]);
        }
    }  
    cout<<res<<endl;
}


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

int main() {
	int n;

	std::cin >> n;

	std::vector<int> v(n), c(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	int ans = 0;

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> c[i];
		if (v[i] - c[i] > 0) {
			ans += v[i] - c[i];
		}
	}

	std::cout << ans << std::endl;

	
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	string s;
	long long cnt[5]={};
	for (int i = 0; i < n; ++i)
	{
		cin>>s;
		if (s[0]=='M')
		{
			++cnt[0];
		}
		else if (s[0]=='A')
		{
			++cnt[1];
		}
		else if (s[0]=='R')
		{
			++cnt[2];
		}
		else if (s[0]=='C')
		{
			++cnt[3];
		}
		else if (s[0]=='H')
		{
			++cnt[4];
		}
	}
	long long ans=0LL;
	for (int i = 0; i < 5; ++i)
	{
		for (int j = i+1; j < 5; ++j)
		{
			for (int k = j+1; k < 5; ++k)
			{
				ans+=cnt[i]*cnt[j]*cnt[k];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const noexcept{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const noexcept{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const noexcept{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const noexcept{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r)noexcept{ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r)noexcept{ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r)noexcept{ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r)noexcept{ return *this*=r.inv();}
    ModInt inv()const noexcept{
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n)const noexcept{
        ModInt a=1;
        while(n>0){
            if(n&1) a*=*this;
            *this*=*this;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

struct combination{
    int N;
    vector<mint> fac,finv,inverse;
    combination(int N=0):N(N){
        fac.resize(N+1);finv.resize(N+1);
        fac[0]=1;
        for(int i=1;i<=N;++i){fac[i]=fac[i-1]*i;}
        finv[N]=fac[N].inv();
        for(int i=N;i>0;--i){finv[i-1]=finv[i]*i;}
    }
    void inverse_build(){
        inverse.resize(N+1);
        inverse[1]=1;
        for(int i=2;i<=N;++i){inverse[i]=finv[i]*fac[i-1];}
    }
    mint c(const int& n,const int& k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k]*finv[k];
    }
    mint p(const int& n,const int& k){
        if(n<k||n<0||k<0) return 0;
        return fac[n]*finv[n-k];
    }
};

int main(){
    combination com(1000000);
    int x,y;
    cin >> x >> y;
    mint ans = 0;
    if(2*y-x<0||2*x-y<0);
    else if((2*y-x)%3 != 0 || (2*x-y)%3 != 0);
    else{
        int s = (2*x-y)/3;
        int t = (2*y-x)/3;
        ans = com.c(s+t,s);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 998244353;

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

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

vector<ll> inv, fact, invfact;
void Mod_build(int n = 101010) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = inv[0] = invfact[0] = 1;
    inv[1] = 1;
    for (ll i = 0; i < n; i++) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        if (i > 0) inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod;
        invfact[i + 1] = invfact[i] * inv[i + 1] % mod;
    }
}
ll perm(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * invfact[n - k] % mod;
}
ll comb(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod;
}
ll powmod(ll n, ll k) {
    k %= mod - 1;
    if (k < 0) k += mod - 1;
    ll ret = 1;
    while (k) {
        if (k & 1) ret = ret * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ret;
}

int numless(string u) {
    ll i;
    int l = u.size();
    ll num = 0;
    for (i = 0; i < u.size(); i++) {
        if (u[l - i - 1] == '1') {
            num += powmod((ll)2, i);
            num %= mod;
        }
    }
    return num;
}

string x;
ll valid(string t) {
    int i, j;
    int y = t.size();
    for (i = 0; i < x.size(); i++) {
        if ((i / y) % 2 == 0) {
            if (x[i] == '1' && t[i % y] == '0') return 1;
            if (x[i] == '0' && t[i % y] == '1') return 0;
        } else {
            if (x[i] == '1' && t[i % y] == '1') return 1;
            if (x[i] == '0' && t[i % y] == '0') return 0;
        }
    }
    return 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j;
    ll n;
    cin >> n;
    cin >> x;
    VI v(2 * n + 1, 0);
    ll ans = 0;
    for (i = 1; i <= 2 * n; i++) {
        if ((2 * n) % i == 0 && n % i != 0) {
            int k = i / 2;
            string t = x.substr(0, k);
            v[i] += numless(t) + valid(t);
            v[i]%=mod;
            for (j = 2; i * j <= 2 * n; j++) {
                v[i * j] += mod - v[i];
                v[i * j] %= mod;
            }
            ans += v[i] * i % mod;
            ans %= mod;
            // cout << v[i] << " " << i << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7316
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(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()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = MAP()
L = [LIST() for i in range(M)]
graph = defaultdict(list)
tree = UnionFind(N)

d = N * (N - 1) // 2
# ans = [0] * M
ans = []
ans.append(d)
for a, b in L[::-1]:
    # e = deepcopy(d)
    if not tree.same(a-1, b-1):
        d -= tree.size(a-1) * tree.size(b-1)
    tree.union(a-1, b-1)
    ans.append(d)
ans = ans[:-1]
ans = ans[::-1]

print(*ans, sep="\n")
    # tree[b-1].append(a-1)
    # group = tree.group_count()
    # print(group)
    # print(group * (group - 1) // 2)




Measured memory_bytes: 37576
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int N = S.size();
  REP(i, N-1){
    if(S[i] == S[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }
  REP(i, N-2){
    if(S[i] == S[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			int k = Integer.parseInt(br.readLine());
			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			String ans = "NG";

			for (int i = a; i <= b; i++) {
				if (i % k == 0) {
					ans = "OK";
					break;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 200007
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
void numberOfMoves(ll size) ;

int main()
{
	//sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	ll t=1;
	//cin>>t;
	while(t--)
	solve();
}
ll dp[maxn];
ll arr[maxn];
ll n;
ll go(ll pos)
{
	if(pos==n-1)
	return 0;
	if(pos>=n)
	return inf;
	if(dp[pos]!=-1)
	return dp[pos];
	ll ans1=inf,ans2=inf;
	
	if(pos+1<n)
	ans1=go(pos+1)+abs(arr[pos+1]-arr[pos]);
	
	if(pos+2<n)
	ans2=go(pos+2)+abs(arr[pos+2]-arr[pos]);
	
	return dp[pos]=min(ans1,ans2);
}
void intl()
{
	ll i;
	for(i=0;i<maxn;i++)
	dp[i]=-1;
}
void solve()
{
	intl();
	cin>>n;
	for(ll i=0;i<n;i++)
	cin>>arr[i];
	cout<<go(0);
}
	
	
	
	
	
	
	
	
	


Measured memory_bytes: 10576
#include<stdio.h>
int main(void){
	char str[3000];
	int i,j,k;
	int n;
	scanf("%d%*c",&n);
	for(i = 0;i < n;i++){
		fgets(str,3000,stdin);
		/*k = 0;
		while(str[k] != '\0'){
			if(str[k] == '\n'){
				str[k] = '\0';
			}
			k++;
		}*/
		j = 0;
		while(str[j] != '\0'){
			if(str[j] == 'H'){
				if(str[j+1] == 'o'){
					if(str[j+2] == 's'){
						if(str[j+3] == 'h'){
							if(str[j+4] == 'i'){
								if(str[j+5] == 'n'){
									if(str[j+6] == 'o'){
										str[j+6] = 'a';
									}
								}
							}
						}
					}
				}
			}
			j++;
		}
		printf("%s",str);
	}
	return 0;
}

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

int main()
{
    
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    rep(i, d) {
        int s_max = 0;
        rep(j, 26) {
            if (s_max < s[i][j]) {
                s_max = s[i][j];
                t[i] = j+1;
            }
        }
        
    }
    rep(i, d) {
        cout << (i*i)%26+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c,k,r,g;
    cin>>r>>g>>b;
    cin>>k;
    if(g<=r) 
    {
        while(g<=r && k>0) 
        {
            g*=2;
            k--;
        }
    }
    if(b<=g)
    {
        while(b<=g && k>0)
        {
            b*=2;
            k--;
        }
    }
    if(b>g && g>r) cout<<"Yes";
    else cout<<"No";
    
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N, A, B;
vector<int> t;

int search(int a){
	int l=0, r=N-1, m;
	for(int i=0; i<30; i++){
		m=(l+r)/2;
		if(t[m]<a){
			l=m;
		}else if(t[m]>a){
			r=m;
		}else{
			return m-1;
		}
	}
	return m;
}

int main(){
	cin>>N>>A>>B;
	N++;
	t.resize(N);
	t[0]=0;
	for(int i=1; i<N; i++){
		cin>>t[i];
	}
	sort(t.begin(), t.end());

	cout<<N-1-(search(B)-search(A))<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;

  ll ans = 0;
  rep(i, n) add(ans, a[i] % mod * (n - 1) % mod);

  rep(i, 61) {
    ll cnt = 0;
    rep(j, n) {
      cnt += a[j] % 2;
      a[j] /= 2;
    }
    add(ans, mod - max(0LL, cnt * (cnt - 1) / 2) % mod * modpow(2LL, i + 1, mod) % mod);
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
long long mod = 1000000007;
 
long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}
 
void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
 
int main() {
    int k, s, sum = 0, ans = 0;
    cin >> k >> s;
    while(k > 1){
        k = k / s;
        sum++;
    }
    if (k % s == 0){
        cout << sum <<endl;
        return 0;
    }
    cout << sum + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main()
{
 
    string s;
    cin>>s;

    if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3))
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;

    return 0;
}   

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

int main(){

  int N;
  cin>>N;
 
  int A[N];
  int B[N];
  int C[N-1];
  
  rep(i,N)cin>>A[i];

  rep(i,N)cin>>B[i];	

  rep(i,N-1)cin>>C[i];
  
  int sum=0;
  int last=-111;
  rep(i,N){
    int index=A[i];
    sum+=B[index-1];

    if(i>0 && index==(last+1))sum+=C[last-1];
	last=index;
    
  }
  cout<<sum;
  
}

Measured memory_bytes: 256
Input = input().split()
X = Input[0]
X = int(X)
Y = Input[1]
Y = int(Y)

A = 0
for i in range(X+1):
    C = i
    T = X - C
    CL = C * 2
    TL = T * 4
    L = CL + TL
    if L == Y:
        A += 1

if A == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, string>> ar(m);
    rep(i,m) cin >> ar[i].first >> ar[i].second;
    int ac = 0;
    int pena = 0;
    vector<int> wa(n,0);
    rep(i,m){
        if (ar[i].second == "AC" && wa[ar[i].first-1] != -1){
            ac++;
            pena += wa[ar[i].first-1];
            wa[ar[i].first-1] = -1;
        }
        else if (ar[i].second == "WA" && wa[ar[i].first-1] != -1) wa[ar[i].first-1]++;
    }  
    cout << ac << " " << pena << endl;
}

Measured memory_bytes: 6912
package main

import (
	"bufio"
	"fmt"
	"os"
)

var N, M int
var graph [][]int
var visited []bool

func main() {
	N, M = ReadInt(), ReadInt()
	graph = make([][]int, N)
	visited = make([]bool, N)
	for m := 0; m < M; m++ {
		x, y, _ := ReadInt()-1, ReadInt()-1, ReadInt()
		graph[x] = append(graph[x], y)
		graph[y] = append(graph[y], x)
	}
	cnt := 0
	for i := 0; i < N; i++ {
		if !visited[i] {
			cnt++
			dfs(i)
		}
	}
	fmt.Println(cnt)
}

func dfs(i int) {
	if visited[i] {
		return
	}
	visited[i] = true
	for j := 0; j < len(graph[i]); j++ {
		dfs(graph[i][j])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 18472
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
	int n,i,j,t,k,flag=0,a[6][6];
	for(i=1;i<=3;i++)
	for(j=1;j<=3;j++)
	cin>>a[i][j];
	cin>>n;
	for(k=1;k<=n;k++)
	{
		cin>>t;
		for(i=1;i<=3;i++)
	for(j=1;j<=3;j++)
	if(t==a[i][j]) a[i][j]=0;
	}
	for(i=1;i<=3;i++)
	if(a[i][1]+a[i][2]+a[i][3]==0) flag=1;
	for(j=1;j<=3;j++)
	if(a[1][j]+a[2][j]+a[3][j]==0) flag=1;
	if(a[1][1]+a[2][2]+a[3][3]==0) flag=1;
	if(a[1][3]+a[2][2]+a[3][1]==0) flag=1;
	if(flag) cout<<"Yes";
	else cout<<"No";
 } 

Measured memory_bytes: 256
import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

nmax=2*10**5+10
graph=[[] for _ in range(nmax)]
level=[-1]*nmax

def dfs(n,s,l):
  if len(graph[s])==0:
    return
  for e in graph[s]:
    if level[e]==-1:
      level[e]=level[s]+1
    if level[e]>level[s]:
      l[e]+=l[s]
      dfs(n,e,l)

def main():
  n,q=LI()
  for _ in range(n-1):
    a,b=LI()
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  l=[0]*n
  for _ in range(q):
    a,b=LI()
    l[a-1]+=b

  level[0]=0
  dfs(n,0,l)

  return ' '.join([str(x) for x in l])

# main()
print(main())


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

int main(void)
{
	int n;
	int Data[101] = { 0, };
	cin >> n;
	for (int i = 0; i < n-1; i++)
		cin >> Data[i];
	vector<int> ans(101, 0);
	ans[0] = Data[0];
	for (int i = 0; i < n-1; i++)
	{
		if (ans[i] > Data[i])
			ans[i] = Data[i];
		ans[i + 1] = Data[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
		sum += ans[i];
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int n;
  cin >> n;
  if (n < 1200) cout << "ABC"<< endl;
  else if (n >= 2800) cout << "AGC" << endl;
  else cout << "ARC" << endl;
  return 0;
}
  

Measured memory_bytes: 256
m,p,q,r,b,*c;C[9][101][101];main(n){for(;~scanf("%d%d",&n,&m);){memset(C,9,9e4);for(;n--;C[0][p][q]=C[0][q][p]=r,C[1][p][q]=C[1][q][p]=b)scanf("%d%d%d%d",&p,&q,&r,&b);for(n=m;n;n--)for(p=m;p;p--)for(q=m;q;q--)for(r=9;r--;*c=*c<b?*c:b)b=C[r][p][n]+C[r][n][q],c=C[r][p]+q;for(scanf("%d",&m);m--;printf("%d\n",C[r][p][q]))scanf("%d%d%d",&p,&q,&r);}}

Measured memory_bytes: 772
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iomanip> 
#include <math.h>
#include <unordered_map>
#include <set>
#include <functional> 

#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 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; }

using namespace std;



int main() {

	ios_base::sync_with_stdio(0);cin.tie(0);
	
	vector<int> a[3];
	
	int n, y;

	cin >> n >> y;

	int size = 0;

	rep(i, 2001) {
		rep(j, 2001) {
			if (n - (i + j) >= 0) {

				if (10000LL * i + 5000LL * j + 1000LL * (n - (i + j)) == y) {
					//cout << 10000LL * a[size][0] + 5000LL * a[size][1] + 1000LL * a[size][2] << endl;
					cout << i << " " << j << " " << n - (i + j) << endl;
					return 0;
				}
			/*	a[0].push_back(i);
				a[1].push_back(j);
				a[2].push_back(n - (i + j));*/
				//size++;
			}
			/*rep(k, 2000) {
				if (i + j + k == n) {
					a[size][0] = i;
					a[size][1] = j;
					a[size][2] = k;
					size++;
				}
			}*/
		}
	}
	//10000  5000 1000


	cout << -1 << " " << -1 << " " << -1 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

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

    vector<int> array(n);
    for (int i = 0; i < n; i++) cin >> array[i];

    ostringstream oss;
    for (int i = array.size() - 1; i >= 0; i--) {
        if (oss.str() != "") oss << " ";
        oss << array[i];
    }

    cout << oss.str() << endl;

	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
const ll INF=1e10+1;
using namespace std;
#define NOT_EXIST -1

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

int main(){
	int a,b;
	cin >> a >> b;
	if(a<=5) cout << 0 << endl;
	else if(6<=a && a<=12) cout << b/2 << endl;
	else cout << b << endl;
}

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

typedef long long ll;

vector<int> v(5);

int k;

int main(){
    for (int i = 0; i < 5; i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());

    cin >> k;

    if(v[4]-v[0] <= k){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
#include<algorithm>
using namespace std;

class WarshallFloyd
{
public:
	WarshallFloyd(int sz) :
		size(sz)
		,cost(size, vector<int>(size, INT_MAX/2))
	{
		for(int i=0; i<size; i++)
			cost[i][i] = 0;
	}
	void calc(void)
	{
		for(int k=0; k<size; k++)
			for(int i=0; i<size; i++)
				for(int j=0; j<size; j++)
					cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j]);
	}
	void setCost(int src, int dst, int c){cost[src][dst] = c; cost[dst][src] = c;}
	int getCost(int src, int dst){return cost[src][dst];}

private:
	const int size;
	vector<vector<int>> cost;
};

int main(void)
{
	int N, M;
	cin >> N >> M;

	WarshallFloyd wf(N);
	vector<int> a(M), b(M), c(M);
	for(int i=0; i<M; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		
		a[i]--;
		b[i]--;

		wf.setCost(a[i], b[i], c[i]);
	}

	wf.calc();

	int ret = M;
	for(int i=0; i<M; i++)
	{
		bool used = false;
		for(int j=0; j<N; j++)
			if(wf.getCost(j, b[i]) - wf.getCost(j, a[i]) == c[i])
				used = true;
		
		if(used == true)
			ret--;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	char ch='0';
	while((ch=getchar())!='\n')putchar((ch=='1')?'9':'1'); 
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
//ll Inc(ll &x, ll y) { (x += y) >= Mod ? x -= y : (x < 0 ? x += Mod : 0); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n;
arr a;
bool cmp(int x, int y) { return x > y; }
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		a[i] = read();
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1, j; i <= n; i++)
	{
		if (i != n && a[i + 1] >= i + 1)
			continue;
		for (j = i; j < n && a[j + 1] >= i; j++);
		if ((a[i] - i) & 1 || (j - i) & 1)
		{
			puts("First");
			break;
		}
		else
		{
			puts("Second");
			break;
		}
	}
	return 0;
}


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

# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

ans = A[0]

for i in range(N - 1):
    ans = gcd(ans, A[i + 1])
print(ans)

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    if(r<1200){
        cout << "ABC" << endl;
    }else if(r<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

string s;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> s;

    int ans = 0;
    REP(i, s.size()) {
        char c = s[i];
        if (c == '+') {
            ans++;
        } else {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n = II()

    print((n-1)//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>//cout
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>//swap
using namespace std;
static const int MAX = 200000;
#define rep(i,n) for(int i=0;i<n;i++)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
 
int main() {
  string s;
  cin >> s;
  cout << "2018/01/" + s.substr(8,2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    pair<pair<string, int>, int> sp[110];
    REP(i,n) {
        string s;
        int p, num = i;
        cin >> s >> p;
        p *= -1;
        sp[i] = make_pair(make_pair(s, p), num);
    }
    sort(sp, sp+n);
    REP(i,n) {
        cout << sp[i].second + 1 << endl;
    }
}

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int n;
int a[N],dp[N],pr[N];
int mx = -inf,cur;
vector <int> v;

main () {
    cin >> n;

    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        dp[i] = a[i];
        pr[i] = i;
    }

    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j < i; j ++) {
            if ((i % 2) == (j % 2) && dp[j] + a[i] >= dp[i]) {
                dp[i] = dp[j] + a[i],pr[i] = j;
            }
        }
        if (mx <= dp[i])
            mx = dp[i],cur = i;
    }

    cout << mx << endl;

    for (int i = n; i > cur; i --)
        v.pb(i);

    while (1) {
        int o = pr[cur];
        int m = (cur + o) / 2;
        for (int i = m; i > o; i --)
            v.pb(i);
        if (cur == o)
            break;
        cur = o;
    }
    for (int i = 1; i < cur; i ++)
        v.pb(1);
        
    cout << v.size() << endl;

    for (int i = 0; i < v.size(); i ++)
        cout << v[i] << endl;
}


Measured memory_bytes: 2304
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    string t = "100100100100110101101001001011001010011000011011111001110101100001011001001111000010011000100110011100000101111110011100010101100111001000000100011100010000100011010011111001010101010110010010000110000100010101000001011101000111100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    reverse(t.begin(), t.end());

    const int m = (int)t.size();

    string s;
    cin >> s;

    int n = (int)s.size();

    vector< vector<int> > v(m, vector<int>(n, -1));
    rep(j, n){
        if(s[j] == 'R'){
            v[0][j] = j + 1;
        }else{
            v[0][j] = j - 1;
        }
    }

    rep(i, m - 1){
        rep(j, n){
            v[i + 1][j] = v[i][v[i][j]];
        }
    }

    vector<int> ans(n, 0);
    rep(j, n){
        int pos = j;
        rrep(i, m){
            if(t[i] == '1'){
                pos = v[i][pos];
            }
        }
        ++ans[pos];
    }

    rep(i, n){
        if(i) cout << ' ';
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 131528
n = gets.chomp.to_i
hs = gets.chomp.split(" ").map(&:to_i)
count = 0
until hs.length == 0
  if hs.find_index {|i| i == 0} == 0
    hs.shift
  elsif hs.find_index {|i| i == 0} == nil
    hs.each_with_index do |h, index|
      hs[index] -= 1
    end
    count += 1
  else
    0.upto(hs.find_index {|i| i == 0} - 1).each do |index|
      hs[index] -= 1
    end
    count += 1
  end
end
puts count

Measured memory_bytes: 3836
n, k, c = map(int, input().split())
s = input()
left = [-1 for _ in range(k)]
right = [-1 for _ in range(k)]

bef = -10 ** 10
cnt = 0
for i, ss in enumerate(s):
    if ss == "o" and i - bef > c:
        if cnt == k:
            exit()
        left[cnt] = i
        bef = i
        cnt += 1

cnt = 0
bef = -10 ** 10
for i, ss in enumerate(s[::-1]):
    if ss == "o" and i - bef > c:
        if cnt == k:
            exit()
        right[k - 1 - cnt] = n - 1 - i
        bef = i
        cnt += 1


for ll, rr in zip(left, right):
    if ll == rr:
        print(ll + 1)

Measured memory_bytes: 25212
#include<stdio.h>

int max(int a, int b) {
  if (a <= b) {
    return b;
  }
  else {
    return a;
  }
}

int main() {
  int H, W;
  scanf("%d %d", &H, &W);
  char S[H][W];
  char S2[W][H];
  for (int i = 0; i < H; i++) {
    scanf("%s", S[i]);
  }
  
  int cnt1[H][W];
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (S[i][j] == '#') {
        cnt1[i][j] = 0;
        continue;
      }
      cnt1[i][j] = 1;
    }
  }

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (S[i][j] == '#') {
        continue;
      }
      if (j-1 >= 0) {
        cnt1[i][j] += cnt1[i][j-1];
      }
    }
  }
  for (int i = 0; i < H; i++)
  {
    for (int j = W-1; j > -1; j--)
    {
      if (S[i][j] == '#') {
        continue;
      }
      if (j+1 <= W-1) {
        cnt1[i][j] = max(cnt1[i][j], cnt1[i][j+1]);
      }
    }
  }

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      S2[j][i] = S[i][j];
    }
  }
  
  int cnt2[W][H];
  for (int i = 0; i < W; i++)
  {
    for (int j = 0; j < H; j++)
    {
      if (S2[i][j] == '#') {
        cnt2[i][j] = 0;
        continue;
      }
      cnt2[i][j] = 1;
    }
  }
  
  for (int i = 0; i < W; i++)
  {
    for (int j = 0; j < H; j++)
    {
      if (S2[i][j] == '#') {
        continue;
      }
      if (j-1 >= 0) {
        cnt2[i][j] += cnt2[i][j-1];
      }
    }
  }

  for (int i = 0; i < W; i++)
  {
    for (int j = H-1; j > -1; j--)
    {
      if (S2[i][j] == '#') {
        continue;
      }
      if (j+1 <= H-1) {
        cnt2[i][j] = max(cnt2[i][j], cnt2[i][j+1]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      ans = max(ans, cnt1[i][j]+cnt2[j][i]-1);
    }
  }
  
  printf("%d\n", ans);
  
  
  
  
}

Measured memory_bytes: 39168
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto it : x) {cerr << " [" <<  it << "]";} cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 2e18;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<ld> a(n);
	for(int i = 0;i < n;++i){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ld cur = a[0];
	for(int i = 1;i < n;++i){
		cur += a[i];
		cur /= 2;
	}
	cout << cur << '\n';
	return 0;
	
}


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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    long double w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << w * h / 2 << " ";
    if((w / 2.0 == x) && (h / 2.0 == y)) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }

    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int n, x[15], y[15], p[15];

long long solve(vector<int> &vx, vector<int> &vy, vector<bool> &through, int idx, int k) {
    if (vx.size() + vy.size() == k) {
        long long ret = 0;
        for (int i=0; i<n; i++)
            if (!through[i]) {
                int cur = min(abs(x[i]), abs(y[i]));
                for (int j : vx)
                    cur = min(cur, abs(j - x[i]));
                for (int j : vy)
                    cur = min(cur, abs(j - y[i]));
                ret += (long long) cur * p[i];
            }
        return ret;
    }
    if (n - idx < k - vx.size() - vy.size())
        return LLONG_MAX;

    through[idx] = true;
    vx.push_back(x[idx]);
    long long ret = solve(vx, vy, through, idx + 1, k);
    vx.pop_back();
    vy.push_back(y[idx]);
    ret = min(ret, solve(vx, vy, through, idx + 1, k));
    vy.pop_back();
    through[idx] = false;
    ret = min(ret, solve(vx, vy, through, idx + 1, k));
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    for (int i=0; i<n; i++)
        cin >> x[i] >> y[i] >> p[i];

    vector<int> vx, vy;
    vector<bool> through(n);
    for (int k=0; k<=n; k++)
        cout << solve(vx, vy, through, 0, k) << "\n";

    return 0;
}


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

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 10;
int n, a[MAXN];

ll abs(ll x){
  return (x < 0 ? -1LL*x : 1LL*x);
}

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

  for(int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  sort(a, a + n);
  printf("%lld", abs(a[n-1] - a[0]));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>
 
const int MAX_N = 100050;
long long N, M;
long long x[MAX_N], y[MAX_N];

long long AC_X[MAX_N], AC_Y[MAX_N];
long long MOD = 1000000007;
 
int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= N; i++) {
        std::cin >> x[i];
    }

    for (int i = 1; i <= M; i++) {
        std::cin >> y[i];
    }

    std::sort(x + 1, x + 1 + N);
    std::sort(y + 1, y + 1 + M);

    AC_X[0] = 0;
    AC_Y[0] = 0;

    for (int i = 1; i <= N; i++) {
        AC_X[i] = AC_X[i-1] + x[i];
    }

    for (int i = 1; i <= M; i++) {
        AC_Y[i] = AC_Y[i-1] + y[i];
    }

    long long length_x = 0;
    long long length_y = 0;

    for (int i = 1; i <= N; i++) {
        length_x = length_x + (AC_X[N] - AC_X[i] - (N - i) * x[i]);
    }

    for (int i = 1; i <= M; i++) {
        length_y = length_y + (AC_Y[M] - AC_Y[i] - (M - i) * y[i]);
    }

    long long ret = ((length_x % MOD) * (length_y % MOD)) % MOD; 

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

Measured memory_bytes: 3328
mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

C = [3] + [0] * N

ans = 1
for a in A:
    ans = ans * C[a] % mod
    C[a] -= 1
    C[a + 1] += 1

print(ans)

Measured memory_bytes: 13956
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += (n - 1) / i;
	cout << ans << '\n';
}

Measured memory_bytes: 3644
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

int main() {
	IOS
	string s;
	cin >> s;
	unsigned long long b=0, ans=0;
	for(int i=0; s[i]; i++) {
		if(s[i]=='B') b++;
		if(s[i]=='W') {
			ans += b;
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 720