akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        mut a: chars,
        mut b: chars,
        mut c: chars,
    }
    a.push('E');
    b.push('E');
    c.push('E');
    a.reverse();
    b.reverse();
    c.reverse();

    let mut tmp = 'A';
    let mut card = a.pop().unwrap();
    loop {
        if card == 'a' {
            tmp = 'A';
            card = a.pop().unwrap();
        } else if card == 'b' {
            tmp = 'B';
            card = b.pop().unwrap();
        } else if card == 'c' {
            tmp = 'C';
            card = c.pop().unwrap();
        } else {
            println!("{}", tmp);
            return;
        }
    }
}


Measured memory_bytes: 4352
s = input()
K = int(input())

substringList = []
if(len(s) < 50):
    for i in range(len(s)):
            for j in range(i, len(s)):
                #print(i,j)
                if(s[i:j+1] in substringList):
                    pass
                else:
                    substringList.append(s[i:j+1])
else:
    for i in range(len(s)):
            for j in range(i, i+5):
                substringList.append(s[i:j+1])
#substringList = list(set(substringList))
print(sorted(list(set(substringList)))[K-1])


Measured memory_bytes: 5068
fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map { it.toLong() }
    
    val aList = readInputLine().split(" ").map { it.toLong() }.toMutableList()
    aList.sort()
    
    // c -> b
    val changeMap = mutableMapOf<Long, Long>()
    
    for (i in 1..m) {
        val (b, c) = readInputLine().split(" ").map { it.toLong() }
        
        val oldB = changeMap.get(c) ?: 0L
        
        changeMap.put(c, oldB + b)
    }
    
    var index = 0
    
    // 小さい方から貪欲に大きい数に変えていく
    for ((k, v) in changeMap.toList().sortedByDescending { it.first }) {
        for (i in 0 until v) {
            if (aList[index] < k) {
                aList[index] = k
                index = (index + 1) % aList.size
            } else {
                break
            }
        }
    }
    
    println(aList.sum())
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main() {
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  int B[3];
  B[0] = abs(A[1]-A[0]);
  B[1] = abs(A[2]-A[1]);
  B[2] = abs(A[0]-A[2]);
  int ans = B[0]+B[1]+B[2] - fmax(B[0],fmax(B[1],B[2]));
  cout << ans << endl;
  return 0;
}  

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

#define ll long long
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define PP pair<P,int>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define all(a) (a).begin(),(a).end()


signed main(){
    int n,k;
    cin>>n>>k;
    vi vec;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        vec.pb(t);
    }
    sort(all(vec),greater<int>());
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=vec[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main ()  {
    int A, S=0, T=0, a, b, i;
     for(i=0; i<4; i++) {
         cin >> a;
         S += a;
     }
     for(i=0; i<4; i++) {
         cin >> b;
         T += b;
     }
     A = S>T? S:T;
    cout << A << endl;
}

Measured memory_bytes: 1160
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from random import randint
import sys
M = 10**5
def main(D, C, S):
    def evaluate(i, t, satisfaction, last):
        satisfaction += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            satisfaction -= c * (i - last[j])
        return (satisfaction, last)

    ans = []
    satisfaction = 0
    last = [-1] * 26
    count = [BinaryIndexedTree(D) for _ in range(26)]
    for i in range(D):
        tt = -1
        ts = -10**10
        tl = None
        ps = satisfaction
        pl = last[:]
        for t in range(26):
            s, l = evaluate(i, t, ps, pl[:])
            if ts < s:
                tt = t
                ts = s
                tl = l
        ans.append(tt + 1)
        satisfaction = ts
        last = tl
        count[tt].add(i, 1)

    for i in range(M):
        tmp_s = satisfaction
        d = randint(0, D - 1)
        new = randint(0, 25)
        old = ans[d] - 1
        tmp_s += S[d][new] - S[d][old]
        cnt_old = count[old].query(d)
        nxt_d_old = count[old].bisect(lambda x: x < cnt_old + 1)
        pre_d_old = count[old].bisect(lambda x: x < cnt_old - 1) if cnt_old > 1 else -1
        tmp_s -= C[old] * (nxt_d_old - d) * (d - pre_d_old)
        ans[d] = new + 1
        count[old].add(d, -1)
        count[new].add(d, 1)
        cnt_new = count[new].query(d)
        nxt_d_new = count[new].bisect(lambda x: x < cnt_new + 1)
        pre_d_new = count[new].bisect(lambda x: x < cnt_new - 1) if cnt_new > 1 else -1
        tmp_s += C[new] * (nxt_d_new - d) * (d - pre_d_new)
        if tmp_s < satisfaction:
            ans[d] = old + 1
            count[old].add(d, 1)
            count[new].add(d, -1)
        else:
            satisfaction = tmp_s

    return ans

class BinaryIndexedTree:
    def __init__(self, n=None, f=lambda x, y: x + y, identity=0, initial_values=None):
        assert(n or initial_values)
        self.__f, self.__id, = f, identity
        self.__n = len(initial_values) if initial_values else n
        self.__d = [identity] * (self.__n + 1)
        if initial_values:
            for i, v in enumerate(initial_values): self.add(i, v)

    def add(self, i, v):
        n, f, d = self.__n, self.__f, self.__d
        i += 1
        while i <= n:
            d[i] = f(d[i], v)
            i += -i & i

    def query(self, r):
        res, f, d = self.__id, self.__f, self.__d
        r += 1
        while r:
            res = f(res, d[r])
            r -= -r & r
        return res

    def bisect(self, func):
        n, f, d, v = self.__n, self.__f, self.__d, self.__id
        x, i = 0, 1 << (n.bit_length() - 1)
        while i > 0:
            if x + i <= n and func(f(v, d[x + i])): v, x = f(v, d[x + i]), x + i
            i >>= 1
        return x

if __name__ == '__main__':
    input = sys.stdin.readline
    D = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(D)]
    ans = main(D, C, S)
    for a in ans:
        print(a)


Measured memory_bytes: 95544
#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 x, y;
  cin >> x >> y;

  bool isSameSign = (x > 0 && y > 0) || (x < 0 && y < 0);
  int res = 0;
  res += abs(abs(y) - abs(x));
  if (y == 0) {
    if (x > 0) {
      res++;
    }
  } else if (x == 0) {
    if (y < 0) {
      res++;
    }
  } else if (isSameSign) {
    if (x > y) {
      res += 2;
    }
  } else {
    res++;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans, flg = 0, 0
    tmp = []
    while True:
        for i in range(N):
            if A[i] % 2 != 0:
                flg = 1
                break
            tmp.append(A[i]/2)
        if flg:
            break
        A = tmp.copy()
        tmp.clear()
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);

void solve() {
  int x,t; cin >> x >> t;
  int ans = x - t;
  if (ans > 0) {
    cout << ans << endl;
  }
  else {
    cout << 0 << endl;
  }
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
int a[105000];
int main() {
    int n = 0;int k = 0;
    s(n);s(k)
    for(int i = 0; i < n; i ++){
        s(a[i]);
    }
    sort(a,a+n);
    ll mini = 10000000000;
    for(int i = k; i <= n; i ++){
        if(a[i-1] - a[i-k] < mini){
            mini = a[i-1]-a[i-k];
        }
    }
    pld(mini) pn
    return 0;
}
//10 11 12 14 15


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

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

using P = pair<int, ll>;
ll dp[3005][3005];
int main() {
    int N, T;
    cin >> N >> T;
    vector<P> A(N);
    for (int i = 0; i < N; i++) {
        int a;
        ll b;
        cin >> a >> b;
        A[i] = P(a, b);
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        for (int t = 0; t < T; t++) {
            chmax(dp[i + 1][min(t + A[i].first, T)], dp[i][t] + A[i].second);
            chmax(dp[i + 1][t], dp[i][t]);
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        chmax(ans, dp[i + 1][T]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 70784
def solve():
    from bisect import bisect_left, bisect_right

    N, K = map(int, input().split())
    As = list(map(int, input().split()))

    As.sort()
    negAs = [-A for A in As[::-1]]
    A2s = [A*A for A in As]
    A2s.sort()

    pstvBs = []
    numB0= 0
    ngtvBs = []
    for A in As:
        if A > 0:
            pstvBs.append(A)
        elif A == 0:
            numB0 += 1
        else:
            ngtvBs.append(A)

    def isOK(x):
        if x >= 0:
            dire = 1
        else:
            dire = -1
        num = 0
        # 正
        iA = 0
        for B in pstvBs[::-dire]:
            key = x//B
            while iA < N and As[iA] <= key:
                iA += 1
            num += iA
        # ゼロ
        if x >= 0:
            num += N*numB0
        # 負
        iA = 0
        for B in ngtvBs[::dire]:
            key = x//(-B)
            while iA < N and negAs[iA] <= key:
                iA += 1
            num += iA
        i = bisect_right(A2s, x)
        num -= i
        num //= 2
        return num >= K

    ng, ok = -(10**18)-1, 10**18+1
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    print(ok)


solve()


Measured memory_bytes: 121828
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N, L;
    cin >> N >> L;

    int sum = 0;
    int minabs = 1000;
    int minval = 0;
    int tmp = 0;
    for (int i = 1; i <= N; i++) {
        tmp = L + i - 1;
        sum += tmp;
        if (minabs > abs(tmp)) {
            minabs = abs(tmp);
            minval = tmp;
        }
    }

    cout << sum - minval << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int x;
  cin>>x;
  if (x == 3 || x == 5 || x == 7){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
import itertools

sys.setrecursionlimit(10**7)

H, W = map(int, input().split())

S = list('#' * (W + 2))
for _ in range(H):
    S.extend('#')
    S.extend(list(input()))
    S.extend('#')
S.extend(list('#' * (W + 2)))

dxs = [-1, 1, -(W + 2), W + 2]
sx, sy = 0, 0


def f(s):
    dist = [-1] * len(S)
    # s = sx * W + sy
    # print('s', s)
    if S[s] == '#':
        return -1
    q = [s]
    dist[s] = 0
    while q:
        qq = []
        for x, dx in itertools.product(q, dxs):
            y = x + dx
            if S[y] == '#':
                continue
            if dist[y] != -1:
                continue
            dist[y] = dist[x] + 1
            qq.append(y)
        q = qq
    return max(dist)


ans = 0
for i in range(len(S)):
    v = f(i)
    if ans < v:
        ans = v
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        Arrays.sort(line, Comparator.reverseOrder());
        int a = Integer.parseInt(line[0] + line[1]);
        int b = Integer.parseInt(line[2]);
        System.out.println(a + b);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 400001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        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);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};


main(){
    ll n=lin();
    ll x=lin();
    ll a[N];
    a[0]=1;
    ll b[N];
    b[0]=1;
    rep(i,50){
        a[i+1]=a[i]*2+3;
        b[i+1]=b[i]*2+1;
    }
    ll ans=0;
    rep3(i,n,0){
        if(x==0){
            cout<<ans;
            return 0;
        }
        if(x>=a[i]){
            x-=a[i];
            ans+=b[i];
            if(x){
                x--;
                ans++;
            }
            if(x>=a[i]){
                x-=a[i];
                ans+=b[i];
            }
            else{
              x--;
            }
        }
        else{
            x--;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 2304
#include<stdio.h>
int main()
{
	int A,B,T,n,m;
	m=0;
	n=0;
	scanf("%d%d%d",&A,&B,&T);
	T=T+0.5;
	m=T/A;
	n=m*B;
		printf("%d\n",n);
		return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int q; cin >> q;
    map<string, int> M;
    rep(i,q){
        int query; cin >> query;
        if(query == 0){
            string key; int x;
            cin >> key >> x;
            M[key] = x;
        }else if(query == 1){
            string key; cin >> key;
            cout << M[key] << endl;
        }else if(query == 2){
            string key; cin >> key;
            M.erase(key);
        }else if(query == 3){
            string L, R; cin >> L >> R;
            auto itr = M.lower_bound(L);
            while(itr != M.end() && (*itr).first <= R){
                if((*itr).second != 0) cout << (*itr).first << " " << (*itr).second << endl;
                itr++;
            }
        }
    }
}


Measured memory_bytes: 27864
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,t,m,i,f=0,j,k,x,r;
    //double n;
    
    cin >> n ;
    double ans=n;
    ans*=3.1415926536;
    ans*=2;
    cout << fixed << setprecision(4) << ans ;
    
    return 0;
}

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

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            int N = input[0];
            int K = input[1];
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            Console.WriteLine(Math.Ceiling((double)(N-1)/(K-1)));

            
        }
    } 
}

Measured memory_bytes: 18400
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int f[100002][2];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;

	int n = s.length(), a = 0,  b = 0;

	for (int i = 0; i < n; ++i) {
		int cur = s[i] - '0';
		a += cur == i % 2;
		b += cur != i % 2;
	}

	cout << min(a, b) << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

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

  int N;
  cin >> N;

  string s;

  int cnt_AB = 0;
  int cnt_A = 0;
  int cnt_B = 0;
  int cnt_BA = 0;
  for(int i = 0; i < N; i++){
    cin >> s;
    if(s[0] == 'B') cnt_B++;
    if(s[s.length()-1] == 'A') cnt_A++;
    if(s[0] == 'B' && s[s.length()-1] == 'A') cnt_BA++;
    for(int j = 0; j < s.length()-1; j++){
      if(s[j] == 'A' && s[j+1] == 'B'){
        cnt_AB++;
      }
    }
  }

  if(!(cnt_BA == cnt_A && cnt_BA == cnt_B)){
    cout << cnt_AB + min(cnt_A, cnt_B) << endl;
  }else if(cnt_BA > 0){
    cout << cnt_AB + cnt_BA - 1 << endl;
  }else{
    cout << cnt_AB << endl;
  }
  
  return 0;
}


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

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

    int sum = 1, dif = 1;
    rep(i, N) {
        int a;
        cin >> a;

        sum *= 3;
        if (a % 2 == 0)
            dif *= 2;
    }

    cout << sum - dif << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;  
#define fi first
#define sec second
int main()
{
	ll n;
	cin>>n;
	pair<ll,ll> d[n];
	for(ll i=0;i<n;i++)
	{
		cin>>d[i].fi>>d[i].sec;
	}
	for(ll i=0;i<=n-3;i++)
	{
		if(d[i].fi==d[i].sec && d[i+1].fi==d[i+1].sec && d[i+2].fi==d[i+2].sec)
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
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 = 1001001000;
const int MOD = 1000000007;
bool E[2005][2005];

using namespace std;

int main() {
  int N;cin >> N;
  vector<pair<int,int>> retu(N);
  for(int i = 0;i<N;i++){
    cin >> retu.at(i).first;
    retu.at(i).second = i;
  }
  sort(retu.begin(),retu.end());
  for(int i = 0;i<N;i++){
    cout << retu.at(i).second+1 << endl;
  }

  /*
  g++ abc.cpp
  ./a.out
  */
 return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};


int main(){
    string s,t;cin >> s >> t;
    cout << t << s << endl;
}


Measured memory_bytes: 256
N = int(input())

if N == 2:
    # K = 2
    print(1)
    exit()

result = 2 # K = N - 1, N
for K in range(2, int(N ** 0.5 + 1)):
    t = N
    while t >= K and t % K == 0:
        t //= K
    if t % K == 1:
        result += 1

    if (N-1) % K == 0 and (N-1) // K > K:
        result += 1
print(result)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                for (int k = j+1; k < n; k++) {
                    // System.out.println(i + " " + j + " " + k);
                    boolean ok = false;
                    int a = array[i];
                    int b = array[j];
                    int c = array[k];
                    
                    if (a+b>c && b+c>a && c+a>b) {
                        if (a == b || b == c || c == a) continue;
                        count++;
                        
                    // System.out.println(i + " " + j + " " + k);
                    }
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 36852
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdlib>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<string> split(const string &str, char delim)
{
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos)
  {
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

int f[10][10];

bool checkf(int x,int y)
{
	if(0 <= x && x < 10 && 0 <= y && y < 10)
	{
		return true;
	}
	else
	{
		return false;
	}
}

void dropInk(int x,int y,int size)
{
	if(size == 1)
	{
		f[x][y]++;
		if(checkf(x+1,y)) f[x+1][y]++;
		if(checkf(x-1,y)) f[x-1][y]++;
		if(checkf(x,y+1)) f[x][y+1]++;
		if(checkf(x,y-1)) f[x][y-1]++;
	}
	else if(size == 2)
	{
		REP(i,-1,2)
		{
			REP(j,-1,2)
			{
				if(checkf(x+i,y+j)) f[x+i][y+j]++;
			}
		}
	}
	else if(size == 3)
	{
		REP(i,-1,2)
		{
			REP(j,-1,2)
			{
				if(checkf(x+i,y+j)) f[x+i][y+j]++;
			}
		}
		if(checkf(x+2,y)) f[x+2][y]++;
		if(checkf(x-2,y)) f[x-2][y]++;
		if(checkf(x,y+2)) f[x][y+2]++;
		if(checkf(x,y-2)) f[x][y-2]++;
	}
}

int main()
{
	memset(f,0,sizeof(f));
	string s;
	while(cin >> s)
	{
		vector<string> _s = split(s,',');
		int x = atoi(_s[0].c_str());
		int y = atoi(_s[1].c_str());
		int size = atoi(_s[2].c_str());

		dropInk(y,x,size);
	}

	int count = 0;
	int ans = 0;
	rep(i,10)
	{
		rep(j,10)
		{
			if(f[i][j] == 0)
			{
				count++;
			}
			ans = max(ans,f[i][j]);
		}
	}

	cout << count << endl << ans << endl;
	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main()
{
	int a, b;
	cin >> a >> b;
	cout << max({ a + b, a - b, a * b }) << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define MAXN 100005
using std::vector;
int n,m,i,ans;
vector<int> v[MAXN];
bool vis[MAXN];
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
inline void dfs(int r)
{
	vis[r]=true;
	for(int i=0;i<v[r].size();i++)
		if(!vis[v[r][i]])
			dfs(v[r][i]);
}
signed main(void)
{
	read(n),read(m);
	for(i=0;i<m;i++)
	{
		int x,y,z;
		read(x),read(y),read(z);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(i=1;i<=n;i++)
		if(!vis[i])
		{
			dfs(i);
			ans++;
		}
	print(ans);
	return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
vector<ll> p(ll x){
  vector<ll> ret;
  for (ll i = 2; i*i <= x; i++)
  {
    dump(x);
    dump(i);
    if(x%i==0){
      ret.push_back(i);
      while(x%i==0){
        x/=i;
      }
    }
  }
  
  if(x>1)ret.push_back(x);
  return ret;
}
void solve(long long A, long long B){
  ll x=gcd(A,B);
  auto ps=p(x);
  dump(ps);
  cout<<1+ps.size()<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

using namespace std;

int p[105];
pair <string, int> a[105];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	
	for (int i = 0; i < n; i++) p[i] = i;
	
	sort(p, p + n, [&](int x, int y) {
		if (a[x].first != a[y].first) return a[x].first < a[y].first;
		return a[x].second > a[y].second;
	});
	
	for (int i = 0; i < n; i++) printf("%d\n", p[i] + 1);
}


Measured memory_bytes: 256
mydict={'AC':0,'WA':0,'TLE':0,'RE':0}

for _ in range(0,int(input())):
    x=str(input())
    if x=='AC':
        mydict[x]+=1
    elif x=='WA':
        mydict[x]+=1
    elif x=='TLE':
        mydict[x]+=1
    elif x=='RE':
        mydict[x]+=1
       
 
        
   
print(f"AC x {mydict['AC']}")
print(f"WA x {mydict['WA']}")
print(f"TLE x {mydict['TLE']}")
print(f"RE x {mydict['RE']}")     
    
  


Measured memory_bytes: 9204
// https://atcoder.jp/contests/abc083/tasks/abc083_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, c, d;
  string r;

  cin >> a >> b >> c >> d;

  r = a + b == c + d ? "Balanced" : a + b < c + d ? "Right" : "Left";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

string s;
int k;

void solve() {
    rep(i, s.length()) {
        if (s[i] != 'a' && s[i] + k > 'z') {
            k -= ('z' - s[i] + 1);
            s[i] = 'a';
        }
    }
    k %= 26;
    if (k > 0) s[s.length() - 1] = char(s[s.length() - 1] + k);
    cout << s << endl;
}

int main() {
    cin >> s;
    cin >> k;
    solve();
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		
		int[][] value = new int[n][2];
		
		for (int i = 0; i < n; i++) {
			value[i][0] = Integer.parseInt(sc.next());
		}
		
		for (int i = 0; i < n; i++) {
			value[i][1] = Integer.parseInt(sc.next());
		}
		
		int maxvalue = 0;
		
		for (int i = 0; i < n; i++) {
			if (value[i][0] - value[i][1] > 0) maxvalue += value[i][0] - value[i][1];
		}

		
		System.out.println(maxvalue);
		
		sc.close();
	}
	
}


Measured memory_bytes: 23380
//////////////////////////
//////////////////////////
////Please give me AC!////
////Please give me AC!////
//////////////////////////
//////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=998244353;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N,S;
  cin>>N>>S;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin>>A.at(i);
  }
  ll dp[3020][3020];
  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%MOD;
      if(j-A.at(i-1)>=0){
        dp[i][j]+=dp[i-1][j-A.at(i-1)]%MOD;
      }
      dp[i][j]%=MOD;
    }
  }
  cout<<dp[N][S]%MOD<<endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    std::array<int, 100010> check{};
    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] < 100010) ++check[A[i]];
        else ++res;
    }
    for (int i = 0; i < check.size(); ++i) {
        if (check[i] == 0) continue;
        if (check[i] == i) continue;
        if (check[i] > i) res += check[i] - i;
        else res += check[i];
        
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4544
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(){
	int W,H,N;
	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&N);
	
	int x[N+5];
	int y[N+5];
	int a[N+5];
	
	for(int i=0;i<N+5;i++){
		x[i]=0;
		y[i]=0;
		a[i]=0;
	}

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

	
	int xy[W+5][H+5];//Wが横　Nが縦
	for(int i1=0;i1<W+5;i1++){
		for(int i2=0;i2<H+5;i2++){
			xy[i1][i2]=0;
		}
	}
	

	
	for(int i=0;i<N;i++){
		if(a[i]==1){
			for(int i1=0;i1<x[i];i1++){
				for(int i2=0;i2<H;i2++){
					xy[i1][i2]=1;
				}
			}
		}
		if(a[i]==2){
			for(int i1=x[i];i1<W;i1++){
				for(int i2=0;i2<H;i2++){
					xy[i1][i2]=1;
				}
			}	
		}
		if(a[i]==3){
			for(int i1=0;i1<W;i1++){
				for(int i2=0;i2<y[i];i2++){
					xy[i1][i2]=1;
				}
			}	
		}
		if(a[i]==4){
			for(int i1=0;i1<W;i1++){
				for(int i2=y[i];i2<H;i2++){
					xy[i1][i2]=1;
				}
			}	
		}
	}
	
		
	int ans=0;
	for(int i1=0;i1<W;i1++){
			for(int i2=0;i2<H;i2++){
					if(xy[i1][i2]==0){
					ans++;
					}
			}
	}
	
	printf("%d\n",ans);
	
}

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

double a,b;
int main(){

    scanf("%lf %lf",&a,&b);
    int d;
    int r;
    double f;
    d = a/b;
    r = (int)a%(int)b;
    f = a/b;
    printf("%d %d %f\n",d,r,f);
  
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;


int main(){
  
  ll n;
  cin >> n;
  
  if(n%1000==0){
    cout << 0 << endl;
    return 0;
    
  }
  
  ll a =1000 - n%1000;
  
  cout <<  a << endl;
  
  
}
       
        
      
  
    

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

int main() {
	int n,m,sum=0;
	cin>>n;
	vector<int>t(n);
	for(int i=0;i<n;i++){
		cin>>t.at(i);
		sum+=t.at(i);
	}
	cin>>m;
	vector<pair<int,int>>p(m);
	for(int i=0;i<m;i++){
		cin>>p.at(i).first>>p.at(i).second;
		cout<<sum-(t.at(p.at(i).first-1)-p.at(i).second)<<endl;
	}

	return 0;

}



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


int main(){
  int n,m,k;
  cin >> n >> m >>k;
  vector<ll> a(n+1),b(m+1);
  a[0]=0;
  b[0]=0;
  for(int i=0;i<n;i++){
     cin >> a[i+1];
     a[i+1] += a[i];
  }
  for(int i=0;i<m;i++){
      cin >> b[i+1];
      b[i+1] += b[i];
  }
  int t;
  vector<int> c(0);
  for(int i=0;i<=m;i++){
    if(b[m-i]<=k){
      c.push_back(m-i);
      t=i;
      break;
    }
  }
  
  for(int i=1;i<=n;i++){
    for(int j=t;j<=m;j++){
      if(a[i]+b[m-j]<=k){
        c.push_back(m+i-j);
        t=j;
        break;
      }
    }
  }
  
  sort(c.begin(),c.end());
  reverse(c.begin(),c.end());
  cout << c[0] << endl;
}

Measured memory_bytes: 7380
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
   ll n;
   cin>>n;
   
   ll a[n];
   
   for(ll i=0;i<n;i++)
   cin>>a[i];
   
   ll dp[n+1][2];
   
   dp[0][0]=0;
   dp[0][1]=-INF;
   
   for(ll 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][1]+a[i],dp[i][0]-a[i]);
   }
   
   ll ans=dp[n][0];
   
   cout<<ans<<endl;
   
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

Measured memory_bytes: 6012
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Diagnostics;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();

            Array.Sort(s);
            Array.Reverse(s);
            long hoge = 0;
            for (int i = 0; i < n-1; i++)
            {
                if (s[i] == s[i+1] && hoge == 0)
                {
                    hoge = s[i];
                    i++;
                }else if (s[i] == s[i + 1] && hoge != 0)
                {
                    WriteLine(hoge * s[i]);
                    return;
                }
            }
            WriteLine(0);
        }
    }
}


Measured memory_bytes: 23008
import numpy as np

def solve():
  N, K = map(int,input().split())
  A = np.array(input().split(), np.int64)
  F = np.array(input().split(), np.int64)

  A.sort()
  F.sort()
  F=F[::-1]
  a_sum = A.sum()
  low, high = -1, 10**13

  while low + 1 < high:
      mid = (low + high) // 2
      if np.minimum(A, mid // F).sum() >= a_sum - K:
          high = mid
      else:
          low = mid
  return high

print(solve())


Measured memory_bytes: 37220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int x,y;
  cin >> x >> y;
  rep(i,x+1){
      if(2*i == y-2*x){
        cout << "Yes" << endl;
        return 0;
      }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[5001];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

Measured memory_bytes: 3072
require 'set'
n,m = gets.split.map(&:to_i)
G = Array.new(n+1){[]}
visited = [false]*(n+1)
conn = [false]*(n+1)
cnt = [0]*(n+1)
par = []*(n+1)

ans = Set.new

if m%2==1
  p -1
  exit
end

m.times do
  a,b = gets.split.map(&:to_i).sort
  G[a] << b
  G[b] << a
  cnt[a]+=1
  ans << [a,b]
end

stack = [1]
conn[1] = true
while !stack.empty?
  v = stack[-1]
  if !visited[v]
    G[v].each do |u|
      if !conn[u]
        par[u] = v
        stack << u
        conn[u] = true
      end
    end
    visited[v] = true
  else
    if cnt[v] % 2 == 1
      x,y = [v,par[v]].sort
      ans.delete([x,y])
      ans << [y,x]
      cnt[x]-=1
      cnt[y]+=1
    end
    stack.pop
  end
end

ans.each do |a|
  puts a.join(" ")
end


Measured memory_bytes: 45692
N,M=gets.split.map(&:to_i)
H=gets.split.map(&:to_i)
G=Array.new(N){[]}
M.times do
  a,b=gets.split.map{|i|i.to_i-1}
  G[a]<<b
  G[b]<<a
end
p N.times.map{|u|G[u].inject(0){|s,v|[s,H[v]].max}<H[u] ? 1 : 0}.inject :+

Measured memory_bytes: 27416
import java.io.*;
import java.util.*;

public class Main {
    public static void main (String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int A = Integer.parseInt(st.nextToken()),
            B = Integer.parseInt(st.nextToken()),
            C = Integer.parseInt(st.nextToken());
        String ans = "No";
        if (A<=C && C<=B) ans = "Yes";
        System.out.println(ans);
    }
}



Measured memory_bytes: 21204
#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 n,q;
    ll k;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i,q) cin >> a.at(i);
    vector<ll> score(n,0);
    rep(i,q) score.at(a.at(i)-1)++;
    rep(i,n){
        if(q-score.at(i)>=k) cout << "No" << endl;
        else cout << "Yes" << endl;
    }


}
    
    

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main () {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    int sum = 0;
    for (int i = 0; i < K; i++) {
        sum += A[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
#define debug(x) cerr << #x << ' ' << x << endl;
using namespace std;

typedef long long ll;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
    int n, x, k, ans = 0;
    cin >> n >> k;
    rep(i, 1, n) {
        cin >> x;
        if(x >= k)  ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(b<=4*a&&b>=2*a&&(b%2)==0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
  int n=0,arc=0,abc=0,ans=0;
  int d[100005];
  scanf("%d", &n);
  for(int i=0;i<n;i++){
    scanf("%d", &d[i]);
  }

 qsort(d,n,sizeof(int), compare_int);
  printf("%d", d[n/2]-d[n/2-1]);

    return 0;
  }

  

Measured memory_bytes: 2280