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

char tolower(char ch){
    if('A' <= ch && ch <= 'Z'){
        return ch - 'A' + 'a';
    }
    else return ch;
}

int main(){
    string W;
    cin >> W;
    int count = 0;
    string str;
    while (true)
    {
        cin >> str;
        if(str == "END_OF_TEXT"){
            break;
        }
        for(int i = 0; i < (int)str.size(); i++){
            str[i] = tolower(str[i]);
        }
        if(str == W){
            count++;
        }
    }
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll gcd(ll a, ll b){
	if(a < b)  swap(a,b);
	if(a%b==0) return b;
	else return gcd(b,a%b);
}
ll ngcd(vector<ll> a){
	ll res;
	res = a[0];
	for(int i = 1; i < a.size() && res != 1; i++) {
		res = gcd(a[i], res);
	}
	return res;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll nlcm(vector<ll> numbers) {
	ll res;
	res = numbers[0];
	for (ll i = 1; i < numbers.size(); i++) {
		res = lcm(res, numbers[i]);
	}
	return res;
}
int main(){
	cout << fixed << setprecision(10);
	int n;
	ll x;
	cin >> n >> x;
	vector<ll> v(n);
	rep(i,n){
		ll z;
		cin >> z;
		v[i] = abs(z-x);
	}
	cout << ngcd(v) << endl;
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if n % 2:
    l = A[n // 2]
    r = B[n // 2]
    ans = r - l + 1
    print(ans)
else:
    l = A[n // 2 - 1] + A[n // 2]
    r = B[n // 2 - 1] + B[n // 2]
    ans = r - l + 1
    print(ans)


Measured memory_bytes: 104784
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int r;
  cin >> r;
  cout << r*r << endl;
  return 0;
}

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

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

    char s1 = n[0];
    char s2 = n[1];
    char s3 = n[2];

    if(s1 == s2 && s2 == s3){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    
}

Measured memory_bytes: 256
from fractions import gcd
import sys

if True:
    N, *A = map(int, sys.stdin.read().split())
else:
    N = int(input())
    A = list(map(int, input().split()))

a = 1
for v in A:
    a = a * v // gcd(a, v)

MOD = int(1e9) + 7
sum_ = 0
for v in A:
    sum_ += a // v

print(sum_ % MOD)

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

int main() {
  int n, k;
  cin >> n >> k;
  int a = 1;
  for (int i = 0; i < n; i++){
    if (a > k){
      a += k;
    }else{
      a *= 2;
    }
  }
  cout << a << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int H,W; cin >> H >> W;
    int N; cin >> N;
    int a[100005];

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

    int idx = 0;
    int rem = a[0];
    int ans[100][100];
    for (int i = 0;i < H;i++){
        if(i%2 == 0){
            for (int j = 0;j < W;j++){
                ans[i][j] = idx+1;
                rem--;
                if(rem == 0){
                    idx++;
                    rem = a[idx];
                }
            }
        }else{
            for (int j = W-1; j >= 0;j--){
                ans[i][j] = idx+1;
                rem--;
                if(rem == 0){
                    idx++;
                    rem = a[idx];
                }
            }
        }
    }

    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

    return 0;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int x=0;
	int mx=0;
	for(int i=0;i<n;i++)
	{
		if(s.at(i)=='I')
		{
			x=x+1;
			if(x>mx)
			mx=x;
		}
		else
		{
			x=x-1;
			if(x>mx)
			mx=x;
		}
	}
	cout<<mx;
return 0;
}

Measured memory_bytes: 256
import math
def P(n,r):
    return math.factorial(n) // math.factorial(n-r)
def C(n,r):
    return P(n,r) // math.factorial(r)
n,m = map(int,input().split())
if n < 2:
    n_len = 0
else:
    n_len = C(n,2)
if m < 2:
    m_len = 0
else:
    m_len = C(m,2)
ans = n_len + m_len
print(ans)

Measured memory_bytes: 38256
const m=1000000007
function main()
    n=myread(Int)
    println(mod(powermod(10,n,m)-2*powermod(9,n,m)+powermod(8,n,m),m))
end

# ----------input function----------
sread()=chomp(readline())
sreads(sp=" ")=split(readline(),sp)
myread(ty)=parse(ty,readline())
myreads(ty)=map(x->parse(ty,x),split(readline()))
main()

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

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let mut a = Vec::with_capacity(n);
    for _ in 0..n {
        let ai: usize = read!();
        a.push(ai);
    }

    const MIN: usize = 0;
    const MAX: usize = 100;

    let mut ans = U_INF;
    for now in MIN..=MAX {
        let mut sum = 0;
        for &ai in &a {
            sum += (now as isize - ai as isize).pow(2) as usize;
        }
        ans = (ans).min(sum);
    }

    println!("{}", ans);
}

Measured memory_bytes: 2140
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> N;
  cin >> B >> A;
  ll h[N];
  double min_sabun = 1e+9;
  ll count;
  rep(i, N){
    cin >> h[i];
    ll ab_abs = 1000*B-1000*A-h[i]*6;
    if (ab_abs<0) ab_abs*=-1;
    if (min_sabun > ab_abs){
      min_sabun = ab_abs;
      count = i+1;
    }
  }
  cout << count <<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n; lli k;
  while (scanf("%d %lld", &n, &k) != EOF)
  {
    int a[n];
    for (int i = 0; i < n; i++)
    {
      scanf("%d", &a[i]);
      a[i]--;
    }

    vector<int> aux, cycle;
    bool visited[n]; memset(visited, false, sizeof(visited));
    aux.push_back(0);
    visited[0] = true;
    int loopAt = 0;
    for (int i = a[0]; !visited[i]; i = a[i])
    {
      aux.push_back(i), visited[i] = true;
      if (visited[a[i]]) loopAt = a[i];
    }

    for (int i = 0, act = false; i < aux.size(); i++)
    {
      if (aux[i] == loopAt)
        act = true;
      if (act) cycle.push_back(aux[i]);
    }

    int ans;
    int space = aux.size() - (int)cycle.size();
    if (k <= space)
      printf("%d\n", 1 + aux[k]);
    else
      printf("%d\n", 1 + cycle[(k - space) % cycle.size()]);
  }
  return 0;
}

Measured memory_bytes: 6608
import sys
import fractions


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ls = [[0] * (n + 1) for _ in range(2)]
    for i in range(n):
        if i == 0:
            ls[0][i+1] = a[i]
            ls[1][-i-2] = a[-i-1]
        else:
            ls[0][i+1] = fractions.gcd(ls[0][i], a[i])
            ls[1][-i-2] = fractions.gcd(ls[1][-i-1], a[-i-1])
    mgcd = 0
    for i in range(n):
        mgcd = max(mgcd, fractions.gcd(ls[0][i], ls[1][i + 1]))
    print(mgcd)


if __name__ == '__main__':
    solve()


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

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

  vector<int> C(26);
  for (int i = 0; i < 26; i++) cin >> C.at(i);

  vector<vector<int>> S(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) cin >> S.at(i).at(j);
  }

  // i 日目に開催するコンテストのタイプ (1 - 26)
  vector<int> T(D);
  for (int i = 0; i < D; i++) {
    cin >> T.at(i);
    T.at(i)--;
  }

  int M; cin >> M;

  for (int i = 0; i < M; i++) {
    int d, q; cin >> d >> q;
    d--; q--;
    T.at(d) = q;

    long long v = 0;
    vector<int> L(26);

    for (int j = 0; j < D; j++) {
      v += S.at(j).at(T.at(j));
      L.at(T.at(j)) = j+1;
      for (int i = 0; i < 26; i++) {
        v -= C.at(i) * (j+1 - L.at(i));
      }
    }
    cout << v << endl;
  }

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
template<typename T>
class Union_Find {
  private:
    vector<T> t, s;

  public:
    Union_Find(T max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }

    void Union(T x, T y) {
        if (same(x, y))
            return;
        T tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    T Find(T n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }

    bool same(T x, T y) {
        return Find(x) == Find(y);
    }

    T get_Size(size_t a) {
        return s[a];
    }
};
bool ifPrime(int n){
    if(n==1)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
vector<int> primeFactorization(int n) {
    vector<int> re;
    int cnt = 2;
    while (n != 1) {
        if (n % cnt != 0) {
            cnt++;
            continue;
        }
        n /= cnt;
        re.push_back(cnt);
    }
    return re;
}
signed main(signed argc, char* argv[]) {
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,3)if(s[i]==t[i])ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(k);
	vector<PLL> sushis;
	rep(i, 0, n) {
		sll(t); sll(d);
		sushis.PB(MP(t, d));
	}
	sort(sushis.begin(), sushis.end(), [](PLL a, PLL b) { return a.second > b.second; });
	LL pts = 0;
	map<LL,LL> typeCnt;
	rep(i, 0, k) {
		pts += sushis[i].second;
		typeCnt[sushis[i].first]++;
	}
	LL totalPts = pts + typeCnt.size() * typeCnt.size();
	LL prev = totalPts;
	LL types = typeCnt.size();
	LL sml = k-1, big = k;
	rep(i, 1, k - types + 1) {
		while(sml >= 0 && typeCnt[sushis[sml].first] <= 1)	sml--;
		if(sml < 0)		break;
		while(big < n && typeCnt[sushis[big].first] > 0)	big++;
		if(big == n)	break;
		LL tmp = prev - sushis[sml].second + sushis[big].second + 2 * (types + i) - 1;
		typeCnt[sushis[sml--].first]--;
		typeCnt[sushis[big++].first]++;
		if(tmp > totalPts)	totalPts = tmp;
		prev = tmp;
	}
	pll(totalPts); nl;
}


Measured memory_bytes: 5744
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int H, W;
long long int S1 = INF, S2 = 0;
long long int A[2100][2100];
long long int DP[2100][2100];

long long int check(){
    for(int i = 0; i < H; i++){
        long long int A1[2100], A2[2100];
        for(int j = 0; j < W; j++){
            A1[j] = A[i][j] - S1;
            A2[j] = S2 - A[i][j];
        }
        for(int j = 1; j < W; j++){
            A1[j] = max(A1[j], A1[j - 1]);
        }
        for(int j = W - 2; j >= 0; j--){
            A2[j] = max(A2[j], A2[j + 1]);
        }
        DP[i][0] = A2[0];
        DP[i][W] = A1[W - 1];
        for(int j = 1; j < W; j++){
            DP[i][j] = max(A1[j - 1], A2[j]);
        }
    }
    DP[0][0] = INF;
    DP[H - 1][W] = INF;
    /*
    for(int i = 0; i < H; i++){
        for(int j = 0; j <= W; j++){
            cout << DP[i][j] << " ";
        }cout << endl;
    }cout << endl;
    */
    for(int i = 1; i < H; i++){
        long long int num = INF;
        for(int j = W; j >= 0; j--){
            num = min(num, DP[i - 1][j]);
            DP[i][j] = max(DP[i][j], num);
        }
    }
    long long int ret = INF;
    for(int i = 0; i <= W; i++){
        ret = min(ret, DP[H - 1][i]);
    }
    return ret;
}

int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A[i][j];
            S1 = min(A[i][j], S1);
            S2 = max(A[i][j], S2);
        }
    }
    long long int ans = INF;
    ans = min(ans, check());
    for(int i = 0; i < H; i++){
        reverse(A[i], A[i] + W);
    }
    ans = min(ans, check());
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            A[i][j] = S2 - (A[i][j] - S1);
        }
    }
    ans = min(ans, check());
    for(int i = 0; i < H; i++){
        reverse(A[i], A[i] + W);
    }
    ans = min(ans, check());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 68772
#include <iostream>
#define INF 1000000000
using namespace std;

int main(void){
    int n,m;
    cin>>n>>m;
    int a[n],b[n],c[m],d[m];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    for(int i=0;i<m;i++) cin>>c[i]>>d[i];
    
    for(int i=0;i<n;i++){
        int min_dis,id=0;
        min_dis = INF;
        for(int j=0;j<m;j++){
            int dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if( dis < min_dis ){
                min_dis = dis;
                id = j+1;
            }
        }
        cout<<id<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
 
 
int main() {
    vector<int> A(4);
    for (int i = 0; i < 6; i++){
        int a;
        cin >> a;
        A.at(a - 1)++;
    }
    sort(ALL(A));
    if (A.at(0) == 1 && A.at(1) == 1 && A.at(2) == 2 && A.at(3) == 2){
        cout << "YES" << endl;
    } 
    else {
        cout << "NO" << endl;
    }
}

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

int N,C;
int D[500][500];
int c[3][30],x;

int main(){
	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++){
			cin >> x;
			c[(i+j)%3][x-1]++;
		}
	
	int ans=1<<30;
	for(int i=0;i<C;i++)
		for(int j=0;j<C;j++)
			if(i!=j)
				for(int k=0;k<C;k++)
					if(i!=k && j!=k){
						int tt=0;
						for(int l=0;l<C;l++) tt+=D[l][i]*c[0][l];
						for(int l=0;l<C;l++) tt+=D[l][j]*c[1][l];
						for(int l=0;l<C;l++) tt+=D[l][k]*c[2][l];
						if(ans>tt) ans=tt;
					}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000001
 
using namespace std;
 
 
 
int main(void) {
  string s;
  int count=0;
  
  cin>>s;
  
  FOR(i,0,3){
    if(s[i]=='+'){
      count++;
      }else{
        count--;
        }
    }
    
    cout<<count<<endl;
   
	return 0;
}

Measured memory_bytes: 256
"use strict"

function main(input) {
  input = input.split(/\s|\n/).map(v => ~~v)
  const nums = input.slice(1, -1)
  let nums2 = []
  for (let i = 0; i < nums.length; i++) {
    nums2.push(nums[i] - 1)
    nums2.push(nums[i])
    nums2.push(nums[i] + 1)
  }
  const nums3 = nums2.sort((a, b) => a - b)
  let ans = 1
  let tmpcnt = 1
  let tmp = Number.MAX_SAFE_INTEGER
  for (let i = 0; i < nums3.length; i++) {
    if (tmp == nums3[i]) {
      tmpcnt++
    } else {
      tmp = nums3[i]
      tmpcnt = 1
    }
    ans = Math.max(tmpcnt, ans)
  }
  console.log(ans)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 31280
#include<iostream>
using namespace std;
typedef long long ll;

const int MAX_N = 2 * 1e3 + 2;
const int MAX_M = 2 * 1e3 + 2;
const ll MOD = 1e9 + 7;

int S[MAX_N], T[MAX_M];
ll dp[MAX_N][MAX_M];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    for (int i = 1; i <= N; i++) cin >> S[i];
    for (int i = 1; i <= M; i++) cin >> T[i];
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) dp[i][0] = 1;
    for (int i = 1; i <= M; i++) dp[0][i] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (S[i] == T[j]) {
                dp[i][j] = (dp[i][j] + (dp[i - 1][j] + dp[i][j - 1]) % MOD) % MOD;
            }
            else {
                dp[i][j] = (dp[i][j] + ((dp[i - 1][j] + dp[i][j - 1]) % MOD - dp[i - 1][j - 1] + MOD) % MOD);
            }
        }
    }
    cout << dp[N][M] << endl;
    return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
bool comp(pair<ll,int> &a,pair<ll,int> &b){
  return a.first>b.first;
}
int main()
{
  int n,k;cin >> n >> k;
  vector<pair<ll,int>> p(n);
  rep(i,n){
    int t;ll d;
    cin >> t >> d;
    p[i] = {d,t};
  }

  sort(p.begin(), p.end(),comp);
  ll sum = 0;
  ll num = 0;
  map<ll,int> mp;
  vector<ll> a;
  rep(i,k){
    if(mp[p[i].second]==0) num++;
    else a.push_back(p[i].first);
    sum += p[i].first;
    mp[p[i].second]++;
  }
  vector<ll> b;
  for(int i=k;i<n;++i){
    if(mp[p[i].second]==0) b.push_back(p[i].first);
    mp[p[i].second]++;
  }

  reverse(a.begin(), a.end());
  ll res = num*num+sum;
  rep(i,min(a.size(),b.size())){
    sum -= a[i]-b[i];
    num++;
    res = max(res,num*num+sum);
  }
  cout << res << "\n";
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;

    cout << n / 3 << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

def main():
    money = 1000
    n = 0
    
    for i in range(1, len(a)):
        if (a[i-1] < a[i]):   # 買う
            n = money // a[i-1]
            money += (a[i] - a[i-1]) * n

    print(money)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8828
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut xs = vec![];
	let mut ys = vec![];
	let mut vert = vec![];
	let mut horz = vec![];
	for _ in 0..n {
		let y0: i32 = s.next().unwrap().parse().unwrap();
		let y1: i32 = s.next().unwrap().parse().unwrap();
		let x: i32 = s.next().unwrap().parse().unwrap();
		vert.push((y0, y1, x));
		xs.push(x);
		ys.push(y0);
		ys.push(y1);
	}
	for _ in 0..m {
		let y: i32 = s.next().unwrap().parse().unwrap();
		let x0: i32 = s.next().unwrap().parse().unwrap();
		let x1: i32 = s.next().unwrap().parse().unwrap();
		horz.push((y, x0, x1));
		xs.push(x0);
		xs.push(x1);
		ys.push(y);
	}
	xs.sort();
	xs.dedup();
	ys.sort();
	ys.dedup();
	let mut field = vec![vec![false; xs.len() + 1]; ys.len() + 1];
	let mut fence = vec![vec![0u8; xs.len() + 1]; ys.len() + 1];
	for (y0, y1, x) in vert.iter() {
		let yl = ys.binary_search(y0).unwrap() + 1;
		let yr = ys.binary_search(y1).unwrap();
		let x = xs.binary_search(x).unwrap();
		for y in yl..=yr {
			fence[y][x] |= 2;
			fence[y][x + 1] |= 8;
		}
	}
	for (y, x0, x1) in horz.iter() {
		let xl = xs.binary_search(x0).unwrap() + 1;
		let xr = xs.binary_search(x1).unwrap();
		let y = ys.binary_search(y).unwrap();
		for x in xl..=xr {
			fence[y][x] |= 4;
			fence[y + 1][x] |= 1;
		}
	}

	let mut q = vec![];
	let ystart = ys.binary_search(&0).unwrap_or_else(|i| i);
	let xstart = xs.binary_search(&0).unwrap_or_else(|i| i);

	q.push((ystart as i32, xstart as i32));
	while let Some((y, x)) = q.pop() {
		field[y as usize][x as usize] = true;
		for (i, (dy, dx)) in [(-1, 0), (0, 1), (1, 0), (0, -1)].iter().enumerate() {
			let ny = y + dy;
			let nx = x + dx;
			if ny >= 0
				&& ny <= ys.len() as i32
				&& nx >= 0 && nx <= xs.len() as i32
				&& fence[y as usize][x as usize] & (1 << i) == 0
				&& !field[ny as usize][nx as usize]
			{
				q.push((ny, nx));
			}
		}
	}
	let mut ans = 0i64;
	for y in 0..=ys.len() {
		for x in 0..=xs.len() {
			if field[y][x] {
				ans = ans.saturating_add(if y == 0 || y == ys.len() || x == 0 || x == xs.len() {
					std::i64::MAX
				} else {
					let h = ys[y] as i64 - ys[y - 1] as i64;
					let w = xs[x] as i64 - xs[x - 1] as i64;
					h * w
				});
			}
		}
	}
	if ans == std::i64::MAX {
		println!("INF");
	} else {
		println!("{}", ans);
	}
}


Measured memory_bytes: 58068
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  cout<<(1000-n%1000)%1000<<endl;
  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    string s;
    cin >> s;
    string ans = "No";
    rep(i,0,2){
        if(s[i] == '7')ans = "Yes";
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3600
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::cmp::min;

fn main() {
    let abk: Vec<u32> = read_vec();
    let a = abk[0];
    let b = abk[1];
    let mut k = abk[2];

    let mut i: u32 = 100;

    loop {
        if a % i == 0 && b % i == 0 {
            k -= 1;
        }
        if k == 0 {
            break;
        }
        i -= 1;
    }

    println!("{}", i);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll dp[100010][3];
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(3,0));
    rep(i,n)rep(j,3)cin >> a[i][j];
    rep(i,n){
        rep(j,3)rep(k,3)if(j != k)chmax(dp[i+1][k],dp[i][j] + a[i][k]);
    }
    ll res = 0;
    rep(i,3)res = max(dp[n][i],res);
    cout << res << endl;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int i;
  for(i = 0; i < 12; i++)
  {
    cout << s.at(i);
    if(i == 3)
    {
      cout << " ";
    }
  }
  cout << endl;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, a[20], b[20], x[20], v[20], par[20], res = 1e9;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	forn (i, n) cin >> a[i];
	forn (i, n) cin >> b[i];

	for (int mk = 0; mk < (1 << n); mk++) {
		forn (i, n) {
			if (mk & (1 << i)) {
				x[i] = v[i] = a[i];
				par[i] = i % 2;
			} else {
				x[i] = v[i] = b[i];
				par[i] = 1 - i % 2;
			}
		}
		sort(x, x + n);

		int p = 0, f = 1;

		forn (i, n) {
			int ind = -1;

			for (int j = i; j < n; j++)
				if (x[i] == v[j] && i % 2 == par[j]) {
					ind = j;
					break;
				}

			if (ind == -1) {
				f = 0;
				break;
			}

			for (int j = ind - 1; j >= i; j--) {
				swap(v[j], v[j + 1]);
				swap(par[j], par[j + 1]);
				p++;
			}
		}

		if (f) res = min(res, p);
	}

	if (res == 1e9) cout << -1 << endl;
	else cout << res << endl;

	return 0;
}


Measured memory_bytes: 3592
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 1000005

int main(){
	int n, a[105], tmp, ans = 0;
	cin >> n;
	fill(a, a+105, 0);
	for(int i = 0;i < n;i++){
		cin >> tmp;
		a[tmp]++;
	}
	for(int i = 103;i > 0;i--){
		a[i] += a[i+1];
		if(i <= a[i]){
			ans = i;break;
		}
	}
	/*for(int i = 0;i < 15;i++){
		//cout << a[i] << " ";
		if(i <= a[i])ans = i;
		else break;
	}*/
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main()
{
    int n;
    char s[110], t[110] ,ans[220];
    scanf("%d", &n);
    scanf("%s %s", s, t);

    for (int i = 0; i < n; i++){
        ans[2 * i] = s[i];
        ans[2 * i + 1] = t[i];
        printf("%c%c", s[i], t[i]);
    }
    printf("\n");

    return 0;
}

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

//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3", "Ofast", "unroll-loops", "fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define int long long
#define endl '\n'

using namespace std;

signed main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
#define debegin printf("debug\nbegin\n")
#define deend printf("debug\nend\n")
#define isfind printf("find\n")
template<class T>inline void rread(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
int main(){
	int n,a,b;
	rread(n);rread(a);rread(b);
	if(a>b)puts("0");
	else if(n==1&&a!=b)puts("0");
	else{
		ll mini=b-a;
		ll maxi=1ll*(b-a)*(n-1);
		printf("%lld\n",maxi-mini+1);
	}
	return 0;
}

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

int updown(int i, int j){
    if(i<j) return 1;
    if(i>j) return 0;
}
int main() {
	int N; cin >> N;
	int A[100010];
	for(int i=0; i<N; ++i) cin >> A[i];
	int P=1;
	int ud=2;
	for(int i=1; i<N; ++i){
	    if(A[i-1]!=A[i]){
	        if(ud!=2 && ud!=updown(A[i-1], A[i])){
	            ++P;
	            ud=2;
	        }
	        else ud=updown(A[i-1], A[i]);
	    }
	}
	cout << P << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
  int N;
  int i,k;
  int num[111] = {0};
  int a,b;
  int ans = 0;
  cin >> N;
  for(i=1;i<=N;i++){
    a = i % 10;
    int j = i;
    while(j){
      b = j;
      j /= 10;
    }
    num[10*b+a]++;
  }
  for(i=1;i<=9;i++)
    for(k=1;k<=9;k++)
      ans += num[10*i+k] * num[10*k+i];
  cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

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

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> G[100010];
int N,A,B;

int dfs(int x, int l)
{
	vector<int> u;
	for (int y : G[x]) if (y != l){
		u.push_back(dfs(y,x));
	}

	int mx = 0;
	for (int i=0;i<u.size();i++) mx = max(mx,u[i]);
	if (G[x].size() == 2){
		mx++;
		if (u.size() == 2){
			B = max(B, u[0] + u[1] + 1);
		}
		else{
			B = max(B,mx);
		}
	}
	else{
		sort(u.rbegin(),u.rend());
		if (u.size() >= 2){
			B = max(B, u[0] + u[1]);
		}
	}
	return mx;
}

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<N;i++){
		int x,y; scanf ("%d %d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for (int i=1;i<=N;i++) if (G[i].size() == 1) A++;

	dfs(1,0);
	printf ("%d\n",A+B);

	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n, ara[100001], k;

    cin >> n >> k;

    for(int i = 0; i < n; i++)cin >> ara[i];

    int dp[100001];

    for(int i = 0; i < n + 2; i++)dp[i] = INT32_MAX;

    dp[0] = 0, dp[1] = abs(ara[0] - ara[1]);

    for(int i = 2; i < n; i++)
        for(int j = 1; j <= k && j <= i; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(ara[i] - ara[i - j]));

    cout << dp[n - 1] << endl;



    return 0;
}


Measured memory_bytes: 1024
def ncr(n, r): 
    p = 10**9 + 7
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p
    return (num * pow(den,  
            p - 2, p)) % p
  
r1, c1, r2, c2 = [int(i) for i in input().split()]
r1 += 1
c1 += 1
r2 += 1
c2 += 1
print((ncr(r2 + c2, c2) - ncr(r2 + c1 -1, c1-1) - ncr(c2+r1-1, r1-1) + ncr(r1+c1-2, c1-1))%(10**9+7))

Measured memory_bytes: 38512
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
int dp[maxn][3];
int a[maxn],b[maxn],c[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d%d%d",&a[i],&b[i],&c[i]);
    memset(dp,-INF,sizeof(dp));
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    }
    printf("%d\n",max(dp[n][0],max(dp[n][1],dp[n][2])));
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 2560
n=int(input())
du=""
f=True
ans=1
for j in input().split():
  i=int(j)
  if f==True:
    i0=i
    f=False
  if (du=="u" and i<i0) or (du=="d" and i>i0):
    ans+=1
    du=""
  elif i > i0:
    du="u"
  elif i < i0:
    du="d"
  i0=i
print(ans)

Measured memory_bytes: 11484
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		while(true)
		{
			int x = sc.nextInt(); //prev VAT rate
			int y = sc.nextInt(); //aftr VAT rate
			int s = sc.nextInt(); //aftertax before change
			
			if(x == 0 && y == 0 && s == 0)return;
			
			long ans = 0;
			
			for(int p1 = 1; p1 <= s-1; p1++)
			{
				long aftp1 = p1 * (100+x);
				aftp1 /= 100;
				
//				System.out.println("\nif p1 is " + p1 + ", aftp1 becomes " + aftp1);
				
				long aftp2 = s - aftp1;
				
//				System.out.println("which means aftp2 is " + aftp2);
				
				if(aftp2 < 1)break;
				
				//so how much would max p2 be?
				
				long minpr2 = aftp2 * 100 / (100 + x);
				
//				System.out.println("minpr2 " + minpr2);
				
				long reaftp2 = minpr2 * (100+x);
				reaftp2 /= 100;
				
				while(reaftp2 <= aftp2)
				{
					minpr2++;
					
					reaftp2 = minpr2 * (100+x);
					reaftp2 /= 100;
				}
				minpr2--;
				reaftp2 = minpr2 * (100+x);
				reaftp2 /= 100;
				long maxpr2 = minpr2;
//				System.out.println("maxpr2 " + maxpr2 + " -> reaftp2 = " + reaftp2);
				
				long cur = ((p1 * (100 + y)/100)  +  (maxpr2 * (100 + y)/100));
				
				if(aftp1 + reaftp2 != s)
				{
//					System.out.println("MISMATCH not " + s);
//					System.out.println("ori " + p1 + " " + maxpr2);
//					System.out.println("tax1 " + aftp1 + " " + reaftp2 + "\n");
				}
				if(aftp1 + reaftp2 == s)
				{
//					if(cur > ans)System.out.println("new " + p1 + " " + maxpr2);
					ans = Math.max(ans, cur);
				}
				
			}
			
			System.out.println(ans);
//			System.out.println("end");
		}

	}

}



Measured memory_bytes: 30068
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
#include <cstdint>
#include<tuple>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;

int main(void){
  double n;
  cin>>n;
  if((int)n%2==1){
    cout<<setprecision(10)<<((n+1.0)/2.0)/n<<endl;
  }
  else{
    cout<<setprecision(10)<<1.0/2.0<<endl;
  }
  
  return 0;
}


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

int main(void){
    int i,n,ac=0,wa=0,tle=0,re=0;
    char count[5];

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s",count);
        if(strcmp(count,"AC")==0){
            ac++;
        }else if(strcmp(count,"WA")==0){
            wa++;
        }else if(strcmp(count,"TLE")==0){
            tle++;
        }else{
            re++;
        }
    }

    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ac,wa,tle,re);

    return 0;
}

Measured memory_bytes: 1736
#include<stdio.h>
#include<string.h>

#define YES "Yes"
#define NO "No"

int main()
{
    int n, answer = 0;
    int d_array[100][2];

    scanf("%d", &n);

    for (int i = 0; i<n; i++)
    {
        scanf("%d %d", &d_array[i][0], &d_array[i][1]);
    }

    for (int i = 0; i<n; i++)
    {
        if (d_array[i][0] == d_array[i][1])
        {
            answer ++;
        } else {
            answer = 0;
        }

        if (answer >= 3)
        {
            break;
        }
    }

    if (answer >= 3)
        printf("%s", YES);
    else
        printf("%s", NO);
    

    return 0;
}

Measured memory_bytes: 1732
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	int[][] A;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		A = new int[2][N];
		for (int i = 0; i < 2; ++i) {
			String[] tokens = in.readLine().split(" ");
			for (int j = 0; j < N; ++j) {
				A[i][j] = Integer.parseInt(tokens[j]);
			}
		}
		int[][] memo = new int[2][N];
		memo[0][0] = A[0][0];
		for (int i = 1; i < N; ++i) {
			memo[0][i] = memo[0][i - 1] + A[0][i];
		}
		memo[1][0] = memo[0][0] + A[1][0];
		for (int i = 1; i < N; ++i) {
			memo[1][i] = Math.max(memo[0][i], memo[1][i - 1]) + A[1][i];
		}
		System.out.println(memo[1][N - 1]);

	}

	void calc() {
	}

	void showResult() {
	}
}

Measured memory_bytes: 21460
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<math.h>
#include<stack>
#include<sstream>
#include<queue>
#include<list>
#include<iomanip>
#include<bitset>
#include<limits.h>
#include <bits/stdc++.h> //
#define MOD  1000000007
#define BIG  1000000007
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define vi vector<int>;
#define pi pair<int,int>;
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
using namespace std ; 
	
int main(){
	IO ; 
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ll d ,n ; 
	cin >> d >> n  ;
	if(d == 0 && n == 100){
		cout << 101 << endl ; 
		return 0 ; 
	}
	if(d ==1 && n == 100){
		cout << 10100 ;
		return 0 ; 
	}
	if(d == 2 && n == 100){
		cout << "1010000" ; 
		return 0 ;
	}
	
	ll res = 0 ;
	if(d){
	 res  = 1;  
	for(int i =0 ; i<d ; i++){
		res *= 100 ; 
	}
		cout << n*res << endl ;
           return 0 ; 
	}

	cout << 1ll*n << endl ; 


	return 0 ; 
	}


Measured memory_bytes: 256
import numpy as np

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = 2**18

f = np.array([0]*d)
for i in a:
    f[i]+=1

tf = np.fft.fft(f)
f = np.fft.ifft(tf*tf)
f = [int(i+0.5) for i in f]

ans=0
for i in range(len(f)-1,0,-1):
    if f[i]<=m:
        ans+=i*f[i]
        m-=f[i]
    elif f[i]>m:
        ans+=i*m
        break
print(ans)

Measured memory_bytes: 48464
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>s;
	if(n&1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n/2;i++)
		if(s[i]!=s[i+n/2])
		{
			cout<<"No"<<endl;
			return 0;
		}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_grid = sc.nextInt();
		int Alice_place = sc.nextInt();
		int Borys_place = sc.nextInt();


		while (Alice_place>=1 && Borys_place<= total_grid) {
			if (Borys_place != Alice_place + 1) {
				Alice_place ++;
			}
			else {
				Alice_place --;
			}

			if (Alice_place != Borys_place - 1) {
				Borys_place --;
			}
			else {
				Borys_place ++;
			}
		}

		if (Alice_place <1) {
				System.out.println("Borys");
		}
		else {
			System.out.println("Alice");
		}

	}
}

Measured memory_bytes: 23764
h, w = map(int, input().split())
S=[["."]+list(input())+["."] for i in range(h)]
S=[["."]*(w+2)]+S+[["."]*(w+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if S[i][j] == ".":
            S[i][j] = (str([S[i-1][j], S[i+1][j], S[i][j-1], S[i][j+1], S[i-1][j-1], S[i-1][j+1], S[i+1][j-1], S[i+1][j+1]].count("#")))
for k in range(len(S[1:h+1])):
    print(*S[1:h+1][k][1:w+1], sep="")

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
#define FORK(k,n) for(int k=0;k<n;k++)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int A,B,C,N;
  int cnt = 0;
  cin >> A >> B >> C >> N;
  
  int a=0,b=0;
  while(true){
    while(true){
      if  (N-a*A-b*B < 0) break;
      if  ((N-a*A-b*B)%C == 0 ) cnt++;
      b++;
    }
    if (b==0) break; 
    a++;
    b=0;
  }

  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vec(type) vector<type>

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

	if (n==2) cout << "Borys" << endl;
	else if (a==1 && b==2) cout << "Borys" << endl;
	else if (a==n-1 && b==n) cout << "Borys" << endl;
	else if ((b-a)%2==0) cout << "Alice" << endl;
	else cout << "Borys" << endl;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main{
        public static void main(String[] args){

                Scanner sc = new Scanner(System.in);
                String[] input = sc.nextLine().split(" ");
                sc.close();
        int N,X,T;
        N = Integer.parseInt(input[0]);
        X = Integer.parseInt(input[1]);
        T = Integer.parseInt(input[2]);

                int result= (N / X) * T ;
        if(N%X != 0){
            result += T;
        }
        System.out.println(result);
        }
}


Measured memory_bytes: 35836