akhauriyash/Code-Regression huggingface dataset:
if __name__ == "__main__":
    N = int(input())
    S = input()

    # (1) Si≠Sj & Sj≠Sk & Sk≠Si ← すべて違う文字(RGBを網羅している)ということ
    # (2) j-i≠k-j ← 等間隔でないということ 

    R = 0
    G = 0
    B = 0
    for s in S:
        if s == "R":
            R += 1
        elif s == "G":
            G += 1
        else:
            B += 1    
    total = R*G*B

    # 条件に合わない件数をカウント
    for i in range(N-2):
        for j in range(i+1, N-1):
            # 文字の位置が等間隔の場合をチェック
            k = j + (j-i)
            # カウントしないケースは以下の通り
            # (1) チェック対象の3文字目の位置がNを超える
            # (2) 同じ文字が含まれる場合 ← すでに除外済み
            if k >= N or S[i] == S[j] or S[i] == S[k] or S[j] == S[k]:
                continue
            
            total -= 1
    
    print(total)

Measured memory_bytes: 9092
#include<stdio.h>
#define MAX 100000
int n,k;
long long T[MAX];

int check(long long P){
  int i=0;
  for(int j=0;j<k;j++){
    long long s=0;
    while(s+T[i]<=P){
      s+=T[i];
      i++;
      if(i==n)return n;
    }
  }
  return i;
}

int solve(){
  long long left=0;
  long long right=100000*10000;
  long long mid;
  while(right-left>1){
    mid=(left+right)/2;
    long long v=check(mid);
    if(v>=n)right=mid;
    else left=mid;
  }
  return right;
}
int main(void){
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++)scanf("%d",&T[i]);
  long long ans=solve();
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 2632
def main():
    N,K=map(int,input().split())
    V=list(map(int,input().split()))
    M=min(N,K)
    result=0
    for l in range(M+1):
        for r in range(M+1-l):
            L=l
            R=r
            count=0
            minus=[]
            m=l+r
            while L>0:
                a=V[L-1]
                if a>=0:
                    count+=a
                else:
                    count+=a
                    minus.append(a)
                L-=1
            while R>0:
                a=V[-R]
                if a>=0:
                    count+=a
                else:
                    count+=a
                    minus.append(a)
                R-=1

            minus.sort()
            i_minus=0
            while K-m>0 and i_minus<len(minus):
                count-=minus[i_minus]
                m+=1
                i_minus+=1
            result=max(result,count)
    print(result)

if __name__=="__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>

/*
 * [Addition Game | Aizu Online Judge](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2189 "Addition Game | Aizu Online Judge")
 * ????????? : ??????<marony@binbo-kodakusan.com>
 * ?????¨?¨???? C++
 */
using namespace std;

auto solve(string q, int t) -> int {
    if (q.length() <= 1)
        return t;

    int x, y;
    stringstream ss;
    ss << q[0];
    ss >> x;
    ss.clear();
    ss.str("");
    ss << q[1];
    ss >> y;
    ss.clear();
    ss.str("");
    ss << x + y;
    ss << q.substr(2);
    return solve(ss.str(), (t + 1) % 2);
}

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

    string q;
    for (int i = 0; i < n; ++i) {
        cin >> q;
        if (solve(q, 0) != 0)
            cout << "Fabre wins." << endl;
        else
            cout << "Audrey wins." << endl;
    }

    return 0;
}

Measured memory_bytes: 6580
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

int main()
{
	for(vi a(3),m(3);cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],a[0]|m[0]|a[1]|m[1]|a[2]|m[2];){
		vi loop(3);
		rep(i,3){
			for(int j=1,k=1;;j++){
				k=a[i]*k%m[i];
				if(k==1){
					loop[i]=j;
					break;
				}
			}
		}
		cout<<lcm(lcm(loop[0],loop[1]),loop[2])<<endl;
	}
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(2 * N);
  for (auto &l: L) {
    cin >> l;
  }

  sort(begin(L),end(L));
  int ans{};
  for (auto i = 0; i != N; ++i) {
    ans += L[2*i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
Ss = input()

ans = 0
for P in range(1000):
    Ds = str(P).zfill(3)
    pos = -1
    for D in Ds:
        pos = Ss.find(D, pos+1)
        if pos == -1:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 39280
#include<stdio.h>
void sort(int *d,int h){
	int i,j,t;
	for(i=0;i<h;i++)
		for(j=i;j<h;j++)
			if(d[i]>d[j]){
				t=d[i];d[i]=d[j];d[j]=t;
			}
}
int main(){
	int n,m,i,j;
	int taro[103],hanako[103];
	int sumT,sumH,sum;
	int ansT,ansH;
	for(;scanf("%d %d",&n,&m)&&(n||m);){
		sumH=0;
		sumT=0;
		sum=500;
		for(i=0;i<n;i++){
			scanf("%d",&taro[i]);
			sumT+=taro[i];
		}
		for(i=0;i<m;i++){
			scanf("%d",&hanako[i]);
			sumH+=hanako[i];
		}
		sort(taro,n);
		sort(hanako,m);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if(sumT-taro[i]+hanako[j]==sumH-hanako[j]+taro[i]){
					if(sum>taro[i]+hanako[j]){
						sum=taro[i]+hanako[j];
						ansT=taro[i];
						ansH=hanako[j];
					}
				}
			}
		}
		if(sum==500)printf("-1\n");
		else printf("%d %d\n",ansT,ansH);
	}
	return 0;
}

Measured memory_bytes: 0
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        x: u64
    }
    println!("{}", if x==7||x==5||x==3 {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<map>
#include <iomanip>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define Yes(a) if(a)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;

int main() {
	int a;
	cin >> a;
	int ans = 0;
	vector<int> s(a);
	rep(i, 0, a) {
		cin >> s[i];
		if (s[i] % 2 == 0) {
			if (s[i] % 3 != 0 && s[i] % 5 != 0)ans++;
		}
	}
	if (ans == 0)cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    s=input()
    s_c=Counter(s)
    if len(s)==1:
        print("YES")
    elif len(s)==2 and s[0]!=s[1]:
        print("YES")
    elif len(s)==3 and len(s_c.items())==3:
        print("YES")
    else:
        s_list=sorted(s_c.values())
        if len(s_list)==3:
            if s_list[2]-s_list[0]<=1:
                print("YES")
            else:
                print("NO")
        else:
            print("NO")

if __name__=='__main__':
    main()

Measured memory_bytes: 39280
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    
    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var LRd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            for (int i = LRd[0]; i <= LRd[1]; i++)
            {
                if (i % LRd[2] == 0)
                {
                    ret++;
                }
            }

            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 27884
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N=0, A=0, B=0;
  int a,b,c,d,e,sum,ans=0;
  cin >> N >> A >> B;
  for(int i=1;i<=N;i++){
    a=i/10000;
    b=i/1000%10;
    c=i/100%10;
    d=i/10%10;
    e=i%10;
    sum=a+b+c+d+e;
    if(sum>=A && sum<=B){
      ans+=i;
    }
  }
  cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N + 1), B(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.at(a)++;
        B.at(i) = a;
    }

    long long sum = 0;
    for (int i = 0; i < N + 1; i++) {
        sum += A.at(i) * (A.at(i) - 1) / 2;
    }

    for (int i = 0; i < N; i++) {
        cout << sum - (A.at(B.at(i)) - 1) << endl;
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,a,b;
  cin >> n >> a >> b;
  n++;
  cout << (n-a)*(n-b) << endl;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;

// int rec(vector<int> dp; )

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    vector<int> dp(n+1);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs((h[i] - h[i-1])), dp[i-2] + abs((h[i] - h[i-2])));
    }
    cout << dp[n-1];
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == k:
    ans = 1
elif (n-k) % (k-1) == 0:
    ans = 1 + (n-k) // (k-1)
else:
    ans = 2 + (n-k) // (k-1)
print(ans)


Measured memory_bytes: 13880
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	double a;

	while(cin>>a){
        double ans=0;
        ans+=a;
        for(int i=2;i<=10;i++){
            if(i%2==0)a*=2;
            else a/=3;
            ans+=a;
        }
        printf("%lf\n",ans);

	}
	return 0;
}

Measured memory_bytes: 1232
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

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

    stack<char> stk;
    REP(i, 0, x.size()){
        if(x[i]=='S') stk.push(x[i]);
        else{
            if(stk.empty()) stk.push(x[i]);
            else if(stk.top()=='T') stk.push(x[i]);
            else stk.pop();
        }
    }
    cout<<stk.size()<<endl;
    return 0;
}

Measured memory_bytes: 644
#include <stdio.h>

int main(){
  int n, k, i;
  scanf("%d %d", &n, &k);
  double ans = 0.0;
  for(i = 0; i < n; i++){
    int kn = k / (i + 1);
    if(k % (i + 1) != 0){
      kn++;
    }
    //int j = 0;
    int a = 1;
    while(a < kn){
      a *= 2;
      //j++;
    }
    ans += 1.0 / a;
  }
  printf("%.12f\n", ans / n);
  return 0;
}


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

#define mx 100005
#define ll long long

int ar[mx];
char ch[mx];

int n,m,k,ii;

void solve()
{
    int re=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(i%2 && x%2)re++;
    }
    cout<<re<<endl;
}

int main()
{
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   int t=1;
  // scanf("%d",&t);
   while(t--)solve();
   return 0;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;
int main()
{
   int a, b, c;
   cin>>a>>b>>c;
   int n;
   cin>>n;
   int answer= 0 ;
   if(n>= a +b){
      answer+=a;
      n=n-(a+b);
      answer=answer-n;
   }
   else{
      answer+=n;

   }
   cout<<answer;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  int n,m,x,i;
  int a[1000],cost[1000]={0};
  scanf("%d%d%d",&n,&m,&x);
  for(i=0;i<m;i++){
    scanf("%d",&a[i]);
    cost[a[i]]=1;
  }
  int ans=0,ans2=0;
  for(i=x;i>0;i--){
    if(cost[i]==1) ans++;
  }
  for(i=x;i<n;i++){
    if(cost[i]==1) ans2++;
  }
  ans=fmin(ans,ans2);
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#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)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

typedef long long int ll;

int main(){

    int n;
    string s;
    cin >> n >> s;
    //cout << s << endl;

    vector<int> a(400000,0);
    int ans = INF;

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

        if(s[i-1] == 'E'){
            a[i]++;
        }
    }
    REP(i,n+1){
        a[i+1] += a[i];
    }



    /*REP(i,n+1){
        cout << a[i] << endl;
    }*/


    int tmp = 0;
    for(int i = 1;i <=s.length();i++){

        tmp = (a[n]-a[i]) + (i-1 - a[i-1]);
        ans = min(ans,tmp);
    }
    cout << ans << endl;

    return 0;
}

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

S = input()

count = 0
for i, s in enumerate(S):
    if i % 2 and s == S[0]:
        count += 1
    if i % 2 == 0 and s != S[0]:
        count += 1

if count > len(S):
    count = len(S) - count

print(count)



Measured memory_bytes: 9120
package main

import (
	"fmt"
	"math/big"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	var sum int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}

	mod := 998244353

	combinations := make([][]int, n)
	combinations[0] = make([]int, sum+1)
	combinations[0][0] = 2
	combinations[0][a[0]] = 1
	for i := 0; i < n-1; i++ {
		combinations[i+1] = make([]int, sum+1)
		for j := 0; j <= sum; j++ {
			combinations[i+1][j] = combinations[i][j] * 2 % mod
			if j-a[i+1] >= 0 {
				combinations[i+1][j] += combinations[i][j-a[i+1]] % mod
			}
		}
	}

	dups := make([][]int, n)
	dups[0] = make([]int, sum+1)
	dups[0][0] = 1
	dups[0][a[0]] = 1
	for i := 0; i < n-1; i++ {
		dups[i+1] = make([]int, sum+1)
		for j := 0; j <= sum; j++ {
			dups[i+1][j] = dups[i][j] % mod
			if j-a[i+1] >= 0 {
				dups[i+1][j] += dups[i][j-a[i+1]] % mod
			}
		}
	}

	bigThree := big.NewInt(3)
	bigNum := big.NewInt(int64(n))
	totalCombinations := bigThree.Exp(bigThree, bigNum, nil)
	half := sum / 2
	if sum%2 != 0 {
		half++
	}
	for i := half; i <= sum; i++ {
		totalCombinations = totalCombinations.Sub(totalCombinations, big.NewInt(int64(combinations[n-1][i]*3)))
		if i == sum/2 {
			totalCombinations = totalCombinations.Add(totalCombinations, big.NewInt(int64(dups[n-1][i]*3)))
		}
	}

	ret := totalCombinations.Mod(totalCombinations, big.NewInt(int64(998244353)))
	fmt.Println(ret)
}


Measured memory_bytes: 436864
#include <iostream>
typedef long long ll;

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

#include <queue>
#include <map>
#include <cstdio>

inline ll getLL(){ ll s; scanf("%lld", &s); return s; }

#include <set>
using namespace std;

const int mod = 1000000009;

int pmat[64][75][75];

void mul(int a[75][75], int b[75][75], int ret[75][75], int n){
  REP(i,n) REP(j,n) ret[i][j] = 0;
  REP(k,n) REP(i,n) REP(j,n)
    ret[i][j] = (ret[i][j] + (ll)a[i][k] * b[k][j]) % mod;
}

void mul(int a[75][75], int b[75], int n){
  int tmp[75];
  REP(i,n){ tmp[i] = b[i]; b[i] = 0; }
  REP(i,n) REP(j,n)
    b[i] = (b[i] + (ll)tmp[j] * a[i][j]) % mod;
}

int main(){
  for(int cc = 1; ; cc++){
    const int w = getLL();
    const ll  h = getLL();
    const int n = getLL();

    if(w + h + n == 0) break;

    map<ll, vector<int> > obj;

    REP(k,63) REP(i,w) REP(j,w) pmat[k][i][i] = 0;
    REP(i,w){
      if(i) pmat[0][i][i - 1] = 1;
      pmat[0][i][i] = 1;
      if(i != w - 1) pmat[0][i][i + 1] = 1;
    }

    for(int i = 1; i < 63; i++)
      mul(pmat[i - 1], pmat[i - 1], pmat[i], w);

    REP(i,n){
      const int x = getLL() - 1;
      const ll y = getLL() - 1;

      obj[y].push_back(x);
    }
    obj[h - 1];

    ll now = 0;
    int b[75] = {1, 0};

    for(const auto &it : obj){
      const ll hh = it.first;
      const ll diff = hh - now;
      const vector<int> &v = it.second;

      REP(i,63) if(diff & (1ll << i)){
        // printf("%d:\n", i);
        // REP(j,w){ REP(k,w) printf("%d ", pmat[i][j][k]); puts(""); }

        mul(pmat[i], b, w);
      }

      REP(j,v.size())
        b[v[j]] = 0;

      now = hh;

      // printf("%lld:\n", hh);
      // REP(i,w) printf("%d ", b[i]); puts("");
    }

    printf("Case %d: %d\n", cc, b[w - 1]);
  }

  return 0;
}

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

int n;
int t = 0; //time
int d[110] = {}; //discover
int f[110]; //finish
bool a[110][110] = {}; //adjacency matrix

void dfs(int u){
  d[u] = ++t; //record the discovering time

  //if be adjoining and have not been discovered, search
  for(int i = 1;i <= n;i++) if(a[u][i] && d[i] == 0) dfs(i);
  
  f[u] = ++t; //record the finishing time
}

int main(){
  
  int u, k, v;

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v;
      a[u][v] = true;
    }
  }

  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      //if be adjoining and have not been discovered, search
      if(a[i][j] && d[i] == 0) dfs(i);
    }
  }

  //output
  for(int i = 1;i <= n;i++) cout << i << " " << d[i] << " " << f[i] << endl;
  
  return 0;
}




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

using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b == c && c == a){
        cout << "No" << endl;
    }else if(a != b && b!= c && c != a){
        cout << "No" << endl;        
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
using namespace std;
long long int a,b,i;
int main()
{
	scanf("%lld %lld %lld",&a,&b,&i);
	lldiv_t outa;
	outa=lldiv(a,i);
	lldiv_t outb;
	outb=lldiv(b,i);
	if(outa.rem==0) printf("%lld\n",outb.quot-outa.quot+1);
	else if(outa.rem!=0) printf("%lld\n",outb.quot-outa.quot);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin>>s;
	ll al[26]={0};
	ll n = s.size();
	for(int i = 0; i < n; i++){
		al[s[i]-'a']++;
	}
	ll ans = (n-1)*n/2+1;
	for(int i = 0; i < 26; i++){
		ans -= (al[i])*(al[i]-1)/2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#define N 10

int main(void)
{
  int high1, high2, high3;
  int i, tmp;

  high1 = 0;
  high2 = 0;
  high3 = 0;

  for(i = 0; i < N; i++){
    scanf("%d", &tmp);
    if(high1 < tmp){
      high3 = high2;
      high2 = high1;
      high1 = tmp;
    } else if(high2 < tmp){
      high3 = high2;
      high2 = tmp;
    } else if(high3 < tmp){
      high3 = tmp;
    }
  }

  printf("%d\n", high1);
  printf("%d\n", high2);
  printf("%d\n", high3);

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(void){
	int a,b,c;
	int temp;
	scanf("%d %d %d",&a,&b,&c);
	//abcを大きい順に並び替える
	if ( a<b){
		temp = a;
		a = b;
		b = temp;
	}
	if ( a<c){
		temp = a;
		a = c;
		c = temp;
	}
	printf("%d",(a*10)+b+c);
	return 0;
}
	

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(N + 1);
  long a;
  for(int i = 1; i <= N; i++){
    cin >> a;
    data.at(i) = data.at(i - 1) + a;
  }
  sort(data.begin(), data.end());
  long ans = 0, count = 1;
  for(int i = 0; i < N; i++){
    if(data.at(i) == data.at(i + 1))count++;
    else {
      ans += count * (count - 1) / 2;
      count = 1;
    }
  }
  ans += count * (count - 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
	int s,k[100],tmp,sum=0;
	cin>>s;
	for(int i=0;i<s;i++){
		cin>>k[i];
	}
	for (int i=0; i<s; ++i) {
    	for (int j=i+1; j<s; ++j) {
      		if (k[i] < k[j]) {
        		tmp =  k[i];
        		k[i] = k[j];
        		k[j] = tmp;
      		}
    	}
    }
    for(int i=0;i<s;i++){
    	if(!(k[i]==k[i+1])) sum++;
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    S=input()
    L=S[0]
    lenL=1
    n=len(S)
    fs=1
    for i in range(1,n):
        if S[i]!=L:
            if lenL==2:
                lenL=0
            else:
                lenL=1
            fs+=1
        else:
            if lenL==0:
                fs+=1
                lenL=1
            elif lenL==1:
                lenL=2
            elif lenL==2:
                fs+=1
                lenL=0
        L=S[i]
    print(fs)
main()


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

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

    int n;
    cin>>n;
    vector<int> inp(n);
    for(auto& x:inp)
        cin>>x;
    int prev = -1,cnt = 0;
    for(int i=0;i<n;++i)
    {
        if(inp[i]==prev)
        {
            prev = -1;
            ++cnt;
        }
        else
            prev = inp[i];
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define FIN freopen("entrada.txt", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define MOD 1000000007
#define ull unsigned long long int
#define ll  long long int
#define pii pair<int, int>
#define pb push_back
#define MAX int(5*10e5+2)

const int INF = 0x3f3f3f3f;
using namespace std;

int caso=1;

int main() {

   //IO

   string n;
   cin >> n;
   if(n.back()=='2' || n.back()=='4' || n.back()=='5' || n.back()=='7' || n.back()=='9')
      puts("hon");
   else if(n.back()=='0' || n.back()=='1' || n.back()=='6' || n.back()=='8')
      puts("pon");
   else
      puts("bon");

   return 0;
}


Measured memory_bytes: 3640
// Problem : C - Step
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};
/*_________________________________________________________*/

const long long MOD=1e9+7,N=1e5+5;
int solve()
{
	int n,ans=0;
	cin>>n;
	int a[n];
	rep(i,0,n) cin>>a[i];
	int mx=0;
	rep(i,0,n){
		ans+=max(mx-a[i],0ll);
		mx=max(a[i],mx);
	}
	//px(a);
	return ans;
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1; 
	//cin>>t;
	while(t--) 
	//solve();
	cout<<solve()<<endl;
	//cout<<(solve()?"YES":"NO")<<endl;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD=1e9+7;
char s[100010];
int dp[100010][13],pw[100010];
int main() {
	scanf("%s",s);
	int n=strlen(s);
	int i,j,k;
	pw[0]=1;
	for(i=1;i<n;i++)pw[i]=10*pw[i-1]%13;
	dp[0][0]=1;
	for(i=0;i<n;i++) {
		if(s[i]=='?') {
			for(j=0;j<13;j++) {
				for(k=0;k<=9;k++) {
					dp[i+1][j]+=dp[i][(j-k*pw[n-1-i]%13+13)%13];
					dp[i+1][j]%=MOD;
				}
			}
		} else {
			for(j=0;j<13;j++) {
				dp[i+1][j]+=dp[i][(j-(s[i]-'0')*pw[n-1-i]%13+13)%13];
				dp[i+1][j]%=MOD;
			}	
		}
	}
	printf("%d",dp[i][5]);
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
using namespace std;
string ans[3],tmp[3],r;
char atas[4]={'#','.','#','.'},bawah[4] = {'.','.','#','#'};
int n;
bool cek;
int main()
{
    scanf("%d",&n);
    while(1)
    {
        for(int i=0;i<4;i++)
        {
            if(cek)
            {
                tmp[0] = ans[0]+atas[i];
                tmp[1] = ans[1]+bawah[i];
            }
            else
            {
                tmp[0] = atas[i]+ans[0];
                tmp[1] = bawah[i]+ans[1];
            }
            for(int i=0;i<2;i++) cout<<tmp[i]<<endl;
            cin>>r;
           // cout<<"r : "<<r<<endl;
            if(r=="end")
            {
                break;
            }
            if(r=="T")
            {
                ans[0] = tmp[0];
                ans[1] = tmp[1];
                break;
            }
            if(i==3)
            {
                cek = 1;
            }
        }
        if(r=="end") break;
    }
    return 0;
}


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

int main() {
	int n; cin>>n;
	int a[n],cnt=0;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<n-1;i++) {
		if((a[i]>a[i-1] && a[i]<a[i+1]) || (a[i]<a[i-1] && a[i]>a[i+1]))
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());

// /mnt/c/Users/vince/Desktop/POST-IOI/  

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int k; cin >> k;
	for(int i = 0; i < k; i++)
		cout << "ACL";
	cout << "\n";
}

Measured memory_bytes: 3596
//Problem B
#include<bits/stdc++.h>
using namespace std;
const int N=505,NN=250005;
int n,m,a[N][N],o,x[NN],y[NN],xx[NN],yy[NN];
void move(int s,int b,int c,int d){--a[s][b];++a[c][d];x[++o]=s;y[o]=b;xx[o]=c;yy[o]=d;}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
    for(int j=1;j<=m;j++)for(int i=n;i>=2;i--)if(a[i][j]&1)move(i,j,i-1,j);
    for(int j=1;j<m;j++)if(a[1][j]&1)move(1,j,1,j+1);
    printf("%d\n",o);
    for(int i=1;i<=o;i++)printf("%d %d %d %d\n",x[i],y[i],xx[i],yy[i]);
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    bool use[n] = {};
    int i = 0, cnt = 0, f = 0;
    while(!use[i]) {
        use[i] = true;
        if (i == 1) {
            f = 1;
            break;
        }
        i = a[i] - 1;
        cnt++;
    }
    if (f) cout << cnt << endl;
    else cout << -1 << endl;
    return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

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

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int su = 0;
    repall (c, s)
        su += c - '0';
    yn(stoi(s) % su == 0);

    return 0;
}


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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> a(n);
  vector<int64_t> b(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  if(n%2==0){
    for(int i=0;i<n/2;i++){
      b.at(i)=a.at(n-1-2*i);
    }
    for(int i=n/2;i<n;i++){
      b.at(i)=a.at((i-n/2)*2);
    }
  }
  else{
    for(int i=0;i<n/2;i++){
      b.at(i)=a.at(n-1-2*i);
    }
    b.at(n/2)=a.at(0);
    for(int i=n/2+1;i<n;i++){
      b.at(i)=a.at(1+2*(i-n/2-1));
    }
  }
  for(int i=0;i<n;i++){
    cout<<b.at(i)<<endl;
  }
}

Measured memory_bytes: 5248
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    int i;

    int datasets;
    scanf("%d", &datasets);

    while (datasets--) {
        int ball[10];
        for (i = 0; i < 10; i++) {
            scanf("%d", ball + i);
        }

        int b_list[10] = {0}, c_list[10] = {0};
        for (i = 0; i < 10; i++) {
            b_list[i] = c_list[i] = 0;
        }

        int b_cnt = -1, c_cnt = -1;
        enum {B, C} classify;
        b_list[++b_cnt] = ball[0];
        classify = B;

        bool isYES = true;

        for (i = 1; i < 10; i++) {
            if (classify == B) {
                if (ball[i] > b_list[b_cnt]) {
                    if (ball[i] > c_list[c_cnt]) {
                        if (b_list[b_cnt] > c_list[c_cnt]) {
                            b_list[++b_cnt] = ball[i];
                        } else {
                            c_list[++c_cnt] = ball[i];
                            classify = C;
                        }
                    } else {
                        b_list[++b_cnt] = ball[i];
                    }
                } else if (ball[i] > c_list[c_cnt]) {
                    c_list[++c_cnt] = ball[i];
                    classify = C;
                } else {
                    isYES = false;
                    break;
                }
            } else {
                if (ball[i] > b_list[b_cnt]) {
                    if (ball[i] > c_list[c_cnt]) {
                        if (b_list[b_cnt] > c_list[c_cnt]) {
                            b_list[++b_cnt] = ball[i];
                        } else {
                            c_list[++c_cnt] = ball[i];
                            classify = C;
                        }
                    } else {
                        b_list[++b_cnt] = ball[i];
                    }
                } else if (ball[i] > c_list[c_cnt]) {
                    c_list[++c_cnt] = ball[i];
                    classify = C;
                } else {
                    isYES = false;
                    break;
                }
            }
        }

        if (isYES == true) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}

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

using namespace std;

int main(){
    int N;
    long long int K;
    long long int ans=0,anss=0,ansss=0,kk=0;
    cin >> N >> K;

    for(int i=1;i<K;i++){
            kk += i;
        }

        kk = kk%1000000007;

    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    for(int i=0;i<N;i++){
        int a=A[i];
        anss=0;
        ansss=0;
        for(int j=0;j<N;j++){
            if(A[j]<a){
                if(i<j){
                    ansss++;
                    anss++;
                }else{
                    anss++;
                }
            }
        }
        ans += anss*kk;
        ans =  ans%1000000007;
        ans += ansss*K;
        ans = ans%1000000007;
    }

    ans =  ans%1000000007;

    cout << ans << endl;
}

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

namespace abc054_c
{
    class Program
    {
        static bool[] used = new bool[8];
        static bool[,] edge = new bool[8,8];
        static int count = 0;
        public static void bfs(int x)
        {
            used[x] = true;
            bool flag = true;
            for (int i = 0; i < 8; i++)
            {
                if (!used[i])
                {
                    flag = false;
                    if (edge[x,i]) bfs(i);
                }
            }
            if (flag) count++;
            used[x] = false;
        }
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int i = x[0]; i < 8; i++) used[i] = true;
            for (int i = 0; i < x[1]; i++)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[0]--; a[1]--;
                edge[a[0],a[1]] = true; edge[a[1],a[0]] = true;
            }
            bfs(0);
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
int main()
{
  int a[3],a1=0,a2=0,i,j;
  for(j=0;j<3;j++){
    a1=0;a2=0;
  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
    if(i==0)a1+=a[i]*3600;
    else if(i==1)a1+=a[i]*60;
    else if(i==2)a1+=a[i];
  }
  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
    if(i==0)a2+=a[i]*3600;
    else if(i==1)a2+=a[i]*60;
    else if(i==2)a2+=a[i];
  }
  a1=a2-a1;
  printf("%d %d %d\n",a1/3600,(a1%3600)/60,(a1%3600)%60);
}
  return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<ll>> g(3005, vector<ll>(3005));
  rep(i, k) {
    int r, c;
    ll v;
    cin >> r >> c >> v;
    g[r][c] = v;
  }
  vector<vector<vector<ll>>> dp(3005, vector<vector<ll>>(3005, vector<ll>(5, 0)));
  for(int i = 1; i <= h; ++i) {
    for(int j = 1; j <= w; ++j) {
      for(int c = 0; c <= 3; ++c) {
        chmax(dp[i][j][0], dp[i-1][j][c]);
        if(g[i][j] > 0) chmax(dp[i][j][1], dp[i-1][j][c]+g[i][j]);

        chmax(dp[i][j][c], dp[i][j-1][c]);
        if(g[i][j] > 0) chmax(dp[i][j][c+1], dp[i][j-1][c]+g[i][j]);
      }
    }
  }
  ll ans = 0;
  for(int c = 0; c <= 3; ++c) chmax(ans, dp[h][w][c]);
  cout << ans << endl;
}


Measured memory_bytes: 709208
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;



int main()
{
    ll x, y;
    cin >> x >> y;
    if (abs(x-y)<2){
        cout << "Brown" << endl;
    }
    else {
        cout << "Alice" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int A,B,C,D;cin >> A >> B >> C >> D;
    int taka = true;
    int ans = true;

    while(true){
        if(taka){
            C -= B;
            if(C <= 0){
                ans = true;
                break;
            }
            taka = false;
        }
        else{
            A -= D;
            if(A <= 0){
                ans = false;
                break;
            }
            taka = true;
        }
    }

    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=10010;
int a[N],b[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n;
    long long sum=0;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),sum-=a[i];
    for(int i=1;i<=n;i++) b[i]=gi(),sum+=b[i];
    for(int i=1;i<=n;i++)
	if(a[i]<b[i]) sum-=(b[i]-a[i]+1)/2;
    puts(sum<0?"No":"Yes");
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=205;
const int max_m=10005;
struct edge{
    int u,v,next;
}G[max_m*2];
int head[max_n],tot;
void init(int n){
    tot=0;
    for(int i=0;i<=n;i++)head[i]=-1;
}
int match[max_n];
bool used[max_n];
void add_edge(int u,int v){
    G[tot]={u,v,head[u]};
    head[u]=tot++;
}
bool dfs(int u){
    used[u]=true;
    for(int i=head[u];~i;i=G[i].next){
        int v=G[i].v,w=match[v];
        if(w<0||!used[w]&&dfs(w)){
            match[u]=v,match[v]=u;
            return true;
        }
    }
    return false;
}
int solve(int n,int m){
    int res=0;
    for(int i=0;i<=n+m;i++)match[i]=-1;
    for(int u=1;u<=n;u++){
        if(match[u]==-1){
            for(int i=0;i<=n+m;i++)used[i]=false;
            if(dfs(u))res++;
        }
    }
    return res;
}
int n,a[max_n];
bool vis[10000005];
bool p[10000005];
int pri[10000005],cnt;
void sieve(int n){
    p[0]=p[1]=true;
    for(int i=2;i<=n;i++){
        if(!p[i])pri[++cnt]=i;
        for(int j=1;j<=cnt&&1ll*i*pri[j]<=n;j++){
            p[i*pri[j]]=true;
            if(i%pri[j]==0)break;
        }
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)vis[a[i]]^=1,vis[a[i]+1]^=1;
    sieve(10000000);
    vector<int> odd,even;
    for(int i=1;i<=10000001;i++){
        if(vis[i]){
            if(i&1)odd.push_back(i);
            else even.push_back(i);
        }
    }
    int nn=odd.size(),mm=even.size();
    init(nn+mm);
    for(int i=0;i<nn;i++){
        for(int j=0;j<mm;j++){
            if(!p[abs(even[j]-odd[i])]){
                add_edge(i+1,j+1+nn),add_edge(j+1+nn,i+1);
            }
        }
    }
    int x=solve(nn,mm);
    int ans=x+(nn-x)/2*2+(mm-x)/2*2+(nn-x)%2*3;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef function<int(vector<int>)> node_t;
size_t cur; string s;
node_t parse() {
    char c = s[cur++];
    if(isdigit(c))
      return [=](vector<int> arg) { return c - '0';};
    if(isalpha(c))
      return [=](vector<int> arg) { return arg[c - 'P'];};
    node_t left = parse();
    if(c == '-')
      return [=](vector<int> arg) { return 2 - left(arg);};
    assert(c == '(');
    char op = s[cur++];
    node_t right = parse();
    ++cur;
    if(op == '*')
      return [=](vector<int> arg) {
          int l = left(arg), r = right(arg);
          return !l || !r ? 0 : (l == 1 || r == 1 ? 1 : 2);
      };
    if(op == '+')
      return [=](vector<int> arg) {
          int l = left(arg), r = right(arg);
          return l == 2 || r == 2 ? 2 : (!l && !r ? 0 : 1);
      };
}
      
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> s && s != ".") {
        int count = 0;
        auto tree = parse();
        cur = 0;
        rep(p, 3) rep(q, 3) rep(r, 3) {
            vector<int> arg = {p, q, r};
            if(tree(arg) == 2) ++count;
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3076