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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef pair<int,int> pii;
void solve()
{
    int n,u,v,w;
    cin >> n;
    vector<vector<pii>> Adj(n);
    vector<int> Vis(n),Dis(n);
    for(int i=1;i<n;++i)
    {
        cin >> u >> v >> w;
        --u;
        --v;
        Adj[u].pb(mp(v,w));
        Adj[v].pb(mp(u,w));
    }
    queue<int> Q;
    Q.push(0);
    Vis[0] = 1;
    Dis[0] = 0;
    while(!Q.empty())
    {
        auto temp = Q.front();
        Q.pop();
        for(auto x : Adj[temp])
            if(!Vis[x.f])
            {
                Dis[x.f] = x.s + Dis[temp];
                Vis[x.f] = true;
                Q.push(x.f); 
            }
    }
    for(int i=0;i<n;++i)
        cout << (Dis[i]&1) << '\n';
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

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

int main() {
  ll n,count=0;
  cin >>n;
  if(n%2==1)cout<<0<<endl;
  else{
    ll r=5;
    n/=2;
    while(n>=r){
      count+=n/r;
      r*=5;
    }
    cout<<count<<endl;
  }
}

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

const int offset=4000;
bool unmatch01[8001];
bool unmatch12[8001];
bool unmatch02[8001];

inline bool match(char x, char y) { return x == y || x == '?' || y =='?'; }

signed main() {
  string S[3];
  cin >> S[0] >> S[1] >> S[2];

  for(int i=0; i<S[0].size(); i++) for(int j=0; j<S[1].size(); j++)
    if(!match(S[0][i], S[1][j])) unmatch01[i-j+offset] = true;

  for(int i=0; i<S[1].size(); i++) for(int j=0; j<S[2].size(); j++)
    if(!match(S[1][i], S[2][j])) unmatch12[i-j+offset] = true;

  for(int i=0; i<S[0].size(); i++) for(int j=0; j<S[2].size(); j++)
    if(!match(S[0][i], S[2][j])) unmatch02[i-j+offset] = true;

  int ans = 1<<30;
  for(int s1=-4000; s1<=4000; s1++) for(int s2=-4000; s2<=4000; s2++)
      if (!unmatch01[s1 + offset] && !unmatch12[s2-s1+offset] && !unmatch02[s2+offset])
        ans = min(ans, 1 + max((int)S[0].size()-1, max(s1+(int)S[1].size()-1, s2+(int)S[2].size()-1)) - min(0, min(s1, s2)));
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	var a int
	var b float64
	fmt.Scanf("%d %f", &a, &b)

	intB := int((b + 0.001) * 100)
	fmt.Printf("%d\n", (a*intB)/100)
}

func scanLongIntSlices(lines int, maxBufSize int) ([][]int, error) {

	res := [][]int{}

	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, maxBufSize)

	for sc.Scan() {
		line := sc.Text()
		strs := strings.Split(line, " ")
		ints := make([]int, len(strs))
		for i, c := range strs {
			n, err := strconv.Atoi(c)
			if err != nil {
				return nil, err
			}
			ints[i] = n
		}
		res = append(res, ints)
	}

	if err := sc.Err(); err != nil {
		return nil, err
	}

	return res, nil
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll n;
vector<vector<pair<ll, ll>>> g;
vector<ll> color;

void dfs(ll v, ll d = 0) {
    if (color[v] != -1) return;
    color[v] = d % 2;
    for(auto x : g[v]) {
        ll to = x.first, cost = x.second;
        dfs(to, d + cost);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].push_back(make_pair(b, c));
        g[b].push_back(make_pair(a, c));
    }
    color.resize(n, -1);
    dfs(0);
    rep(i, n) printf("%lld\n", color[i]);
    return 0;
}


Measured memory_bytes: 9216
n = int(input())
a = []
for i in range(n):
    temp = int(input())
    a.append(temp)
now = -1 #second win
for i in range(n):
    if a[i]%2 != 0:
        now = -1*(-1)
if now == -1:
    print("second")
else:
    print("first")

Measured memory_bytes: 7072
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();
        int div = t / a;
        int ans = b * div;
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23252
N, A = map(int, input().split())
X = [int(a) for a in input().split()]
PO = [x-A for x in X if x > A]
NE = [A-x for x in X if x < A]
ZE = N - len(PO) - len(NE)

Y = [1] + [0] * 3000
Z = [1] + [0] * 3000

for i in PO:
    for j in range(2800)[::-1]:
        Y[i+j] += Y[j]
for i in NE:
    for j in range(2800)[::-1]:
        Z[i+j] += Z[j]

ans = -1
for i in range(len(Y)):
    ans += Y[i] * Z[i] * (2**ZE)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    int dp1[n+1];
    int dp2[n+1];
    vector<int>a(n);
    REP(i,n)IN(a[i]);
    dp1[0]=a[0];
    dp2[n-1]=a[n-1];
    for(int i=1;i<n;i++){
        dp1[i]=__gcd(dp1[i-1],a[i]);
    }
    for(int i=n-2;i>=0;i--){
        dp2[i]=__gcd(dp2[i+1],a[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(i==0){
            ans=max(ans,dp2[1]);
            continue;
        }else if(i==n-1){
            ans=max(ans,dp1[n-2]);
            continue;
        }

        ans=max(ans,__gcd(dp1[i-1],dp2[i+1]));
    }
    OUT(ans);
    return 0;
}

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

using namespace std;

int const maxn = 1e5 + 5, logg = 20;
vector < int > g[maxn];
int h[maxn], was[maxn], H[maxn], mxh[maxn];
int dp[maxn][logg];

void dfs(int v, int p) {
    dp[v][0] = p;
    h[v] = h[p] + 1;
    mxh[v] = h[v];
    for (int i = 1; i < logg; ++i) dp[v][i] = dp[dp[v][i - 1]][i - 1];
    for (auto u : g[v]) if (u != p) dfs(u, v), mxh[v] = max(mxh[v], mxh[u]);
}

int get_la(int u, int x) {
    for (int i = 0; i < logg; ++i) {
        if ((x&(1 << i)) > 0) u = dp[u][i];
    }
    return u;
}

int get_lca(int v, int u) {
    if (h[v] > h[u]) v = get_la(v, h[v] - h[u]);
    else u = get_la(u, h[u] - h[v]);
    if (u == v) return u;
    for (int i = logg - 1; i >= 0; --i) {
        if (dp[u][i] != dp[v][i]) u = dp[u][i], v = dp[v][i];
    }
    return dp[u][0];
}

int get(int v) {
    for (auto u : g[v]) {
        if (dp[v][0] != u && mxh[u] == mxh[v]) {
            return get(u);
        }
    }
    return v;
}

void dfs1(int v, int hh) {
    was[v] = 1;
    H[v] = hh;
    for (auto u : g[v]) {
        if (was[u] != 0) continue;
        dfs1(u, hh + 1);
    }
}

void go(int v, int p) {
    was[v] = 1;
    for (auto u : g[v]) if (u != p) go(u, v);
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x, y, u, v;
    cin >> n >> x >> y;
    for (int i = 1; i < n; ++i) {
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 0);
    int t = get_lca(x, y);
    if (h[x] - h[t] >= h[y] - h[t]) {
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            int go = get_lca(i, x);
            if (get_lca(t, go) == go) continue;
            int dd = h[y] + h[go] - 2 * h[get_lca(go, y)];
            int dd1 = h[x] + h[go] - 2 * h[get_lca(go, x)];
            if (dd1 < dd) {
                int dist1 = h[i] + h[x] - 2 * h[get_lca(i, x)];
                int dist2 = h[y] + h[i] - 2 * h[get_lca(i, y)];
                ans = max(ans, dist2 - 1);
            }
        }
        cout << ans << '\n';
    }
    else {
        go(y, dp[y][0]);
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (was[i] == 1) continue;
            int dist1 = h[i] + h[x] - 2 * h[get_lca(i, x)];
            int dist2 = h[y] + h[i] - 2 * h[get_lca(i, y)];
            ans = max(ans, dist2 - 1);
        }
        cout << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 20480
#include <iostream>
#include <string>
#include <algorithm>

struct Tuple {
	int value;
	int weight;
	char type;
	long long int date;
	std::string name;
	bool operator<(const Tuple& t) const { 
		if (this->value < t.value) return true;
		else if (this->value > t.value) return false;
		if (this->weight < t.weight) return true;
		else if (this->weight > t.weight) return false;
		if (this->type < t.type) return true;
		else if (this->type > t.type) return false;
		if (this->date < t.date) return true;
		else if (this->date > t.date) return false;
		if (this->name < t.name) return true;
		else return false;
	}
};

int main()
{
	int n; std::string sn; 
	getline(std::cin, sn); n = std::stoi(sn);
	
	Tuple* A = new Tuple[n];
	std::string buf;
	for (int i=0; i<n; i++) {
		getline(std::cin, buf);
		int sp_pos;
		int offset = 0;
		sp_pos = buf.find(' ', 0);
		A[i].value = std::stoi(buf.substr(0, sp_pos));
		offset = sp_pos + 1;
		sp_pos = buf.find(' ', offset);
		A[i].weight = std::stoi(buf.substr(offset, sp_pos - offset));
		offset = sp_pos + 1;
		sp_pos = buf.find(' ', offset);
		A[i].type = buf[sp_pos-1];
		offset = sp_pos + 1;
		sp_pos = buf.find(' ', offset);
		A[i].date = std::stoll(buf.substr(offset, sp_pos - offset));
		A[i].name = buf.substr(sp_pos+1);
	}
			

	std::sort(A, A+n);
	
	for (int i=0; i<n; i++) {
		std::cout << A[i].value << " " << A[i].weight << " " << A[i].type << " " << A[i].date << " " << A[i].name << std::endl;
	}
	
	delete[] A;
	
	return 0;
}



Measured memory_bytes: 11116
#include <iostream>
#include <functional>
#include <map>
using namespace std;
using LL = long long;

int main(void) {
    string s;
    cin >> s;
    
    auto pow2 = [](LL p) -> LL {
        LL ret = 1;
        for(int i = 1; i <= p; ++i) {
            ret *= 2;
        }
        return ret;
    };
    
    function<LL(string)> rec = [&](string s) -> LL {
        LL ret = 0;
        LL len = s.length();
        if(len == 1) return stoll(s);
        ret += stoll(s);
        for(int i = 1; i < len; ++i) {
            ret += stoll(s.substr(0, i)) * pow2(len-i-1);
            ret += rec(s.substr(i));
        }
        return ret;
    };
    
    cout << rec(s) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#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 = 2e5 + 5;

int n;
int a[N];

int32_t main()
{
	IOS;
	int sum = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int cur = 0;
	int ans = 1e18;
	for(int i = 1; i <= n - 1; i++)
	{
		cur += a[i];
		int rem = sum - cur;
		ans = min(ans, abs(rem - cur));
	}		
	cout << ans;
	return 0;
}

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

double x,y;

bool input(){
  cin>>x>>y;
  return (x!=0)||(y!=0);
}


double solve(){
  double tmp = sqrt((x/2)*(x/2)+y*y);
  return (x*x) + 4* x*tmp/2;
}

int main(){
  while(input()){
    cout<<setprecision(100)<<solve()<<endl;
  }
}

Measured memory_bytes: 1276
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	X = int(input())
	for i in range(1, 361):
		if (X * i) % 360 == 0:
			print(i)
			return

if __name__ == '__main__':
	main()

Measured memory_bytes: 64712
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    bool flag = false;
    lint ans = 1;
    vector<lint> a(n);
    rep(i, n)
    {
        cin >> a.at(i);
        if (a.at(i) == 0)
            flag = true;
    }
    if (flag)
    {
        cout << 0 << endl;
        return 0;
    }
    rep(i, n)
    {
        if (a.at(i) <= 1000000000000000000 / ans)
        {
            ans *= a.at(i);
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n;cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    int cupple = 0;
    rep(i, n) {
        if (a[a[i]] == i) cupple++;
    }
    cout << cupple/2 << endl;
}

Measured memory_bytes: 640
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> values(n);
    int sum =0;
    rep(i, 0, n)
    {
        cin >> values[i];
        sum += values[i];
    }

    int threshold = sum / (4 * m);
    if (sum%(4*m))
        ++threshold;
    int cnt =0;
    rep(i, 0, n)
    {
        if (values[i]>=threshold)
            ++cnt;
    }
    if (cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
const double EPS = 1e-12;
const double PI = 3.14159265359;
typedef long long ll;
const ll mod = ll(1e6 + 3);
void ff()
{
	system("pause");
}

int main(){

	Compiler_Beso


		string s;
	cin >> s;
	cout << "2018/01/" << s.substr(s.size() - 2, 2);

	//ff();
	return 0;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

int digit(ll k)
{
    int res = 0;
    while (k) res++, k /= 10;
    return res;
}

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

    ll n; cin >> n;

    int ans = inf;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ans = min(ans, digit(n / i));
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int dp[10001][101][2];

int solve(string &K,int &D, int pos, int d, bool tight) {
    if(dp[pos][d][tight] != -1) return dp[pos][d][tight];
    
    int ub = (tight) ? (K[pos] - '0') : 9;
    int len = K.length()-1;
    if(pos == len) {
        int ans = 0;
        for(int x=0; x<=ub; x++) if(x%D == d) ans++;
        return ans;
    }

    int ans = 0;
    for(int x=0; x<=ub; x++) ans = (ans + solve(K, D, pos+1, (D + d - x%D)%D, tight && (x == ub)))%mod;
    return dp[pos][d][tight] = ans;
}

int32_t main() {
    string K;
    int D;
    cin>>K>>D;
    memset(dp, -1, sizeof dp);
    cout<< (mod + solve(K, D, 0, 0, 1) -1)%mod;
    return 0;
}


Measured memory_bytes: 20364
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main(): 
    s = input() + 'a'
    x,y = map(int,input().split())
    
    cnt_t = 0
    cnt_f = 0
    p = []
    q = []
    before = True
    for i in range(len(s)-1):
        if s[i] == 'T' :
            cnt_t += 1
        elif s[i] == 'F' and s[i+1] == 'F':
            cnt_f += 1
        else:
            cnt_f += 1
            if cnt_t == 0:
                x -= cnt_f
            elif cnt_t%2 == 0:
                if before:
                    p.append(cnt_f)
                else:
                    q.append(cnt_f)
            else:
                if before:
                    q.append(cnt_f)
                    before = False
                else:
                    p.append(cnt_f)
                    before = True
            cnt_t = 0
            cnt_f = 0
    
    
    p.sort(reverse=True)
    q.sort(reverse=True)

    s = 0
    for i in range(len(p)):
        if s <= x:
            s += p[i]
        else:
            s -= p[i]
    
    t = 0
    for i in range(len(q)):
        if t <= y:
            t += q[i]
        else:
            t -= q[i]
    
    if s == x and t == y:
        print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main()



Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int X, Y;

int main() {
	cin >> X >> Y;
	int ans = 0;
	map<int, int>sh;
	sh[1] = 300000;
	sh[2] = 200000;
	sh[3] = 100000;
	if (X == 1 && Y == 1) {
		ans += 400000;
	}
	ans += sh[X];
	ans += sh[Y];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  vl L;
  L.push_back(2);
  L.push_back(1);
  rep(i, 2, N + 1) {
    L.push_back(L[i - 1] + L[i - 2]);
  }
  print(L[N]);
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i*500 + j*100 + k*50 == x:
                ans += 1
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int ans=1e9;
int N,C,d[33][33];
int m[3][33];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N>>C;
    for(int i=0;i<C;i++)
        for(int j=0;j<C;j++)
            cin>>d[i][j];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int x;
            cin>>x;
            x--;
            m[(i+j)%3][x]++;
        }
    }
    for(int i=0;i<C;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<C;k++){
                if(i==j||j==k||k==i)continue;
                int x=0;
                for(int s=0;s<C;s++)
                    x+=m[0][s]*d[s][i];
                for(int s=0;s<C;s++)
                    x+=m[1][s]*d[s][j];
                for(int s=0;s<C;s++)
                    x+=m[2][s]*d[s][k];
                ans=min(ans,x);
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	string s;
	cin>>s;
	long long k=0,sum=0;
	while(s[k]=='W'&&k<s.size())k++;
	for(int i=k;i<s.size();i++)
	{
		if(s[i]=='W')
		{
			sum+=i-k;
			k++;
		}
 	}
	cout<<sum;
	return 0;	
}

Measured memory_bytes: 640
using System;

namespace Volume0_0011
{
    class Program
    {
        /// <summary>
        /// ?????????????????????????????????
        /// i?????????ans[a[i]]??¨ans[b[i]]???????????????????????????i=1??????i=w?????§?????????
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int w = Int32.Parse(Console.ReadLine());
            var ans = new int[w];
            for(int i=0;i<w;i++) { ans[i] = i + 1; }
            int n = Int32.Parse(Console.ReadLine());
            int[] a = new int[n]; 
            int[] b = new int[n];
            var input = new string[2];
            for(int i=0;i<n;i++)
            {
                input = Console.ReadLine().Split(',');
                a[i] = Int32.Parse(input[0]);
                b[i] = Int32.Parse(input[1]);
            }

            int c = 0;
            for(int i=0; i<n ; i++)
            {
                c = ans[a[i]-1];
                ans[a[i]-1] = ans[b[i]-1];
                ans[b[i]-1] = c;
            }

            for(int i=0;i<w;i++)
            {
                Console.WriteLine("{0}", ans[i]);
            }
        }
    }
}

Measured memory_bytes: 9124
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),m=s.nextInt(),l=s.nextInt();
		long inf=999_999_999_999L;
		long[][] g=new long[n][n];

		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
				if(i!=j)
					g[i][j]=inf;

		for(int i=0;i<m;++i) {
			int src=s.nextInt()-1,dst=s.nextInt()-1,cost=s.nextInt();
			g[src][dst]=g[dst][src]=cost;
		}

		for(int k=0;k<n;++k)
			for(int i=0;i<n;++i)
				for(int j=0;j<n;++j)
					g[i][j]=Math.min(g[i][j],g[i][k]+g[k][j]);

		//Arrays.stream(g).map(Arrays::toString).forEach(System.err::println);

		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
				if(i!=j)
					g[i][j]=g[i][j]<=l?1:inf;

		for(int k=0;k<n;++k)
			for(int i=0;i<n;++i)
				for(int j=0;j<n;++j)
					g[i][j]=Math.min(g[i][j],g[i][k]+g[k][j]);

		//Arrays.stream(g).map(Arrays::toString).forEach(System.err::println);

		for(int q=s.nextInt();q>0;--q) {
			long v=g[s.nextInt()-1][s.nextInt()-1];
			System.out.println(v==inf?-1:v-1);
		}
	}
}

Measured memory_bytes: 92372
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (x, y, z) = scan!(i64, i64, i64);
    println!("{}", (x - z) / (y + z))
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  int N; cin >> N;
  V h(N);
  rep(i, N) cin >> h[i];

  V dp(N);
  rep2(i, 1, N) dp[i] = INF;
  rep(i, N) {
    chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }

  int ans = dp[N-1];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    REP(i, n){
        cin >> t.at(i);
    }
    sort(t.begin(), t.end());
    ll ans = 0;
    ll i = 0;
    REP(j, n){
        if(t.at(j) - t.at(i) > k){
            ans++;
            i = j;
        }
        if(j - i + 1 > c){
            ans++;
            i = j;
        }
    }
    ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int i,j,n,sum;
  while(1){
    scanf("%d",&sum);
    if(sum==0) break;
    for(i=0;i<9;i++){
      scanf("%d",&n);
      sum-=n;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int a[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    bool bingo[3][3] = {};
    rep(i, n){
        int b;
        cin >> b;
        rep(i, 3){
            rep(j, 3){
                if(b == a[i][j]){
                    bingo[i][j] = true;
                }
            }
        }
    }

    bool ok = false; 
    rep(i, 3){
        bool x = true;
        rep(j, 3){
            if(!bingo[i][j]) x = false;
        }
        if(x){
            ok = true;
        }
    }

    rep(i, 3){
        bool x = true;
        rep(j, 3){
            if(!bingo[j][i]) x = false;
        }
        if(x){
            ok = true;
        }
    }

    if(bingo[0][0] && bingo[1][1] && bingo[2][2]){
        ok = true;
    }

    if(bingo[0][2] && bingo[1][1] && bingo[2][0]){
        ok = true;
    }

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

    return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
p = list(map(int, input().split()))

swap = False
for i in range(n):
  if p[i] != i+1:
    if swap == False and p[p[i]-1] == i+1:
      swap = True
      p[p[i]-1] = p[i]
    else:
      print('NO')
      sys.exit()

print('YES')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {
  
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H) cin >> S[i];
  
  rep(i,H) {
    rep(j,W) {
      if (S[i][j] == '#') {
        cout << '#';
        continue;
      }
      int count = 0;
      for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {
        if (i + y < 0 || i + y >= H || j + x < 0 || j + x >= W) continue;
        if (S[i + y][j + x] == '#') count++;
      }
      cout << count;
    }
    cout << endl;
  }

  return 0;
}

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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    int x[m];
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }
    if (m <= n) {
        cout << 0 << "\n";
        return 0;
    }
    sort(x, x + m);;
    vector<int> d;
    for (int i = 0; i < m - 1; ++i) {
        d.PB(abs(x[i] - x[i + 1]));
        ans += d[i];
    }
    sort(d.rbegin(), d.rend());
    for (int i = 0; i < n - 1; ++i) {
        ans -= d[i];
    }
    cout << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 4144
use std::io;

struct Iroha {
    five: u32,
    seven: u32,
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read line.");
    let x: Vec<&str> = input.trim().split_whitespace().collect();
    if x.len() == 3 {
        let a: u32 = x[0].trim().parse().unwrap();
        let b: u32 = x[1].trim().parse().unwrap();
        let c: u32 = x[2].trim().parse().unwrap();
        let mut count = Iroha { five:0, seven:0 };
        match a {
            5 => count.five += 1,
            7 => count.seven += 1,
            _ => (),
        }
        match b {
            5 => count.five += 1,
            7 => count.seven += 1,
            _ => (),
        }
        match c {
            5 => count.five += 1,
            7 => count.seven += 1,
            _ => (),
        }
        if count.five == 2 && count.seven == 1 { println!("YES"); }
        else { println!("NO"); }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    double x[10], y[10];
    cin>>N;
    rep(i, N) cin>>x[i]>>y[i];
    double dist=0;
    rep(i, N-1) reps(j, i+1, N){ dist+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        //cout<<i<<sp<<j<<endl;
    }
    cout<<setprecision(10)<<2*dist/N<<endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
up = gets.split(' ').map {|x| x.to_i}
down = gets.split(' ').map {|x| x.to_i}

up_sum_list = []
down_sum_list = []

up_sum = 0
up.each do |x|
  up_sum += x
  up_sum_list.push(up_sum)
end

down_sum = 0
down.reverse.each do |x|
  down_sum += x
  down_sum_list.push(down_sum)
end
down_sum_list.reverse!

max_reward = 0
0.upto(n - 1) do |i|
  reward = up_sum_list[i] + down_sum_list[i]
  max_reward = reward if max_reward < reward
end

puts max_reward

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s ;
  cin >> s ;
  ll bcnt = 0 ;
  ll ans = 0 ;
  int n = SZ(s) ;
  REP(i,n){
    if(s[i]=='B'){
      bcnt++ ;
    }
    else{
      ans += bcnt ;
    }
  }
  cout << ans <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 720
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int n,c,m,a[30][30],b[30],i,j;
	cin>>n>>m>>c;
	for(i=0;i<m;i++)cin>>b[i];
	
	for(i=0;i<n;i++)
	for(j=0;j<m;j++)cin>>a[i][j];
	int ans=0;
	for(i=0;i<n;i++)
	{
		int k=c;
		for(j=0;j<m;j++)
		{	k+=a[i][j]*b[j];
			//cout<<a[i][j]<<"*"<<b[j]<<" ";
		}
		//cout<<"k is "<<k<<"\n";
		if(k>0)ans++;
	}
	cout<<ans;

}	


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe
main=print.solve.map(fst.fromJust.B.readInt).B.words=<<B.getLine
m=1000000007
solve(a:b:_)
 |d<1=(2*q)`mod`m
 |d<2=(i*q)`mod`m
 |otherwise=0
 where
  (i,j)=if a>b then(a,b)else(b,a)
  d=i-j
  p=f j
  q=(p*p)`mod`m
f 0=1
f n=(n*f(n-1))`mod`m

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

#define MAX_LEN (100000)
#define MAX_Q (100000)
#define SIZE_BUF (30)

int mod(int n, int k) {
  return n % k >= 0 ? n % k : n % k + k;
}

int main(int argc, char *argv[]) {
  // read inputs
  char S[MAX_LEN + 1], T[MAX_LEN + 1], buf[SIZE_BUF];
  int Q, as[MAX_Q], bs[MAX_Q], cs[MAX_Q], ds[MAX_Q];
  scanf("%s", S);
  fgets(buf, SIZE_BUF, stdin);
  scanf("%s", T);
  scanf("%d", &Q);
  for (int q = 0; q < Q; q++) {
    scanf("%d %d %d %d", &as[q], &bs[q], &cs[q], &ds[q]);
    as[q]--;  // NOTE : modified input
    bs[q]--;  // NOTE : modified input
    cs[q]--;  // NOTE : modified input
    ds[q]--;  // NOTE : modified input
  }
  const int len_S = strlen(S), len_T = strlen(T);

  // count accumulative number of 'A's and 'B's
  int acc_num_A_S[MAX_LEN + 1], acc_num_B_S[MAX_LEN + 1],
      acc_num_A_T[MAX_LEN + 1], acc_num_B_T[MAX_LEN + 1];
  acc_num_A_S[0] = 0;
  acc_num_B_S[0] = 0;
  for (int i = 0; i < len_S; i++) {
    acc_num_A_S[i + 1] = acc_num_A_S[i] + (S[i] == 'A');
    acc_num_B_S[i + 1] = acc_num_B_S[i] + (S[i] == 'B');
  }
  acc_num_A_T[0] = 0;
  acc_num_B_T[0] = 0;
  for (int i = 0; i < len_T; i++) {
    acc_num_A_T[i + 1] = acc_num_A_T[i] + (T[i] == 'A');
    acc_num_B_T[i + 1] = acc_num_B_T[i] + (T[i] == 'B');
  }

  // solve
  for (int q = 0; q < Q; q++) {
    const int a = as[q], b = bs[q], c = cs[q], d = ds[q];
    const int num_A_S = acc_num_A_S[b + 1] - acc_num_A_S[a],
              num_B_S = acc_num_B_S[b + 1] - acc_num_B_S[a],
              num_A_T = acc_num_A_T[d + 1] - acc_num_A_T[c],
              num_B_T = acc_num_B_T[d + 1] - acc_num_B_T[c];
    if (mod(num_A_S - num_B_S, 3) == mod(num_A_T - num_B_T, 3)) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }

  return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;


int main(int argc, const char * argv[]) {
	int N,h[100010][3];
	int dp[100010][3];
	//dp[i][j] : i日目にjをしたときの最大幸福
	cin >> N;
	REP(i,N){
		REP(j,3) cin >> h[i][j];
	}

	REP(i,3) dp[0][i] = h[0][i];
	FOR(i,1,N-1){ // i日目に
		REP(j,3){ // jを選ぶ場合
			dp[i][j]=0;
			REP(k,3){ // 前日がkのとき
				if(k!=j){
					dp[i][j] = max(dp[i][j],dp[i-1][k]+h[i][j]);
				}
			}
		}
	}
	int maxx = 0;
	REP(i,3) maxx = max(maxx, dp[N-1][i]);
	println(maxx);
}


Measured memory_bytes: 2560
#E
#greedy 
n = input()
n = n[::-1] + "0"
l = len(n)

ans = 0

kuriagari=0

for i,v in enumerate(n):
    v = int(v)
    if kuriagari:
        v += 1
    
    if v<5:
        ans += v
        kuriagari = 0
    if v>5:
        ans += 10 - v
        kuriagari = 1
    if v==5:
        if int(n[i+1])<5:
            #delete is better
            ans += v
            kuriagari = 0
        if int(n[i+1])>=5:
            #kuriagari is promising
            ans += 10 - v
            kuriagari = 1
        
print(ans)

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n,mod=1000000007;
string s1,s2;
int dp[55][2][2][2][2][2][2];
int solve(int i,bool r1,bool c1,bool g1,bool r2,bool c2,bool g2)
{
    if(i>=n)return 1;
    int &x=dp[i][r1][c1][g1][r2][c2][g2];
    if(x!=-1)return x;
    x=0;
    if(s1[i]==s1[i+1])
    {
        if(r1)
        {
            if(c2)x=((x+solve(i+2,0,1,1,1,0,1))%mod);
            if(g2)x=((x+solve(i+2,0,1,1,1,1,0))%mod);
        }
        if(c1)
        {
            if(r2)x=((x+solve(i+2,1,0,1,0,1,1))%mod);
            if(g2)x=((x+solve(i+2,1,0,1,1,1,0))%mod);
        }
        if(g1)
        {
            if(r2)x=((x+solve(i+2,1,1,0,0,1,1))%mod);
            if(c2)x=((x+solve(i+2,1,1,0,1,0,1))%mod);
        }
    }
    else
    {
        if(r1&&r2)x=((x+solve(i+1,0,1,1,0,1,1))%mod);
        if(c1&&c2)x=((x+solve(i+1,1,0,1,1,0,1))%mod);
        if(g1&&g2)x=((x+solve(i+1,1,1,0,1,1,0))%mod);
    }
    return x;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin>>n>>s1>>s2;
    cout<<solve(0,1,1,1,1,1,1);
}


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

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

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

using namespace std;


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


  vector<vector<int>> dp(N, vector<int>(3, -INF));
  REP(i, N) cin >> dp[i][0] >> dp[i][1] >> dp[i][2];

  REP(i, N-1){
    dp[i+1][0] += max(dp[i][1], dp[i][2]);
    dp[i+1][1] += max(dp[i][0], dp[i][2]);
    dp[i+1][2] += max(dp[i][0], dp[i][1]);
  }

  cout << max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << endl;

  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;


typedef long long int ll;
typedef unsigned long long  ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef deque <int> di;
typedef deque <char> dc;

#define f(i, a, b) for (int i = a; i < b; i++)
#define f2(i, a, b) for (int i = a; i <=b; i++)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front;
int main() {
int a, b;
cin >> a >> b;
if (a > 8 || b > 8) {
    cout << ":(";
}
else {
    cout << "Yay!";
}
return 0;
}


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

int main() {
  int N, K, S;
  S = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (S >= K) S += K;
    else S *= 2;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <queue>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

bool gsub(char* out, const char* str, const char* pat, const char* rep)
{
  bool ret = false;
  int n = strlen(pat), m = strlen(rep);
  const char *cur, *prev = str;
  for (;; ret = true) {
    cur = strstr(prev, pat);
    if (cur == NULL) { break; }
    memcpy(out, prev, cur - prev);
    out += cur - prev;
    memcpy(out, rep, m);
    out += m;
    prev = cur + n;
  }
  strcpy(out, prev);
  return ret;
}

struct Entry {
  char str[101];
  int cost;
};

char pat[10][11], rep[10][11];
char gamma[11], delta[11];

int main() {
  int n;
  while (scanf("%d", &n), n) {
    REP(i, n) {
      scanf("%s%s", pat[i], rep[i]);
    }
    scanf("%s%s", gamma, delta);
    size_t m = strlen(delta);
    queue<Entry> Q;
    Entry s;
    s.cost = 0;
    strcpy(s.str, gamma);
    Q.push(s);
    while (!Q.empty()) {
      Entry e = Q.front(); Q.pop();
      if (strcmp(e.str, delta) == 0) {
        printf("%d\n", e.cost);
        goto next;
      }
      REP(i, n) {
        Entry f;
        f.cost = e.cost + 1;
        if (gsub(f.str, e.str, pat[i], rep[i]) && strlen(f.str) <= m) {
          Q.push(f);
        }
      }
    }
    puts("-1");
next:;
  }
}

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

# define ll long long

const int N = 100001;
int dp[3][N];
int a[N], b[N], c[N];

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

	for (int i = 1; i < n + 1; i++)
	{
		int A, B, C;
		cin >> A >> B >> C;
		a[i] = A;
		b[i] = B;
		c[i] = C;
	}
	dp[0][0] = a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	for (int i = 1; i < n + 1; i++)
	{
		dp[0][i] = a[i] + max(dp[1][i - 1], dp[2][i - 1]);
		dp[1][i] = b[i] + max(dp[0][i - 1], dp[2][i - 1]);
		dp[2][i] = c[i] + max(dp[0][i - 1], dp[1][i - 1]);
	}
	int ans = 0;
	for (int j = 0; j < 3; ++j) {
		ans = max(ans, dp[j][n]);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5944
import sys
input = sys.stdin.readline
#import heapq
#from fractions import gcd
#from collections import defaultdict
#sys.setrecursionlimit(10**9)
#map(int,input().split())




def main():
    h,w,D=map(int,input().split())
    li=[0]*(h*w+1)
    kyori=[0]*(h*w+1)
    for i in range(h):
        A=list(map(int,input().split()))
        for j in range(w):
            li[A[j]]=(i+1,j+1)

    for i in range(D+1,h*w+1):
        kyori[i]=kyori[i-D]+abs(li[i][0]-li[i-D][0])+abs(li[i][1]-li[i-D][1])

    Q=int(input())
    for i in range(Q):
        l,r=map(int,input().split())
        print(kyori[r]-kyori[l])


if __name__ == '__main__':
    main()

Measured memory_bytes: 14960