akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
using namespace std;
const int N=2005;
int n,k,x,y,w[N][N],b[N][N],bh[N][N],wh[N][N],sum,c[N],d[N],e[N],f[N],ans;//,bs[N][N],whs[N][N]
char ch[10];
int main()
{
	scanf("%d%d",&n,&k);
	k<<=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d %s",&x,&y,ch);
		if(ch[0]=='W')
			w[x%k][y%k]++;
		else
			b[x%k][y%k]++;
	}
	for(int i=0;i<k;i++)
	{
		sum=0;
		for(int j=0;j<k/2;j++)
			sum+=b[i][j];
		bh[i][0]=sum;
		for(int j=1;j<k;j++)
		{
			sum=sum-b[i][j-1]+b[i][(j+k/2-1)%k];
			bh[i][j]=sum;
		}
	}
	for(int i=0;i<k;i++)
	{
		sum=0;
		for(int j=0;j<k/2;j++)
			sum+=w[i][j];
		wh[i][0]=sum;
		for(int j=1;j<k;j++)
		{
			sum=sum-w[i][j-1]+w[i][(j+k/2-1)%k];
			wh[i][j]=sum;
		}
	}
	// for(int i=0;i<k;i++)
	// {
		// for(int j=0;j<k;j++)
			// cout<<b[i][j]<<" ";
		// cout<<endl;
	// }
		// cout<<endl;
	// for(int i=0;i<k;i++)
	// {
		// for(int j=0;j<k;j++)
			// cout<<bh[i][j]<<" ";
		// cout<<endl;
	// }
		// cout<<endl;
	// for(int i=0;i<k;i++)
	// {
		// for(int j=0;j<k;j++)
			// cout<<w[i][j]<<" ";
		// cout<<endl;
	// }
		// cout<<endl;
	// for(int i=0;i<k;i++)
	// {
		// for(int j=0;j<k;j++)
			// cout<<wh[i][j]<<" ";
		// cout<<endl;
	// }
		// cout<<endl;
	// for(int i=0;i<k;i++)
	// {
		// sum=0;
		// for(int j=0;j<k/2;j++)
			// sum+=b[j][i];
		// bs[0][i]=sum;
		// for(int j=1;j<k;j++)
		// {
			// sum=sum-b[(j+k-1)%k][i]+b[(j+k/2)%k][i];
			// bs[j][i]=sum;
		// }
	// }
	// for(int i=0;i<k;i++)
	// {
		// sum=0;
		// for(int j=0;j<k/2;j++)
			// sum+=w[j][i];
		// whs[0][i]=sum;
		// for(int j=1;j<k;j++)
		// {
			// sum=sum-w[(j+k-1)%k][i]+w[(j+k/2)%k][i];
			// whs[j][i]=sum;
		// }
	// }
	for(int i=0;i<k;i++)
	{
		for(int j=0;j<k;j++)
			c[j]=bh[j][i],d[j]=wh[j][i],e[j]=bh[j][(i+k/2)%k],f[j]=wh[j][(i+k/2)%k];
		int s1=0,s2=0;
		for(int j=0;j<k/2;j++)
			s1=s1+c[j]+d[j+k/2],s2=s2+f[j]+e[j+k/2];
		ans=max(ans,s1+s2);
		for(int j=1;j<k;j++)
		{
			s1=s1-c[j-1]+c[(j+k/2-1)%k]-d[(j+k/2-1)%k]+d[(j+k-1)%k];
			s2=s2-f[j-1]+f[(j+k/2-1)%k]-e[(j+k/2-1)%k]+e[(j+k-1)%k];
			ans=max(ans,s1+s2);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 63104
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main() {
	cin>>a;b=a;
	reverse(a.begin(),a.end());
	for(int i=0; i<a.size(); i++) {
		if(a[i]=='b') a[i]='d';
		else if(a[i]=='d') a[i]='b';
		else if(a[i]=='p') a[i]='q';
		else if(a[i]=='q') a[i]='p';
	}
	if(a==b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

long long ans;

int main()
{
	int n,k;
	int h[200005];
    cin>>n>>k;
    
    for(int i=0; i<n; i++) cin>>h[i];
    
    sort(h,h+n);
    
    for(int i=0; i<n-k; i++)
	{
        ans+=h[i];
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n, k;
	string s;

	cin >> n >> s >> k;

	char s2 = (char)s[k - 1];

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != s2) {
			s[i] = '*';
		}
	}

	cout << s << endl;





	getchar();
	getchar();
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A[3];

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

    for(int i=0;i<3;++i){
        std::cin >> A[i];
    }

    char c = 'A' + (std::max_element(A, A + 3) - A);
    std::cout << c << std::endl;
}



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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n,k;
    Scd2(n,k);

    int ans = 1;
    Rep(i,n){
        if( ans > k){
            ans += k;
        }else{
            ans *= 2;
        }
    }

    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  string s, t; cin >> s >> t;
  int i{}, j{};
  while (i < s.size() || j < t.size()) {
    if (i < s.size()) {
      cout << s[i];
      ++i;
    }
    if (j < t.size()) {
      cout << t[j];
      ++j;
    }
  }
  cout << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <stdexcept>
// #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; i++)
#define rep1(i,h) for(int i = 0; i <= h; i++)
#define rep2(i,n,h) for(int i = n; i < h; i++)
#define rep3(l,n,h) for(int l = n; i <= h; i++)

using namespace std;


int main(void) {
    int s;
    cin >> s;
    int n = s,i = 0;
    vector<int> data(1e7);
    data.at(0) = s;
    while(i <= 1e7) {
        if(data.at(n) != 0) {
            cout << i + 1;
            return 0;
        }
        if(n % 2 == 0) {
            data.at(n) = n / 2;
        } else {
            data.at(n) = 3 * n + 1;
        }
        n = data.at(n);
        i++;
    }
    return 0;
}






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

namespace ABC
{
    class ProgramB
    {
        // 解説用
        static readonly int[] dx = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 };
        static readonly int[] dy = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 };


        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var h = int.Parse(inputs[0]);
            var w = int.Parse(inputs[1]);
            var matrix = new char[h, w];
            var count = new int[h, w];

            for (var i = 0; i < h; i++)
            {
                var list = Console.ReadLine().ToCharArray();
                for (var j = 0; j < w; j++)
                {
                    matrix[i, j] = list[j];
                }
            }

            for (var i = 0; i < h; i++)
            {
                for (var j = 0; j < w; j++)
                {
                    if (matrix[i, j] != '#') continue;

                    // if (i - 1 >= 0 && j - 1 >= 0) count[i - 1, j - 1]++;
                    // if (i - 1 >= 0) count[i - 1, j]++;
                    // if (i - 1 >= 0 && j + 1 < w) count[i - 1, j + 1]++;

                    // if (j - 1 >= 0) count[i, j - 1]++;
                    // if (j + 1 < w) count[i, j + 1]++;

                    // if (i + 1 < h && j - 1 >= 0) count[i + 1, j - 1]++;
                    // if (i + 1 < h) count[i + 1, j]++;
                    // if (i + 1 < h && j + 1 < w) count[i + 1, j + 1]++;

                    // 解説版
                    for (var k = 0; k < 8; k++)
                    {
                        var ki = i + dy[k];
                        var kj = j + dx[k];
                        if (ki < 0 || h <= ki) continue;
                        if (kj < 0 || w <= kj) continue;
                        count[ki, kj]++;
                    }
                }
            }

            for (var i = 0; i < h; i++)
            {
                var t = "";
                for (var j = 0; j < w; j++)
                {
                    t += matrix[i, j] == '#' ? "#" : count[i, j].ToString();
                }
                Console.WriteLine(t);
            }
        }
    }
}

Measured memory_bytes: 27684
#!/usr/bin/env python3
import sys

def solve(N: int, C: int, x: "List[int]", v: "List[int]"):
    l_cum = [[0, 0] for _ in range(N + 1)]
    r_cum = [[0, 0] for _ in range(N + 1)]
    cal = 0
    for i in range(N):
        cal += v[i]
        val = cal - x[i]
        if val > l_cum[i][0]:
            l_cum[i + 1] = [val, x[i]]
        else:
            l_cum[i + 1] = l_cum[i]
    cal = 0
    for i in range(N - 1, -1, -1):
        cal += v[i]
        pos = C - x[i]
        val = cal - pos
        if val > r_cum[i + 1][0]:
            r_cum[i] = [val, pos]
        else:
            r_cum[i] = r_cum[i + 1]
    #print(l_cum)
    #print(r_cum)
    ret = 0
    for i in range(N + 1):
        ret = max(ret, l_cum[i][0] + r_cum[i][0] - min(l_cum[i][1], r_cum[i][1]))
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]" 
    v = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, C, x, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40896
#include <stdio.h>
long long int gcd(long long int a, long long int b)
{
    long long int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(){
  int t = 0;
  scanf("%d\n",&t);
  long long int a[t],b[t],c[t],d[t];
  int i = 0;
  for(i=0;i<t;i++){
    scanf("%lld %lld %lld %lld",&a[i],&b[i],&c[i],&d[i]);
  }
  long long int tmp=0;
  for(i=0;i<t;i++){
    if(a[i] < b[i] || d[i] < b[i]){
      printf("No\n");
      continue;
    }
    if(b[i]-1<=c[i]){
      printf("Yes\n");
      continue;
    }
    tmp = gcd(d[i],b[i]);
    if(c[i]<b[i]-tmp+(a[i]%tmp)){
      printf("No\n");
    }else{
      printf("Yes\n");
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    string s,t;
    cin>>s;
    cin>>t;
    if((s[0]==t[2])&&(s[2]==t[0])&&(s[1]==t[1])){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rp(i,j) for(long long i=0;i<j;i++)
#define rep(i,j,k) for(long long i=j;i<k;i++)
#define mod 1000000007
#define NIL -1
#define MAX 100
#define INFTY -1000
typedef long long ll;
int n;
vector<int>A[MAX];
int d[MAX];
int color[MAX]={0};
void bfs(){
  	rp(i,n)d[i]=INFTY;
    queue<int>Q;
    Q.push(0);
    color[0]=1;
  	d[0]=0;
    while(!Q.empty()){
        int x=Q.front();
        Q.pop();
        for(auto i:A[x]){
            if(color[i]==0){
                Q.push(i);
                d[i]=d[x]+1;
              	color[i]=1;
            }
        }
    }
    rp(i,n){
      	if(d[i]==INFTY)cout<<i+1<<" "<<-1<<endl;
      	else cout<<i+1<<" "<<d[i]<<endl;
    }
}
int main(){
   int u,k,v;
   cin>>n;
   rp(i,n){
       cin>>u;u--;
       cin>>k;
       rp(j,k){
           cin>>v;v--;
           A[u].push_back(v);
       }
   }
   bfs();
}


Measured memory_bytes: 3168
A, B, C, X, Y = map(int, input().split())

if A+B<=C*2:
    print(X*A+Y*B)
elif A<=C*2 and B<=C*2:
    if X>=Y:
        print(Y*C*2+(X-Y)*A)
    else:
        print(X*C*2+(Y-X)*B)
elif A>=C*2 and B>=C*2:
    print(max(X, Y)*C*2)
elif A>=C*2:
    if X>=Y:
        print(C*2*X)
    else:
        print(C*2*X+(Y-X)*B)
else:
    if X>=Y:
        print((X-Y)*A+C*2*Y)
    else:
        print(C*2*Y)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
import queue
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = queue.Queue()
q.put(k-1)
while not q.empty():
    x = q.get()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.put(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 89500
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main(string[] args) {
        var s = ReadLine();
        Boolean b = true;

        for (int i = 0; i < s.Length; i++) {
            if ((s.Length - s.Replace(s[i].ToString(), "").Length) != 1) {
                b = false;
                break;
            }
        }

        var res = (b) ? "yes" : "no";
        WriteLine(res);
    }
}



Measured memory_bytes: 11092
n, m = list(map(int, input().split()))
s = input()

if s.find('1' * m) != -1:
  print('-1')
  exit(0)

i = n
rans = []
flag = True
while flag:
  for j in range(m, 1 - 1, -1):
    if i - j == 0:
      flag = False
    if i - j >= 0 and s[i - j] == '0':
      rans.append(j)
      i = i - j
      break
  
print(' '.join(map(str,reversed(rans))))


Measured memory_bytes: 10484
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  long long n,time;
  cin >> n >> time;
  vector<long long> t(n);
  for(auto& x: t)
    cin >> x;
  long long ans = 0;
  for(long long i = 0; i < n-1; i++){
    ans += min(time, t[i+1] - t[i]);
  }
  ans += time;
  cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Numerics;

namespace PaizaSkillCheck
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');

            int n = int.Parse(line[0]);
            int m = int.Parse(line[1]);

            line = Console.ReadLine().Split(' ');
            List<Data> list = new List<Data>();
            for (int i = 0; i < line.Length; i++)
            {
                list.Add(new Data(int.Parse(line[i])));
            }

            list.Sort((a, b) => a.position - b.position);

            for (int i = 0; i < m; i++)
            {
                if (i != 0)
                {
                    list[i].distance = Math.Abs(list[i - 1].position - list[i].position);
                }
            }

            int ans = list.Select(i => i.distance).OrderByDescending(i => i).Skip(n).Sum();

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        public class Data
        {
            public int distance;
            public int position;

            public Data(int position)
            {
                this.position = position;
                this.distance = int.MaxValue;
            }
        }
    }

}


Measured memory_bytes: 30940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=1e6+5;
ll n,h,d,f[N],dp[N],s;
int main()
{
    scanf("%lld%lld%lld",&n,&h,&d);
    f[0]=1;
    for(int i=1;i<=n;i++)
        f[i]=f[i-1]*i%mod,s=(s+f[i])%mod;
    dp[1]=1;
    for(int i=2;i<=h;i++)
        dp[i]=(dp[i-1]+(dp[i-1]-dp[max(0ll,i-d-1)])*s)%mod;
    printf("%lld\n",((dp[h]-dp[h-d])*f[n]%mod+mod)%mod);
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
  string s;
  cin >> s;
  int n = s.size() ;
  vector<int> num(n);
  rep(i,n){
    if(s.at(i) != 'A' && s.at(i) != 'C'&& s.at(i) != 'G'&& s.at(i) != 'T' ){
      num.at(i)++;
    }
  }
  int ans = 0, ansmax = 0;
  rep(i,n){
    if(num.at(i) == 0){
      ans++;
      if(i == n-1){
        if(ans > ansmax) ansmax = ans;
      }
    }
    else if(num.at(i) == 1) {
      if(ans > ansmax){
        ansmax = ans;
      }
      ans = 0;
    }
  }
  cout << ansmax << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(void){
	int n, c = 0, p = 0, tmp, suffer;
	bool AllRun;
	scanf("%d", &n);
	int num[n];
	for (int i = 0; i < n; ++i){
		scanf("%d", &num[i]);
	}
	sort(num, num+n);
	while (p < n){
		suffer = 0;
		tmp = num[p];
		while (p < n && tmp == num[p]){
			suffer++;
			p++;
		}
		c += suffer % 2;
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 640
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    put!(n*n*n);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;cin >> n >> m;
    if (n==1 && m==1)
    {
        cout << 1 << endl;
    }
    else if (n == 1 || m == 1)
    {
        cout << n * m - 2 << endl;
    }
    else
    {
        cout << (n-2) * (m-2) << endl;
    }
    
    
}


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

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll mod = 1e9 + 7;
ll modexp(ll x, ll y) {
	ll ans = 1;
	while(y) {
		if(y & 1) {
			ans = (ans * x) % mod;
		}
		x = (x * x) % mod;
		y /= 2;
	}
	return ans;
}
ll comb(ll n, ll r) {
	ll num = 1, den = 1;
	while(r > 0) {
		num = (num * n) % mod;
		den = (den * r) % mod;
		n--;
		r--;
	}
	den = modexp(den, mod - 2);
	return (num * den) % mod;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, a, b;
    cin>>n>>a>>b;
    ll ans = modexp(2, n) - 1;
    ans = ((ans - comb(n, a) - comb(n, b)) % mod + mod) % mod;
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N; cin >> N;
  vector<int> ans;
  ll tmp = 0;
  int res = 0;
  for(int i = 1; i <= N; ++i) {
    tmp += i;
    ans.push_back(i);
    if(tmp >= N) {
      res = tmp - N;
      break;
    }
  }
  REP(i, ans.size()) {
    if(ans[i] == res) continue;
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements <=num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
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;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define d double
//#define int long long int
//Binary_Search->dp->greedy
void solve(){
	ll n,s;
	cin>>n>>s;
	vl vec(n);
	cin>>vec;
	vvl dp(n,vl(3001));
	ll ans=0;
	for(int i=n-1;i>=0;i--) dp[i][0]=n-i+1;
	ll md=998244353;
	dp[n-1][vec[n-1]]=1;
	for(int i=n-2;i>=0;i--){
		for(int j=1;j<=3000;j++){
			dp[i][j]=dp[i+1][j]+(j>=vec[i]?dp[i+1][j-vec[i]]:0);
            dp[i][j]%=md;
		}
	}
	for(int i=0;i<n;i++) ans+=dp[i][s],ans%=md;
	cout<<ans<<endl;
 
 
}
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
}   

Measured memory_bytes: 70656
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();
		long num = Math.min(b-1, n);
		
		long ans = (long) (Math.floor(a*num/b) - (a * Math.floor(num/b))); 
		
		System.out.println(ans);
		sc.close();
	}

}

Measured memory_bytes: 35596
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>


#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

const double pi = acos(-1);


using namespace std;


int main() {
	double a,b,r;
	cin >> a >> b >> r;
	r = r*pi / 180;
	double s = a*b*sin(r) / 2;
	double l = sqrt(a*a + b*b - 2 * a*b*cos(r))+a+b;
	double h = b*sin(r);
	cout <<setprecision(8)<< s <<" "<< l <<" "<< h << endl;
	

	return 0;
}

Measured memory_bytes: 3456
dice_num_list = []
equal_index_list = []

N = int(input())

for i in range(1, N + 1):
    d1, d2 = input().split(" ")
    dice_num_list.append([d1, d2])

equal_index_list = [i for i, x in enumerate(dice_num_list) if x[0] == x[1]]

l = len(equal_index_list)
if l < 3:
    print('No')
    exit(0)

for i in range(l - 2):
    if equal_index_list[i] + 1 == equal_index_list[i + 1] and equal_index_list[i] + 2 == equal_index_list[i + 2]:
        print("Yes")
        exit(0)

print("No")

Measured memory_bytes: 9148
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int n; cin>>n;
    vector<int> v(1001,0);
    rep(i,a,b)v[i]++;

    rep(i,0,n){
        int s,f;
        cin>>s>>f;
        rep(j,s,f){
            if(v[j]){
                cout<<1<<endl;
                return 0;
            }
        }
    }
    cout<<0<<endl;

    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std;
int main(){

	int a,b;
	double aa,Output;
	int output;
	char op[2];
	while(1){
	cin>>a>>op>>b;
	if(strcmp(op,"+")==0){
		output=a+b;
		cout<<output<<endl;

	}else if(strcmp(op,"-")==0){
		output=a-b;
		cout<<output<<endl;

	}else if(strcmp(op,"*")==0){
		output=a*b;
		cout<<output<<endl;

	}else if(strcmp(op,"/")==0){
		aa=(double)a;
		Output=a/b;
		cout<<Output<<endl;

	}else{
		break;
	}
	}

	return 0;
}

Measured memory_bytes: 1240
// no pragma

#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair

const int inf = 1e9;

int n, m, k, xs, ys, xf, yf;

vector<vector<int>> f;
vector<vector<char>> t;
vector<vector<vector<bool>>> vis;

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

bool valid(int x,int y){
	return (x>0 && y>0 && x<=n && y<=m && t[x][y]!='@');
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> k >> xs >> ys >> xf >> yf;
	f.assign(n+1,vector<int>(m+1,inf));
	vis.assign(n+1,vector<vector<bool>>(m+1,vector<bool>(4)));
	t.assign(n+1,vector<char>(m+1));
	
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			cin >> t[i][j];
		}
	}
	
	// Dijkstra
	queue<pii> q;
	q.push({xs,ys});
	f[xs][ys] = 0;
	while(!q.empty()){
		auto now = q.front();
		q.pop();
		int x,y;
		tie(x,y) = now;
			// 4 directions
			for(int i=0;i<4;++i){
				for(int j=1;j<=k;++j){
					int nx = x+j*dx[i],ny = y+j*dy[i];
					if(!valid(nx,ny) || f[nx][ny]<=f[x][y]) break;
					else if(f[nx][ny]==inf) f[nx][ny] = f[x][y]+1, q.push({nx,ny});
				}
			}
	}	
	cout << (f[xf][yf]==inf ? -1 : f[xf][yf]);
}

Measured memory_bytes: 222084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
10^12=2^40
論理和とって0になればOK

*/
int main(){
  ll N; cin>>N;
  vector<ll> A(N,0),B(0,0),C(0,0);
  vector<bool> used(N,false);
  ll x=0,cnt=0,oo=1e12;
  for(ll i=0; i<N; i++) cin>>A[i];
  for(ll i=0; i<N; i++) x^=A[i];
  if(x==0){
    cout<<0<<endl;
    return 0;
  }
  x^=A[0];
  x^=A[1];
  ll tmp=A[0]+A[1];
  ll res=0;
  for(ll i=10; i>=0; i--){
    ll n=(1<<30);
    n*=(1<<i);
    if((x&n)==0){
      if(tmp>=n*2){
        res+=n*2;
        tmp-=n*2;
      }
    }
    else{
      B.push_back(n);
      tmp-=n;
    }
  }
  for(ll i=29; i>=0; i--){
    ll n=(1<<i);
    if((x&n)==0){
      if(tmp>=n*2){
        res+=n*2;
        tmp-=n*2;
      }
    }
    else{
      B.push_back(n);
      tmp-=n;
    }
  }
  if(tmp!=0){
    cout<<-1<<endl;
    return 0;
  }
  res/=2;
  for(auto v:B){
    if(res+v > A[0]) C.emplace_back(res+v);
    else res+=v;
  }
  C.emplace_back(res);
  sort(C.begin(),C.end());
  ll ans=1e12;
  for(auto v: C){
    if(v>A[0] || v==0) continue;
    ans=min(ans,A[0]-v);
  }
  if (ans==oo) cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3608
import std.stdio, std.string, std.conv, std.range, std.algorithm;

void main() {
	auto _n = readln;
	string[] n = [];
	string line;
	while((line = readln.chomp) != "") {
		n ~= line;
	}

	foreach (_s; ["S", "H", "C", "D"])
		foreach (_i; 1..14) {
			auto t = _s ~ " " ~ _i.to!string;
			if (!n.canFind(t)) t.writeln;
		}
}

Measured memory_bytes: 2444
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ld = long double;
ll Q=1000000007;
const double PI=3.14159265358979323846;

int main(){
  ll X,Y;
  cin >> X >> Y;
  if((X+Y)%3!=0){
    cout << 0 << endl;
    return 0;
  }else if(Y>2*X||X>2*Y){
    cout << 0 << endl;
    return 0;
  }
  ll N=(X+Y)/3;
  ll M=2*N - X;
  // answer is nCm % Q
  vector<ll> inv(N+1,0);
  inv[1]=1;
  for(int i=2;i<=N;i++){
    inv[i]=Q-(Q/i)*inv[Q%i]%Q;
  }
  ll ans = 1;
  for(int i=1;i<=M;i++){
    ans = (ans *((N-i+1)*inv[i]%Q))%Q;
  }
  cout << ans%Q << endl;
}

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

int main() {
	// your code goes here
	int n, q, l, r;
	cin >> n >> q;
	string s;
	cin >> s;
	int freq[n];
	freq[0] = 0;
	
	for(int i = 1; i < n; ++i) {
		
		if(s[i - 1] == 'A' && s[i] == 'C')
			freq[i] = freq[i - 1] + 1;
		else
			freq[i] = freq[i - 1];
	}
	for(int i = 0; i < q; ++i) {
		
		cin >> l >> r;
		if(l == 1)
			cout << freq[r - 1];
		else
			cout << freq[r - 1] - freq[l - 1];
		cout << '\n';
	} 
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a, b, c, ans=0, maxnum, minnum;
    cin >> a >> b >> c;
    while(1){
        if(a==b && b==c && a==c) break;
        maxnum=max({a, b, c});
        if(maxnum-a==1 || maxnum-b==1 || maxnum-c==1){
            if(maxnum==a){
                b++;
                c++;
            }
            else if(maxnum==b){
                a++;
                c++;
            }
            else{
                a++;
                b++;
            }
        }
        else{
            if(min({a, b, c})==a) a+=2;
            else if(min({a, b, c})==b) b+=2;
            else c+=2;
        }
        ans++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3600
a,b,c,d=input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

z1 = a*c
z2 = a*d
z3 = b*c
z4 = b*d

l = [z1, z2, z3, z4]
max_value = max(l)
print(max_value)

Measured memory_bytes: 9196
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	A := make([]int, N)
	B := make([]int, N)
	C := make([]int, N)
	for i := 0; i < N; i++ {
		A[i], B[i], C[i] = sc.nextInt(), sc.nextInt(), sc.nextInt()
	}
	dp := make([][]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = make([]int, 3)
	}
	for i := 1; i <= N; i++ {
		for j := 0; j < 3; j++ {
			if j == 0 {
				dp[i][j] = A[i-1] + max(dp[i-1][1], dp[i-1][2])
			} else if j == 1 {
				dp[i][j] = B[i-1] + max(dp[i-1][0], dp[i-1][2])
			} else {
				dp[i][j] = C[i-1] + max(dp[i-1][0], dp[i-1][1])
			}
		}
	}

	fmt.Fprintln(wtr, max(dp[N][0], dp[N][1], dp[N][2]))
	wtr.Flush()
}


Measured memory_bytes: 8704
N=int(input())
L=list(map(int, input().split()))
ans=0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
        tmp=[L[i], L[j], L[k]]
        tmp.sort(reverse=True)
        if tmp[0]<tmp[1]+tmp[2]:
          ans+=1
print(ans)

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

  int N, i;
  int l,r;
  int seat=0;

  cin >> N;
  for(i=0;i<N;++i){
    cin >> l >> r;
    seat += r - l + 1;
  }
cout << seat << endl;

}

Measured memory_bytes: 256
n = int(input())
t = input()
p = []
for k in range(0,n,1):
  p.append(int(t.split(' ')[k]))
c = 0
for k in range(0,n,1):
  if p[k] == k+1:
    c += 1
if c == n - 2 or c == n:
  print('YES')
else:
  print('NO')

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

int main(){
  int n;
  cin >> n;
  for(int i;i<n;++i){
    char a;
    cin >> a;
    if(a == 'Y' ){
    cout << "Four" << endl;
      return 0;
    }  
  }
  cout << "Three" << endl;
}

Measured memory_bytes: 256
use proconio::input;

fn traverse(graph: &Vec<Vec<usize>>, counters: &Vec<i64>, visited: &mut Vec<bool>, computed: &mut Vec<i64>, i: usize, mut sum: i64) {
  	sum += counters[i];
  	computed[i] = sum;
  	for &j in &graph[i] {
  		if !visited[j] {
  			visited[j] = true;
  			traverse(graph, counters, visited, computed, j, sum);
  		};
  	}
}

fn main() {
  input! {
    n: usize, q: usize,
    edges: [(usize, usize); n-1],
    queries: [(usize, i64); q],
  }

  let mut counters = vec![0; n];
  let mut graph = vec![vec![]; n];
  
  for (a, b) in edges {
  	graph[a-1].push(b-1);
  	graph[b-1].push(a-1);
  }

  for (p, x) in queries {
  	counters[p-1] += x;
  }

  let mut computed = vec![0; n];
  let mut visited = vec![false; n];
  visited[0] = true;
  traverse(&graph, &counters, &mut visited, &mut computed, 0, 0);

  let ans = computed.iter().map(|x| x.to_string()).collect::<Vec<String>>().join(" ");
  println!("{}", ans);
}

Measured memory_bytes: 49316
#include<bits/stdc++.h>
using namespace std;
long long n,l,r,z;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>l>>r;
        z+=(r-l)+1;
    }
    cout<<z;
    return 0; 
}

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

int main(){
    long long L, R;

    cin >> L >> R;
    if(R - L > 2100){
        cout << 0 << endl;
    }else{
        long long ans = 2019;
        for (long long i = L; i < R; ++i){
            for (long long j = i + 1; j <= R; ++j){
                ans = min(ans, (i * j) % 2019 ); 
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    string s;
    cin >> s;
    if(s.size() % 2 == 1){
        puts("No");
        return 0;
    }
    rep(i, s.size()){
        if((i%2 == 0 && s[i] != 'h') || (i%2 == 1 && s[i] != 'i')){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

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

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-10;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 1e6+10;
const int MAXM = (int) 1e6+10;
const int sigma_size = (int) 26;

///--------------------START-------------------------
int n;
int a[MAXN],p[MAXN];
vector<int> ll,rr;

bool is_judge(int l,int r){
    for(int i=l+1;i<=r;i+=2)if(i!=a[i]) return false;
    ll.clear();
    rr.clear();
    for(int i=l;i<=r;i+=2){
        if(a[i]<=i) rr.push_back(a[i]);
        else ll.push_back(a[i]);
    }
    int lsiz=ll.size();
    int rsiz=rr.size();
//    for(int i=0;i<lsiz;i++) printf("%d ",ll[i]);
//    printf("\n");
//    for(int i=0;i<rsiz;i++) printf("%d ",rr[i]);
//    printf("\n");
    for(int i=0;i<lsiz-1;i++){
        if(ll[i]>ll[i+1]) return false;
    }
    for(int i=0;i<rsiz-1;i++){
        if(rr[i]>rr[i+1]) return false;
    }
    return true;
}

void work(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        p[a[i]]=i;
    }
    int ok=1;
    int L=1,R=1,i=1;
    while(i<=n){
        while(i<=n){
            if(p[i]>=R) R=p[i];
            if(i==R) break;
            i++;
        }
        if(!is_judge(L,R)){
            ok=0; break;
        }
        L=R+1;
        i=R+1;
        R++;
    }
    printf("%s\n",ok ? "Yes":"No");
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






Measured memory_bytes: 6716
#include<string>
#include<vector>
#include<iostream>
using namespace std;
int main(){
	string s;
	char c;
	while(cin>>s>>c,c!='X'){
		int now=1,pre=0;
		vector<string> box;
		while(1){
			if(now==s.size()){
				box.push_back(s.substr(pre,now-pre));
				break;
			}
			if(isupper(s[now])){
				box.push_back(s.substr(pre,now-pre));
				pre=now;
			}else if(s[now]=='_'){
				box.push_back(s.substr(pre,now-pre));
				now++;
				pre=now;
			}
			now++;
		}
		for(int i=0;i<box.size();i++){
			string t=box[i];
			char d=t[0];
			if(c=='L'){
				if(i==0&&isupper(d)){
					t[0]=tolower(d);
				}
				if(i!=0&&islower(d)){
					t[0]=toupper(d);
				}
			}else if(c=='U'){
				if(islower(d))
				t[0]=toupper(d);
				
			}else if(c=='D'){
				if(isupper(d))
				t[0]=tolower(d);
				if(i!=0)
				cout<<'_';
			}
			cout<<t;
		}
		cout<<endl;
	//	for(int i=0;i<box.size();i++)
	//	cout<<box[i]<<endl;
		
		
	}
	return 0;
}

Measured memory_bytes: 0
n,k = map(int,input().split())
R,S,P = map(int,input().split())
T = str(input())
t=[T[i] for i in range(n)]

ans = 0
for i in range(k):
     
     if t[i] == 'r':
          ans  += P
     elif t[i] == 's':
          ans += R
     else:
          ans += S

for i in range(k,n):

     if t[i] == t[i-k]:
          t[i] = 'o'
          continue
     else:
          if t[i] == 'r':
               ans += P
          elif t[i] == 's':
               ans += R
          else:
               ans += S
print(ans)

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

#define int long long

signed main(){
    string s,t;
    
    cin >> s >> t;
    
    int ans = 0;
    for(int i= 0;i<3;i++)if(s[i]==t[i])ans++;
    cout << ans << endl;
    return 0;
    }
    
 
        


Measured memory_bytes: 256