akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int a, b;
	cin >> a >> b;

	if ( b < a )
	{
		cout << a - 1 << endl;
	}
	else
	{
		cout << a << endl;
	}

	return ( 0 );
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    ll money = 1000;
    ll property = 0;
    for (int i = 0; i < N-1; ++i) {
        if (A[i] < A[i+1]) {
            ll buy = money / A[i];
            property += buy;
            money -= buy * A[i];
        } else if (A[i] > A[i+1]) {
            ll sell = property;
            property -= sell;
            money += sell * A[i];
        }
    }
    money += property * A[N-1];
    cout << money << endl;
}


Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#define MIN_MAX 1200001
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(void){
    int n, m, x;
    cin >> n >> m >> x;
    vi C(n);
    vvi A(n, vi(m));
    for(int i=0; i<n; i++){
        cin >> C[i];
        for(int j=0; j<m; j++) cin >> A[i][j];
    }
    int min = MIN_MAX;
    for(int bit=0; bit<1<<n; bit++){
        int sumC = 0;
        vi sumA(m);
        for(int i=0; i<n; i++)if(bit & 1<<i){
            sumC += C[i];
            for(int j=0; j<m; j++) sumA[j] += A[i][j];
        }
        bool suc = true;
        for(int &a : sumA)if(a<x){suc = false; break;}
        if(suc && sumC < min) min = sumC;
    }
    if(min < MIN_MAX) cout << min << '\n';
    else cout << -1 << '\n';
    return 0;
}

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

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;  // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main() {
  int x;
  cin >> x;
  REP(i, x, 100004) {
    if (IsPrime(i)) {
      cout << i << endl;
      break;
    }
  }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  int g = __gcd(n,m);
  long long lcm = n/g*1LL*m;
  int ok = 1;
  for (int i = 0; i < g; i++) {
    if (a[i*(n/g)] != b[i*(m/g)]) ok = 0;
  }
  cout << (ok ? lcm : -1) << endl;
}


Measured memory_bytes: 512
//タイピング
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

int n;
vector<int> primes;
int cnt[1000];

void setPrimes(int n) {
	bool isprime[10001] = {false};
	int i, j;
	
	for (i = 2; i <= n; i++) isprime[i] = true;
	for (i = 2; i <= n; i++) {
		if (isprime[i]) {
			for (j = i * 2; j <= n; j += i) {
				isprime[j] = false;
			}
		}
	}
	
	for (i = 0; i <= n; i++) {
		if (isprime[i]) {
			primes.push_back(i);
		}
	}
}

signed main() {
	cin >> n;
	setPrimes(10000);
	
	for (int i = 2; i <= n; i++) {
		int tmp = i;
		for (int j = 0; primes[j] * primes[j] <= tmp; j++) {
			while (tmp % primes[j] == 0) {
				tmp /= primes[j];
				cnt[j]++;
			}
		}
		if (tmp != 1) {
			int id = lower_bound(primes.begin(), primes.end(), tmp) - primes.begin();
			cnt[id]++;
		}
	}
	
	int ans = 1;
	for (int i = 0; i < 1000; i++) {
		ans *= (cnt[i] + 1);
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {

	unsigned long long int x;
	cin >> x;

	unsigned long long int save = 100;
	int count = 0;
	while (1) {

		save += (double)save * 0.01;
		count++;

		if (save >= x) {
			break;
		}
	}
	cout << count << endl;

	return 0;
}

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


int main(){

  int N;
  cin>>N;
  vector<long long> a;

  a.resize(N);
  
  rep(i,N)cin>>a[i];
  

  sort(a.begin(),a.end());
  if(a[0]==0){cout<<0<<endl;return 0;}
  
  unsigned long long prod=1;
  rep(i,N){

    if(a[i]<=(BIG/prod) )prod*=a[i];
    else {cout<<-1<<endl;return 0;}
    
  }
  
  cout<<prod<<endl;
  
}


Measured memory_bytes: 4060
N,A,B=map(int,input().split())

if A<B:
    if N>2:
        ans=(B-A)*(N-2)+1
    elif N==2:
        ans=1
    else:
        ans=0
elif A==B:
    if N>=1:
        ans=1
    else:
        ans=0
else:
    ans=0

print(ans)

Measured memory_bytes: 9072
import java.util.*;

class Main {
    public static void main(String[] args) {
        Map<Integer, Integer> ary = new HashMap<>();

        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        for (Integer i = 0; i < n; i++) {
            ary.put(i, 0);
        }

        for (Integer i = 0; i < n; i++) {
            Integer val = sc.nextInt();
            Integer count = ary.get(val);
            ary.put(val, count + 1);
        }

        Integer i = (n % 2 == 0) ? 1 : 2;
        Long sum = 1L;
        for (; i < n; i += 2) {
            Integer val = ary.get(i);
            if (val != 2) {
                System.out.println("0");
                return;
            }

            sum *= 2;
            sum %= 1000000000 + 7;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 65492
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int N;
    cin >> N;
    vector<int> D(N);
    REP(i, N) {
        cin >> D.at(i);
    }
    int M;
    cin >> M;
    vector<int> T(M);
    REP(i, M) {
        cin >> T.at(i);
    }
    int cnt = 0;
    sort(D.begin(), D.end());
    sort(T.begin(), T.end());
    int j = 0;
    if(M > N) {
        cout << "NO" << endl;
        return 0;
    }
    REP(i, N) {
        // if(j == M-1) {
        //     break;
        // }
        if(D.at(i) == T.at(j)) {
            if(j != M-1) {
                j++;
            } else {
                cout << "YES" << endl;
                return 0;
            }
        }
        // if(j == M-1) {
        //     cout << "YES" << endl;
        //     return 0;
        // }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    cout << n * 800 - (n / 15) * 200 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
vector<int> b,j;

int main(){
    int a[5];
    for(int i=0;i<5;i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << i+1 << endl;

        }
    }
    return 0;

}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,K,mx=0,gc=0;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A){
    cin>>i;
    mx=max(mx,i),gc=__gcd(gc,i);
  }
  if(K<=mx && K%gc==0)puts("POSSIBLE");
  else puts("IMPOSSIBLE");
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    if(n%2==0)cout<<n<<endl;
    else cout<<2*n<<endl;

    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
    ll N, K;
    cin >> N >> K;
    if (K == 1) {
      cout << 0 << endl;
      return 0;
    }
    cout << N - K << endl;
    return 0;
}


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

using namespace std;

long long n, v, minv, ans;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < 5; ++i) {
		cin >> v;
		if (i == 0)
			minv = v;
		else
			minv = min(v, minv);
	}

	ans = n / minv + 4;
	if (n % minv)
		++ans;
	
	cout << ans << endl;

	return 0;
}

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

int main()
{
  ll N;
  ll A, B;
  cin>>N>>A>>B;

  ll x, y;
  x = N/(A+B)*A;
  y = N%(A+B);

  ll cnt = x;
  if(y>0){
    if(y>A)  cnt += A;
    else  cnt += y;
  }

  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

vector<vi> adj;
vi vis;
int len=0;
vi pos;
int timer=0;
int k;
mii mp;
int base;

void dfs(int root)
{
	if(len==k)
	{
		cout<<root;
		exit(0);
	}
	pos[len]=root;
	mp[root]=len;
	++len;
	vis[root]=1;
	for(auto i:adj[root])
		if(!vis[i])
			dfs(i);
		else
		{
			base=i;
			return;
		}
}

void dfs2(int root)
{
	pos[len]=root;
	++len;
	vis[root]=1;
	for(auto i:adj[root])
		if(!vis[i])
			dfs(i);
}

int32_t main()
{
	fastIO
	inp_out();
	int n;
	cin>>n>>k;
	adj=vector<vi>(n+1);
	vis=pos=vi(n+1);
	vi a(n);
	for(int i=0;i<n;++i)
	{
		cin>>a[i];
		adj[i+1].pb(a[i]);
	}
	dfs(1);

	k-=mp[base];

	len=0;
	vis=vi(n+1);
	pos=vi(n+1);
	dfs2(base);

	cout<<pos[k%len];

	return 0;
}

Measured memory_bytes: 42964
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
const long long INF = 1LL << 60;

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

template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

const ll MOD = 1000000007;

int main() {
	ll n;
	cin >> n;
	V<ll> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	ull s = 1;
	ull M = 1000000000000000000;
	rep(i, n) {
		if (a[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	rep(i, n) {
		//cout << log10(s) << ":" << log10(a[i]) << endl;
		if (log10(s) + log10(a[i]) > 18) {
			cout << -1 << endl;
			return 0;
		}
		s *= a[i];
		if (s > M) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 4116
import java.util.*;
import java.lang.Object;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] weight = new int[n];
        int g1 = 0;
        int sum = 0;
        int sabun = 222222;
        int min = 222222;
        int g2 = 0;

        for(int i = 0;i<n;i++){
            weight[i] = sc.nextInt();
            sum +=weight[i];
        }

        for(int i = 0;i<n;i++){
            for(int j =0;j<=i;j++){
                g1+=weight[j];
            }
            //System.out.println("g1: "+g1);
             g2 = sum - g1;
             sabun = Math.abs(g2-g1);
            if(min>sabun){
                min = sabun;
                
            }
            g1=0;
        }
            System.out.println(min);


    }
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define ll long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define M 1000000007
#define MM 998244353
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define r2 1.41421356237
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //testcase {
  string s;
  cin>>s;
  int ss=0;
  for(int i=0;s[i];i++) { ss+=s[i]-'0'; }
  if(ss%9==0) { cout<<"Yes"; }
	else { cout<<"No"; }
  //}
  return 0;
}

Measured memory_bytes: 3756
<?php
$b=trim(fgets(STDIN));
$a=explode(' ',trim(fgets(STDIN)));
for($i=1;$i<$b;$i++)$a[$i]+=$a[$i-1];
$c=1<<31;
for($i=0;$i<$b-1;$i++)$c=min($c,abs($a[$b-1]-2*$a[$i]));
echo $c.PHP_EOL;

Measured memory_bytes: 20980
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertion(int A[],int n){
  int i,j ,v;

  for(i = 2;i<=n;i++){
    v = A[i];
    j = i -1;
  
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,n);
  }
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

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

Measured memory_bytes: 1776
#include <stdio.h>

// 数値のハッシュ関数
#define HASHSIZ 25013
int hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(int n)
{
	int *p;
	
	n++; p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return 1;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(int n)
{
	int *p;
	
	n++; p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return;
		if (++p == hashend) p = hash;
	}
	*p = n;
}

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int n, q, C;

	n = in();
	while (n--) insert(in());

	C = 0;
	q = in();
	while (q--) if (lookup(in())) C++;
	
	printf("%d\n", C);
	return 0;
}


Measured memory_bytes: 2044
import java.util.Scanner;

//AtCoder Grand Contest 034
//A	Kenken Race
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		sc.nextLine();
		String S = sc.nextLine();

		sc.close();

		if (S.substring(A - 1, C).matches(".*#{2}.*")) {
			System.out.println("No");
			return;
		}

		if (S.substring(B - 1, D).matches(".*#{2}.*")) {
			System.out.println("No");
			return;
		}

		if (C < D) {
			System.out.println("Yes");
			return;
		}

		if (S.substring(B - 2, D + 1).matches(".*\\.{3}.*")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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


int main()
{
/*	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
  */  long n;
    cin>>n;
    long a[n][3];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<3;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    long dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(long i=1;i<n;i++)
    {
    	dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vi;

vector<int> num(9),use(9);
vector<char> col(9);

int rec(int d){
  if(d==9){    
    rep(i,9){
      rep(j,9){
	if(use[i]==use[j] && col[i]!=col[j])return 0;
      }
    }

    vector< vi > sets(3);    
    rep(i,9){
      sets[use[i]].push_back(num[i]);
    }
    rep(i,3)sort(sets[i].begin(),sets[i].end());

    rep(i,3){
      if(sets[i].size()!=3)return 0;
      if(sets[i][0] == sets[i][1] && sets[i][1] == sets[i][2])continue;
      if(sets[i][0]+1 == sets[i][1] && sets[i][1]+1 == sets[i][2])continue;
      return 0;
    }
    return 1;
  }

  for(int i=0;i<3;i++){
    use[d] = i;
    if(rec(d+1))return 1;
  }
  return 0;
}

int main(){
  int t;
  cin >> t;
  while(t--){
    rep(i,9)cin >> num[i];
    rep(i,9)cin >> col[i];

    cout << rec(0) << endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N= 4e3+5;
int t, k,n;
string str;

int32_t main()
{
	IOS;
 
 	cin>>n;
 	cin>>str;
 	
 	int idx1=0, idx2=0, idx3=0;
 	for(int i=0;i<n;i++){
 		if(str[i]=='R'){
 			
 			idx1++;
 		}
 		else if(str[i]=='B'){
 			
 			idx2++;
 		}
 		else {
 			
 			idx3++;
 		}
 	}
 	
 	int sum= idx1*idx2*idx3;

 	for(int i=0;i<n;i++){
 		int l= i-1,r= i+1; 
 		while(l>=0 && r<=n-1){
 			if(str[l]!= str[r] && str[i]!= str[l] &&  str[i]!= str[r])
 				sum--;
 			l--, r++;
 		}
 	}
	cout<<sum<<endl;
	return 0;
}

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

const ll MOD = 1e9 + 7;

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

ll qp(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}

const int N = 2e5 + 10;
ll fac[N];

ll C(ll a, ll b) {
    ll ans = fac[a] * qp(fac[b], MOD - 2) % MOD;
    ans = ans * qp((fac[a-b] + MOD) % MOD, MOD - 2) % MOD;
    return ans;
}

int main(int argc, char const *argv[]) {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % MOD;
  ll n = read(), m = read(), k = read();
  ll ans = C(n * m, k) * C(k, 2) % MOD * qp(3, MOD - 2) % MOD;
  ans = ans * (n + m) % MOD;
  ans %= MOD;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
$q = [];
$r = 0;
foreach ($a as $b) {
	$i = floor($b / 400);
	if ($i <= 7) {
		$q[$i] = 1;
	} else {
		$r++;
	}
}
$x = $y = count($q);
if ($r) {
	$y = $x + $r;
	$x = max(1, $x);
}
echo "$x $y";

Measured memory_bytes: 4604
n, q = gets.split.map(&:to_i)
used = Array.new(n,false)

g = Array.new(n+1){[]}
(n-1).times do
  a,b = gets.split.map{ |i| i.to_i}# 0-indexedに変更
  g[a].push(b)
  g[b].push(a)
end

points = Array.new(n+1,0)
q.times do |i|
  node,x = gets.split.map(&:to_i)
  points[node] += x
end

que = [1] # BFS, 木の根である頂点0から足す

while node = que.shift # 破壊的メソッド。空配列は変更が行わずnilを返す
  used[node] = true #
  g[node].each do |k|
    next if used[k]
    points[k] += points[node]
    que.push(k) unless used[k]
  end
end

puts points.drop(1).join(' ')


Measured memory_bytes: 27388
#include<iostream>
#include<string>
#include<stdio.h>
main(){
    std::string c;std::cin>>c;
    int len=c.length();
    if(c[0]==c[len-1]){
        if(len%2==0) puts("First");
        else puts("Second");
    }
    else{
        if(len%2==0) puts("Second");
        else puts("First");
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll N;
  cin >> N;
  for (ll h = 1; h <= 3500; ++h) {
    for (ll n = h; n <= 3500; ++n) {
      if (4*h*n - N*(n+h) > 0) {
        if (N*h*n % (4*h*n - N*(n+h)) == 0) {
          ll w = N*h*n / (4*h*n - N*(n+h));
          cout << h << " " << n << " " << w << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    string S;
    cin>>S;
    int N=S.size();
    bool f=true;
    REP(i,(S.size()-1)/2){
        if(S[i]!=S[S.size()-1-i])f=false;
    }
    REP(i,(N-1)/4){
        if(S[i]!=S[(N-1)/2-1-i])f=false;
    }
    for(int i=0;i<(N+3)/4;i++){
        if(S[i+(N+3)/2-1]!=S[N-1-i])f=false;
    }
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
n = gets.to_i
w = gets.split.map(&:to_i)
wr = w.reverse

lth = 0
rth = 0
a = 0
b = 0
for num in 0..n-1 do
  if a <= b 
    a += w[lth]
    lth += 1
  else
    b += wr[rth]
    rth += 1
  end    
end
p (a-b).abs

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,count=0;
  cin>>N;
  vector<long long> A(N);
  unordered_map<long long,long long> mp;
  for(int i=0;i<N;i++){
    cin>>A.at(i); 
    mp[A.at(i)]++;
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  for(int i=0;i<N;i++){
    if(mp[A.at(i)]>=4){
      if(count==0){
        cout<<A.at(i)*A.at(i)<<endl;
        return 0;
      }
      if(count>0){
        cout<<count*A.at(i)<<endl;
        return 0;
      }
    }
    if(mp[A.at(i)]>=2){
      if(count==0){
        count=A.at(i);
        mp[A.at(i)]=0;
      }
      else{
        cout<<count*A.at(i)<<endl;
        return 0;
      }
    }
  }
  cout<<0<<endl;
}

Measured memory_bytes: 8024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<vector>

using namespace std;

typedef long long ll;

int main(){
  int n,a[100005],sum=0,ans=1;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  sort(a,a+n);

  for(int i=0;i<n;i++){
    if(i%2){
      sum+=a[i];
      ans=(ans*2)%1000000007;
    }else{
      sum-=a[i];
    }
  }

  if(sum==0){
    printf("%d\n",ans);
  }else {
    printf("0\n");
  }
  
  return 0;
}



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

int main(){
	int n;
	cin >> n;
	int flag=0;
	int cnt=0;
	if(n/10==0&&n!=0) cnt=n;
	else if(n/100==0&&n%100!=0) 
		cnt=9;
	else if(n/1000==0&&n%1000!=0){
		cnt=9+n-99;
	}
	else if(n/10000==0){
		cnt=909;
	}
	else if(n/100000==0){
		cnt=909+n-9999;
	}
	else{
		cnt=90909;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
test = False
if test:
    n = 100
    from random import randint
    h = [randint(0, 100) for _ in range(n)]
else:
    n = int(input())
    h = list(map(int, input().split()))

a = [0] * n
cost = 0
changed = True
while changed:
    changed = False
    left = 0
    while left < n and a[left] == h[left]:
        left += 1
    right = left
    while right < n and a[right] < h[right]:
        right += 1
    if left < n:
        cost += 1
        changed = True
        for i in range(left, right):
            a[i] += 1
print(cost)

Measured memory_bytes: 3064
k = int(input())
n = 3
c = {i: pow(k//i, n) for i in range(1, k+1)}
for i in range(k, 0, -1):
    for j in range(2*i, k+1, i):
        c[i] -= c[j]
_sum = 0
for x in range(1, k+1):
    _sum += c[x] * x
print(_sum)


Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;
  if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  string s;
  cin >> s;
  if (s[0] != s[1] && s[0] != s[2] && s[1] != s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
	


int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

#define PI 3.14159265359	

using namespace std;

int main(){
	int n, b, f, r, v;
	cin >> n;
	int room[4][3][10];
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 10; k++){
				room[i][j][k] = 0;
			}
		}
	}
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		room[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0; k < 10; k++){
				cout << " " << room[i][j][k];
			}
			cout << endl;
		}
		if (i != 3){
			for (int k = 0; k < 20; k++) cout << "#";
			cout << endl;
		}
	}
}

Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int ans = 0;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            int k = n - i * r - j * g;
            if(k % b == 0 && 0 <= k && k <= n) ans++;
        }
    }


    cout << ans << endl;
    return 0;
}


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

namespace ARC097D {
    class Program {
        static void Main(string[] args) {
            int[] NMinput = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int N = NMinput[0];
            int M = NMinput[1];
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            UnionFind u = new UnionFind(N);
            for(int i = 0; i < M; i++) {
                int[] inp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                u.unite(inp[0] - 1, inp[1] - 1);
            }
            int ans = 0;
            for(int i = 0; i < N; i++) {
                if(u.same(i , input[i] - 1)) {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }

        public class UnionFind {
            private int[] par;
            private int[] rank;
            private int[] samenum;

            //最初に呼ばれます
            public UnionFind(int n) {
                par = new int[n];
                rank = new int[n];
                samenum = Enumerable.Repeat(1, n).ToArray();
                for (int i = 0; i < n; i++) {
                    par[i] = i;
                }
            }

            //xの根を求めます
            public int find(int x) {
                if (par[x] == x) {
                    return x;
                } else {
                    par[x] = find(par[x]);
                    return par[x];
                }
            }

            //xとyを連結します
            public void unite(int x, int y) {
                x = find(x);
                y = find(y);
                if (x == y) {
                    return;
                } else {
                    if (rank[x] < rank[y]) {
                        par[x] = y;
                        samenum[y] += samenum[x];
                    } else {
                        par[y] = x;
                        samenum[x] += samenum[y];
                        if (rank[x] == rank[y]) {
                            rank[x]++;
                        }
                    }
                }
            }

            //xとyが同じ連結成分にあるかどうか判定します
            public bool same(int x, int y) {
                return find(x) == find(y);
            }

            //xと同じ連結成分にある頂点の個数(xを含む)を求めます
            public int numfind(int x) {
                x = find(x);
                return samenum[x];
            }
        }
    }
}


Measured memory_bytes: 27612
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, K, Q; cin >> N >> K >> Q;

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

    int ans = 0;
    for(int i=0; i<N; i++) {
        int pt = K - Q + ndec[i];
        if(pt > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int price = 0;
  price += A > B ? B : A;
  price += C > D ? D : C;
  cout << price << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
   int n;
   cin >> n;
   vector<int> a(n);
   REP(i,n) cin >> a[i];
   ll sum = 0;
   int h = 0; 
   REP(i,n) {
     h = max(h, a[i]);
     sum += h - a[i];
   }
   cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3964
a,b,k=map(int,input().split())
if k>(b-a):
    k=b-a
list1=[i for i in range(a,a+k)]
list1.extend([i for i in range(b-k+1,b+1)])
ans=list(set(list1))
ans.sort()
if a==b:
    ans=[a]
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 38384
#include <stdio.h>
#define N_MAX 4000
#define TH 1000000

int num[N_MAX], f;
long long price[N_MAX];

int main(void){
     int i, j, n, x, y, z;
	
     while(scanf("%d",&n), n!=0){
	  f=0;
	  for(i=0; i<N_MAX; i++) price[i]=0;

	  i=0;
	  for(;n--;){
	       scanf("%d %d %d",&x,&y,&z);

	       for(j=0; j<i; j++) if(num[j]==x) break;
	       if(j==i) num[j]=x, i++;
	       price[j] += (long long)y*z;
	  }
	  
	  for(j=0; j<i; j++) if(price[j]>=TH) printf("%d\n",num[j]), f=1;
	  if(!f) puts("NA");
     }

     return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

unsigned long my_func(unsigned long A, unsigned long B, unsigned long div) {
  const unsigned long A_div = A / div;
  const unsigned long B_div = B / div;

  unsigned long div_min = A_div;
  if (A % div != 0) {
    div_min += 1;
  }
  const unsigned long div_max = B_div;

  return div_max - div_min + 1;
}

int main() {
  unsigned long A, B, C, D;
  std::cin >> A >> B >> C >> D;

  const unsigned long C_num = my_func(A, B, C);
  const unsigned long D_num = my_func(A, B, D);
  const unsigned long gcd = std::__gcd(C, D);
  const unsigned long lcm = (C / gcd) * (D / gcd) * gcd;
  const unsigned long CD_num = my_func(A, B, lcm);

  std::cout << (B - A + 1) - (C_num + D_num - CD_num) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 55;

int n, p;
int a[maxn];

lli dp[maxn][2];

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

void solve()
{
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < 2; ++j)
        {
            int nj = (j + a[i + 1]) % 2;
            dp[i + 1][nj] += dp[i][j];
            dp[i + 1][j] += dp[i][j];
        }
    cout << dp[n][p] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 3632
#include <stdio.h>
int jisuan(int x){
    int s=0;
    while(x){
        s+=x%10;
        x/=10;
    }
    return s;
}
int main() {
    int n;
    scanf("%d",&n);
    int s=jisuan(n-1)+jisuan(1);
    int tim=s;
    for(int i=2;i<=n/2;i++){
        int t1=1,t2=-1;
        int tt1=i,tt2=n-i;
        while(tt1%10==0){
            tt1/=10;
            t1-=9;
        }
        while(tt2%10==9){
            tt2/=10;
            t2+=9;
        }
        tim=tim+t1+t2;
        s=(s>tim)?(tim):s;
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
constexpr int N_max = 2'000;

int main() {
    int n, x, y;
    cin >> n >> x >> y;

    for (int k = 1; k <= n - 1; ++k) {
        auto cnt = 0;
        for (int v = 1; v <= n; ++v) {
            if (v >= y) {
                if (v + k <= n)
                    ++cnt;
                continue;
            }

            if (v <= x) {
                int dist_vxy = (x - v) + 1;
                if (dist_vxy > k) {
                    ++cnt;
                    continue;
                }
                if (dist_vxy == k) {
                    cnt += 2;
                    continue;
                }

                int end1 = v + k;
                int end2 = y - (k - dist_vxy);
                int end3 = y + (k - dist_vxy);
                if (end1 <= end2)
                    ++cnt; // count end1
                if (end1 < end2)
                    ++cnt; // count end2
                if (end3 <= n)
                    ++cnt; // count end3
                continue;
            }

            // x < v < y
            int dist_vxy = (v - x) + 1;
            if (dist_vxy > k) {
                if (v + k <= n)
                    ++cnt;
                continue;
            }

            int dist_vy = y - v;
            if (dist_vy <= dist_vxy) {
                if (v + k <= n)
                    ++cnt;
                continue;
            }

            int end1 = v + k;
            int end2 = y - (k - dist_vxy);
            int end3 = y + (k - dist_vxy);
            if (end1 <= end2)
                ++cnt; // add end1
            if (end1 < end2)
                ++cnt; // add end2
            if (end3 != end2 && end3 <= n)
                ++cnt; // add end3;
        }

        cout << cnt << "\n";
    }

    return 0;
}


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

int main() {
  long long N;
  string S;
  cin>>N>>S;
  queue <int> rr;
  queue <int> gg;
  queue <int> bb;
  long long rg=0;
  long long gr=0;
  long long rb=0;
  long long br=0;
  long long gb=0;
  long long bg=0;
  long long ans=0;
  cin>>rg>>gr>>rb>>br>>gb>>bg>>ans;
  
  for (int i = 0; i < N; i++) {
    if(S.at(i)=='R'){
      rr.push(i);
      gr+=gg.size();
      br+=bb.size();
      ans+=gb;
      ans+=bg;
        
      
        
    }
    else if(S.at(i)=='G'){
      gg.push(i);
      rg+=rr.size();
      bg+=bb.size();
      ans+=br;
      ans+=rb;
        
        
    }
    else{
      bb.push(i);
      rb+=rr.size();
      gb+=gg.size();
      ans+=gr;
      ans+=rg;
        
    }
  }
  for (long long  i = 1; i < N-1; i++) {
    for (long long j = 1; j < min(N-i,i+1); j++) {
      if(S.at(i-j)!=S.at(i)&&S.at(i)!=S.at(i+j)&&S.at(i-j)!=S.at(i+j)){
        ans--;
        
      
 
}

    } 
}

 cout<<ans<<endl;


  
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;

using ll = long long;


ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r;
string s, t, u;
ll v, w, x, y, z;

int main() {

    cin >> n >> s >> t >> u;
    rep(i, n) {
        set<char> z{ s[i], t[i], u[i] };
        r += z.size() - 1;
    }
    cout << r << endl;


}

Measured memory_bytes: 3640
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u)
{
  int v;
  color[u]=GRAY;
  tt++;
  d[u]=tt;
  for(v=0;v<n;v++)
    {
      if(M[u][v]==0) continue;
      if(color[v]==WHITE)
	{
	  dfs_visit(v);
	}
    }
  color[u]=BLACK;
  f[u]=++tt;
}

void dfs()
{
  int i,u;
  for(i=0;i<n;i++) color[i]=WHITE;
  tt=0;
  for(u=0;u<n;u++)
    {
      if(color[u]==WHITE) dfs_visit(u);
    }
  for(i=0;i<n;i++)
    {
      printf("%d %d %d\n",i+1,d[i],f[i]);
    }
}

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

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  M[i][j]=0;
	}
    }

  for(i=0;i<n;i++)
    {
      scanf("%d %d",&u,&k);
      u--;
      for(j=0;j<k;j++)
	{
	  scanf("%d",&v);
	  v--;
	  M[u][v]=1;
	}
    }

  dfs();

  return 0;
}

      



Measured memory_bytes: 2108
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  --a[0];
  bool found = false;
  for (int i = 1; i < n; ++i) {
    if (a[i] < a[i - 1]) {
      found = true;
      break;
    } else if (a[i] > a[i - 1]) {
      --a[i];
    }
  }
  puts(found ? "No" : "Yes");
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int[] point = new int[n];
			for (int i = 0; i < n; i++) {
				point[i] = sc.nextInt();
			}
			int max = 0;
			int min = 1000;
			for (int i = 0; i < n; i++) {
				if (point[i] >= max) {
					max = point[i];
				}
				if (point[i] <= min) {
					min = point[i];
				}
			}
			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += point[i];
			}
			int ave;
			ave = (sum - max - min) / (n - 2);
			System.out.println(ave);
		}

		sc.close();
	}

}

Measured memory_bytes: 28752
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n;

int main () {
    fastIO;
    cin >> n;
    cout << n*3*n;
}


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

int main() {
	string s;
	cin >> s;
	int first = 0, last = 0;
	bool found_A = false;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A'&&found_A == false) {
			first = i;
			found_A = true;
		}
		if (s[i] == 'Z')last = i;
	}
	cout << last - first + 1 << endl;
}

Measured memory_bytes: 640
S = input()
N = len(S)

num = [0] * 2019
num[0] = 1
now, ans = 0, 0
_10 = 1

for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % 2019
    _10 *= 10
    _10 %= 2019
    ans += num[now]
    num[now] += 1
print(ans)


Measured memory_bytes: 68360