akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N; ll C;
    cin >> N >> C;

    vll x(N); vi v(N);
    vll pref(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> v[i];
        pref[i + 1] = pref[i] + v[i];
    }

    vll rtL(N + 1), rtR(N + 1);
    for (int i = 0; i < N; i++) {
        rtL[i] = pref[i+1] - 2 * x[i];
        rtR[i] = pref[N] - pref[i] - 2 * (C - x[i]);
    }

    vll left(N + 1), right(N + 1);
    for (int i = 0; i < N; i++) {
        left[i] = max(rtL[i], i ? left[i-1] : 0);
    }
    for (int i = N - 1; i >= 0; i--) {
        right[i] = max(rtR[i], right[i+1]);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, rtL[i] + x[i] + right[i+1]);
        ans = max(ans, rtR[i] + C - x[i] + (i ? left[i-1] : 0));
    }
    cout << ans << endl;

    return 0;
}



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

using namespace std;

int s[5001];

int main()
{
    int n;

    while (scanf("%d", &n), n) {
        memset(s, 0, sizeof(s));

        for (int i = 1; i <= n; ++i) {
            int a; scanf("%d", &a);
            s[i] = a + s[i - 1];
        }

        int ma = INT_MIN;

        for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
            ma = max(ma, s[i] - s[j - 1]);
        }

        printf("%d\n", ma);
    }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX=1e5+5;
vector<LL> GRAPH[MAX];
bool vis[MAX];
stack<LL> s;
LL dist[MAX];

void DFS(LL x)
{
    vis[x] = true;
    for(int i=0;i<GRAPH[x].size();i++)
    {
        if(!vis[GRAPH[x][i]])
        {
            DFS(GRAPH[x][i]);
        }
    }
    s.push(x);
}

void solve()
{
    while(!s.empty())
    {
        LL x = s.top();
        //cout << x << endl;
        s.pop();
        for(int i=0;i<GRAPH[x].size();i++)
        {
            if(dist[GRAPH[x][i]]<dist[x]+1)
            {
                dist[GRAPH[x][i]] = dist[x] + 1;
            }
        }
    }
}

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        vis[i]=false;
        dist[i]=0;
    }
    while(m--)
    {
        LL x,y;
        cin>>x>>y;
        GRAPH[x].push_back(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
            DFS(i);
    }
    solve();
    LL ans=-1;
    for(int i=1;i<=n;i++)
    {
        //cout<<dist[i]<<" ";
        ans = max(ans , dist[i]);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == T.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
object Main {
  def main(args: Array[String]): Unit = {
    var a, b = 0
    val n = io.StdIn.readInt()
    for (_ <- 0 until n) {
      val Array(ca, cb, _*) = io.StdIn.readLine().split(" ")
      if (ca > cb) {
        a += 3
      } else if (ca < cb) {
        b += 3
      } else {
        a += 1
        b += 1
      }
    }
    println(s"$a $b")
  }
}

Measured memory_bytes: 44736
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int powMod(int n, int p) {
  int res = 1;
  while (p) {
    if (p & 1) (res *= n) %= MOD;
    (n *= n) %= MOD;
    p >>= 1;
  }
  return res;
}
int invMod(int n) {
  return powMod(n, MOD - 2);
}

signed main() {
  int N;
  cin >> N;

  bool ng = false;
  map<int, int> m;
  REP(i, N){
    int a;
    cin >> a;
    m[a]++;
    if(i == 0 && a != 0) ng = true;
  }

  int ans = 1;
  if(m[0] != 1) ng = true;
  for(auto p : m){
    if(p.first == 0) continue;
    if(m[p.first-1] == 0) ng = true;
    (ans *= powMod(m[p.first-1], p.second)) %= MOD;
  }

  if(ng) ans = 0;
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 6528
def main():
    N = int(input().strip())
    stx = sty = stt = 0
    for i in range(N):
        t, x, y = [int(x) for x in input().strip().split()]
        mvt = abs(stt - t)
        mvx = abs(stx - x)
        mvy = abs(sty - y)
        
        mvxy = mvx + mvy
        
        if mvt < mvxy:
            return "No"
        if mvt % 2 != mvxy % 2:
            return "No"
        # 次のスタート地点
        stx = x
        sty = y
        stt = t
    return "Yes"
        
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#n=int(input())
w,h,x,y=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

ans=w*h/2

if 2*x==w and 2*y==h:
    pt=1
else:
    pt=0
print('{:.9f} {}'.format(ans,pt))



Measured memory_bytes: 3188
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;

void solution()
{
    int64_t a,b;
    cin >> a >> b;
    cout << abs(a*b)/__gcd(a,b) << '\n';
}

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


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

int main()
{
        int N, K, d;
        cin >> N >> K;

        vector<int> okashi_have(N+1, 0);

        for(int i = 0; i < K; i++)
        {
                cin >> d;
                vector<int> A(d);
                for(int j = 0; j < d; j++)
                {
                        cin >> A.at(j);
                        okashi_have.at(A.at(j))++;
                }
        }

        int count = 0;
        for(int i = 1; i < N+1; i++)
        {
                if(okashi_have.at(i) == 0)
                {
                        count++;
                }
        }

        cout << count << endl;

        return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
int main(){
	string A;
	string B;
	string C;
	cin>>A>>B>>C;
	char b = B[0];
	char c = C[0];
	char a = A.back();
	char d = B.back();
	if((a==b)&&(c==d)){
		cout<<"YES"<<endl;}
	else{
		cout<<"NO"<<endl;}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 200005


int main(){

    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(ARRAY_MAX,0);
    ll ans = 0;
    set<ll> st;
    st.insert(-1);
    st.insert(n);

    REP(i,n){
        cin >> a[i];
        b[a[i]] = i;
    }

    for(int i = 1;i <= n;i++){

        ll tmp = b[i];
        auto it = st.upper_bound(tmp);
        ll r = *it;
        ll l = *(--it);
        ans += i*(r-tmp)*(tmp-l);
        st.insert(tmp);
    }
    cout << ans << endl;


    return 0;
}

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

int n;
int x0[20],y0[20],x1[20],y1[20];
int order[20];
int cnt;

void rec(vector<int> v){
  for(;;){
    bool f = true;
    while(f){
      f = false;
      for(int i=0;i<(int)v.size();i++){
	if(order[v[i]]){
	  v.erase(v.begin()+i);
	  f = true;
	  break;
	}
      }
    }

    if(v.empty())return;

    int num = v[0];
    for(int i=1;i<(int)v.size();i++){
      if(!order[v[i]]){
	if(x0[v[i]] < x0[num])num = v[i];
	else if(x0[v[i]] == x0[num] && y0[v[i]]<y0[num])num = v[i];
      }
    }
    
    order[num] = cnt;
    cnt++;
    
    for(int i=0;i<(int)v.size();i++)
      if(v[i]==num)v.erase(v.begin()+i);

    int left = 1000;
    for(int i=0;i<(int)v.size();i++)
      if(y0[v[i]] < y1[num] && y1[num] < y1[v[i]])left = min(left,x0[v[i]]);

    vector<int> vec;
    for(int i=0;i<(int)v.size();i++)
      if(x1[v[i]]<left && y1[v[i]]<=y1[num])vec.push_back(v[i]);
        
    rec(vec);
  }
}

int main(){
  bool first = true;
  while(cin >> n,n){
    if(!first)cout << endl;
    first = false;
    for(int i=0;i<n;i++){
      cin >> x0[i] >> y0[i] >> x1[i] >> y1[i];
      if(x1[i]<x0[i])swap(x1[i],x0[i]);
      if(y1[i]<y0[i])swap(y1[i],y0[i]);
    }

    vector<int> v;
    for(int i=0;i<n;i++){
      v.push_back(i);
      order[i] = 0;
    }
    cnt = 1;

    rec(v);

    for(int i=0;i<n;i++)cout << order[i] << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(long long N, long long L){
  ll ans=0;
  rep(i,N){
    ans+=(L+i);
  }
  if(L>0){
    ans-=(L);
  }else if(L==0){
    ans-=0;
  }else if(L>=-(N-1)){
    ans-=0;
  }else{
    ans-=(L+N-1);
  }
  op(ans)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    solve(N, L);
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    string str;
    cin>>str;
    fr(i,0,3)
        cout<<str[i];
    cout<<"\n";
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
	return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 1e3 + 50;
cs int INF = 1e9 + 7;
void ckmn(int &a, int b){ if(a > b) a = b; }
void ckmx(int &a, int b){ if(a < b) a = b; }
int n, a[N], m, ans[N];
int now[N], nxt[N], my;
bool cmp(cs int &i, cs int &j){
	int x=a[i]==my,y=a[j]==my;
	if(x!=y)return x<y; return i<j;
}
bool work(int len){
	for(int i=1;i<=len;i++)--a[now[i]];
	int mn=INF,mx=0;
	for(int i=1; i<=n; i++)
	mn=min(mn,a[i]),mx=max(mx,a[i]);
	
	if(mn*2>=mx){
		for(int i=1; i<=len; i++)
		++a[nxt[i]=now[i]];
		sort(nxt+1,nxt+len+1);
		nxt[len+1]=0;
		return true;
	}
	
	if(mn*2+1<mx){
		for(int i=1; i<=len; i++) ++a[now[i]];
		return false;
	}
	
	static int t1[N], t2[N]; int z1=0, z2=0;
	for(int i=1; i<=len; i++)
	if(a[now[i]]==mn||a[now[i]]==mx)
	t1[++z1]=now[i]; else t2[++z2]=now[i]; 
	
	my=mn;
	sort(t1+1,t1+z1+1,cmp);
	sort(t2+1,t2+z2+1);
	
	for(int i=1,p=1,q=1; i<=len; i++)
	if((p<=z1 && t1[p]<t2[q])||q>z2) nxt[i]=t1[p++];
	else nxt[i]=t2[q++]; nxt[len+1]=0;

	bool ok=true;
	for(int i=len+1;i<=n;i++)ok&=(a[now[i]]!=mn);
	ok|=(z1==0)|(a[t1[1]]==mn);
	
	for(int i=1; i<=len; i++)++a[now[i]];
	return ok;
}
bool cmp(int *a, int *b){ 
	int i=1;for(;a[i]==b[i];i++);
	return a[i]<b[i];
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
//	freopen("my.out","w",stdout);
	#endif
	scanf("%d",&n);
	int mn=INF,mx=0,sm=0;
	for(int i=1; i<=n; i++)
	scanf("%d",&a[i]),sm+=a[i],
	ckmn(mn,a[i]),ckmx(mx,a[i]);
	if(mn*2<mx) return puts("-1"),0;
	for(int i=1; i<=n; i++)	
	now[i]=i; if(!work(n))return puts("-1"),0;
	for(int i=1; i<=n; i++)
	now[i]=ans[++m]=nxt[i],--a[now[i]];
	while(m<sm){
		static int trs[N];
		int len=0;trs[1]=n+1;
		for(int i=1; i<=n; i++){
			if(work(i)&&cmp(nxt,trs))
			len=i,memcpy(trs,nxt,sizeof(int)*(len+2));
		}
		for(int i=1; i+len<=n; i++)
		now[i]=now[i+len];
		for(int i=1; i<=len; i++)
		now[i+n-len]=ans[++m]=trs[i],--a[trs[i]];
	}
	for(int i=1; i<=m; i++)cout<<ans[i]<<" ";
	for(int i=1; i<=n; i++)assert(a[i]==0);
	return 0;
}

Measured memory_bytes: 3768
riffle = lambda half, x: [j for i in zip(x[:half], x[half:]) for j in i]
cut = lambda index, x: x[index:] + x[:index]

cards = [str(x) for x in range(1, int(input())*2 + 1)]
half = int(len(cards) / 2)
for _ in range(int(input())):
  order = int(input())
  if order == 0:
    cards = riffle(half, cards)
  else:
    cards = cut(order, cards)
print("\n".join(cards))

Measured memory_bytes: 7720
mod=10**9+7
N=int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])

ans=0
for i in range(60):
    ones=str_a[59-i::60].count("1")
    ans+= pow( 2, i ,mod)* ones *(N-ones)
print(ans%mod)

Measured memory_bytes: 65704
n = int(input())
a = list(map(int, input().split())) 
count = 0

for i in range(len(a)-2):
  if a[i] < a[i+1] and a[i+1] < a[i+2]:
      count += 1
  if a[i] > a[i+1] and a[i+1] > a[i+2]:
    count += 1
  
print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int P,Q,R;
  cin >> P >> Q >> R;
  if(max(P,max(Q,R)) == P) print(Q+R);
  else if(max(P,max(Q,R)) == Q) print(P+R);
  else print(P+Q);

  

 return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <vector>
#include <iostream>
using namespace std;
using ll = int64_t;

ll MOD = 998244353LL;
ll ADD(ll x, ll y) { return (x+y)%MOD; }
ll SUB(ll x, ll y) { return ADD(x, MOD-y); }

ll LSB(ll n) { return n&(-n); }

struct fenwick {
  fenwick(ll n) : A(n+1, 0) {}
  void add(ll i, ll x) {
    while(i<A.size()) {
      A[i] = ADD(A[i], x);
      i += LSB(i);
    }
  }
  ll sum(ll i) {
    assert(0<=i && i<A.size());
    ll ans = 0;
    while(i>0) {
      ans = ADD(ans, A[i]);
      i -= LSB(i);
    }
    return ans;
  }
  ll sum_interval(ll L, ll R) {
    if(L>=A.size()) { return 0; }
    if(R>=A.size()) { R=A.size()-1; }
    assert(L>=1);
    ll sumR = sum(R);
    ll sumL = sum(L-1);
    //cerr << " sum_interval L=" << L << " R=" << R << " sumR=" << sumR << " sumL=" << sumL << endl;
    return SUB(sumR, sumL);
  }
  vector<ll> A;
};

// DP[i] = \sum DP[i+d] for d in moves = \sum_j DP[i+L[j]]+DP[i+L[j]+1]+...+DP[i+R[j]]
int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> L(k, 0);
  vector<ll> R(k, 0);
  for(ll i=0; i<k; i++) {
    cin >> L[i] >> R[i];
  }
  fenwick F(n);
  // DP[n] = 1
  F.add(n, 1); 
  for(ll i=n-1; i>=1; i--) {
    ll dpi = 0;
    for(ll j=0; j<k; j++) {
      ll Lj = i+L[j];
      ll Rj = i+R[j];
      ll jsum = F.sum_interval(Lj, Rj);
      //cerr << "L=" << Lj << " R=" << Rj << " sum=" << jsum << endl;
      dpi = ADD(dpi, jsum);
    }
    //cerr << i << " " << dpi << endl;
    F.add(i, dpi);
  }
  cout << F.sum(1) << endl;
}


Measured memory_bytes: 4408
using System.Collections.Generic;
using System.Linq;
using System;

class D
{
    static int N;
    static List<int>[] e;
    static void Main()
    {
        N = int.Parse(Console.ReadLine());
        e = new List<int>[N];

        for (int i = 0; i < N; i++) e[i] = new List<int>();
        for (long i = 0; i < N - 1; i++)
        {
            var XY = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1);
            e[XY.ElementAt(0)].Add(XY.ElementAt(1));
            e[XY.ElementAt(1)].Add(XY.ElementAt(0));
        }

        var Black = DFS(0);
        var White = DFS(N - 1);

        var b = 0;
        for (int i = 0; i < N; i++)
        {
            if (Black[i] <= White[i]) b++;
        }

        Console.WriteLine(b > N - b ? "Fennec" : "Snuke");
    }

    static int[] DFS(int root)
    {
        var s = new Stack<int>();
        var v = new bool[N];
        var d = new int[N];
        s.Push(root);
        v[root] = true;
        while (s.Count > 0)
        {
            var current = s.Pop();
            foreach (var next in e[current])
            {
                if (!v[next])
                {
                    s.Push(next);
                    v[next] = true;
                    d[next] = d[current] + 1;
                }
            }
        }
        return d;
    }
}

Measured memory_bytes: 28192
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  ll ans1[n + 1];
  ans1[n] = 0;
  for(int i = 0;i < n;i++)
    cin >> a[i];
  for(int i = 0;i < n;i++)
    cin >> b[i];
  for(int i = 0;i < n;i++)
    cin >> c[i];
  sort(a, a + n);
  sort(b, b + n);
  sort(c, c + n);
  int cur = n - 1;
  for(int i = n - 1;i >= 0;i--){
    while(cur >= 0 && c[cur] > b[i])
      cur--;
    ans1[i] = n - cur - 1;
    ans1[i] += ans1[i + 1];
  }
  cur = n - 1;
  ll res = 0;
  ll ans2[n + 1];
  ans2[n] = 0;
  for(int i = n - 1;i >= 0;i--){
    while(cur >= 0 && b[cur] > a[i])
      cur--;
    ans2[i] = ans1[cur + 1];
    res += ans2[i];
  }
  cout << res;

  return 0;
}


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

using namespace std;

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

  int vertexc = str.size();

  if (str[vertexc - 1] != '0') {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 1; i <= vertexc - 1; i++) {
    if (str[i - 1] != str[vertexc - i - 1]) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (str[1 - 1] != '1') {
    cout << -1 << endl;
    return 0;
  }

  vector<int> allowed;
  for (int i = 2; i <= vertexc; i++) {
    if (str[i - 1] == '1') {
      allowed.push_back(i);
    }
  }

  int curRoot = 1;
  int curVertexc = 1;
  for (int v : allowed) {
    int newRoot = curVertexc + 1;
    curVertexc++;
    cout << curRoot << " " << newRoot << endl;
    curRoot = newRoot;
    
    while (curVertexc < v) {
      int u = curVertexc + 1;
      curVertexc++;
      cout << curRoot << " " << u << endl;
    }
  }

  while (curVertexc < vertexc) {
    int u = curVertexc + 1;
    curVertexc++;
    cout << curRoot << " " << u << endl;
  }
}


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

from copy import deepcopy

POSS = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
TMAX = 20
NMAX = 100000

def do_dp(n):
    dp = [i for i in range(NMAX + 1)]
    for t in range(TMAX):
        for i in reversed(range(NMAX + 1)):  # 配る
            for p in POSS:
                if i + p <= NMAX:
                    dp[i + p] = min(dp[i + p], dp[i] + 1)
    return dp[n]

def main():
    n = int(input())
    print(do_dp(n))

main()


Measured memory_bytes: 45680
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int from,to,cost;};
vector<edge> G;
vector<int> O[10];
P sg[10];
int d[1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int fi[1005][1005];
int ans[1005][1005]={};
bool graph[55][55];
bool visited[55];
int a[55],b[55];
int n,m;
int dp[41][405][405];
signed main(){
    int a,b;cin>>a>>b;
    string s;cin>>s;
    if(s.size()!=a+b+1){
        cout<<"No"<<endl;
        return 0;
    }rep(i,s.size()){
        if(i==a){
            if(s[a]!='-'){
                cout<<"No"<<endl;
                return 0;
            }
        }else {
            if(s[i]=='-'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : C - Colorful Leaderboard
// Contest : AtCoder - AtCoder Beginner Contest 064
// URL : https://atcoder.jp/contests/abc064/tasks/abc064_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
vi v(n);cin>>v;
map<int,int> mp;
int non=0;
for(int i:v)
{
	if(i<=399)mp[0]++;
	else if(i<=799)mp[1]++;
	else if(i<=1199)mp[2]++;
	else if(i<=1599)mp[3]++;
	else if(i<=1999)mp[4]++;
	else if(i<=2399)mp[5]++;
	else if(i<=2799)mp[6]++;
	else if(i<=3199)mp[7]++;
	else
	non++;
}
int x=size(mp);
cout<<max2(1LL,x)<<" "<<x+non;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3664
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

def lcm(x,y):
    return x*y//gcd(x,y)

A, B, C, D = map(int, input().split())

n = B - A + 1
c = B//C - (A-1)//C
d = B//D - (A-1)//D
cd = B//lcm(C,D) - (A-1)//lcm(C,D)

print(n - (c + d - cd))

Measured memory_bytes: 3064
n=int(input())
s=input()
a=[]
for i in range(n):
    if i==0:
        if s[0]=="#":
            a.append(1)
        else:
            a.append(0)
    else:
        if s[i]=="#":
            a.append(a[i-1]+1)
        else:
            a.append(a[i-1])
min=n
for i in range(n):
    m=a[i]
    r=n-i-1-(a[n-1]-a[i])
    q=m+r
    if q<min:
        min=q
if a[n-1]==n:
    min=0
if min>a[n-1]:
    min=a[n-1]
if min>n-a[n-1]:
    min=n-a[n-1]
print(min)

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

int main() {
  int A,B;
  cin >> A >> B;
  int n = 0;
  for(int i = A; i < (B+1);i++){
    int d1,d2,d3,d4,d5;
    d1 = i % 10;
    d2 = (i / 10) % 10;
    d3 = (i /100) % 10;
    d4 = (i /1000) % 10;
    d5 = (i / 10000) % 10;
    if(d1 == d5 && d2 == d4){
      n++;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
X,N=map(int,input().split())
p=[int(x) for x in input().split()]

ans=X
if N!=0:
    k=0
    while True:
        if X-k not in p:
            ans=X-k
            break
        elif X+k not in p:
            ans=X+k
            break
        k+=1
print(ans)

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N;
    string S;
    cin >> N>>S;

    REP(i,S.size()){
        char tmp = S.at(i);
        int tmp1 = (int)tmp;
        tmp1 += N;
        if(tmp1>90){
            tmp1 -= 26;
        }
        S.at(i) = (char)tmp1;
    }
    cout << S << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;
double max_calory = 0;
int N, A, B, C;
vector<int> topping;

void solve()
{
	cin >> N;
	cin >> A >> B;
	cin >> C;
	for(int i = 0; i < N; ++i)
	{
		int price;
		cin >> price;
		topping.push_back(price);
	}
	sort(topping.begin(), topping.end(), greater<int>());
	int calory = C;
	int cost = A;
	max_calory = (double)C / A;
	int item = 0;
	while(true)
	{
		calory += topping[item];
		cost += B;
		if((double)calory / cost > max_calory)
		{
			max_calory = (double)calory / cost;
		}
		else
		{
			break;
		}
		++item;
	}
	cout << (int)max_calory << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1220
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let q: usize = itr.next().unwrap().parse().unwrap();

    let mut cnt = vec![0; 100010];
    for i in 0..n {
        cnt[a[i]] += 1;
    }
    let mut sum = a.iter().sum::<usize>();

    let mut out = Vec::new();
    for _ in 0..q {
        let b: usize = itr.next().unwrap().parse().unwrap();
        let c: usize = itr.next().unwrap().parse().unwrap();
        // b -> c
        let v1 = cnt[c] * c;
        let v2 = cnt[b] * b;
        sum -= v2 + v1;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        sum += cnt[c] * c;
        writeln!(out, "{}", sum).ok();
    }
    stdout().write_all(&out).unwrap();
}


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

int main(void){
    long long n;
    long long a=0;
    cin>>n;
    long long m=n/2;
    if(n%2==1) cout<<0;
    else if(n%2==0){
        for(long long i=1;m>=5;i++){
            a+=m/5;
            m/=5;
        }
        cout<<a;
    }
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

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

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

    if ((a + b) < (c + d)) puts("Right");
    else if ((a + b) > (c + d)) puts("Left");
    else puts("Balanced");
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <functional>
#include <map>
#include <cmath>
#include <iostream>


using namespace std;



int A, B;

int main()
{
	cin >> A >> B;
	int area = A * B - (A + B - 1);
	cout << area << endl;
	return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n; cin >> n;
    set<int> A;
    rep(i,n){
        int Ai; cin >> Ai;
        A.insert(Ai);
    }
    int m; cin >> m;
    set<int> B;
    rep(i,m){
        int Bi; cin >> Bi;
        B.insert(Bi);
    }
    // 和集合
    set<int> C;
    for(auto Ai: A){
        C.insert(Ai);
    }
    for(auto Bi: B){
        C.insert(Bi);
    }
    for(auto Ci: C){
        cout << Ci << endl;
    }
}


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

int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  
  if((B-A)%2==0)  cout << (B-A)/2 << endl;
  else{
    long long ans1=(A-1)+1+(B-A)/2;
    long long a=N-B+1;
    long long b=N-A+1;
    long long ans2=(a-1)+1+(b-a)/2;
    cout << min(ans1,ans2) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if(c % 2 == 1) cout << "Odd" << endl;
  else cout << "Even" << endl;
  return 0;
}

Measured memory_bytes: 3612
A,B,K = map(int,input().split())
ans = set()
for a in range(A,A+K):
    if a > B: break
    ans.add(a)
for b in range(B-K+1,B+1):
    if b < A: break
    ans.add(b)
print(*sorted(ans), sep='\n')

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int a=0,b=0,c=0,d=0;
  cin >> a >> b >> c >> d;
  int x=(c-a);
	int y=(d-b);	
	cout << c-y << " " << d+x << " " << a-y << " " << b+x << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    map<ll, ll> mp;
    REP(i, n) {
        ll num;
        cin >> num;
        mp[num] = i;
    }

    for (auto elem : mp) {
        cout << elem.second + 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 7040
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define N 100000
#define mod 1000000007
int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    ll ans=x;
    for(int i=0;i<10;i++)
    {
    	cout<<r*ans-d<<endl;
    	ans=(r*ans-d);
	}
    return 0;
}



Measured memory_bytes: 256
class Graph():  #directed
    def __init__(self, n, edge, indexed=1):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0] - indexed].append((e[1] - indexed, e[2]))
            self.deg[e[1] - indexed] += 1

    def bellman_ford(self, s, t=None, INF=10**18):
        dist = [INF for _ in range(self.n)]
        dist[s] = 0
        update = True
        for i in range(self.n):
            update = False
            for node, g in enumerate(self.graph):
                for adj, adjcost in g:
                    if dist[node] != INF and dist[node] + adjcost < dist[adj]:
                        dist[adj] = dist[node] + adjcost
                        update = True
            if not update:
                return dist[t] if t is not None else dist
        if t is None:
            return
        negative_cycle = [0 for _ in range(self.n)]
        for i in range(self.n):
            for node, g in enumerate(self.graph):
                for adj, adjcost in g:
                    if dist[node] != INF and dist[node] + adjcost < dist[adj]:
                        dist[adj] = dist[node] + adjcost
                        negative_cycle[adj] = True
        if not negative_cycle[t]:
            return dist[t]

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
E = []

for _ in range(M):
    a, b, c = map(int, input().split())
    E.append((a, b, -c))

g = Graph(N, E)
bf = g.bellman_ford(0, N - 1)

print(-bf if bf is not None else 'inf')

Measured memory_bytes: 46812
#include <stdio.h>

int main(void){
  int i;
  int r, D, x;
  scanf("%d %d %d", &r, &D, &x);
  
  for(i=1; i<=10; i++){
    x = r * x - D;
    printf("%d\n", x);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    auto best = MP(0, 100 * a);
    for (int i = 0; i * a * 100 <= f; i++)
    {
        for (int j = 0; 100 * (i * a + j * b) <= f; j++)
        {
            for (int k = 0; 100 * (i * a + j * b) + k * c <= f; k++)
            {
                for (int l = 0; 100 * (i * a + j * b) + k * c + l * d <= f; l++)
                {
                    int water = 100 * (i * a + j * b);
                    int sugar = k * c + l * d;
                    int sum = water + sugar;
                    if (sugar <= (i * a + j * b) * e)
                    {
                        if (sugar * best.S > sum * best.F)
                            best = MP(sugar, sum);
                    }
                }
            }
        }
    }
    cout << best.S << " " << best.F;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// qsort
int compare(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}

int main( int argc, char *argv[] )
{
  int i;
  int n,m;
  int w,a;
  int p;
  int ww[100001];
  int aa[100001];
  char ss[3];

  scanf( "%d %d", &n, &m );
  w = 0;
  a = 0;

  for( i = 0 ; i < n ; i ++) {
    ww[i]=aa[i] = 0;
  }
  for( i = 0 ; i < m ; i ++ ){
    scanf( "%d %s", &p, ss ); 
    p--;
    if( ss[0] == 'W' && ss[1]== 'A' ){
      if( aa[p] == 0 ) ww[p] ++;
    }
    if( ss[0] == 'A' && ss[1]== 'C' ){
      aa[p] ++;
    }
  }
  for( i = 0 ; i < n ; i ++) {
    if( aa[i] ){
      a ++;
      w += ww[i];
    }
  }

  printf( "%d %d\n", a, w );
}


Measured memory_bytes: 896
n = int(input())
h = []
for _ in range(n):
    a, b, c = [int(x) for x in input().split()]
    h.append((a, b, c))

vals = {}
a, b, c = h[0]
vals[(0, 'A')] = a
vals[(0, 'B')] = b
vals[(0, 'C')] = c

for i in range(1, n):
    a, b, c = h[i]
    vals[(i, 'A')] = max(vals[(i-1, 'B')], vals[(i-1, 'C')]) + a
    vals[(i, 'B')] = max(vals[(i-1, 'A')], vals[(i-1, 'C')]) + b
    vals[(i, 'C')] = max(vals[(i-1, 'B')], vals[(i-1, 'A')]) + c

print(max(vals[(n-1, 'A')], vals[(n-1, 'B')], vals[(n-1, 'C')]))


Measured memory_bytes: 97620
// https://atcoder.jp/contests/dp/tasks/dp_g
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <limits.h>
#include <vector>

using namespace std;

struct node{
	vector<int> edges;
	int max,marked;
	node()
	{
		max=0;
		marked=0;
	}
};

node arr[100007];

int dfs(int index)
{
	int max=0;
	for(int i=0;i<arr[index].edges.size();i++)
	{
		int z;
		if(arr[arr[index].edges[i]].marked)
			z = arr[arr[index].edges[i]].max;
		else
			z=dfs(arr[index].edges[i]);
		if(z>max)
			max=z;
	}
	arr[index].max = max+1;
	arr[index].marked=1;
	return arr[index].max;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		arr[a-1].edges.push_back(b-1);
	}
	for(int i=0;i<n;i++)
	{
		if(arr[i].marked)
			continue;
		// cout << "hbaefhjk" << endl;
		arr[i].max = dfs(i);
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(arr[i].max>ans)
			ans=arr[i].max;
	}
	cout << ans-1 << endl;
}

Measured memory_bytes: 11408
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
LL n;
int main()
{
    scanf("%lld",&n);
    LL ans=1e17;
    for (LL i=1;i<=sqrt(n);i++)
    {
        if (n%i==0)
        {
            ans=min(ans,i-1+n/i-1);
        }// else
        //{
        //    ans=min(ans,i-1+n/i);
       // }
    }
    printf("%lld\n",ans);
    return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
const int MAX=1400;
int buffer[MAX][MAX],T[MAX][MAX];
int getLargestRectangle(int w,int buf[]){
    stack<pair<int,int> >S;//first:pos,second:height
    pair<int,int>rect;
    buf[w]=0;
    int maxv=0;
    for(int i=0;i<=w;i++){
        rect.first=i;
        rect.second=buf[i];
        if(S.empty())S.push(rect);
        else if (rect.second>S.top().second)S.push(rect);
        else if(rect.second<S.top().second){
            while(!S.empty() && rect.second<S.top().second){
                int x=S.top().first;
                int h=S.top().second;
                S.pop();
                maxv=max(maxv,h*(i-x));
                rect.first=x;
            }
            S.push(rect);
        }
    }
    return maxv;
}
int getLargestRectangle(int h,int w){
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            if(buffer[i][j]==1)T[i][j]=0;
            else
                T[i][j]=i>0?T[i-1][j]+1:1;
    int maxv=0;
    for(int i=0;i<h;i++)
        maxv=max(maxv,getLargestRectangle(w,T[i]));
    return maxv;
}
int main()
{
    int H,W;
    cin>>H>>W;
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
            cin>>buffer[i][j];
    cout<<getLargestRectangle(H,W)<<endl;
    return 0;
}
    


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


int main(){
    int n;
    cin>>n;
    if(n<1200){
        cout<<"ABC"<<endl;
    }
    else if(n<2800){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"AGC"<<endl;
    }
    return 0;
}

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

signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B)cout<<C<<endl;
  if(A==C)cout<<B<<endl;
  if(B==C)cout<<A<<endl;
  return 0;
}

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

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

  vector<int> c(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    c[a - 1]++; c[b - 1]++;
  }

  for (int i = 0; i < n; i++) {
    cout << c[i] << endl;
  }
}


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

namespace Dice_II
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int q = int.Parse(Console.ReadLine());
            
            Dice dice = new Dice(input);

            List<string> result = new List<string>();
            string ctr = " zzzxyyyzxxxzyyyzxxxyzzz";

            for (int i = 0; i < q; i++)
            {
                string[] topFront = Console.ReadLine().Split(' ');

                for (int j = 0; j < ctr.Length; j++)
                {
                    dice.Rotate(ctr[j]);
                    if (topFront[0].Equals(dice.top) && topFront[1].Equals(dice.front))
                    {
                        result.Add(dice.right);
                        break;
                    }
                }
            }

            foreach (string item in result)
            {
                Console.WriteLine(item);
            }



        }
    }

    class Dice
    { 
        public string top, front, right, left, back, bottom;

        public Dice(string[] input)
        {
            this.top = input[0];
            this.front = input[1];
            this.right = input[2];
            this.left = input[3];
            this.back = input[4];
            this.bottom = input[5];
        }

        void RotateX()
        {
            string temp = this.top;
            this.top = this.front;
            this.front = this.bottom;
            this.bottom = this.back;
            this.back = temp;
        }

        void RotateY()
        {
            string temp = this.front;
            this.front = this.right;
            this.right = this.back;
            this.back = this.left;
            this.left = temp;
        }

        void RotateZ()
        {
            string temp = this.top;
            this.top = this.left;
            this.left = this.bottom;
            this.bottom = this.right;
            this.right = temp;
        }

        public void Rotate(char ctr)
        {
            switch (ctr)
            { 
                case 'x':
                    RotateX();
                    break;
                case 'y':
                    RotateY();
                    break;
                case 'z':
                    RotateZ();
                    break;
                default:
                    break;
            }
        }

    }
}



Measured memory_bytes: 15888