akhauriyash/Code-Regression huggingface dataset:
//>>>>>>>>>>>>>>>>>>>>>>>>>>JAI BAJRANG BALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😇😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😝😝😝😝😝😝😝😝😝😝😝😝😝😂😂😂😂😂😂😂😜😜😜😜😜😜😜😜😜😜😜
#define HARSH_JUDGE
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define db(x)                   cout<<#x<<"="<<x<<'\n'
#define db2(x,y)                 cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define setbits(x)      __builtin_popcountll(x)
#define str string
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n;i>=a;i--)
#define cases   long long t;cin>>t;while(t--)
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define ff first
#define ss second
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define sp(x,y)         fixed<<setprecision(y)<<x
#define nl '\n'
#define sz(x) ((int)(x).size())
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
const ll N = 1e5 + 5;
#define printall(a) fo(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;



typedef vector<int> vi;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<ll, int> mli;
typedef map<char, int> mci;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpl;
typedef vector<vector<int> > vv;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b)
{

	return a.ss < b.ss;
}

// >>>>>>>>>>>>>>>>>>>>>>>>>>TOR DE DUSHMAN KI NALI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//

void solve()
{

	ll n;
	cin >> n;
	vll dp(3, 0), new_dp(3, 0);
	fo(i, 0, n)
	{
		vll ins(3);
		fo(j, 0, 3)
		{
			cin >> ins[j];
		}
		fo(j, 0, 3)
		{
			fo(k, 0, 3)
			{
				if (j != k)
				{
					new_dp[j] = max(new_dp[j], ins[j] + dp[k]);
				}
			}
		}
		dp = new_dp;


	}
	cout << max({dp[0], dp[1], dp[2]}) << nl;
	return;
}


int main()
{	fio
#ifndef HARSH_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	// clock_t timest = clock();
	// cerr << "[Executes in " << (double)(clock() - timest) / CLOCKS_PER_SEC << "s]" << endl;
	while (t--)
	{
		solve();

	}
}

Measured memory_bytes: 3652
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        a:isize,
        b:isize,
        c:isize,
        d:isize,
    };

    println!("{}", if solve(a, b, c, d) {"Yes"} else {"No"});
}

fn solve(a: isize, b: isize, c: isize, d: isize) -> bool {
    if (a - c).abs() <= d {
        return true;
    }
    return ((a - b).abs() <= d) && ((b - c).abs() <= d);
}
macro_rules! tests {
    ($($test_name:ident:$name:ident($( $args:expr ),*) => $expected:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $test_name() {
                    assert_eq!($expected,super::$name($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:solve(4,7,9,3) => true,
    test2:solve(100,10,1,2) => false,
    test3:solve(10,10,10,1) => true,
    test4:solve(1,100,2,10) => true,
}


Measured memory_bytes: 4352
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[ min(j - i, abs(X - i) + 1 + abs(Y - j))] += 1
for i in range(1, N):
    print(ans[i])


Measured memory_bytes: 9324
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int fir=0,sec=0;
  rep(i,n){
    if(fir<a[i]){
      sec = fir;
      fir = a[i];
    }
    else if(sec<a[i]){
      sec = a[i];
    }
  }
  rep(i,n){
    if(a[i]==fir) cout << sec << "\n";
    else cout << fir << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 2432
a, b, c, x = [int(input()) for i in range(4)]
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        y = i * 500 + j * 100
        if x-y >= 0 and (x-y) % 50 == 0 and (x-y)//50 <= c:
            cnt += 1
            #print(i,j,(x-y)//50)

print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b;
    if((a+b)>(a-b))
        c=a+b;
    else
        c=a-b;
    if(c>(a*b))
        cout<<c;
    else
        cout<<a*b;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string str1,str2;
  cin>>str1>>str2;
  int count=0;
  for(int i=0;i<str1.size();i++)
  {
    if(str1[i]==str2[i])
      count++;
  }
  cout<<count<<endl;
  return 0;
}

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

int n;
int pls[100002], mns[100002];

int main(){
  while(scanf("%d", &n) != EOF){
    memset(pls, 0, sizeof(pls));
    memset(mns, 0, sizeof(mns));

    for(int i = 0; i < n; i++){
      int a, b;
      scanf("%d%d", &a, &b);
      pls[a]++;
      mns[b]++;
    }

    int sum = 0;
    int ans = 1;

    for(int i = 1; i <= n + 1; i++){
      sum += pls[i];

      if(i <= sum + 1){
        ans = i;
      }

      sum -= mns[i];
    }

    cout << ans - 1 << endl;
  }
}

Measured memory_bytes: 1616
#include<iostream>
#include <numeric>
#include <algorithm>
#include<queue>
#include<vector>
using namespace std;
using P = pair<int,int>;
using Graph = vector<vector<bool>>;
int n, m, cnt=0;

int main(){
  cin >> n >> m;
  Graph G(n+1, vector(n+1, false));
  vector<int> Nodes(n+1);
  iota(Nodes.begin(),Nodes.end(), 0);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    G[a][b] = true;
    G[b][a] = true;
  }
  
  do{
    bool flag = true;
    for(int i=2; i<=n; i++){
      if(G[Nodes[i]][Nodes[i-1]]) continue;
      else{
        flag = false;
        break;
      }
    }
    if(flag) cnt++;
  }while(next_permutation(Nodes.begin()+2, Nodes.end()));
  
  cout << cnt << endl;
}

Measured memory_bytes: 3608
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int z=0,max=0,sec=0,cout=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			if(max<A[z]){
				max=A[z];cout=z;
			}
			z++;
		}z=0;
		while(z<N){
			if(sec<A[z]&&z!=cout)
				sec=A[z];
			z++;
		}z=0;
		while(z<N){
			if(z!=cout)
				System.out.println(max);
			else
				System.out.println(sec);
			z++;
		}
	}
}

Measured memory_bytes: 109884
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define vi vector<int>
using namespace std;

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b & a!=c) || (a==c & a!=b) || (c==b & a!=b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}




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

string ans,s;
int cnt = 0;
char tmp[10][9] = {{" "},{"',.!?"},{"abcABC"},{"defDEF"},{"ghiGHI"},{"jklJKL"},{"mnoMNO"},{"pqrsPQRS"},{"tuvTUV"},{"wxyzWXYZ"}};

void solve(int i){
    int value = s[i-1] -'0';
    if(value==2||value==3||value==4||value==5||value==6||value==8) ans += tmp[value][cnt%6];
    else if (value==7||value==9) ans += tmp[value][cnt%8];
    else if(value==1) ans += tmp[value][cnt%5];
    else if(value == 0) ans.append(cnt,' ');
    cnt = 0;
}

int main(){
    while(cin >> s){
        for(int i=0;i<s.size();i++){
            for(;i<s.size();i++){
                if(s[i-1] != s[i]){
                    solve(i);
                    break;
                }
                cnt++;
            }
        }
        if(s[s.size()-1] != 0) solve(s.size());
        cout << ans << endl;
        ans.erase();
    }
}

Measured memory_bytes: 1188
def dfs(formula, index):
    if index + 1 == max_index:
        return sum(list(map(int, formula.split("+"))))

    else:
        return dfs(formula + '+' + S[index + 1], index + 1) + dfs(formula + S[index + 1], index + 1)


S = input()
max_index = len(S)

print(dfs(S[0], 0))


Measured memory_bytes: 38896
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int n;
    ll ans = 0;
    cin >> n;
    vector<int> h(n);
    int mini = INF;
    REP(i,n){
        cin >> h[i];
    }

    while(true){

        bool num = false;
        for(int i = 0;i < n;i++){
            num |= h[i];
        }

        if(!num){
            break;
        }

        //まだ伸ばせる
        
        int maxi = -1;
        int mini = INF;
        int left = 0;
        while(h[left] == 0 && left < n){
            left++;
        } 
        //0でないものが出てきた
        int right = left;
        while(right < n && h[right] != 0){
            mini = min(mini,h[right]);
            right++;
        }

        ans += mini;
        for(int i = right-1;i >= left;i--){
            h[i] -= mini;
        }
    }

    cout << ans << endl;



    return 0;
}

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

using namespace std;

int main (void) {
    string S_, T;
    cin >> S_ >> T;

    int replacable_idx = -1;
    int S_len = S_.size();
    int T_len = T.size();
    for ( int i=0; i<S_len; i++ ) {
        /* 一致しそうな開始位置を見つけたらチェックを始める */
        if ( S_.at(i) == '?' || S_.at(i) == T.at(0) ) {
            bool ok = true;
            for ( int j=1; j<T_len; j++ ) {
                if ( i + j >= S_len ) {
                    /* 置き換えられないのでだめです */
                    ok = false;
                    break;
                }
                if ( S_.at(i+j) != '?' && S_.at(i+j) != T.at(j) ) {
                    /* だめです */
                    ok = false;
                    break;
                }
            }
            if ( ok )
                replacable_idx = i;
        }
        if ( S_.at(i) == '?' )
            S_.at(i) = 'a';
    }

    /* 置き換え可能な場所が見つからなかったらだめです */
    if ( replacable_idx == -1 )
        goto UNRESTORABLE;
    /* 見つかっていたら、最後尾の位置を置き換える */
    for ( int i=0; i<T_len; i++ )
        S_.at(replacable_idx + i) = T.at(i);
    cout << S_ << endl;

    return 0;
UNRESTORABLE:
    cout << "UNRESTORABLE" << endl;
    return 0;
}


Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 xxx.cpp

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

int main() {
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int K; cin>>K;
    cout << arr[K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
int main()
{
	fast;
	int n;cin>>n;
	vector<ll> xx,yy;
	for(int i=0;i<n;i++)
	{
		ll x,y;cin>>x>>y;
		xx.push_back(x+y);
		yy.push_back(x-y);
	}
	sort(xx.begin(),xx.end());
	sort(yy.begin(),yy.end());
	ll ans=0;
	ans=max(ans,abs(xx[0]-xx[n-1]));
	ans=max(ans,abs(yy[0]-yy[n-1]));

	cout<<ans<<nl;

}

Measured memory_bytes: 6680
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

int n, k, a[51]; 
ll dp[51][2501][52];

ll go(int idx, int acc, int cnt){
    if(idx == n){
        //if(acc % cnt == 0)return (acc/cnt) == k;
        //return 0;
        //cout << acc << ' ' << cnt << endl;
        if(cnt > 0 && acc % cnt == 0)return (acc/cnt) == k;
        return 0;
    }
    if(dp[idx][acc][cnt] != -1)return dp[idx][acc][cnt];
    ll ans = go(idx+1,acc,cnt) + go(idx+1,acc+a[idx],cnt+1);
    return dp[idx][acc][cnt] = ans;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    memset(dp, -1, sizeof dp);
    cout << go(0,0,0) << endl;
    return 0;
}

Measured memory_bytes: 52096
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = I
        self.seg = [I]*(N*2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = gcd(self.seg[i << 1], self.seg[(i << 1) + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k //= 2
            self.seg[k] = gcd(self.seg[k << 1], self.seg[(k << 1) + 1])
 
    def query(self, a, b):
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a & 1:
                R = gcd(R, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = gcd(self.seg[b], R)
            a >>= 1
            b >>= 1
        return R

def main():
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 81340
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int n;
char u[55], d[55];
int s[55];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> u[i];
	for (int i = 0; i < n; i++) cin >> d[i];
	int top = 0;
	for (int i = 0; i < n; i++) {
		if (u[i] == d[i]) {
			s[top++] = 1;
		}
		else {
			s[top++] = 2;
			i++;
		}
	}
	for (int i = top - 1; i > 0; i--) {
		if (s[i] == 1) {
			if (s[i - 1] == 1) s[i] = 2;
			else s[i] = 1;
		}
		else {
			if (s[i - 1] == 1) s[i] = 2;
			else s[i] = 3;
		}
	}
	if (s[0] == 1) s[0] = 3;
	else if (s[0] == 2) s[0] = 6;
	ll res = 1;
	for (int i = 0; i < top; i++) {
		res = (res*s[i]) % 1000000007;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    int N;
    cin >> N;

    cout << (N+1)/2;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, x; cin >> n >> x;
  int g = 0;
  for(int i = 0; i < n; i++){
    int v; cin >> v; v -= x;
    g = __gcd(g, abs(v));
  }
  cout << g << endl;
  return 0;
}

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

typedef long long ll;

vector<ll>div(ll n)
{
    ll i,a,b;
    vector<ll>res;
    for(i=1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            a=n/i;
            res.push_back(i);
            if(a!=i)res.push_back(a);
        }
    }
    sort(res.begin(),res.end());

    return res;
}

int main()
{

    ll n,a,b,i,m;
    cin >> n >> m;
    vector<ll>v=div(m);
    reverse(v.begin(),v.end());
    for(i=0; i<v.size(); i++)
    {
        a=v[i];
        b=m/a;
        if(b>=n)
        {
            cout << a << "\n";
            return 0;
        }
    }
    cout << 1 << "\n";



    return 0;
}



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

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

    int i = 1;
    while (i * i <= n) {
        i++;
    }

    if (i * i > n) {
        i--;
    }

    cout << i * i << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	_ = scanInt()
	m := scanInt()

	ps := make(pairs, m)
	for i := 0; i < m; i++ {
		p := scanString()
		y := scanInt()
		p = strings.Repeat("0", 6-len(p)) + p
		ps[i] = pair{p, y, i}
	}
	sort.Sort(ps)
	pre := "#"
	x := 1
	ans := make([]string, m)
	for i := 0; i < m; i++ {
		if pre != ps[i].p {
			x = 1
		}
		t := strconv.Itoa(x)
		t = strings.Repeat("0", 6-len(t)) + t
		ans[ps[i].num] = ps[i].p + t
		x++
		pre = ps[i].p
	}

	for i := 0; i < m; i++ {
		fmt.Fprintln(wr, ans[i])
	}
}

type pair struct {
	p      string
	y, num int
}

type pairs []pair

func (a pairs) Len() int      { return len(a) }
func (a pairs) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a pairs) Less(i, j int) bool {
	if a[i].p == a[j].p {
		return a[i].y < a[j].y
	}
	return a[i].p < a[j].p
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<string> S(N);
    rep(n,0,N) cin>>S.at(n);

    set<char> initS{'M','A','R','C','H'};
    map<char,int> mapS;
    for(auto s:initS) mapS[s]=0;
    for(auto s:S){
        char c=s.front();
        if(initS.count(c)) mapS[c]++;
    }

    int64_t ans=0;
    for(auto i=mapS.begin();i!=prev(mapS.end(),2);i++){
        int64_t numI=i->second;
        for(auto j=next(i);j!=prev(mapS.end());j++){
            int64_t numJ=j->second;
            for(auto k=next(j);k!=mapS.end();k++){
                int64_t numK=k->second;
                ans+=numI*numJ*numK;
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct Point{
	double x,y;
};
void koch(int n, Point p1, Point p2){
	if(n==0){
		//printf("%f %f \n", p2.x, p2.y);
		return;
	}
	Point s,t,u;
	double co=0.5;
	double si=sqrt(3)/2;
	s.y=(2*p1.y+p2.y)/3;
	s.x=(2*p1.x+p2.x)/3;
	t.y=(p1.y+2*p2.y)/3;
	t.x=(p1.x+2*p2.x)/3;
	u.x=(t.x-s.x)*co-(t.y-s.y)*si+s.x;
	u.y=(t.x-s.x)*si+(t.y-s.y)*co+s.y;
	koch(n-1, p1, s);
	printf("%f %f \n", s.x, s.y);
	koch(n-1, s, u);
	printf("%f %f \n", u.x, u.y);
	koch(n-1, u, t);
	printf("%f %f \n", t.x, t.y);
	koch(n-1, t, p2);
	//printf("%f.8 %f .8\n", p2.x, p2.y);
}
int main(){
	Point p1,p2;
	p1.x=0;
	p1.y=0;
	p2.x=100;
	p2.y=0;
	int n;
	scanf("%d", &n);
	printf("%f %f \n", p1.x, p1.y);
	koch(n,p1,p2);
	printf("%f %f \n", p2.x, p2.y);
	return 0;
}


Measured memory_bytes: 3200
N = int(input())
S = []
for _ in range(N):
    S.append(int(input()))
w = sum(S)

if w % 10 != 0:
    print(w)
else:
    S.sort()
    for i in range(N):
        if S[i] % 10 != 0:
            print(w - S[i])
            break
    else:
        print(0)


Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

stack<int> topologicalSort(vector<vector<int>>adjacentList)  {
  int V = adjacentList.size();
  stack<int> sorted;
  vector<bool> visited(V, false);

  function<void (int)> dfs = [&](int i) {
    if(visited[i]) return;
    visited[i] = true;
    for(int nn: adjacentList[i]) dfs(nn);
    sorted.push(i);
  };

  for(int i = 0; i < V; i++) dfs(i);

  return sorted;
}

int main () {
  int V, E;
  cin >> V >> E;

  vector<vector<int>> adjacentList(V, vector<int>());

  REP(i,E) {
    int s, t;
    cin >> s >> t;
    adjacentList[s].push_back(t);
  }

  stack<int> sorted = topologicalSort(adjacentList);

  while(!sorted.empty()) {
    cout << sorted.top() << endl;
    sorted.pop();
  }

  return 0;
}

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

using ll = long long;
using p = pair<ll, ll>;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 998244353;

int main(void) {
  ll N, S;
  cin >> N >> S;
  vector<ll> A(N);
  for (auto&& a : A) {
    cin >> a;
  }

  vector<vector<ll> > dp(N + 1, vector<ll>(S + 1, 0));
  dp[0][0] = 1;
  for (ll i = 1; i <= N; i++) {
    for (ll j = 0; j <= S; j++) {
      dp[i][j] += dp[i - 1][j] * 2;
      dp[i][j] %= MOD;

      if (j + A[i - 1] > S) {
        continue;
      }

      dp[i][j + A[i - 1]] += dp[i - 1][j];
      dp[i][j + A[i - 1]] %= MOD;
    }
  }

  cout << dp[N][S] << endl;
  
  return 0;
}


Measured memory_bytes: 73684
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a,b;cin>>a>>b;
    int k=50;

    VVI result(100);
    REP(i,100){
        if(i<50){
            result[i].resize(100,0);
        }
        else{
            result[i].resize(100,1);
        }
    }

    int xa=0,ya=0;
    REP(i,a-1){
        result[xa][ya]=1;
        if(ya<98){
            ya+=2;
        }
        else{
            xa+=2;
            ya=0;
        }
    }
    int xb=0,yb=0;
    REP(i,b-1){
        result[xb+k+2][yb]=0;
        if(yb<98){
            yb+=2;
        }
        else{
            xb+=2;
            yb=0;
        }
    }
    cout<<"100 100"<<endl;
    REP(i,100){
        REP(j,100){
            if(result[i][j]==1){
                cout<<".";
            }
            else{
                cout<<"#";
            }
        }
        cout<<endl;
    }
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int MAXN = 1e5+5;
const LL INF = 1LL<<30;
const long double eps = 1e-10;
const double PI=3.1415926535897932;

int main(){
	DRIII(a,b,c);
	REP(i,1000000){
		if(a%2||b%2||c%2){printf("%d",i);return 0;}
		int na=(b+c)/2,nb=(a+c)/2,nc=(a+b)/2;
		a=na,b=nb,c=nc;
	}
	printf("-1");
}


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

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    
    string a,b;
    while(cin>>a>>b){
        int answer=10e6;
        int times=a.length()-b.length();
        for(int i=0;i<=times;i++){
            int rec=0;
            for(int j=0;j<b.length();j++){
                if(a[j+i]!=b[j])++rec;
            }
            answer=min(answer,rec);
        }
        cout<<answer<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int horizon[2000][2000];
int vertical[2000][2000];

int main()
{
    int H, W;
    cin >> H >> W;
    string S[H];
    for (int i = 0; i < H; i++)
        cin >> S[i];
    
    for (int i = 0; i < H; i++)
    {
        horizon[i][0] = (S[i][0] == '#')? 0: 1;
        for (int j = 1; j < W; j++)
        {
            if (S[i][j] == '.')
                horizon[i][j] = horizon[i][j - 1] + 1;
            else
                horizon[i][j] = 0;
        }
        for (int j = W-2; j >= 0; j--)
        {
            if (horizon[i][j + 1] == 0)
                continue;
            else if (horizon[i][j] > 0)
                horizon[i][j] = horizon[i][j+1];
            // cout << horizon[i][j] << ' ';
        }
        // cout << endl;
    }
    // cout << "asdffffffffffffffff" << endl;
    for (int j = 0; j < W; j++)
    {
        vertical[0][j] = (S[0][j] == '#')? 0: 1;
        for (int i = 1; i < H; i++)
        {
            if (S[i][j] == '.')
                vertical[i][j] = vertical[i - 1][j] + 1;
            else
                vertical[i][j] = 0;
        }
        for (int i = H-2; i >= 0; i--)
        {
            if (vertical[i+1][j] == 0)
                continue;
            if (vertical[i][j] > 0)
                vertical[i][j] = vertical[i + 1][j];
        }
    }
    
    int ans = 0;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            ans = max(ans, horizon[i][j] + vertical[i][j] - 1);
    cout << ans << endl;
   	return 0;
}

Measured memory_bytes: 35584
import math

a,b,h,m = [int(i) for i in input().split()]

s = m/60*2*math.pi
t = h/12*2*math.pi+m/60*math.pi/6

if abs(s-t) <= math.pi:
    print(math.sqrt(a**2+b**2-2*a*b*math.cos(abs(s-t))))
else:
    print(math.sqrt(a**2+b**2-2*a*b*math.cos(2*math.pi - abs(s-t))))

Measured memory_bytes: 9420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    struct Works
    {
        public bool[] finishedworks;
        public int[] costs;
        public int[] limits;
        public int time;
        public int worknum;
        public bool[] availableworks;
        public bool failed;
    }


    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split(' ');
            var ds = new int[num];
            for (int i = 0; i < num; i++)
            {
                ds[i] = int.Parse(s[i]);
            }
            int count = 0;
            Array.Sort(ds);
            if (ds.Length % 2 == 1)
            {
                Console.WriteLine(0);
            }
            else if (ds[ds.Length / 2 - 1] == ds[ds.Length / 2])
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(ds[ds.Length / 2] - ds[ds.Length / 2 - 1]);
            }
            

            

#if DEBUG
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 16864
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = int(1e10)

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N+1)
	for i := 1; i <= N; i++ {
		a[i] = getInt()
	}
	dp := make([]int, N+1)

	dp[0] = 1000
	for k := 1; k <= N; k++ {
		for i := 0; i < k-1; i++ {
			m := inf
			for j := i + 1; j < k; j++ {
				m = min(m, a[j])
			}
			dp[k] = max(dp[k], dp[i]/m*a[k]+dp[i]%m)
		}
		// out(dp)
	}
	ans := 0
	for i := 0; i <= N; i++ {
		ans = max(ans, dp[i])
	}
	out(ans)
}


Measured memory_bytes: 1776
n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = float('inf')
for i in range(n):
    if a[i] < 0:
        a[i] *= -1
        cnt += 1
    m = min(m, abs(a[i]))
if cnt % 2:
    print(sum(a) - 2 * m)
else:
    print(sum(a))


Measured memory_bytes: 14412
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

const long long MOD = 4294967291LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long mult_mod(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

double dp[305][305][305];
int freq[4];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    // dp[i,j,k,l,m...] expected number

    // we can compress this down to dp[i][j][k] (1s, 2s, 3s), 0s can be deduced

    int n; cin >> n;

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

    int a = freq[1], b = freq[2], c = freq[3];

    for(int k = 0; k <= c; ++k){
        for(int j = 0; j <= b + c; ++j){
            for(int i = 0; i <= n; ++i){
                if(i > 0) dp[k][j][i] += dp[k][j][i - 1] * i;
                if(j > 0) dp[k][j][i] += dp[k][j - 1][i + 1] * j;
                if(k > 0) dp[k][j][i] += dp[k - 1][j + 1][i] * k;
                if(i + j + k > 0) dp[k][j][i] = (dp[k][j][i] + n) / (i + j + k);
            }
        }
    }

    cout << setprecision(10) << fixed << dp[c][b][a];

    return 0;
}


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

struct A_B
{
    long A;
    long B;
    A_B(long A1,long B1){
        A=A1;
        B=B1;
    }

    bool operator < (const A_B &another)const{
        if(another.B==B){
            return (-1)*A<(-1)*another.A;
        }else{
            return  B<another.B;
        }
    }
};


int main()
{
    long N;
    std::vector<A_B> A_Bs;
    std::cin >> N;
    for(long i=0; i<N; i++){
        long A,B;
        std::cin >> A >> B;
        A_Bs.push_back(A_B(A,B));
    }
    std::sort(A_Bs.begin(),A_Bs.end());
    int flag=1;
    long nowtime=0;
    for(long i=0; i<N; i++){
        nowtime+=A_Bs[i].A;
        if(nowtime>A_Bs[i].B){
            flag=0;
            break;
        }
    }
    if(flag==0){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 6512
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
    n:usize,m:usize,
    mut a:[i64;n],
    mut bc:[(usize,i64);m],
    }
    let mut pq = PriorityQueue::new();
    for &x in a.iter() {
        pq.push(x);
    }
    bc.sort_by_key(|&bc| -(bc.1 as i64));
    for &(b, c) in bc.iter() {
        for _ in 0..b {
            if *pq.peek_min().unwrap() >= c {
                break;
            } else {
                pq.pop_min();
                pq.push(c);
            }
        }
    }
    let mut ans = 0;
    while let Some(x) = pq.pop_min() {
        ans += x;
    }
    println!("{}", ans);
}

struct PriorityQueue<T: Ord + Copy> {
    que_max: BinaryHeap<T>,
    que_min: BinaryHeap<Reverse<T>>,
}
impl<T: Ord + Copy> PriorityQueue<T> {
    fn new() -> PriorityQueue<T> {
        PriorityQueue {
            que_max: BinaryHeap::<T>::new(),
            que_min: BinaryHeap::<Reverse<T>>::new(),
        }
    }
    fn is_empty(&mut self) -> bool {
        self.que_max.is_empty()
    }
    fn push(&mut self, x: T) {
        self.que_max.push(x);
        self.que_min.push(Reverse(x));
    }
    fn len(&mut self) -> usize {
        self.que_max.len()
    }
    fn pop_max(&mut self) -> Option<T> {
        self.que_min.pop();
        self.que_max.pop()
    }
    fn pop_min(&mut self) -> Option<T> {
        self.que_max.pop();
        if let Some(x) = self.que_min.pop() {
            let Reverse(y) = x;
            Some(y)
        } else {
            None
        }
    }
    fn peek_max(&mut self) -> Option<&T> {
        self.que_max.peek()
    }
    fn peek_min(&mut self) -> Option<&T> {
        if let Some(x) = self.que_min.peek() {
            let Reverse(y) = x;
            Some(y)
        } else {
            None
        }
    }
}


Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define per(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define MP make_pair

typedef double db;

const db EPS = 1e-8;

inline int sign(db a) {
	return a < -EPS ? -1 : a > EPS;
}

inline int cmp(db a, db b){
	return sign(a-b);
}

struct P {
	db x, y;
	P() {
	}
	P(db _x, db _y) :
			x(_x), y(_y) {
	}
	P operator+(P p) {
		return P(x + p.x, y + p.y);
	}
	P operator-(P p)  {
		return P(x - p.x, y - p.y);
	}
	P operator*(db d) {
		return P(x * d, y * d);
	}
	P operator/(db d) {
		return P(x / d, y / d);
	}
	bool operator<(P p) const {
		int c = sign(x - p.x);
		if (c)
			return c == -1;
		return sign(y - p.y) == -1;
	}
	db dot(P p) {
		return x * p.x + y * p.y;
	}
	db det(P p) {
		return x * p.y - y * p.x;
	}
	db distTo(P p) { return (*this-p).abs(); }

	db alpha() {
		return atan2(y, x);
	}
	void read() {
		cin>>x>>y;
	}
	db abs() {
		return sqrt(abs());
	}
	db abs2() {
		return x * x + y * y;
	}
	P rot90(){
		return P(-y,x);
	}
};

#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))

P isLL(P p1, P p2, P q1, P q2) {
	db a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);
	return (p1 * a2 + p2 * a1) / (a1 + a2);
}

bool intersect(db l1,db r1,db l2,db r2){
	if(l1>r1) swap(l1,r1); if(l2>r2) swap(l2,r2); 
	return !( cmp(r1,l2) == -1 || cmp(r2,l1) == -1 );
}

bool isSS(P p1, P p2, P q1, P q2){
    return intersect(p1.x,p2.x,q1.x,q2.x) && intersect(p1.y,p2.y,q1.y,q2.y) && 
    crossOp(p1,p2,q1) * crossOp(p1,p2,q2) <= 0 && crossOp(q1,q2,p1)
            * crossOp(q1,q2,p2) <= 0;
}

bool isMiddle(db a, db m, db b) {
    return sign(a - m) == 0 || sign(b - m) == 0 || (a < m != b < m);
}
 
bool isMiddle(P a, P m, P b) {
    return isMiddle(a.x, m.x, b.x) && isMiddle(a.y, m.y, b.y);
}

bool onSegment(P p1, P p2, P q){
	return crossOp(p1,p2,q) == 0 && isMiddle(p1, q, p2);
}

P proj(P p1, P p2, P q) {
    P dir = p2 - p1;
    return p1 + dir * (dir.dot(q - p1) / dir.abs2());
}

P reflect(P p1, P p2, P q){
	return proj(p1,p2,q) * 2 - q;
}

db nearest(P p1,P p2,P q){
	P h = proj(p1,p2,q);
	if(isMiddle(p1,h,p2))
		return q.distTo(h);
	return min(p1.distTo(q),p2.distTo(q));
}

db getrad(P p1,P p2){
	return atan2l(p1.det(p2),p1.dot(p2));
}

db incircle(P p1, P p2, P p3){
	db A = p1.distTo(p2);
	db B = p2.distTo(p3);
	db C = p3.distTo(p1);
	return sqrtl(A*B*C/(A+B+C));
}

int main(){
	int n;cin>>n;
	rep(i,0,n){
		P p1,p2,q1,q2;
		p1.read(),p2.read(),q1.read(),q2.read();

		cout<<isSS(p1,p2,q1,q2)<<endl;
	}

	return 0;
}

Measured memory_bytes: 3196
// 2020-08-25 21:02:59
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

ll ans[2], cur[2];
void answer() {
  int n;
  cin >> n;
  rep(i, n) {
    ll a;
    cin >> a;
    int x = i%2, y = (i+1)%2;
    cur[x] += a;
    cur[y] += a;
    if(cur[x] <= 0) ans[x] += 1 - cur[x], cur[x] = 1;
    if(cur[y] >= 0) ans[y] += 1 + cur[y], cur[y] = -1;
  }
  cout << min(ans[0], ans[1]) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
/* #define INF 1e10 */
typedef long long ll;
const ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


void solve(long long N, vector<long long> h){
    vector<ll> dp(N+10000, INF);

    // initial point
    dp[0] = 0;

    for (ll i = 0; i < N; ++i) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    cout << dp[N-1] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    cin >> N;
    vector<long long> h(N+100, 0);
    for(int i = 0 ; i < N ; i++){
        cin >> h[i];
    }
    solve(N, move(h));
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define clr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define _val(x) cerr << #x << " is " << x << "\n";
#define all(container) container.begin(), container.end()
#define rall(container) container.rbegin(), container.rend()
#define rep(i, a, b, c) for(ll i = a; i <= b; i += c)
#define rrep(i, a, b, c) for(ll i = a; i >= b; i -= c)
#define pb push_back
#define mp make_pair

using namespace std;

const double eps = 1e-10;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long> > vpll;
const int INF = 0x3f3f3f3f;

int main(void){
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	ll n, k; cin >> n >> k;
	ll h[n], dp[n];
	rep(i, 0, n-1, 1) cin >> h[i];
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
	rep(i, 2, n-1, 1) {
		dp[i] = INF;
		ll start = max((ll)0, i-k);
		rep(j, start, i-1, 1) {
			dp[i] = min(dp[i], dp[j]+abs(h[j]-h[i]));
		}
	}
	cout << dp[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

#define N	100000
#define M	100000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int ds[N], rr[N];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

int join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return 0;
	if (ds[i] > ds[j]) {
		ds[i] = j;
		rr[j] = rr[i];
	} else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
	return 1;
}

int aa[N], bb[N];
int ii[M], jj[M];

int compare(const void *a, const void *b) {
	int h1 = *(int *) a;
	int h2 = *(int *) b;
	int i1 = ii[h1];
	int i2 = ii[h2];

	return aa[i1] != aa[i2] ? aa[i1] - aa[i2] : i1 - i2;
}

int main() {
	static int hh[M], ss[N], dp[N];
	int n, m, h, i, j;
	long long ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &aa[i], &bb[i]);
		aa[i] = max(aa[i] - bb[i], 0);
	}
	for (h = 0; h < m; h++) {
		int tmp;

		scanf("%d%d", &i, &j), i--, j--;
		if (aa[i] < aa[j] || aa[i] == aa[j] && i < j)
			tmp = i, i = j, j = tmp;
		ii[h] = i, jj[h] = j, hh[h] = h;
	}
	qsort(hh, m, sizeof *hh, compare);
	for (i = 0; i < n; i++) {
		ds[i] = -1, rr[i] = i;
		dp[i] = aa[i], ss[i] = bb[i];
	}
	for (h = 0; h < m; h++) {
		i = ii[hh[h]], j = rr[find(jj[hh[h]])];
		if (join(i, j)) {
			dp[i] = min(dp[i], max(dp[j], aa[i] - ss[j]));
			ss[i] = min(ss[i] + ss[j], INF);
		}
	}
	ans = dp[rr[find(0)]];
	for (i = 0; i < n; i++)
		ans += bb[i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 5220
N, K = map(int, input().split())
s = list(input())

cnt_list = []
i = 0
if s[0] == "0":
    key = "0"
else:
    key = "1"
last = 0
while i < N:
    j = i
    tmp = 1
    for j in range(i + 1, N):
        if s[j] == key:
            tmp += 1
            if j == N - 1:
                last = 1
        else:
            break

    cnt_list.append([int(key), tmp])

    if key == "0":
        key = "1"
    else:
        key = "0"
    i = max(j, i + 1)
    if last:
        break

cnt = K
i = 0
tmp = 0
while cnt > 0 and i < len(cnt_list):
    tmp += cnt_list[i][1]
    if cnt_list[i][0] == 0:
        cnt -= 1
    i += 1

if i < len(cnt_list):
    tmp += cnt_list[i][1]
    i += 1

anslist = []
anslist.append(tmp)

start = 0
while i < len(cnt_list) and start < len(cnt_list):
    if cnt_list[start][0] == 1:
        tmp -= cnt_list[start][1]
        if start + 1 < len(cnt_list):
            tmp -= cnt_list[start + 1][1]
        start += 2
    else:
        tmp -= cnt_list[start][1]
        start += 1

    if cnt_list[i][0] == 0:
        tmp += cnt_list[i][1]
        if i + 1 < len(cnt_list):
            tmp += cnt_list[i + 1][1]
        i += 2
    else:
        tmp += cnt_list[i][1]
        i += 1
    anslist.append(tmp)

print(max(anslist))

Measured memory_bytes: 15672
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int N,K;cin>>N>>K;
    int ans=0;
    for(int i=K;i<=N+1;i++){
        int ls=i*(i-1)/2,rs=N*i-ls;
        ans+=rs-ls+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632