akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef priority_queue<int> Pr; typedef vector<int> Vi; typedef vector<Pi> Vp;
typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef vector<Int> VI;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n; cin>>n; int h[n]={},o[n]={}; Vi g[n];
    for (int i = 0; i < n-1; i++){
        int a; cin>>a;
        h[--a]++; g[i+1].push_back(a);
    }
    stack<int> st;
    for (int i = 0; i < n; i++)if(!h[i])st.push(i);
    int s[n]={}; vector<bool> used; Vi ed[n];
    while (!st.empty()){
        used.assign(n,0);
        int i=st.top(),d=0,ma=-1; st.pop();
        sort(ALL(ed[i])); int l=ed[i].size();
        for (int j = 0; j < l; j++)cmax(ma,ed[i][l-j-1]+j);
        o[i]=ma+1;
        for(auto e:g[i]){
            h[e]--; if(!h[e])st.push(e);
            ed[e].push_back(o[i]);
        }
    }
    /*for(auto e:o)cout<<e<<' ';
    cout<<endl;*/
    cout<<o[0]<<'\n';
}

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

TTT = "TTT".freeze
AGC = "AGC".freeze
AGCT = "AGCT".freeze

n = gets.to_s.to_i

dp = Array.new(n+1){ Hash.new(0) }
dp[0][TTT] = 1

n.times do |i|
  
  dp[i].each do |(k, v)|
    
    x, y, z = k.chars
    AGCT.each_char do |c|
      
      next if (x+y+z+c)[AGC]
      next if (y+x+z+c)[AGC]
      next if (x+z+y+c)[AGC]
      next if (x+y+c+z)[AGC]
      
      s = y + z + c
      dp[i+1][s] += v
      dp[i+1][s] %= mod if dp[i+1][s] >= mod
    end
  end
end

ans = dp[n].values.reduce(0){|s,t| s+t } % mod

puts ans

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	string s;
	vs ss(n);
	vl v(n);
	rep(i,n){
		cin>>ss[i]>>v[i];
	}
	cin>>s;
	bool ok=false;
	rep(i,n){
		if(ok)ans+=v[i];
		if(s==ss[i])ok=true;
	}
	puta(ans);
}


Measured memory_bytes: 256
#include<iostream>
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;int f(int a,int b,int x){return (x?(x-1?a*b:a-b):a+b);}int r[4];int main(){while(cin>>r[0]>>r[1]>>r[2]>>r[3]&&r[0]){lol(q,99){string z="+-*";lol(i,3)lol(j,3)lol(k,3){if(f(f(r[0],r[1],i),f(r[2],r[3],k),j)==10){cout<<"("<<r[0]<<z[i]<<r[1]<<")"<<z[j]<<"("<<r[2]<<z[k]<<r[3]<<")\n";goto l;}if(f(f(f(r[0],r[1],i),r[2],j),r[3],k)==10){cout<<"(("<<r[0]<<z[i]<<r[1]<<")"<<z[j]<<r[2]<<")"<<z[k]<<r[3]<<"\n";goto l;}}if(q%6==5)swap(r[0],r[1]);else if(q%2==1)swap(r[1],r[2]);else swap(r[2],r[3]);}cout<<"0"<<endl;l:;}return 0;}

Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int r, g, b;
    cin >> r >> g >> b;

    YESNO((r * 100 + g * 10 + b) % 4 == 0, "YES", "NO");
    return 0;
}

Measured memory_bytes: 256
import heapq
def dijkstra(s, neighbor):
	dist = [float('inf')] * N
	dist[s] = 0
	que = [(0, s)]
	heapq.heapify(que)
	while que:
		d, v = heapq.heappop(que)
		if d > dist[v]:
			continue
		for u, l in neighbor[v]:
			tmp_d = d + l
			if tmp_d < dist[u]:
				dist[u] = tmp_d
				heapq.heappush(que, (tmp_d, u))
	return dist
 
N, M, s, t = map(int, input().split())
yen = [[] for _ in range(N)]
snuuk = [[] for _ in range(N)]
for _ in range(M):
	u, v, a, b = map(int, input().split())
	yen[u-1].append((v-1, a))
	yen[v-1].append((u-1, a))
	snuuk[u-1].append((v-1, b))
	snuuk[v-1].append((u-1, b))
 
dist_s = dijkstra(s-1, yen)
dist_t = dijkstra(t-1, snuuk)
ans = [-1] * N
tmp = float('inf')
for i in range(N-1, -1, -1):
	if dist_s[i] + dist_t[i] < tmp:
		tmp = dist_s[i] + dist_t[i]
	ans[i] = 10 ** 15 - tmp
print(*ans, sep='\n')


Measured memory_bytes: 88128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
WSV = [[int(x) for x in input().split()] for _ in range(N)]

# 上から見てこの順であるとしてよい
WSV.sort(key = lambda x: x[0] + x[1])

# 総重量 -> 価値
dp = np.zeros(2*10**4+100,dtype=np.int64)
for w,s,v in WSV:
    np.maximum(dp[w+s:w-1:-1], dp[s::-1] + v, out=dp[w+s:w-1:-1])

answer = dp.max()
print(answer)

Measured memory_bytes: 12672
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    frame = [['#' if (i ==0 or i == W-1 or j == 0 or j == H-1) else '.' for i in range(W)] for j in range(H)]
    print('\n'.join([''.join(frame[j]) for j in range(H)]))
    print()


Measured memory_bytes: 5864
n = int(input())
button_dict = {i:int(input()) for i in range(1, n+1)}

s = 1
counter = 1
serched_set = set([1])

while button_dict[s]!=2:
  s = button_dict[s]
  counter += 1
  if s in serched_set:
    counter = -1
    break
  else:
    serched_set.add(s)

print(counter)

Measured memory_bytes: 22240
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010;
map<ll,int> Mp;
map<ll,ll> rev;
int n,ans,pri[N],vis[N],up;
ll a[N],b[N],p[N],_;

int main(){
    int _ = 2154;
    for(int i=2;(ll)i*i*i<=1e10;++i) if(!vis[i]){
        pri[up++]=i;
        for(int j=i+i;j<=_;j+=i) vis[j]=true;
    }
    scanf("%d",&n);
    rep(i,0,n){
        scanf("%lld",a + i);
        ll y = 1,x = 1,t = a[i];
        for(int i=0;i<up&&t>=pri[i];++i) if(t%pri[i] == 0){
            int cc=0;while(t%pri[i]==0) t/=pri[i],cc++;
            cc%=3;
            if(cc) {
                rep(re,0,cc) x*=pri[i];
                rep(re,cc,3) y*=pri[i];
            }
        }
        if((ll)sqrt(t+0.5)*(ll)sqrt(t+0.5)==t) y*=(int)sqrt(t+0.5);
        else if(t*t<=(ll)1e10/y) y*=t*t;
        else y=-1;
        b[i]=x*t;
        Mp[b[i]]++;
        rev[b[i]] = y;
    }
    ans += (Mp[1] >= 1);
    for(auto e : Mp) if(e.fi != 1){
        if(Mp.find(rev[e.fi]) == Mp.end()) ans += e.se;
        else if(rev[e.fi] > e.fi) ans += max(Mp[e.fi] , Mp[rev[e.fi]]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 14336
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e18+1;

/*


数列に含まれる数のうちすべてが%5で1な数なら、
和は5で割り切れる
また5つの整数の合計は10以上なので必ず合成数になる

したがって、5で割って1余る、55555以下の素数をN個列挙すればよい　(!)

素数の数は55555以下で5000、そのうち1/4程度が%5で1であることが予想
されるので余裕である

条件を満たすものを構成されるよう求められたら、
制約の限り
自分に都合のよい数だけ考えればよい

一般性を持つことが必ずしも必要でないときもある
*/

bool isprime[60000];

void f(vector<int>& prime) {
    for (int i = 2; i < 60000; i++){
        if (isprime[i]) {
            prime.push_back(i);
            for (int j = 2 * i; j < 60000; j += i) {
                isprime[j] = false;
            }
        }
    }
}

int main() {
    int N; cin >> N;
    for (int i = 0; i < 60000; i++) isprime[i] = true;
    vector<int> prime;
    f(prime);
    int cnt = 0;
    for (int i = 0; i < prime.size(); i++) {
        if (prime[i] % 5 == 1) {
            cout << prime[i] << " "; 
            cnt++;
        }
        if (cnt == N) break;
    } cout << endl;
    
}



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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    auto win = [R, S, P](char c) -> int {
        int ret = 0;
        switch (c)
        {
        case 'r':
            ret = P;
            break;

        case 's':
            ret = R;
            break;

        case 'p':
            ret = S;
            break;

        default:
            break;
        }
        return ret;
    };

    int sum = 0;
    for (int l = 0; l < K; l++)
    {
        // T[mK+l]を考える
        int m = 0;
        char prev = 0;
        while (m * K + l < N)
        {
            if (T[m * K + l] == prev)
            {
                m++;
                prev = 0;   // 次は重複してもよい
                continue;
            }
            sum += win(T[m * K + l]);
            prev = T[m * K + l];
            m++;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 512
using System;

class Program
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    var input = Console.ReadLine().Split(' ');
    int T = int.Parse(input[0]);
    int A = int.Parse(input[1]);
    var list = new int[N];
    double ans = 100000;
    int goal = 0;
    input = Console.ReadLine().Split(' ');
    for(int i = 0; i < N; i++)
    {
      list[i] = int.Parse(input[i]);
      if(ans > Math.Abs(A - (T - list[i] * 0.006)))
      {
        ans = Math.Abs(A - (T - list[i] * 0.006));
        goal = i;
      }
    }
    Console.WriteLine(goal + 1);
  }
}

Measured memory_bytes: 13204
import sys
readline = sys.stdin.readline

N, M = map(int, readline().split())
ACed = [False]*N
count = [0]*N

for _ in range(M):
    p, S = readline().strip().split()
    p = int(p)-1
    if S == 'AC':
        ACed[p] = True
    elif not ACed[p]:
        count[p] += 1

print(sum(ACed), sum(count[i] for i in range(N) if ACed[i]))


Measured memory_bytes: 42460
#include<iostream>
using namespace std;
int main(){
	int N,M,P;
	while(cin>>N>>M>>P){
		if(N==0)break;
		int c=0;
		int d[1100]={},cn=0;
		for(int i=1;i<=N;i++){
			cin>>c;
			d[i]=c;
			cn+=c;
		}
		if(d[M]==0){
			cout<<0<<endl;
		}
		else{
			cout<<((cn*(100-P))-((cn*(100-P))%d[M]))/d[M]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int N,A,B,C;
vector<int> vec;
int dfs(int cur,int a,int b,int c){
  if(cur==N){
    return min({a,b,c})>0? abs(a-A)+abs(b-B)+abs(c-C)-30:1e9;
  }
  int ret0=dfs(cur+1,a,b,c);
  int ret1=dfs(cur+1,a+vec[cur],b,c)+10;
  int ret2=dfs(cur+1,a,b+vec[cur],c)+10;
  int ret3=dfs(cur+1,a,b,c+vec[cur])+10;
  return min({ret0,ret1,ret2,ret3});
}

int main()
{
  cin>>N>>A>>B>>C;
  vec.resize(N);  
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  cout<<dfs(0,0,0,0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 16
using namespace std;
int n,x,y,z,ans,val[1<<(N+1)],cnt[N*2],dp[1<<N];
vector<int>G[N*2];
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		scanf("%d%d%d",&x,&y,&z);
		x++;y++;
		val[x]^=z;val[y]^=z;
	}
	for (int i=1;i<=n;i++) cnt[val[i]]++;
	for (int i=1;i<=15;i++) ans+=cnt[i]/2,val[i]=cnt[i]%2;
	int now=0,tot=0;
	for (int i=1;i<=15;i++) if (val[i]) now|=(1<<i),tot++;
	memset(dp,127,sizeof(dp));int inf=dp[now];dp[now]=0;
	for (int i=0;i<(1<<16);i++) G[__builtin_popcount(i)].push_back(i);
	/*for (int i=tot;i;i--){
		for (int j=0;j<(int)G[i].size();j++){
			int S=G[i][j];
			if (dp[S]==inf) continue;
			for (int x=1;x<=15;x++){
				for (int y=1;y<=15;y++){
					if (x==y||(!(S>>x&1))||(!(S>>y&1))) continue;
					int tmp=x^y;
					int S1=S^(1<<x)^(1<<y);
					if (S1&(1<<tmp)) dp[S1^(1<<tmp)]=min(dp[S1^(1<<tmp)],dp[S]+2);
					else dp[S1|(1<<tmp)]=min(dp[S1|(1<<tmp)],dp[S]+1);
				}
			}
		}
	}*/
	for (int i=tot;i;i--){
		for (int j=0;j<(int)G[i].size();j++){
			int S=G[i][j];
			if (dp[S]==inf) continue;
			x=__builtin_ctz(S);
				for (int y=1;y<=15;y++){
					if (x==y||(!(S>>x&1))||(!(S>>y&1))) continue;
					int tmp=x^y;
					int S1=S^(1<<x)^(1<<y);
					if (S1&(1<<tmp)) dp[S1^(1<<tmp)]=min(dp[S1^(1<<tmp)],dp[S]+2);
					else dp[S1|(1<<tmp)]=min(dp[S1|(1<<tmp)],dp[S]+1);
				}
		}
	}
	//cerr<<inf<<endl;
	printf("%d\n",min(dp[1],dp[0])+ans);
	return 0;
}

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

int main(){
	int n[1000000]={0};
	int tmp=0,a;
	
	n[0]=1;
	n[1]=1;
	for(int i=2;i<1000000;i++){
		for(int j=2;i*j<1000000&&n[i]!=1;j++){
			n[i*j]=1;
		}
	}
	
	while(cin>>a){
		tmp=0;
		for(int i=0;i<=a;i++){
			if(n[i]==0) tmp++;
		}
		cout<< tmp << endl;
	}
	return 0;
}

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



int main(){
	
	int c[3][3];
	for(int i = 0; i < 3; i++)
	{
		cin >> c[i][0] >> c[i][1] >> c[i][2];
	}
	
	string ans = "Yes";
	int x[3], y[3];
	x[0] = 0;
	for(int i = 0; i < 3; i++)
	{
		y[i] = c[0][i] - x[0];
	}
	for(int i = 0; i < 3; i++)
	{
		x[i] = c[i][0] - y[0];
	}
	
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(c[i][j] != x[i]+y[j]) ans = "No";
		}
		
	}
	
	
	cout << ans << endl;

	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;
const int delta = 11353;

int seg[N << 2], DP[N], n, a[N], m, ps[N];
vi R[N];

void shift(int id){
	seg[id << 1] = max(seg[id << 1], seg[id]);
	seg[id << 1 | 1] = max(seg[id << 1 | 1], seg[id]);
}

void mx(int id, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		seg[id] = max(seg[id], x);
		return;
	}
	shift(id);
	int md = (l + r) >> 1;
	mx(id << 1, lq, rq, x, l, md);
	mx(id << 1 | 1, lq, rq, x, md, r);
}

int get(int id, int lq, int rq, int l, int r){
	if (rq <= l || r <= lq)return 0;
	if (lq <= l && r <= rq){
		return seg[id] + ps[l];
	}
	int md = (l + r) >> 1;
	shift(id);
	return(get(id << 1, lq, rq, l, md) + get(id << 1 | 1, lq,rq, md, r));
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		ps[i] = a[i] + ps[i - 1];
	}
	for (int i = 0; i < (N << 2); i++) seg[i] = -INF;
	cin >> m;
	for (int i = 1; i <= m; i++){
		int l, r;
		cin >> l >> r;
		R[r].pb(l);
	}
	for (int i = 1; i <= n; i++){
		DP[i] = DP[i - 1] + (a[i] == 0);
		sort(all(R[i]));
		for (auto u:R[i]){
			int ziad = max(DP[u - 1], get(1, u - 1, u, 1, n + 1));	
			//cout << ziad << '\n';
			DP[i] = max(DP[i], ziad + ps[i] - ps[u - 1]);
			mx(1, u, i + 1, ziad - ps[u - 1], 1, n + 1);
		}
	//	cout << i << ' ' << DP[i] << '\n';
	}	
	cout << n - DP[n];




	return 0;
}


Measured memory_bytes: 18604
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]
goodt = [1] * n
for i in range(m):
  if h[ab[i][0]-1] < h[ab[i][1]-1]:
    goodt[ab[i][0]-1] = 0
  elif h[ab[i][0]-1] > h[ab[i][1]-1]:
    goodt[ab[i][1]-1] = 0
  else:
    goodt[ab[i][0]-1] = 0
    goodt[ab[i][1]-1] = 0

print(sum(goodt))

Measured memory_bytes: 32036
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> p(100010);
    vector<string> S(100010);
    for (int i=0;i<M;i++) cin >> p[i] >> S[i];

    int ac = 0, wa = 0;
    vector<int> A(100010,0);
    for (int i=0;i<M;i++) {
        if (S[i] == "AC" && A[p[i]]>=0) {
            ac++; wa += A[p[i]];
            A[p[i]] = -1;
        } else if (S[i] == "WA" && A[p[i]] >= 0) A[p[i]]++;
    }
    cout << ac << " " << wa << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main(void)
{
    int offset;
    string str;

    cin >> offset >> str;

    for(int i = 0; i < str.size(); i++){
        printf("%c", ((str[i] + offset) - 'A' )% 26 + 'A');
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
l=[[]]*3
for k in range(3):
  l[k]=list(map(int,input().split()))
n=int(input())
ll=[[0]*3 for i in range(3)]
for k in range(n):
  i=int(input())
  for j in range(3):
    if i in l[j]:
      ll[j][l[j].index(i)]=1
a=0
if ll[0][0]==1:
  if ll[0][1]==1 and ll[0][2]==1:
    a=1
  if ll[1][1]==1 and ll[2][2]==1:
    a=1
  if ll[1][0]==1 and ll[2][0]==1:
    a=1
if ll[0][1]==1 and ll[1][1]==1 and ll[2][1]==1:
  a=1
if ll[0][2]==1:
  if ll[1][1]==1 and ll[2][0]==1:
    a=1
  if ll[1][2]==1 and ll[2][2]==1:
    a=1
if ll[1][0]==1:
  if ll[1][1]==1 and ll[1][2]==1:
    a=1
if ll[2][0]==1:
  if ll[2][1]==1 and ll[2][2]==1:
    a=1
if a==0:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 3064
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"5 3
10 30 40 50 20"# => r#"30"#,

r#"3 1
10 20 10"# => r#"20"#,

r#"2 100
10 10"# => r#"0"#,

r#"10 4
40 10 20 70 80 10 20 70 80 60"# => r#"41"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize, k: usize,
        h: [isize; n],
    }

    let mut dp = vec![10010 * (n as isize); n];
    dp[0] = 0;

    for i in 0..n {
        for j in 1..k + 1 {
            if n <= i + j {
                break;
            }
            dp[i + j] = std::cmp::min(dp[i + j], dp[i] + isize::abs(h[i] - h[i + j]));
        }
    }

    dp[n - 1].to_string()
}

Measured memory_bytes: 6396
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc127/tasks/abc127_c>
 問題文============================================================
 =================================================================
 解説=============================================================
 最初に区間[1,N]を持って
 入力に応じて区間を狭めていく
 最後に得られる区間を[l,r]とすると max(r-l+1,0)が答え
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    ll l = 1,r = N;
    for(int i = 0; i < M;i++){
        ll L,R; cin >> L >> R;
        l = max(l,L);
        r = min(r,R);
    }
    res = max(r-l+1,0LL);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int tmp[10];
int counter[10];

bool dfs(bool two) {
  bool ok = 1;
  REP(i, 1, 10) if(counter[i]) { ok = 0; }
  if(ok) return true;
  
  REP(i, 1, 10) {
    if(i < 8 && counter[i] && counter[i+1] && counter[i+2]) {
      counter[i] --; counter[i+1] --; counter[i+2] --;
      if(dfs(two)) return true;
      counter[i] ++; counter[i+1] ++; counter[i+2] ++;
    }
    if(!two && counter[i] > 1) {
      counter[i] -= 2;
      if(dfs(true)) return true;
      counter[i] += 2;
    }
    if(counter[i] > 2) {
      counter[i] -= 3;
      if(dfs(two)) return true;
      counter[i] += 3;
    }
  }
  return false;
}

int main()
{
  string str;
  while(cin >> str) {
    rep(i, 10) tmp[i] = 0;
    rep(i, 13) tmp[str[i]-'0'] ++;
    
    vector<int> ans;
    REP(insert, 1, 10) {
      rep(i, 10) counter[i] = tmp[i];
      counter[insert] ++;
      if(counter[insert] > 4) continue;
      if(dfs(false)) { ans.push_back(insert); }
    }

    if(ans.empty()) { cout << 0; }
    
    rep(i, ans.size()) {
      if(i) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  
  return 0;
}

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

using namespace std;
using ll = long long;
const ll mod = 998244353;
 
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<ll> v(n);
    map<ll, ll> mp;
    for (int i=0; i<n; i++){
        cin >> v[i];
      	mp[v[i]]++;
    }
    if (mp[0] != 1 || v[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for (int i=1; i<n; i++){
    	if(mp[i]){
        	ans *= modpow(mp[i-1], mp[i]);
          	ans %= mod;
        }
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int main(){
string S,T;
bool yes=false;
cin >> S >> T;
 
for(int i=0;i<S.size();i++){
rotate(S.begin(),S.end()-1,S.end());
if(S==T)yes = true;
}
 
if(yes)cout << "Yes";else cout << "No";
}

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

const int N = 100005;

int n, m;
vector <int> g[N];
int par[N];
int in[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 1; i <= n + m - 1; ++i) {
		int u, v; cin >> u >> v;
		g[u].push_back(v);
		++in[v];
	}
	
	int root = 0;
	for (int i = 1; i <= n; ++i) if (!in[i]) root = i;
	
	queue <int> q;
	q.push(root);
	
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for (int &v : g[u]) {
			if (--in[v] == 0) q.push(v), par[v] = u;
		}
	}
	
	for (int i = 1; i <= n; ++i) printf("%d\n", par[i]);
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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;}

vector<int> a(1000000);
int main() {
  int s; cin >> s;
  a[s] = 1;
  for(int i=2; ;++i) {
    if(s%2) s = 3*s+1;
    else s = s/2;
    if(a[s]) {
      cout << i << endl;
      break;
    } else {
      a[s]++;
    }
  }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int YY[8] = { +1, 0, -1, +1, -1, +1, 0, -1};
int dx[4] = { -1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int n;
vector<vector<vector<double>>> dp(301, vector<vector<double>>(301, vector<double>(301, -1)));

double solve(int one, int two, int three) {
	if (one < 0 or two < 0 or three < 0) return 0;
	if (one == 0 and two == 0 and three == 0) {
		return 0;
	}

	if (dp[one][two][three] > 0) return dp[one][two][three];

	double exp = n + one * solve(one - 1, two, three) + two * solve(one + 1, two - 1, three) + three * solve(one, two + 1, three - 1);
	return dp[one][two][three] = exp / (one + two + three);
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

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

	cin >> n;
	int one = 0, two = 0, three = 0;
	for0(i, n) {
		int x;
		cin >> x;
		if (x == 1) one++;
		else if (x == 2) two++;
		else three++;
	}

	cout << fixed << setprecision(10) << solve(one, two, three) << endl;

	return 0;
}

Measured memory_bytes: 219896
//aea ctmr
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 100500;
const ll mod = 1e9 + 7;
using namespace std;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

int xd[N];
int take[N];

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

    for(int i = 0; i < m; i++){
        int a; string s;
        cin >> a >> s; 

        if(!take[a]){
            if(s == "WA"){
                xd[a]++;
            }
            else{
                take[a] = true;
            }
        }

    }
    int ans1 = 0, ans2 = 0;
    for(int i = 0; i < N; i++){
        if(take[i]){
            ans1++;
            ans2 += xd[i];
        }
    }

    cout << ans1 << " " << ans2 << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,n,total=0;
    vector <int> c,d;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        c.push_back(a);
    }
    for(int i=0;i<n;i++){
        cin >> b;
        d.push_back(b);
    }
    for(int i=0;i<n;i++){
        if(c[i]-d[i]>0){
            total+=c[i]-d[i];
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template<typename T> struct is_pair : false_type{};
template<typename T1, typename T2> struct is_pair<pair<T1, T2>> : true_type{};
template<typename T> struct is_vector : false_type{};
template<typename T> struct is_vector<vector<T>> : true_type{};

template<typename T1, typename T2>
istream &operator >> (istream &istr, pair<T1, T2> &p) {
  istr >> p.first >> p.second;
  return istr;
} 
template<typename T1, typename T2>
ostream &operator << (ostream &ostr, const pair<T1, T2> &p) {
  ostr << p.first << " " << p.second;
  return ostr;
}
template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) return ostr;
  bool vp = is_vector<T>() || is_pair<T>();
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    ostr << (vp ? "\n" : " ") << *itr;
  }
  return ostr;
}

template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int modpow(int a, long long n, int mod = MOD) {
  int ret = 1;
  do {
    if (n & 1) ret = 1LL * ret * a % mod;
    a = 1LL * a * a % mod;
  } while (n >>= 1);
  return ret;
}

template<typename T>
T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<typename T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

template<typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
  return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) return a.first < b.first;
  if (a.first == 0) return a.second >= 0 || b.first > 0;
  if (b.first == 0) return b.second < 0 && a.first < 0;
  return a.second * b.first < a.first * b.second;
}


/* -------- <templates end> -------- */


void solve() {
  int h; cin >> h;
  int ans = 0;
  int n = 1;
  while (h > 0) {
    h /= 2;
    ans += n;
    n <<= 1;
  }
  cout << ans << endl;
}


/* -------- <programs end> -------- */


signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
/*AOJ-ITP-3-3*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
 
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int x , y;
        
        while (true) {
        	String st[] = br.readLine().split(" ");
            x = Integer.parseInt(st[0]);
            y = Integer.parseInt(st[1]);
            if(x == 0 && y ==0){break;}
            sb.append(Integer.toString(x<y?x:y)).append(" ").append(Integer.toString(x<y?y:x)).append("\n");
        }
        System.out.print(sb);
    }
 
}

Measured memory_bytes: 26696
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<long long,long long>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
        
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(0));
    int n,m;
    cin>>n>>m;
    int a[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sum=(sum+(4*m)-1)/(4*m);
    for(int i=0;i<n;i++){
        if(a[i]>=sum)m--;
    }
    if(m<=0)cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
        return false;
}
ll isprime(ll n)
{
    ll ans=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            ans = i;
    }
    return ans;
}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%m;
    ll temp=power(a,b/2,m);
    if(b%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return ((((temp%m)*(temp%m))%m)*a%m)%m;
}

/*-----------------------------------------------------------------------------*/

ll c(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;

            else
                C[i][j] = (C[i - 1][j - 1]%MOD +
                          C[i - 1][j])%MOD;
        }
    }
    return C[n][k]%MOD;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {

        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;


        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
ll func(ll n)
{
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i/10==0)
                ans+=1+func(i)*func(n/i);
            else
                ans+=func(i)*func(n/i);
        }
    }
    return ans;
}
ll dp[205][205][205];
ll check(ll red[],ll gre[],ll blu[],ll r,ll g,ll b,ll i,ll j,ll k)
{
   if(dp[i][j][k]!=-1)
    return dp[i][j][k]; 
   if(i<r&&j<g&&k<b)
   {
       return dp[i][j][k]=max(red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k),max(gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1),blu[k]*red[i]+check(red,gre,blu,r,g,b,i+1,j,k+1)));
   }
   else if(i<r&&j<g) 
   {
       return dp[i][j][k]=red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k);
   }
   else if(j<g&&k<b)
   {
       return dp[i][j][k]=gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1);
   }
   else if(i<r&&k<b)
   {
       return dp[i][j][k]=red[i]*blu[k]+check(red,gre,blu,r,g,b,i+1,j,k+1);
   }
   else
   {
       return 0;
   }
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
        string s;
        cin>>s;
        ll tmp=0,mx=0;
        for(ll i=0;i<3;i++)
        {
            if(s[i]=='R')
             tmp++;
            else
            {
                mx=max(mx,tmp);
                tmp=0;
            }  
        }
        mx=max(mx,tmp);
        cout<<mx<<endl;
    }
}


Measured memory_bytes: 3668
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,f=0,s=0,res=1000000000000000000LL; cin>>n; 
    vi a(n+1);
    for (int i=1;i<=n;i++) cin>>a[i], s += a[i];
    for (int i=1;i<=n;i++) {
        s -= a[i]; f += a[i];
        res = min(res,abs(f-s));
    }
    cout << res << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4828
n = gets.to_i
s = gets.chomp

each_length = []
(n-1).times do |i|
    x = s.slice(0, i+1)
    y = s.slice(i+1, n-(i+1))

    chars = []
    x.length.times do |j|
        chars << x[j] if y.include?(x[j]) && !chars.include?(x[j])
    end

    each_length << chars.length
end

puts each_length.max

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

int main(void) {
    double sum=0;
    int N;
    int n;
    char x[10][30];
    char str[10][10];
    int hantei[10];
    double kazu[10];
    
    
    
    scanf("%d",&N);
    for(n=0;N>n;n++){
        scanf("%s", x[n]);
        scanf("%s", str[n]);
        kazu[n]=0;
    }
    for(n=0;N>n;n++){
        hantei[n]=0;
      kazu[n]=atof(x[n]);
    }
    
    for(n=0;N>n;n++){
        if(str[n][0]=='B'){
            hantei[n]=1;
            kazu[n]=kazu[n]*380000;
        }
        	
        	sum=sum+kazu[n];
    }
    
   
    printf("%f",sum);

    
  


	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int h,w;
char s[60][60];
signed main()
{
    h=read(), w=read();
    for(ri int i=1;i<=h;i++) scanf("%s",s[i]+1);
    for(ri int i=1;i<=h;i++)
    for(ri int j=1;j<=w;j++)
    if(s[i][j]=='#')
    {
        if(s[i-1][j]!='#'&&s[i+1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#')
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

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

int main()
{
	int n, x,max = 0;
	long long ans = 0;
	scanf("%d", &n);
	while (n--)
	{
		cin >> x;
		max = max > x ? max : x;
		ans += x;
	}
	ans -= max / 2;
	cout << ans << endl;

}

Measured memory_bytes: 256
// abc109_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, X;
    cin >> N >> X;

    vector<int> v(N);
    REP(i, N) cin >> v[i];

    ll ans = 0;
    REP(i, N){
        int n = abs(v[i] - X);
        ans = gcd(ans, n);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n = sc.nextInt

  val dl = Seq.fill(n)(sc.nextInt)

  val sum = (
    for {
      x <- dl
      y <- dl
    } yield x * y
    ).sum

  val squreSum = dl.map(x => x * x).sum

  val res =  (sum - squreSum) / 2

  println(res)



}

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

int main() {
	int x[2999], y[2999], n;
	for (int i = 0; i < 3000; i++) {
		cin >> x[i] >> y[i];
		if (x[i] == 0 && y[i] == 0)break;
		else if (x[i] > y[i]) {
			n = x[i];
			x[i] = y[i];
			y[i] = n;
		}
		cout << x[i] << " " << y[i] << endl;
	}
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
//#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;
///if(///////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}



///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

dd x,t; cin>>x>>t;
cout<<x/t<<el;

return 0;
}


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

int main() {
    int K;
    string S;
    
    cin >> K >> S;

    int size = S.size();

    if(size <= K){
        cout << S << endl;
    }else{
        cout << S.erase(K) << "..." << endl;
    }
}

Measured memory_bytes: 3624