akhauriyash/Code-Regression huggingface dataset:
// Problem : D - Dice in Line
// Contest : AtCoder - AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,k;
    cin>>n>>k;
    db ans = 0;
    int sum = 0;
    vi a(n);
    for(int &i : a) cin>>i;
    for(int i=0;i<n;i++){
        if(i < k) sum += a[i];
        else{
            db cur = (db)(sum+k)/2;
            ans = max(ans,cur);
            sum -= a[i-k];
            sum += a[i];
        }
    }
    db cur = (db)(sum+k)/2;
    ans = max(ans,cur);
    cout<<fixed<<setprecision(12)<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

int main (){
    int N;
    long long w=0;
    
    cin >> N;
    for (int i=0; i<=N; i++){
        if (i%3==0&&i%5==0)w=w;
        else if (i%3==0||i%5==0)w=w;
        else w+=i;
    }
    cout << w << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	typedef long long ll;
	ll n;
	cin >> n;
	ll x[200000];
	ll y[200000];
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(x, x + n);
	for (ll i = 0; i < n; i++) {
		if (y[i] <= x[n / 2 - 1]) {
			cout << x[n / 2] << endl;
		}
		else {
			cout << x[n / 2 - 1] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, c, a[3][33] = {}, b[33][33] = {}, o, z = mod;
    cin >> n >> c;
    for (int i = 1; i <= c; i++) for (int j = 1; j <= c; j++) cin >> b[i][j];
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> o, a[(i + j) % 3][o]++;
    for (int i = 1; i <= c; i++) for (int j = 1; j <= c; j++) for (int k = 1; k <= c; k++) if (i != j && j != k && k != i) {
        int y = 0;
        for (int l = 1; l <= c; l++) y += a[0][l] * b[l][i];
        for (int l = 1; l <= c; l++) y += a[1][l] * b[l][j];
        for (int l = 1; l <= c; l++) y += a[2][l] * b[l][k];
        z = min(z, y);
    }
    cout << z;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b,c = map(int,input().split())
if c-(a+b) < 0:
  print("No");exit()
if 4*a*b < (c-(a+b)) ** 2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
import sys

n=int(input())
H=list(reversed(list(map(int,input().split()))))
for i in range(n-1):
    if H[i+1]-H[i]>1:
        print("No")
        sys.exit()
    elif H[i+1]-H[i]==1:
        H[i+1]-=1
print("Yes")

Measured memory_bytes: 14396
import java.util.*;

public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    }

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int n,ma,sum,in;
int main(){
  cin>>n;
  for(int i=0;i<n;++i){
     cin>>in;
    sum+=in;
    ma=max(ma,in);
  }
  sum-=ma/2;
  cout<<sum<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 20 09:11:30 2020

@author: NEC-PCuser
"""

n, m = map(int, input().split())
cnt = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    cnt[p].append([y, i])
buf = [-1] * m
for i in range(len(cnt)):
    if not cnt[i]:
        continue
    cnt[i].sort()
    for j in range(len(cnt[i])):
        buf[cnt[i][j][1]] = '{:06d}{:06d}'.format(i, j + 1)
print('\n'.join(buf))

Measured memory_bytes: 42912
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
    string s, t1 = "", t2 = "";
    cin >> s;
    t1 += s[0];
    int cnt = 1;
    for (int i = 1; i < s.length(); ++i) {
        t2 += s[i];
        if (t1 != t2) {
            ++cnt, t1 = t2, t2 = "";
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	char c;
	cin >> c;
	c += 1;
	cout << c << endl;
  return 0;
}


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

int main()
{
  long long n;cin>>n;
  if(n%2!=0)cout<<0<<endl;
  else
  {
    long long ans=0;
    n/=2;
    while(n>0)
    {
      ans+=(n/5);
      n/=5;
    }
    cout<<ans<<endl;
  }
  
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int n = input();
    vector< int > as(n);
    cin >> as;
   
    vector< int > ans(n);
    range(i, 1, n) {
        ans[0] ^= as[i];
    }

    range(i, 1, n) {
        ans[i] = as[i] ^ as[i - 1] ^ ans[i - 1];
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 4776
import java.util.Scanner;
public class Main {
	Scanner sc = new Scanner(System.in);
	int n;
	int count=0;	//素数カウント変数
	int[] A;
	
	public void input() {
		n = sc.nextInt();
		A = new int[n];
		for(int i=0; i<n; i++) {
			A[i] = sc.nextInt();
		}
	}
	
	//0で素数を返す
	public int conpute(int number) {
		if(number<2) return 0;
		if(number==2) return 0;
		if(number%2==0) return 1;
		double a = Math.sqrt(number);
		for(int i=3; i<=a; i++) {
			if(number%i == 0) return 1;
		}
		return 0;
	}
	
	public void output() {
		for(int i=0; i<n; i++) {
			if( conpute(A[i]) == 0 ) count++;
		}
		System.out.println(count);
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.output();
	}
}




Measured memory_bytes: 41876
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main(void)
{
	char s[101], p[101], scircle[201];
	int s_length, p_length;
	int i, j;
	bool answer = 0;

	scanf("%s", s);
	scanf("%s", p);

	s_length = strlen(s);
	p_length = strlen(p);
	sprintf(scircle, "%s%s", s, s);

	for (i = 0; i < s_length; i++) {
		answer = 1;
		for (j = 0; j < p_length; j++) {
			if (p[j] != scircle[i + j]) {
				answer = 0;
				break;
			}
		}
		if (answer)
			break;
	}

	if (answer)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
bool B(int x,int i){return (x>>i)&1;}
int c[20][20];	//mn
int next_bit[1<<20][20];
int N,M,K;
int main(){
	cin>>N>>M>>K;
	N--;
	rep(i,1<<N){
		bool b[20]={};
		rep(j,N) b[j] = B(i,j);
		rep(j,N){
			int res = -1;
			for(int k=j;k<N;k++){
				if(b[k]){
					res = k;
					break;
				}
			}
			next_bit[i][j] = res;
		}
	}
	rep(i,M) rep(j,N) c[i][j] = -1;
	rep(i,K){
		int a,b,x;
		cin>>a>>b>>x;
		a--,b--;
		c[a][b] = x;
	}

	vector<mint> dp(1<<N);
	dp[0] = 1;
	rep(i,M) rep(j,N){
		vector<mint> ndp(1<<N);
		rep(k,1<<N) if(dp[k]){
			if(c[i][j]!=1){
				if(!B(k,j)){
					ndp[k] += dp[k];
				}
			}
			if(c[i][j]!=0){
				int nxt = next_bit[k][j];
				int nk = k ^ (nxt==-1?0:(1<<nxt)) ^ (1<<j);
				ndp[nk] += dp[k];
			}
		}
		dp = ndp;
	}
	mint ans = 0;
	rep(k,1<<N) ans += dp[k];
	cout<<ans<<endl;
}

Measured memory_bytes: 47484
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
using namespace std;
int main(){
    int n,cnt=0;
    bool f=true;
    string s;
    cin>>n; 
    rep(i,n){
        cin>>s;
        if(f){
            if(s=="A")
                cnt++;
            else{
                if(cnt--==0){
                    f=false;
                }
            }
        }
    }
        if(f&&!cnt)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3156
n, m, x = [int(i) for i in input().split()]
c = [0] * n
a = [0] * n
for i in range(n):
    tmp = [int(j) for j in input().split()]
    c[i] = tmp[0]
    a[i] = tmp[1:]

mn = -1
for bit in range(1 << n):
    tmp = [0] * m
    t = 0
    for i in range(n):
        if (bit & (1<<i)):
            t += c[i]
            for j in range(m):
                tmp[j] += a[i][j]
    if t != 0 and (mn > t or mn == -1) and len([i for i in tmp if i >= x]) == len(tmp):
        mn = t

print(mn)


Measured memory_bytes: 9232
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;

int N, M;
int vec_p;
vector<int> A;
priority_queue<int> Q;

void input_init(void) {
	cin >> N >> M;
	A.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	sort(A.begin(), A.end());
}

void solve(void) {
	int p, q;
	vec_p = N - 1;
	p = A[vec_p];
	--vec_p;
	Q.push(p / 2);
	for (int i = 2; i <= M; ++i) {
		if (vec_p >= 0) {
			p = A[vec_p];
			q = Q.top();
			if (p > q) {
				Q.push(p / 2);
				--vec_p;
			}
			else {
				Q.pop();
				Q.push(q / 2);
			}
		}
		else {
			q = Q.top();
			if (q == 0)
				break;
			Q.pop();
			Q.push(q / 2);
		}
	}
}

ll calcu(void) {
	ll sum = (ll)0;
	while (!Q.empty()) {
		int q = Q.top();
		Q.pop();
		sum += (ll)q;
	}
	for (int i = 0; i <= vec_p; ++i)
		sum += (ll)A[i];
	return sum;
}

int main(void) {
	input_init();
	solve();
	ll ans = calcu();

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1276
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

const dx = [0, 1, 0, -1];
const dy = [1, 0, -1, 0];
int H, W;
bool[55][55] memo;
string[] s;


int bfs(int h, int w) {
    if (!(0 <= h && h < H && 0 <= w && w < W)) return 0;
    if (s[h][w] == '.') return 0;
    if (s[h][w] == '#' && memo[h][w] == true) return 0;
    memo[h][w] = true;
    int ans;
    for (int i = 0; i < 4; i++) {
        ans += bfs(h + dy[i], w + dx[i]);
    }
    return ans + 1;
}


void main() {
    int[] buf = readln.chomp.split.to!(int[]);
    H = buf[0], W = buf[1];
    for (int i = 0; i < H; i++) {
        s ~= readln.chomp;
    }

    bool flg = true;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            flg &= (bfs(i, j) == 1 ? false : true);
        }
    }

    writeln(flg ? "Yes" : "No");
}

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>

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


void solve()
{
	long long int N, K;
	cin >> N >> K;
	vector<long long int> A(N);
	for (long long int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	int c[64][2] = {};
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 60; ++j)
		{
			c[j][A[i] >> j & 1]++;
		}
	}
	long long int num = 0;
	for (int i = 59; i >= 0; --i)
	{
		if (c[i][0] > c[i][1] && (num | (1ll << i)) <= K)
		{
			num |= (1ll << i);
		}
	}
	long long int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		ans += num ^ A[i];
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

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

int main() {
 int N;
 string S;
 cin >> N >> S;
 int count = 0;
  
  for (int i = 0; i <= N-3; i++){
   if (S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
     count++;
   }
  }
  cout << count << endl;
}


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

using namespace std;

const int N = 1e5 + 2;

int n, h[N], dp[N];

int main(){
    cin >> n;

    for(int i = 1; i <= n; i ++)
        cin >> h[i];

    dp[2] = abs(h[1] - h[2]);   

    for(int i = 3; i <= n; i ++){
        dp[i] = 2e9;
        dp[i] = dp[i - 1 ] + abs(h[i] - h[i - 1]);
        dp[i] = min(dp[i], dp[i - 2 ] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
require 'pp'

N,K = readline.split.map(&:to_i)
H = readline.split.map(&:to_i)

dp = Array.new(N,0)

dp[0] = 0

(1..(N-1)).each do |i|
  k = (i<K) ? i : K
  min = 1e10.to_i
  (1..k).each do |k|
    cost = dp[i-k] + (H[i-k]-H[i]).abs
    min = cost if cost < min
  end
  dp[i] = min
end

puts dp.last


Measured memory_bytes: 11772
S=str(input())
if len(S)%2==0:
  S=S[:-2]
else:
  S=S[:-1]

l=len(S)
for i in range(l//2):
  b=(l)//2
  if S[:b]==S[b:l]:
    print(l)
    exit()
  l -= 2
print(1)

Measured memory_bytes: 2940
#include<stdio.h>
void insertionSort(int a[],int n);
int main(void){
  int i,n;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  insertionSort(a,n);
  return 0;
}
void insertionSort(int a[],int n){
  int i,j,k,v;
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[n-1]);
  for(i=1;i<n;i++){
    v=a[i];
    j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=v;
    for(k=0;k<n-1;k++){
      printf("%d ",a[k]);
    }
    printf("%d\n",a[n-1]);
  }
}

Measured memory_bytes: 1780
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;




int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	int n = sz(s);
	s += '<';
	vi a(n + 1);
	for (int i = 0; i < n + 1; i++)
	{
		if ((i == 0 && s[i] == '<') ||  (i > 0 &&
			s[i - 1] == '>' && s[i] == '<'))
		{
			for (int j = i - 1; j >= 0; j--)
			{
				if (s[j] != '>')
					break;
				a[j] = max(a[j + 1] + 1, a[j]);
			}
			for (int j = i + 1; j < n + 1; j++)

			{
				if (s[j - 1] != '<')
					break;
				a[j] = max(a[j - 1] + 1, a[j]);
			}
		}
	}
	cout << accumulate(all(a), 0LL);
	return 0;
}

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

int main() {
  long long n, l, m = 1000000000, sum = 0;
  cin >> n >> l;
  vector<long long> t(n);
  for(int i = 1; i < n + 1; i++) {
    t.at(i-1) = l + i - 1;
    if(abs(m) > abs(t.at(i-1))) m = t.at(i-1);
    sum += t.at(i-1);
  } 
  cout << sum - m;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N;
	int s[100];

	int sum;

	int i;

	scanf("%d", &N);
	for (i = 0; i < N; i++){
		scanf("%d", &s[i]);
	}

	sum = 0;
	for (i = 0; i < N; i++) sum += s[i];

	if (sum % 10 == 0){
		int buf;

		buf = 101;		
		for (i = 0; i < N; i++){
			if (s[i] % 10 != 0 && s[i] < buf) buf = s[i];
		}

		if (buf != 101) sum -= buf;
		else sum = 0;
	}

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

	return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
   	String s = sc.next();
    int count = s.length() - 1;
    int count1 = (s.length()-1)/2 -1;
    int count2 = (s.length()+3)/2 -1;
    boolean ro = true;
	
    for(int i = 0; i < s.length() && ro;i++){
      if(s.charAt(i) != s.charAt(count - i)) ro = false;
      if(i <= count1){
        if(s.charAt(i) != s.charAt(count1 - i)) ro = false;
      }
      if(i >= count2){
        if(s.charAt(i) != s.charAt(count + count2 - i)) ro = false;
      }
    }
    
    if(ro) System.out.println("Yes");
    else System.out.println("No");

  }
}


Measured memory_bytes: 35608
#include<stdio.h>

int f(int n)
{
	int c[8]={7,112,1792,273,1092,546,1057,292},i=0;
	for(;i<8;i++)
		if((n&c[i])==c[i])
			return 1;
	return 0;
}
int main()
{
	int i,t,b=0,w=0;
	for(i=0;(t=getchar())!=48;i++)
	{	
		if(i==11)
		{
			if(f(b))
				puts("b");
			else if(f(w))
				puts("w");
			else
				puts("NA");
			i=b=w=0;
			i--;
		}
		else
		{
			if(t==98)
				b+=(1<<i%11);
			else if(t==119)
				w+=(1<<i%11);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int mo = 1e9 + 7;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

const ll ni2 = ksm(2, mo - 2);

const int N = 3005;

int n, q, a[N], x[N], y[N];
ll f[N][N];

int main() {
	scanf("%d %d", &n, &q);
	fo(i, 1, n) scanf("%d", &a[i]);
	fo(i, 1, n) fo(j, 1, n) f[i][j] = a[i] > a[j];
	fo(i, 1, q) {
		scanf("%d %d", &x[i], &y[i]);
		fo(j, 1, n) if(j != x[i] && j != y[i]) {
			f[j][y[i]] = f[j][x[i]] = (f[j][y[i]] + f[j][x[i]]) * ni2 % mo;
			f[y[i]][j] = f[x[i]][j] = (f[y[i]][j] + f[x[i]][j]) * ni2 % mo;
		}
		f[x[i]][y[i]] = f[y[i]][x[i]] = (f[x[i]][y[i]] + f[y[i]][x[i]]) * ni2 % mo;
	}
	ll w = ksm(2, q), ans = 0;
	fo(i, 1, n) fo(j, i + 1, n) ans = (ans + f[i][j] * w) % mo;
	pp("%lld\n", ans);
} 


Measured memory_bytes: 70784
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}
///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    var aryA = readInts().sorted()
    var mi = Int.max
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    for i in 1..<n {
        let surplus = aryA[i] % aryA[0]
        if surplus > 0 {
            mi = min(mi, surplus)
        }
    }
    
    while aryA[0] > 1 && mi > 1 && mi < Int.max{
        if aryA[0] > mi {
            aryA[0] = aryA[0] - mi
        }
        else {
            mi = mi - aryA[0]
        }
    }
    print(aryA[0] > 0 && mi > 0 ? min(aryA[0], mi): max(aryA[0], mi))
}
main()


Measured memory_bytes: 18228
import math

def minOPs():
    N = int(input())
    s = input()
    count = 0
    L = 0
    R = N-1
    while(L < R):
        if(s[L] == 'W' and s[R] == 'R'):
            L+=1
            R-=1
            count+=1
        elif(s[L] == 'R' and s[R] == 'W'):
            L+=1
            R-=1
        elif(s[L] == 'R' and s[R] == 'R'):
            L+=1
        else:
            R-=1
    return(count)

if __name__ == '__main__':
    print(minOPs())

Measured memory_bytes: 9432
#include <iostream>

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

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

	cout << ((a*b % 2 == 1) ? "Odd" : "Even") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long N;
	cin >> N;
	long A[N], cnt[N+1];
	long ans = 0;
	for(long i=0;i<N+1;i++){
		cnt[i] = 0;
	}
	for(long i=0;i<N;i++){
		cin >> A[i];
		cnt[A[i]]++;
	}

	for(long j=0;j<N+1;j++){
		ans += cnt[j] * (cnt[j] - 1) / 2;
	}
	for(long i=0;i<N;i++){
		long tmp = ans;
		tmp -= cnt[A[i]] * (cnt[A[i]] - 1) / 2;
		tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2;
		cout << tmp << endl;
	}
}


Measured memory_bytes: 6720
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>

#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)

using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
    Ryuga;
    
   

    string s;
    cin>>s;
    if(s[0]=='7' or s[1]=='7' or s[2]=='7')
    {
        cout<<"Yes\n";
    }
    else
        cout<<"No\n";
    
}//Goodbye...

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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 3e3 + 2;
const int mod = 1e5 + 7;
ll mem[N][N][2];
int arr[N];
int n, k;

ll solve(int i = 0, int j = n - 1, int player = 0) {
    if (i > j)return 0;
    if (~mem[i][j][player])return mem[i][j][player];
    if (!player) {
        return mem[i][j][player] = max(solve(i + 1, j, !player) + arr[i], solve(i, j - 1, !player) + arr[j]);
    } else {
        return mem[i][j][player] = min(solve(i + 1, j, !player) - arr[i], solve(i, j - 1, !player) - arr[j]);
    }
}

int main() {
    cin >> n;
    memset(mem, -1, sizeof mem);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    cout << solve() << endl;
}


Measured memory_bytes: 141312
#include <iostream>
#include <string>

using namespace std;

class Solution {
private:
	bool isPalindrome(const string& s, int L, int R) {
		--L, --R; /* convert to 0-index */
		while (L < R) {
			if (s[L] != s[R])
				return false;
			++L, --R;
		}
		return true;
	}
public:
	/* time: O(1), space: O(1) */
	bool stringPalindrome(const string& s) {
		const int n = s.size();
		if (!isPalindrome(s, 1, n))
			return false;
		if (!isPalindrome(s, 1, (n - 1) / 2))
			return false;
		if (!isPalindrome(s, (n + 3) / 2, n))
			return false;
		return true;
	}
};

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

	Solution sol;
	const bool ans = sol.stringPalindrome(s);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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

bool f(string s){
  for(int i=0;i<s.length()-1;i++){
    if(s[i]!=s[i+1]) return 0;
  }
  return 1;
}

int solve(string s,char c){
  bool flag=1;
  for(int i=0;i<s.length();i++){
    if(s[i]==c) flag=0;
  }
  if(flag) return INT_MAX;
  int ans=0;
  while(!f(s)){
    for(int i=0;i<s.length()-1;i++){
      if(s[i+1]==c){
        s[i]=c;
      }
    }
    s.pop_back();
    ans++;
  }
  return ans;
}

int main(){
  string s;
  cin>>s;
  int ans=INT_MAX;
  for(char c='a';c<='z';c++){
    ans=min(ans,solve(s,c));
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll k;
    cin>>k;
    ll n = 50;
    Vec a(n,49);

    ll x = k/50;
    ll y = k%50;

    rep(i,n){
        if(i<y){
            a[i] += n+1-y;
        }else{
            a[i] -= y;
        }
        a[i] += x;
    }

    //debug
//    ll sum = 0;
//    rep(i,n)sum += a[i];
//    dbg(sum-49*n);

    cout<<n<<endl;
    rep(i,n){
        cout<<a[i]<<" ";
    }
    return  0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct DisjointSet {
	int n;
	vector<int>p, rank;
	DisjointSet(int m) :n(m) {
		p.resize(n);
		rank.assign(n, 0);
		for (int i = 0; i < n; i++)p[i] = i;
	}
	int findset(int x) {
		if (x != p[x])p[x] = findset(p[x]);
		return p[x];
	}
	int same(int x, int y) {
		return findset(x) == findset(y);
	}
	void unite(int x, int y) {
		if (same(x, y))return;
		x = findset(x);
		y = findset(y);
		if (rank[x] < rank[y]) p[x] = y;
		else {
			p[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	DisjointSet uf(n);
	rep(i, 0, q) {
		int com, x, y; cin >> com >> x >> y;
		if (com)cout << uf.same(x, y) << endl;
		else uf.unite(x, y);
	}
	return 0;
}

Measured memory_bytes: 3280
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j=0,N,ans=0;
  cin>>N;
  vec a(N),b(N),x(N*3),prefix(N*3);
  rep(i,N)cin>>a[i];
  rep(i,N)cin>>b[i];
  x[0]=b[0]^b[N-1];
  x[N*2]=x[N]=a[0]^a[N-1];
  rep1(i,N){
    x[i+N*2]=x[i+N]=a[i]^a[i-1];
    x[i]=b[i]^b[i-1];
  }
  rep1(i,N*3){
    if(i+prefix[i-j]<j+prefix[j]){
      prefix[i]=prefix[i-j];
    }else{
      int k=max(0LL,j+prefix[j]-i);
      while(i+k<N*3&&x[k]==x[i+k])++k;
      prefix[i]=k;
      j=i;
    }
  }
  rep(i,N){
    if(prefix[i+N]>=N){
      cout<<i<<" "<<(a[i]^b[0])<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(), ppp.end()
#define out(ppp) cout << (ppp) << endl
#define out1(ppp) cout << (ppp)
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF = INT_MAX;

void solve()
{
    int N;
    cin >> N;
    vl A(N + 1);
    FOR(i, 0, N)
    {
        cin >> A[i];
    }
    vvl dp(N + 1, vl(2, -(1ll<<60)));
    dp[0][0] = 0;
    dp[0][1] = -1ll<<60;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
       // cout<<dp[i+1][0]<<" "<<dp[i+1][1]<<endl;
    }
    out(dp[N][0]);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;
li a[100100];

li imos[100100];
li imoss[100100];

// ワープがkireta[i]からkireta[i+1]になったらどれくらい損するか
li kireta[100100];

int main() {
    cin >> n >> m;
    rin{
        cin >> a[i];
        if (i > 0) {
            kireta[a[i]] += (a[i] + m - a[i - 1]) % m - 1;
            imos[a[i - 1] + 1]++;
            imos[a[i]]--;
            if (a[i - 1] > a[i]) {
                imos[m + 1]--;
                imos[0]++;
            }
        }
    }

    imoss[0] = imos[0];
    repp(i, 1, m + 2) {
        imoss[i] = imoss[i - 1] + imos[i];
    }

    // calc init
    li init = 0;
    {
        li pos = a[0];
        repp(i, 1, n) {
            if (pos < a[i]) {
                init += a[i] - pos;
            } else {
                init += a[i];
            }
            pos = a[i];
        }
    }
    li res = init;
    repp(i, 2, m + 1) {
        init += kireta[i - 1];
        init -= imoss[i - 1];
        res = min(res, init);
    }
    cout << res << endl;

    return 0;
}

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

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    int a,b,i;
    cin >> a >> b;
    for(i=0;i<=100000;i++)
    {
        if(((a*i)-i+1)>=b)
            break;
    }
    cout << i;
    return 0;
}


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

void solve0(int N)
{
    for(int i=0; i<N; i++) cout << "1\n";
    return;
}

void solve1(int N, string& S)
{
    for(int i=0; i<N; i++)
    {
        if(S[i]=='1')
        {
            cout << "0\n";
        }
        else
        {
            if(S[N-1]=='1' || i==N-1) cout << "2\n";
            else cout << "1\n";
        }
        
    }
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    string S;
    cin >> S;

    int cnt = 0;
    for(auto c : S) if(c == '1') cnt++;
    if(cnt == 0)
    {
        solve0(N);
        return 0;
    }
    if(cnt == 1)
    {
        solve1(N, S);
        return 0;
    }
    int umod = cnt+1;
    int lmod = cnt-1;
    // cout << umod << " " << lmod << endl;

    vector<int> u(N), l(N);
    u[N-1] = 1; l[N-1] = 1;
    for(int i=N-2; i>=0; i--)
    {
        u[i] = (u[i+1] * 2) % umod;
        l[i] = (l[i+1] * 2) % lmod;
        // cout << N-i << ", " << u[i] << ", " << l[i] << endl;
    }

    int ust = 0;
    int lst = 0;
    for(int i=0; i<N; i++)
    {
        if(S[i] == '1')
        {
            ust = (ust + u[i]) % umod;
            lst = (lst + l[i]) % lmod;
        }
    }


    for(int i=0; i<N; i++)
    {
        int ans = 1;
        if(S[i]=='0')
        {
            int num = (ust + u[i]) % umod;
            // cout << "0 " << num << ", " << ust << ", " << u[i] << endl;
            while(num)
            {
                num %= __popcount<int>(num);
                ans++;
            }
        }
        else
        {
            int num = (lst - l[i] + lmod) % lmod;
            // cout << "1 " << num << endl;
            while(num)
            {
                num %= __popcount<int>(num);
                ans++;
            }
        }
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 5164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	ll power=0;
	ll o=1;

	cin>>n;

	for(ll i=1; i<n+1; ++i){
		power=o*i%1000000007;
		o=power;
	}

	cout<<power<<endl;

	return 0;
}


Measured memory_bytes: 256
#pragma warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include <functional>
using namespace std;
#define MAX_V 100 + 2
int indegree[MAX_V], outdegree[MAX_V];
int n, m, s, t;
#define INF 0x3f3f3f3f
///////////////////////////////最小?用流?始///////////////////////////////////////////

typedef pair<int, int> P;	// first保存最短距?，second保存?点?号
//用于表示?的??体
struct edge
{
	int to;		// ?点
	int cap;	// 容量
	int cost;	// ?用
	int rev;	// 反向?
	edge(int to, int cap, int cost, int rev) :to(to), cap(cap), cost(cost), rev(rev){}
};
int V;			// ?点数
vector<edge> G[MAX_V];	// ?的?接表
int h[MAX_V];	// ?点的?
int dist[MAX_V];// 最短距?
int prevv[MAX_V];	// 最短路中的前??点
int preve[MAX_V];	// 最短路中的前??点??的?

// 向?中?加一条从from到to的容量?cap?用?cost的?
void add_edge(int from, int to, int cap, int cost)
{
	G[from].push_back(edge(to, cap, cost, G[to].size()));
	G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}

// 求解从s到t流量?f的最小?用流，如果没有流量?f的流，?返回-1
int min_cost_flow(int s, int t, int f)
{
	int res = 0;
	memset(h, 0, sizeof(h));
	while (f > 0)
	{
		// 使用Dijkstra算法更新h
		priority_queue<P, vector<P>, greater<P> > que;
		memset(dist, INF, sizeof(dist));
		dist[s] = 0;
		que.push(P(0, s));
		while (!que.empty())
		{
			P p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < G[v].size(); ++i)
			{
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to])
				{
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF)
		{
			// 不能再?广
			return -1;
		}
		for (int v = 0; v < V; ++v)
		{
			h[v] += dist[v];
		}

		// 沿s到t的最短路尽量?广
		int d = f;
		for (int v = t; v != s; v = prevv[v])
		{
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevv[v])
		{
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

void clear()
{
	for (int i = 0; i < V; ++i)
	{
		G[i].clear();
	}
}


///////////////////////////SubMain//////////////////////////////////
int main()
{
	scanf("%d%d", &n, &m);
	V = n + 2;
	t = V - 1;
	s = 0;
	int total = 0;
	for (int i = 1; i <= m; i++)
	{
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		x++, y++;
		add_edge(x, y, INF, -z);
		outdegree[x]++, indegree[y]++;
		total += z;
	}

	int max_f = 0;
	for (int i = 1; i <= n; i++)
	{
		if (indegree[i] > outdegree[i])
		{
			add_edge(s, i, indegree[i] - outdegree[i], 0);
			max_f += indegree[i] - outdegree[i];
		}
		else
		{
			add_edge(i, t, outdegree[i] - indegree[i], 0);
		}
	}

	min_cost_flow(1, n, 1);
	add_edge(n, 1, INF, -dist[n]);
	int ans = min_cost_flow(s, t, max_f);
	printf("%d\n", ans - total);
	return 0;
}

Measured memory_bytes: 1268