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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  
  sort(d.begin(),d.end());
  int count = 1;
  for(int i=0; i<N-1; i++){
    if(d.at(i) != d.at(i+1))  count++;
  }
  cout << count << endl;
}



Measured memory_bytes: 256
use std::collections::{BTreeMap, BTreeSet};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n = sc.read();
    let a: Vec<usize> = sc.read_vec(n);
    if a.iter().all(|&x| x % 2 == 0) {
        println!("second");
    } else {
        println!("first");
    }
    // let mut map = BTreeMap::new();
    // map.insert(vec![0, 0, 0], 0);
    // grundy(vec![5, 5, 5], &mut map);
    // for (t, &v) in map.iter() {
    //     if v == 0 {
    //         println!("{:?}", t);
    //     }
    // }
}

fn grundy(t: Vec<usize>, map: &mut BTreeMap<Vec<usize>, usize>) -> usize {
    if map.contains_key(&t) {
        return *map.get(&t).unwrap();
    }
    let sum = t.iter().sum::<usize>();
    let mut set = BTreeSet::new();
    let n = t.len();
    for mask in 0..(1 << n) {
        let mut t = t.clone();
        for i in 0..n {
            if (1 << i) & mask != 0 && t[i] > 0 {
                t[i] -= 1;
            }
        }
        let clone_sum = t.iter().sum::<usize>();
        if clone_sum == sum {
            continue;
        }
        set.insert(grundy(t, map));
    }
    for i in 0.. {
        if !set.contains(&i) {
            map.insert(t, i);
            return i;
        }
    }
    unreachable!()
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

const int INF = 1e9;
int n;
int D1[100000], D2[100000];
vector<int> G[100000];

void dfs1(int now){
    for(int i = 0; i < G[now].size(); i++){
        int to = G[now][i];
        if(D1[to] > D1[now] + 1){
            D1[to] = D1[now] + 1;
            dfs1(to);
        }
    }
}

void dfs2(int now){
    for(int i = 0; i < G[now].size(); i++){
        int to = G[now][i];
        if(D2[to] > D2[now] + 1){
            D2[to] = D2[now] + 1;
            dfs2(to);
        }
    }
}

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

    cin >> n;

    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    for(int i = 0; i < n; i++){
        D1[i] = INF;
        D2[i] = INF;
    }

    D1[0] = 0;
    dfs1(0);
    D2[n - 1] = 0;
    dfs2(n - 1);

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(D1[i] <= D2[i]) cnt++;
        else cnt--;
    }

    if(cnt > 0) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    
    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
using namespace std;
long long gcd(long long a,long long b)
    {
        if(b==0) return a;
        return gcd(b,a%b);
    }

long long lcm(long long a,long long b)
    {
        long long c=a*b;
        return c/gcd(a,b);
    }

int main()
    {
        long long a,b;
        while(cin>>a>>b)
            {
                cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
            }
        return 0;
    }



Measured memory_bytes: 3040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] x = new int[n];
			int[] y = new int[n];
			long[] h = new long[n];

			for (int i = 0; i < n; i++) {
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
				h[i] = sc.nextLong();
			}

			for (int i = 0; i <= 100; i++) {
				for (int j = 0; j <= 100; j++) {
					boolean collect = true;
					long higher = 0;
					for (int k = 0; k < n; k++) {
						if (0 < h[k]) {
							higher = h[k] + Math.abs(x[k] - i) + Math.abs(y[k] - j);
						}
					}

					for (int k = 0; k < n; k++) {
						long kyori = Math.abs(x[k] - i) + Math.abs(y[k] - j);

						if (0 <= higher - kyori) {
							if (higher - kyori != h[k]) {
								collect = false;
								break;
							}
						} else {
							if (h[k] != 0) {
								collect = false;
								break;
							}
						}
					}
					if (collect) {
						System.out.println(i + " " + j + " " + higher);
						return;
					}
				}
			}

		}
	}
}


Measured memory_bytes: 25300
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    vector<int> pos(5);
    for(int i=0; i<5; i++) cin >> pos[i];

    int K; cin >> K;
    bool ng = false;
    for(int i=0; i<5; i++) {
        for(int j=i+1; j<5; j++) {
            if(abs(pos[i] - pos[j]) > K) {
                ng = true;
            }
        }
    }
    cout << (ng ? ":(" : "Yay!") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main (void){
  string S,T;
  cin >> S >> T ;
  int max = 0;
  int count;
  for(int i = 0; i <= (int)S.size()-(int)T.size(); i++){
    string sub = S.substr(i,T.size());
    count = 0;
    for(int j = 0; j < (int)T.size(); j++){
      if(sub[j] == T[j]){
        count++;
      }
    }
    if(max < count){
      max = count;
    }
  }
  cout << (int)T.size() - max << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

/* a と b の最小公倍数を求める */
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int N, M;
    cin >> N >> M;
    set<ll> A, evens;
    REP(i, N) {
        ll a;
        cin >> a;
        a /= 2;
        A.insert(a);
        int p = 1;
        while(a % 2 == 0) {
            a /= 2;
            p++;
        }
        evens.insert(p);
    }

    if(evens.size() > 1) {
        cout << 0 << endl;
        return 0;
    }

    ll lcm = *A.begin();
    for(ll a: A) {
        lcm = LCM(a, lcm);
        if(lcm > M) {
            cout << 0 << endl;
            return 0;
        }
    }
    // cerr << "lcm : " << lcm <<endl;
    if(lcm > M) {
        cout << 0 << endl;
    } else {
        cout << (M/lcm - 1) / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3772
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
    else
        cout << c << " " << a << " " << b << endl;
}
    


Measured memory_bytes: 3084
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    int N,M,K;
    bool F=false;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M>>K;
    if(N>M)swap(N,M);
    EREP(i,N){
        EREP(j,M){
            if(M*i-(j*i)+j*(N-i)==K){
                F=true;
            }
            if(F)break;
        }
        if(F)break;

    }
    cout<<((F||K==0||K==N*M)?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define P pair<int, int>
using namespace std;


int main() {
  int x;
  cin >> x;
  int ans = 1;
  for(int b = 1; b*b <= x; b++){
    for(int p = 2; p <= 10; p++){
      int tmp = pow(b, p);
      if(tmp <= x) ans = max(ans, tmp);
    }
  }
  
  cout << ans << endl;

}




Measured memory_bytes: 4004
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,p;
    cin >> a  >> p;
    p+=a*3;
    cout << p/2 << endl;

    return 0;
}

Measured memory_bytes: 892
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
S = list(input())

c = 0
now = 0
left = 0
right = 0
for i in range(N):
    if S[i] == '(':
        now -= 1
        left += 1
    else:
        now += 1
        right += 1
    if c < now:
        c = now

S = ['(']*c + S + [')']*(left+c-right)
print(''.join(S))

Measured memory_bytes: 65380
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;


int main()
{
    int s, cnt = 1;
    cin >> s;
    char a[1000000] = {0};
    bool isfound = false;

    a[s] = 1;

    while (!isfound) {
        cnt++;
        if (s%2) {
            s = 3*s+1;
            if (a[s]) {
                cout << cnt << endl;
                return 0;
            }
            else a[s] = 1;
        }
        else {
            s = s/2;
            if (a[s]) {
                cout << cnt << endl;
                return 0;
            }
            else a[s] = 1;
        }
    }

}

Measured memory_bytes: 1280
from collections import Counter


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    k = min(k, n - k)
    ans = 1
    for i in range(1, k + 1):
        ans *= n - i + 1
        ans //= i
    return ans


s = input()
n = len(s)
a = [0] * (n + 1)
a[n - 1] = int(s[n - 1])
base = 10
for i in reversed(range(n - 1)):
    a[i] = (a[i + 1] + int(s[i]) * base) % 2019
    base *= 10
    base %= 2019
# print(a)

cnt = Counter(a)
# print(cnt)

ans = 0
for v in cnt.values():
    ans += comb(v, 2)

print(ans)


Measured memory_bytes: 16496
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var n = int.Parse(Console.ReadLine().Trim());
        var conf = 0;
        for (int i = 0; i < n; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var rfrom = int.Parse(line2[0]);
            var rto = int.Parse(line2[1]);
            if (rfrom>= a  && rfrom < b) { conf = 1; break; }
            else if (rto > a && rto <= b) { conf = 1; break; }
            else if (rfrom < a  && rto > b) { conf = 1; break; }
        }
        Console.WriteLine(conf);
    }
}

Measured memory_bytes: 9252
N,M = map(int,input().split())
amax = 1
for i in range(1,int(M**0.5)+1):
    if M%i==0:
        a = i
        b = M//i
        if b>=N:
            amax = max(amax,a)
        a,b = b,a
        if b>=N:
            amax = max(amax,a)
print(amax)

Measured memory_bytes: 63824
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_right

sys.setrecursionlimit(10**7)
N = int(input())
P = list(map(int, input().split()))

cnt = 0
minv = P[0]
for p in P:
    minv = min(minv, p)
    if p == minv:
        cnt += 1

print(cnt)


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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

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

    if(a > 0 && b > 0) {
        cout << "Positive" << endl;
    }
    else if(a < 0 && b > 0) {
        cout << "Zero" << endl;
    }
    else if(a < 0 && b < 0) {
        if((b-a) % 2 == 0) {
            cout << "Negative" << endl;
        }
        else
            cout << "Positive" << endl;
    }
	
    return 0;
}

Measured memory_bytes: 896
inputs = $stdin.read.split("\n")
count = inputs.first.to_i
samples = inputs.last.split(' ').map(&:to_f).sort

samples_1 = samples
samples_2 = samples - [samples.min]

distance = 9999999999999999999999
min_dis_index = 0
samples_2.each_with_index do |v, i|
  if (v - samples_1[i]) < distance
    distance = v - samples_1[i]
    min_dis_index = i
  end
end

d = samples_1[min_dis_index]
c = samples_2[min_dis_index]

a = (samples - [d, c]).max
samples = (samples - [d, c]) - [a]
b = samples.max
samples = samples - [b]

result_1 = ((a + b) / (c - d)).round(5)

# puts result_1
# puts "A:#{a}, B:#{b},C:#{c}, D:#{d}"

a = samples.max
samples = samples - [a]
b = samples.max
samples = samples - [b]

samples = inputs.last.split(' ').map(&:to_f).sort

a = samples.max
samples = samples - [a]
b = samples.max
samples = samples - [b]

samples_1 = samples
samples_2 = samples - [samples.min]

distance = 9999999999999999999999
min_dis_index = 0
samples_2.each_with_index do |v, i|
  if (v - samples_1[i]) < distance
    distance = v - samples_1[i]
    min_dis_index = i
  end
end

d = samples_1[min_dis_index]
c = samples_2[min_dis_index]

result_2 = ((a + b) / (c - d)).round(5)

# puts result_2
# puts "A:#{a}, B:#{b},C:#{c}, D:#{d}"

puts [result_1, result_2].max

Measured memory_bytes: 9048
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int M = sc.nextInt();
        int[] l1 = new int[N+1];
        int ans = 0;
        for(int i = 1;i < N+1;i++)  l1[i] = -1;
        for(int i = 0;i < M;i++){
            int ai = sc.nextInt();
            int bi = sc.nextInt();
            l1[bi] = Math.max(ai, l1[bi]);
        }
        int right = N;
        int left = 0;
        while(true){
            if(right == 1)  break;
            if(l1[right] > 0){
                left = l1[right];
            }else{
                right--;
                continue;
            }
            while(true){
                if(left == right){
                    ans++;
                    break;
                }
                left = Math.max(left, l1[right]);
                right--;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 65688
//abc157-2
//date 03/05
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int A[3][3]={0};
  int B[3][3]={0};
  int N;
  int n;
  for (size_t i = 0; i < 3; i++) {
    for (size_t j = 0; j < 3; j++) {
      scanf("%d", &A[i][j]);
    }
  }
  scanf("%d", &N);
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &n);
    for (size_t i = 0; i < 3; i++) {
      for (size_t j = 0; j < 3; j++) {
        if (n == A[i][j]) {
          B[i][j]=1;
        }
      }
    }
  }
  if (B[0][0]+B[0][1]+B[0][2] == 3) {
    printf("Yes\n");
  }
  else if(B[1][0]+B[1][1]+B[1][2] == 3) {
    printf("Yes\n");
  }else if(B[2][0]+B[2][1]+B[2][2] == 3) {
    printf("Yes\n");
  }else if(B[0][0]+B[1][0]+B[2][0] == 3) {
    printf("Yes\n");
  }else if (B[0][1]+B[1][1]+B[2][1] == 3) {
    printf("Yes\n");
  }else if (B[0][2]+B[1][2]+B[2][2] == 3) {
    printf("Yes\n");
  }else if (B[0][0]+B[1][1]+B[2][2] == 3) {
    printf("Yes\n");
  }else if(B[2][0]+B[1][1]+B[0][2] == 3) {
    printf("Yes\n");
  }else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mod 1000000007
#define nn 221
int n,ai[nn];
void add(int&x,int y){
	x=(x+y)%mod;
}
int dp[2][nn][nn];
signed main(){
	cin>>n;for(int i=1;i<=n*2-1;i++) cin>>ai[i];sort(ai+1,ai+n*2);
//	int tst=0;for(int i=1;i<=n*2-1;i++) if(ai[i]!=ai[i-1]) ai[i]=++tst;else ai[i]=tst;
	int now=0;dp[now][1][0]=1;
	for(int i=n-1;i>=1;i--){
		now^=1;memset(dp[now],0,sizeof dp[now]);
		for(int l=0;l<nn-2;l++) for(int r=0;r+l<nn-2;r++) {
			int res=dp[now^1][l][r];
			int el=l,er=r;
			if(ai[i]!=ai[i+1]) l++;
			if(ai[2*n-i]!=ai[2*n-i-1]) r++;
			add(dp[now][l][r],res);//same
			for(int sl=1;sl<l;sl++) add(dp[now][l-sl][r+1],res);
			for(int sr=1;sr<=r;sr++) add(dp[now][l+1][r-sr],res);
			l=el,r=er;
		}
	}
	
	int ans=0;for(int i=0;i<nn;i++) for(int j=0;j<nn;j++) add(ans,dp[now][i][j]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t=input()

def zyanken(x):
    if x=="r":
        return p
    elif x=="s":
        return r
    elif x=="p":
        return s

str_list = []
for i in range(k):
    str_list.append(t[i::k])

ans = 0

for g in str_list:
    dp = [0]*len(g)
    dp[0]=zyanken(g[0])
    before = g[0]
    for l in range(1,len(g)):
        if before!=g[l]:
            dp[l]=dp[l-1]+zyanken(g[l])
            before=g[l]
        else:
            dp[l]=dp[l-1]
            before="n"
    ans += dp[len(g)-1]
print(ans)

Measured memory_bytes: 8820
#include <iostream>

using namespace std;

// return x^n % mod
// it takes O(log{n})
long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    // 最下位bitが立っていたら x^{2^i}を掛ける
    if (n & 1) { res = res * x % mod; }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

// return x^{-1} % mod
// it takes O(log{mod})
long long mod_inverse(long long x, long long mod) {
  return mod_pow(x, mod-2, mod);
}

// return nCk % mod
// it takes O(k)
long long mod_comb(long long n, long long k, long long mod) {
  long long numer = 1, denom = 1;
  for (long long i = 0; i < k; i++) {
    // numer: 分子, denom: 分母
    numer = numer * ((n-i) % mod) % mod;
    denom = denom * ((i+1) % mod) % mod;
  }
  return numer * mod_inverse(denom, mod) % mod;
}

int main() {
  long long n, a, b;
  long long mod = 1000000007;

  cin >> n >> a >> b;

  long long ans = mod_pow(2, n, mod)-1;
  ans = (ans - mod_comb(n, a, mod)) % mod;
  ans = (ans - mod_comb(n, b, mod)) % mod;
  cout << (ans + mod) % mod << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define MN 200005
using namespace std;
int n,sx,sy,tx,ty,maxn=1e8,top,st[MN],ans,y[MN],lst,resnow[MN];
struct po{int x,y;}p[MN];
bool cmp(po x,po y){return x.x==y.x?x.y<y.y:x.x<y.x;}
int main(){
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
	if(tx<sx)swap(sx,tx),swap(sy,ty);
	if(sy>ty){
		sy=maxn-sy,ty=maxn-ty;for(int i=1;i<=n;i++)p[i].y=maxn-p[i].y;
	}int resx=sx,resy=sy,retx=tx,rety=ty;p[++n]=(po){sx,sy},p[++n]=(po){tx,ty};
	for(int i=1;i<=n;i++)y[i]=p[i].y;sort(p+1,p+n+1,cmp);sort(y+1,y+n+1);int ny=unique(y+1,y+n+1)-y;
	for(int i=1;i<=n;i++)p[i].y=lower_bound(y+1,y+ny,p[i].y)-y;
	sy=lower_bound(y+1,y+ny,sy)-y,ty=lower_bound(y+1,y+ny,ty)-y;int i;st[0]=0;
	for(int i=1;i<=n;i++)st[i]=n+1;
	for(i=1;i<=n;i++)if(p[i].y>=sy&&p[i].y<=ty&&p[i].x>=sx&&p[i].x<=tx){
		if(p[i].x==sx&&p[i].y==sy)continue;
		resnow[i]=upper_bound(st,st+n+1,p[i].y)-st;
		st[resnow[i]]=p[i].y;
		if(p[i].x==tx&&p[i].y==ty)break;
	}ans=resnow[i]-1;
	double res=1.0*(retx-resx+rety-resy)*100;res+=1.0*(acos(-1)-4)*5*ans;
	if(ans==min(retx-resx+1,rety-resy+1))res+=5.0*(ans!=0)*acos(-1);printf("%.15f\n",res);
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int a, b;
    cin >> a >> b;
    if(a-2*b>0){
        cout << a - 2 * b << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

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

using namespace std;
using uint = unsigned int;
using int64 = long long;
using i64 = int64;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
template<typename T>
using p_que = priority_queue<T>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

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

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U> p) {
	return os << "P(" << p.first << ", " << p.second << ")";
}

template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << e << " ";
	return os << "}";
}

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Cut from here! */

//#define int long long

void Main() {
	int n, c; cin >> n >> c;
	int cake = 0;
	for (int i = 0; i < c; ++i) {
		int p; cin >> p;
		cake += p;
	}

	cout << cake / (n + 1) + (cake % (n + 1) > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 3200
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
        
        String s = r.readLine();
        int x = Integer.parseInt(s);
        x = x*x*x;
        
        System.out.println(x);
    }
}

Measured memory_bytes: 24100
#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 x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  int ans = 0;
  if (x1 == 0) ans = 1;
  if (x2 == 0) ans = 2;
  if (x3 == 0) ans = 3;
  if (x4 == 0) ans = 4;
  if (x5 == 0) ans = 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
char s[100001];
int ans=0;
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for (int i=1;i<len;i++)
	  if (s[i]!=s[i-1]) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        if(n<1200){
            System.out.println("ABC");
        }
        else {
            System.out.println("ARC");
        }
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

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

        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextLong();
        long sum = 0;
        for (int i = 1; i<=N; i++) {
            if (i % 3 == 0 || i % 5 == 0 ) {
                continue;
            }
            sum += i;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a;
  cin >> a;
  
  if(a/100 == a%10) co("Yes");
  else co("No");
  return 0;
}


Measured memory_bytes: 384
a=65280; b=61680; c=52428; d=43690; e=65535
from heapq import heappush, heappop
Q = [(1, a), (1, b), (1, c), (1, d)]
L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1}
H = []
get = L.get
push = H.append
while Q:
    l, p = heappop(Q)
    if L[p] < l: continue
    if l+1 < get(p ^ e, 17):
        L[p ^ e] = l+1
        l < 15 and heappush(Q, (l+1, p ^ e))
    if l < 13:
        li = 13-l; l3 = 3+l
        for q, r in H:
            if r <= li:
                k = p & q
                if r < get(k, 17)-l3:
                    L[k] = l3+r
                    r < li and heappush(Q, (l3+r, k))
                k = p ^ q
                if r < get(k, 17)-l3:
                    L[k] = l3+r
                    r < li and heappush(Q, (l3+r, k))
            else: break
    if l < 7: push((p, l))
print(*map(L.__getitem__, eval("e&"+",e&".join(open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]))),sep='\n')

Measured memory_bytes: 8508
import math

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
F = [int(x) for x in input().split()]
#%%

A.sort(reverse=True)
F.sort()
max_af = 0
for ind,a in enumerate(A):
    max_af = max(a*F[ind], max_af)

if(sum(A)<=K):
    print(0)
else:
    lower = -1
    higher = 10**12+1

    while(higher-lower>1):
        x = (lower + higher)//2
        
        k = K
        for ind,a in enumerate(A):
            mu = a*F[ind]
            if(mu<=x):
                continue
            else:
                k -= math.ceil((mu-x)/F[ind])
        if(k>=0):
            higher = x
        else:
            lower = x

    print(higher)


Measured memory_bytes: 120396
#include <iostream>

int main( void )
{
	int n;
	std::cin >> n;

	int imax = 0, imin = 0;
	for( int i = 0; i < n; i++ ) {
		int a;
		std::cin >> a;

		if( i == 0 ) {
			imax = a;
			imin = a;
			continue;
		}
		imax = std::max( a, imax );
		imin = std::min( a, imin );
	}

	std::cout << std::abs( imax - imin ) << std::endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    K, S = map(int, input().split())

    ans = 0
    for x in range(min(K, S) + 1):
        for y in range(min(K, S - x) + 1):
            z = S - x - y
            if z < 0 or z > K: continue
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
t[1001][1001][4];m,n,i,j,x,k;f(z){return t[i][j][z]-t[m-1][j][z]-t[i][n-1][z]+t[m-1][n-1][z];}main(c){for(scanf("%d%d%d ",&m,&n,&k);x=i++<m;)for(;c=getchar()-10;++t[i][x++][c%4])for(j=4;j--;)t[i][x][j]=t[i][x-1][j];for(;i=x++<n;)for(;i++<m;)for(j=4;j--;)t[i][x][j]+=t[i-1][x][j];for(;x=k--;printf("%d %d %d\n",f(0),f(1),f(3)))scanf("%d%d%d%d",&m,&n,&i,&j);}

Measured memory_bytes: 15000
import copy
from collections import deque
s = deque(input())
sc = copy.deepcopy(s) 
sc.reverse()
n = int(input())
l = [list(input().split()) for i in range(n)]

for i in range(n):
    if l[i][0] == '1':
        save = s
        s = sc
        sc = save
    elif l[i][1] == '1':
        s.appendleft(l[i][2])
        sc.append(l[i][2])
        #s = l[i][2] + s
        #sc += l[i][2]
    else:
        s.append(l[i][2])
        sc.appendleft(l[i][2])
        #s += l[i][2]
        #sc = l[i][2] + sc

print(''.join(s))


Measured memory_bytes: 38008
/*
    In the name of
        "ALLAH"
    And say "AL-HAM-DU-LILLAH"
*/

#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0;}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define dbg(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 100005
//////////////////////////////////////////


int main(){

    ll x=LL,y=LL;


        if(x%y==0) printf("-1");
        else{
                for(int i=1;i<=10;i++){
                    if((x*i)%y!=0){
                        printf("%lld\n",x*i);
                        done;
                    }
                }
                printf("-1");
        }


    done;
}




Measured memory_bytes: 256
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

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

  for(int i = 0; i < k; i++){
    if(i % 2 == 0){
      // 高橋
      if(a % 2 != 0) a--;
      a /= 2;
      b += a;
    }else{
      if(b % 2 != 0) b--;
      b /= 2;
      a += b;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

struct pole
{
    int dl;
    char c;
    int pos;
};

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int n = nap.size();
    vector< vector<int> > p(n + 1, vector<int>(26, -1));
    for (int i = n - 1; i >= 0; --i)
    {
        p[i][nap[i] - 'a'] = i;
        for (int j = 0; j < 26; ++j)
            if (j != nap[i] - 'a')
                p[i][j] = p[i + 1][j];
    }
    vector<pole> dp(n, {0, 'z'});
    for (int i = n - 1; i >= 0; --i)
    {
        int dl = 10000000;
        char lit;
        int pos;
        for (int j = 0; j < 26; ++j)
        {
            if (i + 1 >= n || p[i + 1][j] == -1)
            {
                dl = 0;
                lit = (char) (j + 'a');
                pos = -1;
                break;
            }
            if (dp[p[i + 1][j]].dl < dl)
            {
                dl = dp[p[i + 1][j]].dl;
                lit = (char) (j + 'a');
                pos = p[i + 1][j];
            }
        }
        dp[i] = {dl + 1, lit, pos};
    }
    pole akt = {10000000, 'a', -1};
    for (int i = 0; i < 26; ++i)
    {
        if (p[0][i] == -1)
        {
            cout << (char) (i + 'a');
            return 0;
        }
    }
    int w;
    for (int i = 0; i < 26; ++i)
    {
        if (dp[p[0][i]].dl < akt.dl)
        {
            akt = dp[p[0][i]];
            w = p[0][i];
        }
    }
    while (true)
    {
        cout << nap[w];
        if (akt.pos == -1)
            break;
        w = akt.pos;
        akt = dp[akt.pos];
    }
    cout << akt.c;
    return 0;
}


Measured memory_bytes: 29332
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    long long x,y;
    scanf("%lld%lld",&x,&y);
    int cnt = 0;
    while(x<=y)
    {
        cnt++;
        x = x*2;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class LightList
{
private:
	const static int INVALID = -1;
	int front, back, size;
	int *allocate_array;

public:
	LightList(int size) : 
		front(0), back(0), size(0)
	{
		allocate_array = new int[size];
	}
	~LightList()
	{
		delete[] allocate_array;
	}
	void insert(int x)
	{
		allocate_array[front] = x;
		front++;
		size++;
	}
	void remove(int x)
	{
		for (int i = front - 1; i >= back; i--) {
			if (allocate_array[i] == x) {
				allocate_array[i] = INVALID;
				if (i == front - 1)
					front--;
				if (i == back)
					back++;
				break;
			}
		}
	}
	void deleteFirst()
	{
		if (size > 0) {
			front--;
			size--;
		}
	}
	void deleteLast()
	{
		if (size > 0) {
			back++;
			size--;
		}
	}
	void print()
	{
		int i = front - 1;
		while (i >= back && allocate_array[i] == INVALID) i--;
		cout << allocate_array[i];
		i--;
		for (; i >= back; i--) {
			if (allocate_array[i] != INVALID)
				cout << ' ' << allocate_array[i];
		}
		cout << endl;
	}
	/*
	void debug_print()
	{
		cout << "front = " << front
			<< "back = " << back
			<< "size = " << size << endl;
		for (int i = 10; i >= 0; i--) {
				cout << allocate_array[i] << (i == back ? '\0' : ' ');
		}
		cout << endl;
	}
	*/
};

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

	int n, size = 1000020;
	cin >> n;
	if (n < 1000020) size = n;
	LightList number_list(size);

	for (int i = 0; i < n; i++) {
		char command[12];
		int x;
		cin >> command;
		if (command[0] == 'i') { // insert x
			cin >> x;
			number_list.insert(x);
		}
		else { // delete???
			switch (command[6]) {
			case '\0': // delete x
				cin >> x;
				number_list.remove(x);
				break;
			case 'F': // deleteFirst
				number_list.deleteFirst();
				break;
			case 'L': // deleteLast
				number_list.deleteLast();
				break;
			}
		}
	}
//	number_list.debug_print();
	number_list.print();
	return 0;
}

Measured memory_bytes: 4896
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char x){
    int b;
    if(x=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(x=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(x=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(x=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(x=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  
  cout << (f?"Yes":"No") << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ma=0,mi=1000000;
  cin>>n;
  for(int i=0;i<n;++i){
    int a;
    cin>>a;
    ma=max(ma,a);
    mi=min(mi,a);
  }
  cout<<ma-mi<<endl;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void){
int a;
int b;
int c;
int d;
int menseki1;
int menseki2;

scanf("%d%d%d%d",&a,&b,&c,&d);

menseki1 = a*b;
menseki2 = c*d;

if(menseki1>menseki2){
printf("%d",menseki1);
}else if(menseki1 == menseki2){
printf("%d",menseki1);
}else{
printf("%d",menseki2);
}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define eps 1e-10
#define dbs long double

ll i,j,k,sum=0,ans=0,n;

void fastio(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve()
{
	cin>>n;

	int a[n][3];
	int dp[n][3];
	for(i=0;i<n;i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];

	for(i=1;i<n;i++)
	{
		dp[i][0] = max(a[i][0]+dp[i-1][1],a[i][0]+dp[i-1][2]);
		dp[i][1] = max(a[i][1]+dp[i-1][0],a[i][1]+dp[i-1][2]);
		dp[i][2] = max(a[i][2]+dp[i-1][0],a[i][2]+dp[i-1][1]);
	}
	n = n-1;
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));


	
	
}

int main(){
	fastio();
	int t=1;
	//cin>>t;
	 while(t--)
	 	solve();
	return 0;
}

Measured memory_bytes: 2688
import fractions
from functools import reduce
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def myAnswer(N:int,T:list) -> int:
   return lcm_list(T)

def modelAnswer():
   return
def main():
   N = int(input())
   T = [int(input()) for _ in range(N)]
   print(myAnswer(N,T))
if __name__ == '__main__':
   main()

Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  ll n;
  cin >>n;
  ll ans=0;
  for(int i=1;i<=n;i++){
    ll a=n/i;
    ll g=a*(a+1)/2;
    ans+=i*g;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#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 YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
LLI n,a,b,h[100003];
LLI om(LLI a,LLI b){
    if(a<=0){
        return -((-a)/b);
    }else{
        return (a-1)/b+1;
    }
}
 
bool solve(LLI k){
    LLI sum=0;
    FOR(i,0,n){
        sum+=max(om(h[i]-b*k,a-b),(LLI)0);
    }
    return (sum<=k);
}
 
int main(){
    cin>>n>>a>>b;
    FOR(i,0,n) cin>>h[i];
    int st=0,en=INF;
    while(st+1!=en){
        int mid=(st+en)/2;
        if(solve(mid)){
            en=mid;
        }else{
            st=mid;
        }
    }
    co(en);
}


Measured memory_bytes: 1152
s, k = input(), int(input())

if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()

ans, cnt = [], 1
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 1
else:
    ans.append(cnt)

if s[0] != s[-1]:
    ans = [i//2 for i in ans]
    print(sum(ans) * k)
elif s[0] == s[-1]:
    f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2
    ans = [i//2 for i in ans[1:-1]]
    print(f + sum(ans) * k + m * (k - 1) + l)


Measured memory_bytes: 9124
# include <bits/stdc++.h>
using namespace std;
# define ll long long
const int N = 2e5 + 10, mod = 1e9 + 7, INF = 1e9 + 100;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector < double > a(n);
    double ans = 0, sum = 0;
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 0; i < n; i++){
        sum += (a[i] + 1) / 2;
        if(i >= k - 1){
            ans = max(ans, sum);
            sum -= (a[i - k + 1] + 1) / 2;
        }
    }
    cout << setprecision(9) << ans << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> d(K);
  vector<int> A(N);
  
  vector<int> count(N+1);
  for (int i=0; i<=N; i++) count.at(i) = 0;

  for (int i=0; i<K; i++){
    cin >> d.at(i);
    for (int j=0; j<d.at(i); j++){ 
      cin >> A.at(j);
      count.at(A.at(j)) = 1;
    }    
  }
  int sum = 0;
  for (int i=0; i<=N; i++) sum += count.at(i);
  
  cout << N-sum << endl;
}


Measured memory_bytes: 3596
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n;
char str[MAXN];
int main()
{
    scanf("%d",&n);
    scanf("%s",str+1);
    int cnt=0;
    for(int i=1;i<=n;i++) if(str[i]=='R') cnt++;
    if(cnt>n-cnt) puts("Yes"); else puts("No");
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define se second
#define fi first
#define prout(x) cout.precision(x)
using namespace std;

int main(){
    int n, x, odd=0, even=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x%2==0)even++;
        else odd++;
    }
    if(odd%2==1){
        cout<<"NO"<<endl; return 0;
    }
    cout<<"YES"<<Endl;
}


Measured memory_bytes: 384
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
  cout << fixed << setprecision(12);
  for(int i = 0; i < 1000000000; i++) {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if(op == '?')
      break;
    if(op == '+')
      cout << a + b << endl;
    if(op == '-')
      cout << a - b << endl;
    if(op == '*')
      cout << a * b << endl;
    if(op == '/')
      cout << a / b << endl;
  }

  return 0;
}



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

int main() {

    long long t1, t2, a1, a2, b1, b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;


    long long dif = t1*(a1-b1) + t2*(a2-b2);
    if (dif < 0)    swap(a1, b1), swap(a2, b2);
    long long first = t1*(b1-a1);

    if (dif == 0) {
        cout<<"infinity"<<endl;
        return 0;
    }

    if (first < 0) {
        cout<<0<<endl;
        return 0;
    }

    dif = abs(dif);

    const long long INF = 1e18;
    long long lo = 0, hi = INF;

    while (lo < hi) {
        long long mid = (lo + hi+1)/2;
        if (mid>INF/dif)            hi = mid;
        else if (mid*dif > first)   hi = mid-1;
        else                        lo = mid;
    }

    long long ans = 2*lo+1;
    if (lo*dif == first)    ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import itertools
n=int(input())
a=list(map(int,input().split()))
a=list(itertools.accumulate(a))
ans=0
buf=0
for i in range(n):
    if i%2==0:
        if a[i]+buf<=0:
            ans+=1-(a[i]+buf)
            buf+=1-(a[i]+buf)
    else:
        if a[i]+buf>=0:
            ans+=(a[i]+buf)+1
            buf-=(a[i]+buf)+1
x=ans
ans=0
buf=0
for i in range(n):
    if i%2==0:
        if a[i]+buf>=0:
            ans+=(a[i]+buf)+1
            buf-=(a[i]+buf)+1
    else:
        if a[i]+buf<=0:
            ans+=1-(a[i]+buf)
            buf+=1-(a[i]+buf)
print(min(x,ans))

Measured memory_bytes: 14332