akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);

template<class T> inline T sqr(T x) {return x*x;}

int main() {
	int n;
	cin >> n;
	VI l(2*n);
	REP(i,0,2*n) cin >> l[i];
	sort(all(l));
	int cnt = 0;
	REP(i,0,n) cnt += min(l[2*i], l[2*i+1]);
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a[] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
    ll x, y;
    cin >> x >> y;
    if (a[x] == a[y])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll x;
    cin>>x;
    int ans = x/500 * 1000;
    x -= x/500 * 500;
    ans += x/5 * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxN=258;
int dp[maxN][8];
vector<int>g[8];
bool mrk[maxN][8];
int n,m;
int main(){
  cin>>n>>m;
  while(m--){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dp[1][0]=1;
  for(int mask=3;mask<(1<<n);mask++){
    vector<int>v;
    for(int i=0;i<n;i++){
      if(mask&(1<<i))
	mrk[mask][i]=true;
    }
    for(int i=0;i<n;i++){
      if(mask&(1<<i))
	for(int j=0;j<g[i].size();j++){
	  if(mrk[mask][g[i][j]])
	    dp[mask][i]+=dp[mask-(1<<i)][g[i][j]];
	}
    }
  }
  int ans=0;
  for(int i=0;i<n;i++)ans+=dp[(1<<n)-1][i];
  cout<<ans<<endl;
}


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

int main() {
	int N; cin >> N;
	vector<int> p(N + 1);
	for (int i = 0; i < N; ++i) {
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 1; i < N-1; ++i) {
		if ((p[i]<p[i-1])&&(p[i]>p[i+1])) {
			ans++;
		} else if ((p[i]>p[i-1])&&(p[i]<p[i+1])) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); 
const ll N = 5e5 + 5;

int main() {
    FAST;
    ll n, ans = 0, k, i, t, j, m, x = 0, y = 0, z, c = 0;
    string s;
    cin >> s;
    n = s.size();
    if ( n % 2 ) out("No");
    for ( i = 0 ; i < n ; i += 2 ){
        if ( s[i] != 'h' || s[i + 1] != 'i' ) 
            out("No");
    }
    out("Yes");
}


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

int main(){
  int N;
  cin >> N;
  int a[3*N];
  for (int i=0;i<3*N;i++) cin >> a[i];
  sort(a, a+3*N);

  int64_t sum = 0;
  for (int i=N;i<3*N;i+=2){
    sum += a[i];
  }

  cout << sum << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

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

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int main() {
	int N, A, i;
	scanf("%d %d", &N, &A);
	if (N % 500 > A) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define PI 3.14159265358979323846
using namespace std;

int main()
{
  ll n,m;
  cin >> n >> m;
  ll arr[50]={0};
  fr(i,0,n)
  {
      ll x;
      cin >> x;
      fr(i,0,x)
      {
          ll y;
          cin >> y;
          arr[y]++;
      }
  }
  ll ans=0;
  fr(i,0,50)
  {
      if(arr[i]==n)ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
MOD = 998244353

N = int(input())
A = [int(input()) for _ in range(N)]
S = sum(A)

# 赤の和がS/2以上となるものを求めて3倍
# 和に対して何通りあるのか

dp = np.zeros(S+1, dtype=np.int64)
dp[0] = 1
for a in A:
    prev = dp
    dp = prev * 2 # 赤以外を採用
    dp[a:] += prev[:-a] # 赤
    dp %= MOD

answer = pow(3,N,MOD) - dp[(1+S)//2:].sum() * 3
# 2色が反例となる場合を引きすぎている
if S % 2 == 0:
    dp = np.zeros(S+1, dtype=np.int64)
    dp[0] = 1
    for a in A:
        dp[a:] += dp.copy()[:-a]
        dp %= MOD
    answer += dp[S//2] * 3
answer %= MOD
print(answer)

Measured memory_bytes: 14516
#include<cstdio>
int k,a[100005];
long long maxn=2,minn=2;
int main(){
	scanf("%d",&k);
	for(int i=1;i<=k;++i) scanf("%d",&a[i]);
	for(int i=k;i>=1&&maxn>=minn;--i){
		if(minn%a[i]) minn=minn/a[i]*a[i]+a[i];
		maxn=(maxn/a[i]+1)*a[i]-1;
	}
	if(maxn>=minn) printf("%lld %lld\n",minn,maxn);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, s;
const int MOD = 100000;
int dp[2010][3010];

int main() {
  while (scanf("%d %d %d", &n, &m, &s), n|m|s) {
    MEMSET(dp, 0);
    FOREQ(i, 0, m) {
      dp[i][0] = 1;
    }
    REP(iter, n * n) {
      dp[m][s] = 0;
      for (int i = m; i >= 1; i--) {
        FOREQ(j, 0, s - i) {
          if (i > (s - j) / (n * n - iter)) {
            break;
          }
          dp[i][j + i] = dp[i - 1][j];
        }
        REP(j, i) { dp[i][j] = 0; }
      }
      FOREQ(i, 1, m) {
        FOREQ(j, 0, s) {
          if (i > (s - j + i) / (n * n - iter)) { break; }
          dp[i][j] += dp[i - 1][j];
          dp[i][j] %= MOD;
        }
      }
      if (iter == 0) {
        FOREQ(i, 0, m) {
          dp[i][0] = 0;
        }
      }
    }
    printf("%d\n", dp[m][s]);
  }
}

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

int main()
{
   int n,k,sum=0;
   cin >> n >> k;
    vector<int> v(n);
   for (int i=0 ; i < n; i++){
       cin>>v[i]; 
   }

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

   for (int i=0; i<k; i++)
    sum += v[i];

    cout << sum <<endl;
    

}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}
namespace my {
    template <class Num, class Pred>
    Num upper_bound(Num l, int r, Pred&& is_good) {
        if (l == r) {
            return r;
        }
        if (!is_good(l)) {
            return l;
        }
        while (r - l > 1) {
            int m = l + (r - l) / 2;
            if (is_good(m)) {
                l = m;
            } else {
                r = m;
            }
        }
        return r;
    }
}

#define WHATIS(expr) #expr " = " << (expr)

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    for (const auto& x: v) {
        os << x << ' ';
    }
    return os;
}

template <typename U, typename V>
inline auto divc(U u, V v) {
    return (u + v - 1) / v;
}

#define DEFINE_TO_TUPLE_FUNC(...)                                              \
    auto to_tuple() const {                                                    \
        return std::make_tuple(__VA_ARGS__);                                   \
    }

#define DEFINE_TUPLE_COMPARATOR_FUNCTION(FUNC_NAME, TYPE)                      \
    bool FUNC_NAME(TYPE u, TYPE v) {                                           \
        return u.to_tuple() < v.to_tuple();                                    \
    }

int inf = 1488228228;

template <class Iter>
int len_increasing(int maxn, Iter first, Iter last) {
    std::vector<int> dp(maxn + 1, inf);
    dp[0] = -inf;
    for (; first != last; ++first) {
        int x = std::upper_bound(dp.begin(), dp.end(), *first) - dp.begin();
        if (dp[x - 1] < *first && *first < dp[x]) {
            dp[x] = *first;
        }
    }
    return std::lower_bound(dp.begin(), dp.end(), inf) - dp.begin() - 1;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    if (a + b - 1 > n || divc(n, a) > b) {
        cout << -1 << endl;
        exit(0);
    }
    int mex = n + 1;
    std::vector<int> res(n);
    for (int l = 0; l < n; ) {
        // assert((n - l) > (b - 1));
        int x = (n - l) - (b - 1);
        x = std::min(a, x);
        for (int i = 0; i < x; ++i) {
            res[l + i] = mex - x + i;
        }
        l = l + x;
        b -= 1;
        mex -= x;
    }

    for (int x: res) {
        cout << x << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 3456
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
for i in range(N, 0, -1):
  t = B[(i-1)::i]
  s = sum(t)%2
  B[i-1] = 0 if s == A[i-1] else 1

ans = sum(B)
print(ans)
ans_b = []
if ans > 0:
  for i in range(N):
    if B[i] > 0:
      ans_b.append(str(i+1))
  print(' '.join(ans_b))

Measured memory_bytes: 19388
#include<stdio.h>
#include<math.h>

int main(){
	int  a,b;
	while(1){
		scanf("%d%d",&a,&b);
		if(!(a|b))return 0;
		printf("%lf\n",2*sqrt(((double)a/2)*((double)a/2)+b*b)*a+a*a);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  cin >> s;
  if( s == 'A'){
    cout << 'T';
  }
  else if( s == 'T'){
    cout << 'A';
  }
  else if(s == 'G'){
    cout << 'C';
  }
  else{
    cout << 'G';
  }
}

Measured memory_bytes: 256
loop do
    m,f,r = gets.split.map(&:to_i)
    break if m == -1 && f == -1 && r == -1
    x = m + f
    if m == -1 || f == -1 then
        puts 'F'
    elsif x >= 80 then
        puts 'A'
    elsif x >= 65 then
        puts 'B'
    elsif x >= 50 then
        puts 'C'
    elsif x >= 30 then
        if r >= 50 then
            puts 'C'
        else
            puts 'D'
        end
    else
        puts 'F'
    end
end


Measured memory_bytes: 6868
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int N, A[100005], T, mdp[100005] = { 1000000000 }, diff[100005] = { 0 };

int main() {

	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if(i > 0) mdp[i] = min(mdp[i - 1], A[i]);
		else mdp[i] = A[i];
		
		diff[i] = max(A[i] - mdp[i], 0);
	}

	sort(diff, diff+N);

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (diff[i] == diff[N-1]) cnt++;
	}

	cout << cnt << endl;
	cerr << cnt << endl;

	return 0;
}

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

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

static void A_task();

int main()
{
	A_task();
	
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int X, A;
	scanf(" %d %d", &X, &A);

	printf("%d\n", X < A ? 0 : 10);
}


Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
partic = [0 for _ in range(N)]

for a in A:
    partic[a-1] += 1

for p in partic:
    if p+K-Q > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8660
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
							for(int j=0;j<n;j++){   \
								cout<<a[i][j]<<" "; \
							}                       \
							cout<<endl;             \
						}
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define len(s) (ll)(s.size())
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
	fast_io()
 

	ll t;
	//cin>>t;
	t=1;
	while(t--){
		ll n;
		cin>>n;
		ll h[n],dp[n];
		rep(n){
			cin>>h[i];
		}
		mset(dp,0);
		dp[1]=abs(h[1]-h[0]);
		fori(i,2,n-1){
			dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
		}
		cout<<dp[n-1];
	}
	return 0;
}

Measured memory_bytes: 1792
use std::cmp::max;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let h: usize = read(&mut stdin_lock, &mut buf, b' ');
    let w: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut sv = Vec::new();
    for _ in 0..h {
        let s: String = read(&mut stdin_lock, &mut buf, b'\n');
        let xv: Vec<char> = s.chars().collect();
        sv.push(xv);
    }

    let mut xv = vec![vec![0i32; w]; h];
    for y in 0..h {
        let mut c = 0;
        for x in 0..w {
            if sv[y][x] == '.' {
                c += 1;
            } else {
                c = 0;
            }
            xv[y][x] = c;
        }
        for x in 1..w {
            let rx = w - x - 1;
            if xv[y][rx] != 0 && xv[y][rx] < xv[y][rx + 1] {
                xv[y][rx] = xv[y][rx + 1];
            }
        }
    }

    let mut yv = vec![vec![0i32; w]; h];
    for x in 0..w {
        let mut c = 0;
        for y in 0..h {
            if sv[y][x] == '.' {
                c += 1;
            } else {
                c = 0;
            }
            yv[y][x] = c;
        }
        for y in 1..h {
            let ry = h - y - 1;
            if yv[ry][x] != 0 && yv[ry][x] < yv[ry + 1][x] {
                yv[ry][x] = yv[ry + 1][x];
            }
        }
    }

    let mut ans = 0;
    for y in 0..h {
        for x in 0..w {
            ans = max(ans, xv[y][x] + yv[y][x]);
        }
    }
    println!("{}", if ans > 1 { ans - 1 } else { ans });
}


Measured memory_bytes: 53628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;string s;
    ll N;cin>>N;
    vector<int> a(N);
    REP(i,N) cin>>a[i];
    int low=0,high=1<<30;
    const int geta=N+1;
    while(high-low>1){
        int mid=(low+high)/2;
        ll num=0;
        BIT<ll> bit(N*2+10);
        int sum=0;
        bit.add(sum+geta,1);
        for(int i=0;i<N;i++){
            int val;
            if(a[i]<=mid) val=1;else val=-1;
            sum+=val;
            num+=bit.sum(1,sum+geta);
            bit.add(sum+geta,1);
        }
        if(num > (N+1)*N/2/2) high=mid;
        else low=mid;
    }
    cout<<high<<endl;
}


Measured memory_bytes: 2280
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

const double EPS = 1e-8;

using R = long double;
using P = complex<R>;
using L = pair<P,P>;

inline int sgn(const R& r) { return (r>EPS) - (r<-EPS); }
namespace std {
	bool operator < (const P& a, const P& b) {
		return sgn(real(a-b)) ? real(a-b) < 0 : sgn(imag(a-b)) < 0;
	}
	bool operator == (const P& a, const P& b) {
		return sgn(real(a-b)) == 0 && sgn(imag(a-b)) == 0;
	}
}
inline R dot(const P& a, const P& b) {
  return real(a)*real(b) + imag(a)*imag(b);
}
inline R det(const P& a, const P& b) {
  return real(a)*imag(b)-imag(a)*real(b);
}
// a/b
inline P div(const P &a, const P &b) {
  return {dot(b,a)/norm(b), det(b,a)/norm(b)};
}

// PとLについて入力
inline istream& operator>>(istream& is, P& p) {
  R x, y;
  is >> x >> y;
  p = P(x, y);
  return is;
}
inline istream& operator>>(istream& is, L& l) {
  P a, b;
  is >> a >> b;
  l = L(a, b);
  return is;
}

// 線分abから見たcの位置
enum CCW{LEFT=1, RIGHT=2, BACK=4, FRONT=8, ON=16};
int ccw(P a, P b, P c) {
	P p = div(c-a, b-a);
	if(sgn(imag(p)) > 0) return LEFT;
	if(sgn(imag(p)) < 0) return RIGHT;
	if(sgn(real(p)) < 0) return BACK;
	if(sgn(real(p)-1) > 0) return FRONT;
	return ON;
}

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

  L l;
  cin >> l;
  int q;
  cin >> q;
  REP(i, q) {
    P p;
    cin >> p;
    int ret = ccw(l.first, l.second, p);
    if(ret == LEFT) cout << "COUNTER_CLOCKWISE" << endl;
    else if(ret == RIGHT) cout << "CLOCKWISE" << endl;
    else if(ret == BACK) cout << "ONLINE_BACK" << endl;
    else if(ret == FRONT) cout << "ONLINE_FRONT" << endl;
    else if(ret == ON) cout << "ON_SEGMENT" << endl;
  }

  return 0;
}



Measured memory_bytes: 3348
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
bool dfs(int c,int co){
  for(int i=0;i<=n;i++){
    if(c==k)return 1;
    c-=co;
    c+=m-co;
  }
  return 0;
}
int main(){
 
  cin >> n >> m >> k;
  int c=0;
  int co=0;
  for(int i=0;i<=m;i++){
    if(dfs(c,co)){
      cout << "Yes" << endl;
      return 0;
    }
    c+=n;
    co++;
  }
  /*  swap(n,m);
  c=0;
  co=0;
    for(int i=0;i<m;i++){
    c+=n;
    co++;
    if(dfs(c,co)){
      cout << "Yes" << endl;
      return 0;
    }
    }*/
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;

int main()
{
	int n; cin >> n;
	ll ans = 0;
	vector<vector<int>> dp(10, vector<int>(10, 0));
	for(int a = 1; a <= n; ++a)
	{
		string s = to_string(a);
		dp[s[0]-'0'][a%10]++;
	}
	for(int i = 1; i <= 9; ++i)
	{
		for(int j = 1; j <= 9; ++j)
		{
			ans += (dp[i][j] * dp[j][i]);
		}
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string a,b,c;cin>>a>>b>>c;
    int p=1;
    char x;
    string ans;
    while (1){
        if (p==1){
            if (a.size()==0){ans="A";break;}
            x=a[0];
            a=a.substr(1,a.size()-1);
        }else if (p==2){
            if (b.size()==0){ans="B";break;}
            x=b[0];
            b=b.substr(1,b.size()-1);
        }else if (p==3){
            if (c.size()==0){ans="C";break;}
            x=c[0];
            c=c.substr(1,c.size()-1);
        }if (x=='a'){
            p=1;
        }else if (x=='b'){
            p=2;
        }else if (x=='c'){
            p=3;
        }
    }cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
 
  int n,m,i,j;
  int a,b;
  int A[100][100] = {0};
  int B[100] = {0};
  int c[100] = {0};
 
  scanf("%d %d " ,&n,&m);
 
  for(j=0; j<n; j++) {
  for(i=0; i < m; i++) {
    scanf("%d",&a);
    A[j][i] = a;
  }
}
 
  for(j=0; j<m; j++) {
    scanf("%d",&b);
    B[j] = b;
  }
 
  for(j=0;j<n ; j++){ 
  for(i = 0; i<m; i++){
     c[j] = c[j] + A[j][i]*B[i];
    }
  }
 
  for(i=0;i<n;i++) {
    printf("%d\n",c[i]);
  }
  return 0;
}


Measured memory_bytes: 2740
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#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
const double PI=3.14159265358979323846;
const in MOD = 998244353;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};
using T=tuple<int,int,int>;

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

    int n,q;
    cin>>n>>q;
    vector<P> cng(q);
    vector<int> num(q);
    rep(i,q){
        cin>>cng[i].first>>cng[i].second>>num[i];
        cng[i].first--;
        cng[i].second--;
    }

    set<T> a;
    a.emplace(n-1,0,1);
    int x=0,y,z;

    using mint=modint998244353;
    vector<mint> mo(n,0);
    mint ten=1;
    mo[n-1]=1;
    for(int i=n-2;i>=0;i--){
        ten *= 10;
        mo[i]=mo[i+1]+ten;
    }
    mo.emplace_back(0);

    mint sum=mo[0];
    int s,t,u;
    T w;
    auto v=a.lower_bound(T(x,0,0));

    rep(i,q){
        tie(x,y)=cng[i];
        z=num[i];

        v=a.lower_bound(T(x,0,0));
        if(v==a.end()){
            // t=inf;
            goto jump;
        }
        else{
            w=*v;
            tie(s,t,u)=(w); 
        }

        while(y>=t){
            v=a.erase(v);
            if(y>=s){
                if(t>=x) sum -= u*(mo[t]-mo[s+1]);
                if(t<x){
                    a.emplace(x-1,t,u);
                    sum -= u*(mo[x]-mo[s+1]);
                }
            }
            else{
                a.emplace(s,y+1,u);
                if(t>=x) sum -= u*(mo[t]-mo[y+1]);
                if(t<x){
                    sum -= u*(mo[x]-mo[y+1]);
                    a.emplace(x-1,t,u);
                }
            }
            // v=a.lower_bound(T(x,0,0));
            if(v==a.end()) break;
            else{
                w=*v;
                tie(s,t,u)=(w);
            }
        }
        jump:
        a.emplace(y,x,z);
        sum += z*(mo[x]-mo[y+1]);
        int out=sum.val();
        cout<<out<<endl;
    }
}/*
./problem.exe
*/

Measured memory_bytes: 19004
#include "bits/stdc++.h"
using namespace std;

int N;
vector<int> A;

bool check(int X) { //答えはX以上か
	vector<bool> B(N * 2 + 1);
	for (int i = 0; i < N * 2 - 1; i++) {
		B[i + 1] = X <= A[i];
	}
	B[0] = B[1], B[N * 2] = B[N * 2 - 1];
	int L = -1, R = -1;
	for (int i = 0; i < N; i++) {
		if (B[N - i] == B[N - i - 1]) return B[N - i];
		if (B[N + i] == B[N + i + 1]) return B[N + i];
	}
}

int main() {
	cin >> N;
	A.resize(N * 2 - 1);
	for (int i = 0; i < N * 2 - 1; i++) cin >> A[i];
	int OK = 1, NG = N * 2;
	while (NG - OK > 1) {
		int MID = (OK + NG) / 2;
		if (check(MID)) OK = MID;
		else NG = MID;
	}
	cout << OK << endl;
}

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

int main(void){
    long n,c[10][10]={},ans=0;
    cin >> n;
    rep(i,10)rep(j,10){
        for(int k=1;k<=n;k++){
            if(k%10==j&&to_string(k)[0]=='0'+i) c[i][j]++;
        }
    }
    rep(i,10)rep(j,10) ans += c[i][j]*c[j][i];
    cout << ans << endl;
}


Measured memory_bytes: 3736
#include <stdio.h>
#include <math.h>

void Matrixchain(int);
int Min(int, int);

int p[55];
int m[105][105];

int main () {
  int n = 0, y = 0, z = 0, i, j = 0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%d %d",&y,&z);
    if(i == 0) p[j] = y;
    p[++j] = z;
  }

  Matrixchain(n);

  printf("%d\n",m[1][n]);

  

  return 0;
}


void Matrixchain(int x) {
  int i, j, l, k, q;
  float inf = FP_INFINITE;

  for(i = 1 ; i <= x ; i++) m[i][i] = 0;

  for(l = 2 ; l <= x ; l++) {
    for(i = 1 ; i <= x - l + 1 ; i++) {
      j = i + l - 1;
      m[i][j] = 2147483647;

      for(k = i ; k <= j - 1 ; k++) {
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = Min(m[i][j],q);
      }
    }
  
  }
}

int Min(int x, int y) {
  if(x > y) return y;
  else return x;
}



Measured memory_bytes: 2100
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
typedef long long ll;
using namespace std;

ll A[10001], B[10001];

int main () {
    ll N;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for(int i = 0; i < N; i++)
    {
        cin >> B[i];
    }
    ll sa = 0, sb = 0;
    for(int i = 0; i < N; i++)
    {
        if(A[i] > B[i]) {
            sb += A[i] - B[i];
        }
        if(A[i] < B[i]) {
            sa += (ll)((B[i] - A[i]) / 2);
        }
    }
    if(sa >= sb) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;

ll n;
ll a, b, x, y;

int main () {
    ios::sync_with_stdio(false);
    
    cin >> n;
    a = b = 1;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        ll k = max((a+x-1)/x,(b+y-1)/y);
        a = k*x;
        b = k*y;
        
    }
    cout << a + b << endl;
    
    return 0;
}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 5;
void solve(){
    double W, H, x, y;
    cin>>W>>H>>x>>y;
    int b=0;
    if(x==W/2 && y==H/2) b=1;
    double ans=W*H/2;
    cout<<setprecision(6)<<fixed<<ans;
    cout<<" "<<b;

}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n" 
#define MOD 1000000009

const int MAXN = 2e5 +15;
 
using namespace std;

vector<pair<pair<int,int>,int> > adj[1001][1001];

ll dist[1001][1001];

string S[1001];

void solve(){    
    int n,m; cin>>n>>m;
    int sx,sy,fx,fy; cin>>sx>>sy>>fx>>fy;
    sx--;sy--;fx--;fy--;
    for(int i=0; i<n; i++){
        cin>>S[i];
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            dist[i][j] = 1e9;
        }
    }
    

    dist[sx][sy] = 0;

    for(int x=0; x<n; x++){
        for(int y=0; y<m; y++){
            if(S[x][y] == '.' ){
                for(int i=x-2; i<=x+2; i++){
                    for(int j=y-2; j<=y+2; j++){
                        if(i >=0 && j>=0 && i<n && j<m){
                            if(S[i][j] == '.'){
                                if(abs(x-i)+abs(y-j) == 1) adj[x][y].pb({{i,j},0});
                                else adj[x][y].pb({{i,j},1});
                            }
                        }
                    }
                }
            }
        }
    }

    set<pair<int,pair<int,int> > > q;
    q.insert({0,{sx,sy}});

    while(!q.empty()){
        pair<int,int> pp = q.begin()->second;
        q.erase(q.begin());
        for(auto v: adj[pp.f][pp.s]){
            pair<int,int> u = v.f;
            int w = v.s;

            if(dist[u.f][u.s] > dist[pp.f][pp.s] + w){
                q.erase({dist[u.f][u.s],u});
                dist[u.f][u.s] = dist[pp.f][pp.s] + w;
                q.insert({dist[u.f][u.s],u});
            }
        }
    }
    if(dist[fx][fy] == 1e9) cout<<-1;
    else cout<<dist[fx][fy];



}
 
int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);    
    cout<<fixed<<setprecision(12);

    int t =1; //cin>>t;
    for(int i=1; i<= t; i++){
        solve();
        cout<<"\n";
    }
    
    return 0;
}   

Measured memory_bytes: 143064
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#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; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
  	int n,x,t;
  	cin>>n>>x>>t;
  
  	int j;
	j=ceil(n/x);
  
  	if(n%x==0){
    cout<<j*t<<endl;
    }
  
  	else{
    	cout<<j*t+t<<endl;
    }


}

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

int main() {
  int a,b,c;
  
  while(true){
    cin>>a>>b>>c;
    if(a==0&&b==0&&c==0)break;
    int  ans=0;
    for(int i=1;i<c;i++){
      int x=i;
      int y=c-i;

      int bx=-1, by=-1;
      rep(j,x+1)
	{
	  int t = j*(100+a)/100;
	  if(t==x)
	    {
	      bx = j;
	    }
	  
	}
      rep(j,y+1)
	{
	  int t = j*(100+a)/100;
	  
	  //if(y==994)printf("%d %d\n",(int)t, j);
	  if(t==y)by = j;
	}
      if(bx==-1||by==-1)continue;
      
      
      
      int t1=bx*(100+b)/100;
      int t2=by*(100+b)/100;

      // printf("%d %d %d %d %d %d\n",x,y,(int)bx,(int)by,(int)t1,(int)t2);
      
      if(t1+t2>ans){
	ans=t1+t2;
      }
    }

      cout<<ans<<endl;
      
      
    
  }
}

Measured memory_bytes: 3060
import sys, math
input = sys.stdin.readline

N = int(input())
A2E = [int(input()) for _ in range(5)]

prev_ceil = math.ceil(N / A2E[0])
ans = int(prev_ceil)
for i in range(1,len(A2E)):
    ans += 1
    prev = A2E[i-1]
    cur = A2E[i]
    current_ceil = math.ceil(N / cur)
    if (prev_ceil < current_ceil):
        delay = int(current_ceil - prev_ceil)
        ans += delay
        prev_ceil = current_ceil

print(int(ans))

Measured memory_bytes: 38360
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W,L;
long long A[200005] = {};
long long B[200005] = {};
long long C[200005] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};
char cc[1000000] = {};

int main() {


	cin >>N;
	a = 0;
	b = 0;
	c = 0;
	d = 0;
	
	for (int i = 0; i < N; i++) {
		cin >> a;
		vl.push_back(a);
	}
	
	sort(vl.begin(), vl.end());
	reverse(vl.begin(), vl.end());

	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			b += vl[i];
		}
		else {
			c += vl[i];
		}
	}

	cout << b - c << endl;
	
	return 0;

}


Measured memory_bytes: 2304
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()



signed main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<int> > dp(n+1,std::vector<int>(3,0));
  rep(i,n) {
    std::vector<int> a(3);
    rep(j,3) std::cin >> a[j];
    rep(j,3) rep(k,3) if(j!=k) dp[i+1][j] = std::max(dp[i+1][j],dp[i][k]+a[j]);
  }
  print(std::max({dp[n][0],dp[n][1],dp[n][2]}));
  return 0;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    string S[110];
    rep(i, H) cin >> S[i];
    rep(i, H) {
        rep(j, W) {
            bool ok = false;
            if(S[i][j] != '#') continue;
            rep(k, 4) {
                int x = i + dx[k];
                int y = j + dy[k];
                if(x < 0 || x >= H || y < 0 || y >= W) continue;
                if(S[x][y] == '#') ok = true;
            }
            if(!ok) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, w;
    cin >> n >> w;
    const int size = 100000;
    vector<ll> dp(size + 1, MLL);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        int w2, v;
        cin >> w2 >> v;
        for(int j = size; j >= 0; j--){
            if(dp[j] != MLL){
                dp[j + v] = min(dp[j + v], dp[j] + w2);
            }
        }
        // printde(dp);
    }
    for(int i = size; i >= 0; i--){
        if(dp[i] <= w){
            cout << i << '\n';
            return 0;
        }
    }
}


Measured memory_bytes: 1024
import numpy as np

N,D = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(N)]
l = np.array(x)

def d(x):
  cnt = 0
  for i in range(len(x)):
    for p2 in l[i+1:]:
      p1 = x[i]
      d = np.linalg.norm(p1-p2)
      if d - int(d) == 0:
        cnt += 1
  return cnt
    
print(d(x))

Measured memory_bytes: 12504
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    if not (b-a)%(a-1):
        print((b-a)//(a-1) + 1)
    else:
        print((b-a)//(a-1) + 2)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int res =0;
string correct = "CODEFESTIVAL2016";
for(int i = 0; i < 16; ++i){
if(s[i]!=correct[i])res++;
}
cout<<res<<endl;
return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

#define INF 10000000

int main(void){

    string s;
    cin >> s;

    bool even = s.size()%2 == 0;

    if(even){
        if(s[0] == s[s.size()-1]){
            cout << "First" << endl;
        }
        else{
            cout << "Second" << endl;
        }
    }
    else{
        if(s[0] == s[s.size()-1]){
            cout << "Second" << endl;
        }
        else{
            cout << "First" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 512
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = []
x = []
for i in range(m):
    P, X = map(int, input().split())
    p.append(P)
    x.append(X)

for i in range(m):
    print(sum(t) - t[p[i]-1] + x[i])

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


def solve(S: str):
    longest = 0
    count = 0
    for s in S:
        if s in ['A','T','G','C']:
            count += 1
        else:
            count = 0
        if count > longest:
            longest = count
    print(longest)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF (1 << 30)
using namespace std;
using ll = long long;
int A, B;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> A >> B;

    if (B % A == 0) cout << A+B << endl;
    else cout << B-A << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main()
{
    int z,i,m,n,a,b,c,sum=0,t,j,d ;
    int ara[3432] ;
    scanf("%d",&t) ;
    for(i=0 ; i<t ; i++)
    {
        scanf("%d",&ara[i]) ;
    }
    for(i=0 ; i<t ; i++)
    {


        d=ara[i] ;
        if(d%2==0)
        {

            if(d%3==0||d%5==0)
            {
               c=0 ;
            }
            else
            {
               c=1 ;
               break ;
            }
        }

    }
    if(c==1)
    {
        printf("DENIED") ;
    }
    else
    {
        printf("APPROVED") ;
    }

  return 0 ;
}


Measured memory_bytes: 128