akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy

n, k, l = list(map(int, input().split()))

road = [[] for i in range(n+1)]
rail = [[] for i in range(n+1)]

for i in range(k):
    p, q = list(map(int, input().split()))
    road[p].append(q)
    road[q].append(p)

for i in range(l):
    r, s = list(map(int, input().split()))
    rail[r].append(s)
    rail[s].append(r)

seen = [0 for i in range(n+1)]

def dfs_stack(u, al, al_c, d):
    stack = deque([u])
    seen[u] = 1

    while len(stack) > 0:
        v = stack.pop()
        ###
        al_c[v] = d
        ###

        for w in al[v]:
            if seen[w] == 0:
                stack.append(w)
                seen[w] = 1

        if stack == []: break


road_c = [-1 for i in range(n+1)]
rail_c = [-1 for i in range(n+1)]

d = 0
for i in range(1,n+1):
    if seen[i] == 0:
        dfs_stack(i, road, road_c, d)
        d += 1

seen = [0 for i in range(n+1)]

d = 0
for i in range(1,n+1):
    if seen[i] == 0:
        dfs_stack(i, rail, rail_c, d)
        d += 1

dict = {}

for i in range(1, n+1):
    if (road_c[i], rail_c[i]) not in dict:
        dict[(road_c[i], rail_c[i])] = [i]
    else:
        dict[(road_c[i], rail_c[i])].append(i)

ans = [0 for i in range(n+1)]

for dd in dict.items():
    for j in dd[1]:
        ans[j] = str(len(dd[1]))

print(' '.join(ans[1:]))


Measured memory_bytes: 125472
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int a=0;
	char b[200100];
	int s=0;
	int t=0;
	for (int i = 0; i < 200100; i++){
		b[i] = 0;
	}
		scanf("%s", b);
	a = strlen(b);
	if (b[0] == 83)t = 1;

	for (int i = 1; i < a; i++){
		if (b[i] == 83){
            t++;
		}
		if(b[i]==84){
			if (t>0){
				t--;
				s++;
			}
		}
		
	}
	printf("%d\n", a-(2*s));
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

string grid[1080];
Int dp[1080][1080];
Int h, w;
int main(){
  cin >> h >> w;
  for(int i = 0;i < h;i++)cin >> grid[i];
  for(int i = 1;i <= h;i++){
    for(int j = 1;j <= w;j++){
      if(i==1 && j ==1){
	dp[i][j] = 1;
	continue;
      }
      if(grid[i-1][j-1] == '#')continue;
      dp[i][j] = (dp[i-1][j] + dp[i][j-1] )% MOD;
    }
  }
  cout << dp[h][w] << endl;
  return 0;
}

Measured memory_bytes: 9728
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        c: char,
    }

    match c {
        'a'|'e'|'i'|'o'|'u' => println!("vowel"),
        _ => println!("consonant"),
    }

}


Measured memory_bytes: 2144
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    ll X, Y;
    cin >> X >> Y;
    ll N = X;
    int cnt = 0;
    while(N <= Y){
        N*=2;
        cnt++;
    }
    cout << cnt << el;
}



Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N, W;
vector<ll> w, v;
vector<vector<ll>> dp;

ll rec(ll n, ll weight){
    if(n == N) return 0;

    if(dp[n][weight] != -1) return dp[n][weight];

    
    ll res;
    if(weight + w[n] <= W)
        res = max(rec(n+1, weight),
              rec(n+1, weight+w[n]) + v[n]);
    else
        res = rec(n+1, weight);

    return dp[n][weight] = res;
}

int main(){
    cin >> N >> W;
    rep(i, N){
        ll a, b; cin >> a >> b;
        w.push_back(a);
        v.push_back(b);
    }
    dp.assign(N+10, vector<ll>(W + 10, -1));

    ll ans = rec(0, 0);

    cout << ans << ln;
}

Measured memory_bytes: 87296
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
using D = long double;
const D PI = std::acos(-1);
int main() {
    D A, B, H, M;
    cin >> A >> B >> H >> M;

    D a = (H + M / 60.0) / 12 * 2.0 * PI;
    D b = M / 60.0 * 2.0 * PI;
    cerr << a << " " << b << endl;
    cout << setprecision(16) << sqrt(A * A + B * B - A * B * 2.0 * cos(min(abs(a - b), abs(2 * PI - abs(a - b))))) << endl;
}


Measured memory_bytes: 4160
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               1000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)


void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    ll a, b, n;
    cin >> a >> b >> n;

    ll x = min(b - 1, n);

    ll ans = (a * x) / b - (a * (x / b));

    cout << ans << endl;



}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define x first
#define y second
#define int int long long // 2e9 & 9e18
using namespace std; const int inf = numeric_limits<int>::max();
struct __io{__io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}} __io; // fast I/O
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif

const int mod = 998244353;
const int N = 200000;
int f[N+1], fi[N+1];

int poww(int a, int n) {
    if (n == 0) return 1;
    if (n % 2) {
        return a * poww(a, n - 1) % mod;
    }
    int a2 = poww(a, n/2);
    return a2 * a2 % mod;
}

int choose(int n, int k) {
    return (f[n] * fi[k] % mod) * fi[n-k] % mod;
}

signed main() {
    f[0] = fi[0] = 1;
    for (int i = 1; i <= N; ++i) {
        f[i] = f[i-1] * i % mod;
        fi[i] = poww(f[i], mod-2);
    }

    int n, m, K;
    cin >> n >> m >> K;

    int ans = 0;
    for (int k = 0; k <= K; ++k) {
        int part = m * poww(m-1, n-k-1) % mod;
        part = part * choose(n-1, k) % mod;
        ans = (ans + part) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6780
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
    cout<<"Yes"<<endl;
  }
  else{cout<<"No"<<endl;}
}


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

using namespace std;

int main() {
	int N; cin >> N;
	auto as = vector<int>(N);
	for (auto &a: as) {
		cin >> a;
	}

	sort(as.begin(), as.end());

	auto current = as[0];
	auto count = 1;
	auto toRemove = 0;
	for (auto i = 1; i < N; ++i) {
		if (as[i] != current) {
			if (count < current) {
				toRemove += count;
			}

			current = as[i];
			count = 1;
		} else {
			count++;
		}

		if (count > current) {
			++toRemove;	
		}
	}

	if (count < current) {
		toRemove += count;
	}

	cout << toRemove << endl;

	return 0;
}

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


int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<int>> c(h,vector<int>(w));
  vector<pair<int,P>> coin;
  rep(i,h){
    rep(j,w) cin>>c[i][j];
    if(i%2==1) reverse(c[i].begin(),c[i].end());
  }
  rep(i,h)rep(j,w){
    if(i%2==0) coin.push_back(make_pair(c[i][j],make_pair(i+1,j+1)));
    else coin.push_back(make_pair(c[i][j],make_pair(i+1,w-j)));
  }
  vector<pair<P,P>> ans; 
  rep(i,h*w-1){
    if(coin[i].first%2 == 1){
      coin[i+1].first++;
      ans.push_back(make_pair(make_pair(coin[i].second.first,coin[i].second.second),make_pair(coin[i+1].second.first,coin[i+1].second.second)));
    }
  }
  cout<<ans.size()<<endl;
  for(auto x : ans){
    cout<<x.first.first<<" "<<x.first.second<<" "<<x.second.first<<" "<<x.second.second<<endl;
  }
}



Measured memory_bytes: 11028
#include <cstdio>
#include <algorithm>
#include <tr1/unordered_map>
using namespace std;

int n , v[20];

tr1::unordered_map<int,int> memo[20];

int f(int pos , int sum){
	return pos == n ? sum : memo[pos].count(sum) ? memo[pos][sum] : memo[pos][sum] = min( f(pos+1,sum+v[pos] ) , f(pos+1,abs(sum-v[pos])) );
}

int main(){
	while(scanf("%d\n",&n)&& n){
		for(int i = 0 ; i < n ; i++) scanf("%d",&v[i]) , memo[i].clear() ;
		printf("%d\n",f(0,0));
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int h[100001];
int dp[100001];
int n,k;
int solve(int stone)
{
    if(stone==n) return 0;
    if(dp[stone]!=-1) return dp[stone];
    int cost=1<<30;
    for(int i=1;i<=k and stone+i<=n;i++)
    cost=min( cost,abs(h[stone]-h[stone+i])+solve(stone+i) );

    return dp[stone]=cost;
}

int main()
{
    int i;
    scanf("%d %d",&n,&k);

    for(i=1; i<=n; i++)
        scanf("%d",&h[i]);

    memset(dp,-1,sizeof(dp));
    printf("%d\n",solve(1));


    return 0;
}



Measured memory_bytes: 5760
a=input()
b=a.split()
if int(b[0])<int(b[1]):
    c=b[0]*int(b[1])
    print(c)
elif int(b[0])>int(b[1]):
    c=b[1]*int(b[0])
    print(c)
else:
    c=b[1]*int(b[0])
    print(c)
    

Measured memory_bytes: 3060
class unionfind:
    sz = 0
    par = []
    def __init__(self, n):
        self.sz = n
        for i in range(n):
            self.par.append(-1)

    def find(self, a):
        if self.par[a]<0: return a
        self.par[a] = self.find(self.par[a])
        return self.par[a]
    
    def size(self, a):
        a = self.find(a)
        return -self.par[a]
    
    def same(self, a,b):
        return self.find(a) == self.find(b)

    def unite(self, a,b):
        a = self.find(a)
        b = self.find(b)
        if self.same(a,b): return False
        if self.size(a) < self.size(b):
            a,b=b,a
        self.par[a] += self.par[b]
        self.par[b] = a
        return True

n,m = map(int,input().split())
g = []
for i in range(m):
    s,t,w = map(int,input().split())
    g.append([w,s,t])
g = sorted(g)
ans = 0
uni = unionfind(n)
for c,i,j in g:
    if uni.unite(i,j): ans += c
print(ans)


Measured memory_bytes: 25552
// AOJ 2180: Water Tank
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define EPS 1e-6
#define MIN(a,b) ((a)<=(b)?(a):(b))

int n, l, s[86402], t[86402], u[86402];

char buf[30], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int check(double *v, double a)
{
	int i, x;
	double e;

	for (e = *v, x = 0, i = 0; i < n; i++) {
		e = MIN(l, e + a*(s[i]-x));
		x = s[i];
		e = MIN(l, e + (t[i]-x)*(a-u[i]));
		if (e < 0) { *v = e; return 1; }
		x = t[i];
	}
	*v = MIN(l, e + a*(86400-x));
	return 0;
}

int calc(double a)
{
	int i;
	double v[3];
	for (v[0] = l, i = 0; i < 2; i++) {
		if (check(v+i, a)) return 0;
		v[i+1] = v[i];
	}
	return fabs(v[0]-v[1]) <= EPS;
}

int main()
{
	int i;
	double up, low, mid;

	while (fgets(p=buf, 30, stdin) && *p != '0') {
		n = getint(), p++, l = getint();
		for (i = 0; i < n; i++) {
			fgets(p=buf, 30, stdin);
			s[i] = getint(), p++, t[i] = getint(), p++, u[i] = getint();
		}

		low = 0, up = 1000000;
		while (fabs(low - up) > EPS) {
			mid = (low + up)/2;
			if (calc(mid)) up = mid; else low = mid;
		}
		printf("%.8lf\n", up);
	}
}

Measured memory_bytes: 2668
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
cost = sum([abs(A[i + 1] - A[i]) for i in range(N + 1)])
for i in range(1, N + 1):
    print(cost - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]))

Measured memory_bytes: 14048
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int n,m;
   cin >> n >> m;
   vector<int> a(n),b(n);
   vector<int> c(m),d(m);
   rep(i,n) cin >> a[i] >> b[i];
   rep(i,m) cin >> c[i] >> d[i];

   int dis = 0;
   int distmp = 0;
   int ans = -1;
   rep(i,n){
      dis = 0;
      distmp = 5*100000000;
      rep(j,m){
         dis = abs(a[i]-c[j]) + abs(b[i]-d[j]);
         if(distmp > dis) {
            ans = j+1;
            distmp = dis;
         }
      }
      cout << ans << endl;
   }


   return 0;
}

Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    loop{
        let i:Vec<i32> = read_vec();


        if i[0] == 0 && i[1] == 0 {
            break;
        }

        if i[0] > i[1] {
            println!("{} {}", i[1], i[0]);
        } else {
            println!("{} {}", i[0], i[1]);
        }

    }
}


Measured memory_bytes: 5032
import itertools
import math
n=int(input())
l=[list(map(float,input().split())) for i in range(n)]

"""
for i in range(n):
    print(l[i])
"""

def cal(p,q):
    add=(l[p][0]-l[q][0])**2+(l[p][1]-l[q][1])**2
    return math.sqrt(add)


a=[]
ans=0
for i in range(n):
    a.append(i)
for x in itertools.permutations(a): 
    for i in range(n-1):
        ans+=cal(x[i],x[i+1])
for i in range(1,n+1):
    ans/=i
print(ans)

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int t, d, l; cin >> t >> d >> l;
        if (!t) break;

        bool dry = true;
        int todry = 0, ans = 0;
        rep(i, 0, t) {
            int h; cin >> h;
            if (i + 1 == t) break;
            if (h >= l) {
                dry = false;
                todry = d;
                ans++;
            } else if (!dry) {
                ans++;
            }
            if (todry) todry--;
            if (!todry) dry = true;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3164
#include<iostream>
#include<cstdlib> 
#include<sstream>
#include<cstdio>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
#define me(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=1111122;
const int M=200005;
int main()
{

    LL a,i,j,n,m,b,x,flag=0;
    cin>>x;
    for(a=-2000;a<=2000;a++)
    {
        for(b=-2000;b<=2000;b++)
        {
            LL ans=a*a*a*a*a;
            LL ans1=b*b*b*b*b;
            if(ans-ans1==x)
            {
                cout<<a<<" "<<b<<endl;
                flag=1;
                break;
            }
        }
        if(flag)break;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    ll n,d;
    cin >> n >> d;

    ll ans = 0;
    rep(i,0,n){
	double x,y;
	cin >> x >> y;

	if((double)d >= sqrt(x*x + y*y))ans ++;
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n, m;
	bool flag = false;
	cin >> n >> m;
	vector<string>a(n), b(m);
	REP(i, n) {
		cin >> a[i];
	}
	REP(i, m) {
		cin >> b[i];
	}
	REP(i, n - m + 1) {
		REP(j, n - m + 1) {
			if (a[i][j] == b[0][0]) {
				bool exist = true;
				REP(k, m) {
					if (a[i + k].substr(j, m) != b[k]) {
						exist = false;
					}
				}
				if (exist) {
					flag = true;
				}
			}
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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


int main(){
    string s1, s2, s3;
    cin>>s1>>s2>>s3;
    
    cout<< s1[0]<<s2[1]<<s3[2] <<endl;

    return 0;
}

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

#define F first
#define S second

int dx[] = { 0 , 0, 1, -1, -1, -1, 1, 1};
int dy[] = { 1, -1 , 0, 0, 1, -1, 1, -1};
const double EPS= 1e-8 ;
const double PI  = acos(-1.0);
#define inf INT_MAX
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }


struct hap{
	int a ; 
	int b ; 
	int c ; 
	
};
 int a[100005][3] ;   // dont ; 
 int n ;  
 int dp[100005][4] ;  

int sol ( int ind , int l ) 
{
	if (ind >= n ) return 0 ; 
	
	
	
	int &res = dp[ind][l]; 
	if ( res != -1 ) return res ; 
	for ( int i = 0  ;i< 3 ;i++)
	{
		if ( l != i )
		{
			res = max (res, sol( ind+1 , i ) + a[ind][i]) ; 
			
		}
	}
	
	
	return res ; 
	
}




int main()
 {
 
 cin>>n ; 

 for ( int i = 0 ; i<n ; i++)
 {
	 int x , y , z ; 
	 cin>>x >> y >> z ; 
	 a[i][0]= x ; 
	 a[i][1] = y ; 
	 a[i][2] = z ; 
	 
	 
 }
 memset ( dp , -1 , sizeof ( dp  ) ) ; 
 
  
  int ans = sol ( 0 , 3 ) ; 
  cout<< ans << endl; 



 return 0 ;
}






 
 
 
 
 
 

 


Measured memory_bytes: 10752
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
    int n;
    vector<double> a(110);
    double sum = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
        sum += 1 / a[i];
    }
    
    cout << setprecision(10) << (1 / sum) << endl;

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((abs(a - c) <= d) || (abs(b - a) <= d && abs(c - b) <= d)) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;
  return 0;
}


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

int main() {
    string num;
    cin >> num;
    ll sum = 0;
    rep(i,num.size()) {
        sum += num.at(i) - '0';
    }
    if(sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
  string s;
  int n;
long long int ans(vector<int> vec){
  long long int tmp = 0;
  //cout << vec.size() << " size" << endl;
  for(int i=0; i<vec.size()-1; i++){
    try{
    tmp += stoll(s.substr(vec.at(i),vec.at(i+1)-vec.at(i)));
    }catch(...){
      cout << stoi("9999999999") << endl;
      cout << "catch" << endl;
      cout << i << endl;
      cout << vec.size() << endl;
      cout << vec.at(0) << endl;
      cout << vec.at(1) << endl;
      cout << tmp << endl;
      cout << s.substr(vec.at(i),vec.at(i+1)-vec.at(i)) << endl;
    }
  }
  //cout << tmp << endl;
  return tmp;
}
long long int dfs(int i, vector<int> vec){
  if(i==n){vec.push_back(n);return ans(vec);}
  vector<int> vec2 = vec;
  vec.push_back(i);
  long long int tm1 = dfs(i+1,vec);
  long long int tm2 = dfs(i+1,vec2);
  return tm1 + tm2;
}

int main(){
  cin >> s;
  n = s.size();
  vector<int> tmpvec;
  tmpvec.push_back(0);
  //cout << tmpvec.at(0) << endl;
  cout << dfs(1,tmpvec) << endl;
}
  

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;


using namespace std;


int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n;
  cin>>n;

  int a[n];

  loop(i,n)
  {
    cin>>a[i];
  }   

   int b[n];

   loop(i,n)
   {
     b[i] = a[i];
   }

   sort(b,b+n);
   reverse(b,b+n);

   int max_score = b[0];
   int min_score = b[1];

   loop(i,n)
   {
     if(a[i] == max_score)
     {
       cout<<min_score<<endl;
     }

     else
     {
       cout<<max_score<<endl;
     }
   }


}

Measured memory_bytes: 5172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int main()
{
  int N, M, P;
  std::cin >> N >> M >> P;

  struct Link { int to; int cost; };

  std::vector<std::vector<Link>> links(N);
  for(int i=0; i<M; i++)
  {
    int a, b, c;
    std::cin >> a >> b >> c;
    links[a-1].push_back(Link{b-1,P-c});
  }

  std::vector<long long> nodes(N, 0);
  std::vector<int> initialsed(N, 0);
  initialsed[0] = 1;
  for(int i=0; i<N; i++)
  {
    for(int fr=0; fr<N; fr++)
    {
      if( ! initialsed[fr] ) { continue; }
      for(const auto& l : links[fr])
      {
        if( ! initialsed[l.to] )
        {
          initialsed[l.to] = 1;
          nodes[l.to] = nodes[fr] + l.cost;
        }
        nodes[l.to] = std::min(nodes[l.to], nodes[fr] + l.cost);
      }
    }
  };
  if( ! initialsed[N-1] ) { std::cout << -1; return 0; }
  long long temp = nodes[N-1];

  for(int i=0; i<N; i++)
  {
    for(int fr=0; fr<N; fr++)
    {
      if( ! initialsed[fr] ) { continue; }
      for(const auto& l : links[fr])
      {
        if( ! initialsed[l.to] )
        {
          initialsed[l.to] = 1;
          nodes[l.to] = nodes[fr] + l.cost;
        }
        nodes[l.to] = std::min(nodes[l.to], nodes[fr] + l.cost);
      }
    }
  };
  if( temp !=  nodes[N-1] ) { std::cout << -1; return 0; }
  std::cout << std::max<long long>(0, -nodes[N-1]);
}

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

int main(){
  int n;
  cin >> n;
  map<string,int>kazu;
  string s;
  for(int i=0;i<n;i++){
    cin >> s;
    kazu[s]++;
  }
  cout << "AC x " << kazu["AC"] << endl;
  cout << "WA x " << kazu["WA"] << endl;
  cout << "TLE x " << kazu["TLE"] << endl;
  cout << "RE x " << kazu["RE"] << endl;
  return 0;
} 

Measured memory_bytes: 3616
//Code By PMD
#include<bits/stdc++.h>
#define faster() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long i64;
map < string , int > cnt;
int n;
vector < string > a;
void input(){
    cin >> n ; a.resize(n);
    for(auto &z : a) cin >> z;
}
void solve(){
    int res = 0 ;
    for(int i = 0 ; i < n ; i++){
        cnt[a[i]]++;
        res = max(res,cnt[a[i]]);
    }
    for(auto z : cnt){
        if ( z.second == res ){
            cout << z.first << endl;
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    faster();int t=1; 
    //cin>>t; cin.ignore();
    while(t--){ input();solve();}
    cerr << "\nRunning is : " << 1.0*clock()/1000 ;
    return 0;
}
//Code By PMD
 

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

int main() {
	int n,t=0;
	ll r1=0,r2=0;
	cin >> n;

	vector<int> a(n);
	rep(i,n)
		cin >> a.at(i);

	rep(i,n) {
		t += a.at(i);

		if(i%2==0 && t<=0) {
			r1 += abs(-t)+1;
			t = 1;
		} else if(i%2 && t>=0) {
			r1 += t+1;
			t = -1;
		}
	}

	t = 0;
	rep(i,n) {
		t += a.at(i);

		if(i%2 && t<=0) {
			r2 += abs(-t)+1;
			t = 1;
		} else if(i%2==0 && t>=0) {
			r2 += t+1;
			t = -1;
		}
	}

	cout << min(r1,r2) << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	static String s = "";

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int ans;

		if(N % 2 == 0) {
			ans = N / 2;
		}else {
			ans = N / 2 + 1;
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 21836
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    s=set()
    for i in range(1,1+int(n**.5)):
        s.add(i)
        s.add(n//i)
    A=sorted(s)
    m=len(A)
    coef=[0]*m
    coef[0]=1
    for i in range(1,m):
        coef[i]=A[i]-A[i-1]
    dp=[0]*m
    dp[0]=1
    for i in range(k):
        for j in range(m-1):
            dp[j+1]+=dp[j]
            dp[j+1]%=MOD
        ndp=[0]*m
        for j in range(m):
            ndp[j]=dp[m-j-1]*coef[j]
            ndp[j]%=MOD
        dp=ndp
    print(sum(dp)%MOD)
resolve()

Measured memory_bytes: 92412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, long long A, long long B, vector<long long> X){
	ll res = 0;
	rep(i,N-1) {
		res += min((X[i+1] - X[i])*A, B);
	}
	cout << res << endl;
}

int main(){	
	long long N;
	long long A;
	long long B;
	scanf("%lld",&N);
	vector<long long> X(N-1+1);
	scanf("%lld",&A);
	scanf("%lld",&B);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&X[i]);
	}
	solve(N, A, B, X);
	return 0;
}



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

int main() {
  ll n, a, b; cin >> n >> a >> b;
  if (!a) {
    cout << 0 << endl;
    return 0;
  }
  cout << n / (a + b) * a + min(a, n % (a + b)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	string S;
	cin >> S;
	int i = 0;
	int j = (int)S.size()-1;
	int count = 0;
	int b = true;
	while (1) {
		if (i >= j)break;
		if (S[i] == S[j]) {
			i++;
			j--;
		}
		else if (S[i] == 'x' && S[j] != 'x') {
			count++;
			i++;
		}
		else if (S[i] != 'x' && S[j] == 'x') {
			count++;
			j--;
		}
		else {
			b = false;
			break;
		}
	}
	if (b) {
		cout << count << endl;
	}
	else {
		cout << -1 << endl;
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<tuple>
#include<set>
#include<cmath>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
const double PI=3.14159265358979323846; 
using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  string ans="Yes";
  for(int i=0;i<s.size();i++){
    if(s[i] != t[i]){
      ans = "No";
      break;
    }
  }

  cout << ans << endl;
}


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

class Class1
{
    static void Main(string[] args)
    {
        var D = int.Parse(Console.ReadLine());
        var c = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
        int[][] ds = new int[D][];

        for (int i = 0; i < D; i++)
        {
            ds[i] = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
        }

        // とりあえず最大値を返すやっつけ処理
        for (int i = 0; i < D; i++)
        {
            int maxCategory = 0;
            int maxValue = 0;

            for (int j = 0; j < 26; j++)
            {
                if (ds[i][j] > maxValue)
                {
                    maxCategory = j + 1;
                    maxValue = ds[i][j];
                }
            }

            Console.WriteLine(maxCategory);
//            Console.WriteLine(maxValue);
        }


//        int[] ts = new int[D];
//        for (int i = 0; i < D; i++)
//        {
//            ts[i] = int.Parse(Console.ReadLine());
//        }
//
//        var M = int.Parse(Console.ReadLine());
//        int[][] dq = new int[M][];
//        for (int i = 0; i < M; i++)
//        {
//            dq[i] = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
//        }
//
//        // 問題Cのアレンジするコード
//        var newTs = new int[D];
//        Array.Copy(ts, newTs, D);
//        for (int i = 0; i < M; i++)
//        {
//            // dqをベースにして変えてみる
////            Console.WriteLine($"{dq[i][0]}日目を{dq[i][1]}に変えて実施");
//            newTs[dq[i][0] - 1] = dq[i][1];
//
////            Console.WriteLine(string.Join(", ", newTs));
//
//            var newAns = _Calc(D, c, ds, newTs);
//            Console.WriteLine(newAns[D - 1]);
//        }
    }

    private static long[] _Calc(int D, int[] c, int[][] ds, int[] ts)
    {
        long[] t_ans = new long[D];
        int[] c_history = new int[26];
        long sum = 0;
        long minus = 0;

        for (int i = 0; i < D; i++)
        {
            long v = ds[i][ts[i] - 1];
            for (int j = 0; j < 26; j++)
            {
                if (j == ts[i] - 1)
                {
                    if (i > 0)
                    {
//                        Console.WriteLine($"plus_prev: {i}, {c[j]}");
//                        Console.WriteLine($"c_history[j]: {c_history[j]}");
                        minus -= c[j] * (i - c_history[j]);
                        continue;
                    }

//                    Console.WriteLine($"skip: {i}, {c[j]}");
                    continue;
                }

                minus += c[j];
            }

//            Console.WriteLine("minus: " + minus);
//            Console.WriteLine("v: " + v);

            sum += v - minus;
            c_history[ts[i] - 1] = i + 1;


//            Console.WriteLine(sum);
            t_ans[i] = sum;
        }

        return t_ans;
    }
}

Measured memory_bytes: 28888
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	string s; cin >> s;

	int cnt = 0;
	int n = s.size();
	for(int i = 0; i < n; ++i)
	{
		if(s[i] == 'R')
			++cnt;
	}

	if(cnt == 3)
	{
		cout << 3 << '\n';
		return 0;
	}
	if(cnt == 2)
	{
		if(s[0] == s[1] || (s[1] == s[2]))
			cout << 2 << '\n';
		else
			cout << 1 << '\n';

		return 0;
	}

	if(cnt == 1)
	{
		cout << 1 << '\n';
		return 0;
	}

	cout << 0 << '\n';

	return 0;
}

Measured memory_bytes: 3616
n = int(input())
explored = set()
next = [[]for _ in range(n)]

from collections import deque
for i in range(n-1):
    u, v, w= map(int, input().split())
    next[u-1].append((v-1, w%2))
    next[v-1].append((u-1, w%2))
ans = [-1] * n
exploring = deque()
next_que = deque([0])
ans[0]=0
explored.add(0)
while next_que:
    i = next_que.popleft()
    exploring.extend(next[i])
    while exploring:
        a, b = exploring.popleft()
        ans[a] = (ans[i]+b)%2
        if a not in explored:
            next_que.append(a)
        explored.add(a)

print(*ans, end='\n')

Measured memory_bytes: 45548
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	int n;
	int a[100100][3];
	ll dp[100100][3];
	cin>>n;
	REP(i,n)
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	REP(i,n)
	{
		if(!i)continue;
		REP(j,3)
			dp[i][j]=-1;
	}
	REP(i,n)
	{
		if(!i)continue;
		REP(j,3)
			REP(k,3)
			{
				if(j!=k)
				{
					dp[i][k]=max(dp[i][k],dp[i-1][j]+a[i][k]);
				}
			}
	}
	ll ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	cout<<ans<<endl;
	return 0;
}



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

int main(){
  string S;
  cin >> S;
  int sum=0;
  for(int i=0;i<S.size();i++){
    int A=S.at(i)-'0';
    sum+=A;
  }
  if(sum%9==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3704
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def main():
    H,W = ints_raw()
    Ss = ["#"+input()[:-1]+"#" for _ in range(H)]
    W = W+2
    H = H+2
    Ss = ["#"*W]+Ss+["#"*W]
    lenHor = [[0]*W for _ in range(H)]
    lenVer = [[0]*W for _ in range(H)]
    for h,S in enumerate(Ss):
        buf = 0
        last_idx = 1
        for idx,c in enumerate(S):
            if c == '#':
                for x in range(last_idx,idx):
                    lenHor[h][x] = buf
                buf =0
                last_idx = idx+1
            else:
                buf+=1
    
    for w in range(W):
        buf = 0
        last_idx = 1
        for idx in range(H):
            c = Ss[idx][w]
            if c == '#':
                for x in range(last_idx, idx):
                    lenVer[x][w] = buf
                buf = 0
                last_idx = idx+1
            else:
                buf += 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, max(lenVer[h][w]-1,0)+max(lenHor[h][w]-1,0)+1)
    return ans

print(main())


Measured memory_bytes: 120924
using System;
using System.Collections.Generic;

namespace PanaA
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51".Split(',');
            List<int> list = new List<int>();
            for (int i = 0; i < s.Length; i++)
            {
                list.Add(int.Parse(s[i]));
            }

            int k = int.Parse(Console.ReadLine());
            Console.WriteLine(list[k-1]);
        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool ok = true;
    if (S.size() & 1) {
        ok = false;
    }
    REP(i, 0, S.size()) {
        if (i & 1) {
            if (S[i] != 'i') {
                ok = false;
            }
        } else {
            if (S[i] != 'h') {
                ok = false;
            }
        }
    }
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
class Dice():
    def __init__(self, spots):
        self.spots = [spots[i] for i in range(6)]
    
    def roll(self, direction):
        if direction == 0:
            self.spots = [self.spots[i] for i in [1, 5, 2, 3, 0, 4]]
        elif direction == 1:
            self.spots = [self.spots[i] for i in [3, 1, 0, 5, 4, 2]]
        elif direction == 2:
            self.spots = [self.spots[i] for i in [4, 0, 2, 3, 5, 1]]
        elif direction == 3:
            self.spots = [self.spots[i] for i in [2, 1, 5, 0, 4, 3]]
            
first_state = list(map(int, input().split()))
q = int(input())

for _ in range(q):
    my_dice = Dice(first_state)
    a, b = map(int, input().split())

    if b == my_dice.spots[0]:
        my_dice.roll(2)
    elif b == my_dice.spots[1]:
        pass
    elif b == my_dice.spots[2]:
        my_dice.roll(3)
        my_dice.roll(2)
    elif b == my_dice.spots[3]:
        my_dice.roll(1)
        my_dice.roll(2)
    elif b == my_dice.spots[4]:
        my_dice.roll(2)
        my_dice.roll(2)
    elif b == my_dice.spots[5]:
        my_dice.roll(0)
    
    if a == my_dice.spots[0]:
        pass
    elif a == my_dice.spots[2]:
        my_dice.roll(3)
    elif a == my_dice.spots[3]:
        my_dice.roll(1)
    elif a == my_dice.spots[5]:
        my_dice.roll(1)
        my_dice.roll(1)
        
    print(my_dice.spots[2])
        


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

int main() {
  int N; cin >> N;
  int a[N+1];
  for (int i=0; i<N; i++) cin >> a[i+1];
  int b[N+1] = {};
  for (int i=N; i>0; i--) {
    int tmp = 0;
    for (int j=2; i*j<=N; j++) {
      tmp += b[i*j];
    }
    b[i] = (tmp + a[i]) % 2;
  }
  int sum=0;
  for (int i=1; i<=N; i++) sum += b[i];
  cout << sum << endl;
  if (sum > 0) {
    for (int i=1; i<=N; i++) {
      if (b[i] == 1) {
        sum -= 1;
        cout << i;
        if (sum > 0) cout << ' ';
        else cout << endl;
      }
    }
  }
}


Measured memory_bytes: 2432
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while(true){
            int n = sc.nextInt();
            if(n == 0) break;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }
            int[][] dp = new int[n][n];
            for (int i = 1; i < n; i++) {
                for (int j = 0; j+i < n; j++) {
                    if(Math.abs(a[j] - a[j+i]) <= 1){
                        if(i == 1 || dp[j+1][j+i-1] == i-1 ) dp[j][j+i] = i+1;
                    }
                    for (int k = 0; k < i; k++) {
                        if(dp[j][j+i] < dp[j][j+k] + dp[j+k+1][j+i])
                            dp[j][j+i] = dp[j][j+k] + dp[j+k+1][j+i];
                    }
                }
            }
            sb.append(dp[0][n-1] + "\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}



Measured memory_bytes: 58468
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,m; cin>>n>>m;
	ll ans=((n-1)*n)/2+((m-1)*m)/2;
	cout<<ans<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int s; cin >> s;
	int p = (s + 999999999) / 1000000000;
	cout << "0 0 1000000000 1 " << p * 1000000000 - s << ' ' << p << endl;
}

Measured memory_bytes: 256
// AGC 18 A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main(){
    int n,k; cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    if(k > a[n-1]){
        cout << "IMPOSSIBLE" << endl; return 0;
    }
    int G = a[0];
    for(int i = 1; i < n; i++){
        G = gcd(G,a[i]);
    }
    if(k%G == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 640