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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

char cc(char x) {
    if (x == 'a') return 'Z';
    if (x == 'A') return 'z';
    return --x;
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    cin >> skipws;

    for (;;) {
        int n; cin >> n;
        if (!n) break;
        vector<int> v(n);
        rep(i, 0, n) cin >> v[i];
        string s; cin >> s;
        rep(i, 0, s.length()) {
            rep(j, 0, v[i % n]) s[i] = cc(s[i]);
        }
        cout << s << endl;
    }
}



Measured memory_bytes: 3256
#include <iostream>
#include <string>
using namespace std;
typedef struct{
	string id;
	long long sales;
} staff;

int main(void)
{
	long long n;
	while(cin>>n){
		if(!n) break;
		staff staff1[4001];
		int pt = 0;
		for(int i=0; i< n; i++){
			string id;
			cin >> id;
			long long price;
			int bnum;
			cin >> price >> bnum;
			int m=-1;
			for(int j=0;j < i; j++){
				if(id==staff1[j].id){
					pt++;
					m=j;
					break;
				}
			}
			if(m==-1){
				staff1[i-pt].id = id;
				staff1[i-pt].sales = price * bnum;
			}else{
				staff1[m].sales += price * bnum;
			}
		}
		int count = 0;
		for(int i=0; i < n-pt; i++){
			if(staff1[i].sales >= 1000000){
				count++;
				cout << staff1[i].id << endl;
			}
		}
		if(!count) cout << "NA" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<ll> sum(n, 0);
	ll all = 0;
	rep(i, n){
		ll a;
		cin >> a;
		if(i != 0) sum.at(i) = sum.at(i-1);
		sum.at(i) += a;
		all += a;
	}

	// rep(i, n){
	// 	if(i != 0) cout << " ";
	// 	cout << sum.at(i);
	// }
	// cout << endl;
	// cerr << all << endl << endl;
	ll ans = 1001001001001001;
	rep(i, n-1){
		ll x = sum.at(i), y = all - x;
		// cerr << "t:" << x << " " << y << endl;
		ll add = fabs(x - y);
		if(ans > add) ans = add;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
def main():
    from bisect import bisect_right as br
    import numpy as np
    n = int(input())
    a = np.array(list(map(int, input().split())))
    b = np.array(list(map(int, input().split())))
    #n = 100000
    #a = np.array([i+1 for i in range(n)])
    #b = np.array([2*i+2 for i in range(n)])
    a = np.sort(a)
    b = np.sort(b[::-1])
    m = n % 2
    xor = 0
    for i in b:
        xor ^= i
    b = pow(2, 28) - b
    ans = 0
    for loop in range(28, -1, -1):
        j = pow(2, loop)
        k = (xor & j) // j
        temp = br(b, j-1)
        b[temp:] -= j
        b = np.sort(b)
        temp = br(a, j-1)
        k += sum((a & j) // j)
        a[temp:] -= j
        x = (k+br(b, 0))*m % 2
        a = np.sort(a)
        x += np.sum(np.searchsorted(b, a+1))
        ans += (x % 2)*j
    print(ans)


main()


Measured memory_bytes: 35924
n, q = map(int, input().split())
s = input()
t = [0]*(n + 1)

for i in range(n):
    if s[i: i + 2] == "AC":
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])

Measured memory_bytes: 6188
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};
use std::{cmp, fmt};

fn main() {
    let (a, b): (u32, u32) = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        (sc.next(), sc.next())
    };
    let d = b - a;
    let h = d * (d + 1) / 2;
    println!("{}", h - b);
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#define FOR(i,L,R) for (int i = L; i < R; i++)
#define READ(n) int (n); scanf("%d",&(n))
#define getInt(a) scanf("%d", &a)

int main(){
    READ(n);
    int arr[200000], max = 1, secMax = 0;
    FOR(i, 0, n){
        getInt(arr[i]);
        if (arr[i] > max)
            max = arr[i];
        else if (arr[i] > secMax && arr[i] <= max)
            secMax = arr[i];
    }
            
    FOR(i, 0, n){
        if (arr[i] == max)
            printf("%d\n", secMax);
        else
            printf("%d\n", max);
    }
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long x = scanner.nextLong();
		long answer = 0;
		if(x % 11 == 0){
			answer = x / 11 * 2;
		}else if(x % 11 < 7){
			answer = x / 11 * 2 + 1;
		}else{
			answer = x / 11 * 2 + 2;
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdlib>
#include <algorithm>
#define NMAX 10
#define MMAX 29
//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int ,int > P;
vector<int > land[NMAX];
vector<int > rest;
int A[MMAX],B[MMAX],C,N,M,W,H,ans = 0,dp[NMAX][NMAX] = {},flag[NMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
dy[8] = {1,1,0,-1,-1,-1,0,1};
void dfs(int a){
  if(rest.empty()){
    ans++;
  }
  // printf("%d :",a);
  for (int i = 0; i < land[a].size(); ++i)
  {
    // printf("%d\n",land[a][i]);
    if(find(rest.begin(), rest.end(),land[a][i]) != rest.end()){
      rest.erase(find(rest.begin(), rest.end(),land[a][i]));
      // printf("%d::::\n",land[a][i]);
      dfs(land[a][i]);
      rest.push_back(land[a][i]);
    }
  }

}

void solve(){

}

void debug(){

}

void answer(){
  cout << ans << "\n";
}

int main(){
  ios::sync_with_stdio(false);
  Fill(flag,1);
  cin >> N >> M;
  for (int i = 1; i < N; ++i)
  {
    rest.push_back(i+1);
  }
  for (int i = 0; i < M; ++i)
  {
    scanf("%d%d",&A[i],&B[i]);
    land[A[i]].push_back(B[i]);
    land[B[i]].push_back(A[i]);
  }
  // for (int i = 0; i < N; ++i)
  // {
  //  for (int j = 0; j < land[i].size(); ++j)
  //  {
  //    printf("%d ",land[i+1][j]);
  //  }
  //  printf("\n");
  // }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  dfs(1);
  answer();

  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
x=[int(x) for x in input().split()]

t=0
if n<m:
  x.sort()
  s=list()
  for i in range(m-1):
    s.append(x[i+1]-x[i])
  s.sort()

  for i in range(m-n):
    t += s[i]

print(t)


Measured memory_bytes: 13840
using System;

class Atcoder66
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = Convert.ToInt32(input[0], 16);
        int y = Convert.ToInt32(input[1], 16);

        if (x < y)
            Console.WriteLine("<");
        else if (x > y)
            Console.WriteLine(">");
        else
            Console.WriteLine("=");
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int N; char c[1001]; int dp[1001][8];

int main(){
	scanf("%d",&N);
	scanf("%s",c);
	dp[0][4]=1;
	for(int i=1;i<=N;i++){
		int n=0;
		if(c[i-1]=='J') n=4;
		if(c[i-1]=='O') n=2;
		if(c[i-1]=='I') n=1;
		for(int j=1;j<8;j++){
			if((j&n)==0) continue;
			for(int k=1;k<8;k++){
				if((k&j)==0) continue;
				dp[i][j]+=dp[i-1][k];
			}
			dp[i][j]%=10007;
		}
	}
	int res=0;
	for(int i=0;i<8;i++) res+=dp[N][i];
	printf("%d\n",res%10007);
}

Measured memory_bytes: 1220
def main():
    h, w = map(int, input().split())

    m = []
    wall = ['.' for _ in range(w + 2)]
    m.append(wall)
    for _ in range(h):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == '#':
                f = any([m[i + x][j + y] == "#" for (x, y) in ((1, 0), (-1, 0), (0, 1), (0, -1))])
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;

pub struct AdjList {
    dim: usize,
    list: Vec<Vec<usize>>,
}

impl AdjList {
    pub fn new(d: usize) -> AdjList {
        AdjList {
            dim: d,
            list: vec![vec![]; d],
        }
    }

    pub fn dim(&self) -> usize {
        self.dim
    }

    pub fn add_edge(&mut self, from: usize, to: usize) {
        match self.list.get_mut(from) {
            Some(v) => v.push(to),
            None => self.list.insert(from, vec![to]),
        }
    }

    pub fn add_undirected_edge(&mut self, from: usize, to: usize) {
        self.add_edge(from, to);
        self.add_edge(to, from);
    }

    pub fn out_edges(&mut self, vertex: usize) -> Vec<usize> {
        self.list.get_mut(vertex).unwrap().to_vec()
    }

    pub fn in_edges(&mut self, v: usize) -> Vec<usize> {
        let mut res = vec![];
        for l in 0..self.dim() {
            if let Some(list) = self.list.get(l) {
                if list.contains(&v) {
                    res.push(l);
                }
            }
        }

        res
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        es: [(Usize1, Usize1); m],
    }

    let bad = 1_000_000 as usize;

    let mut res = vec![bad; n];
    res[0] = 0;

    let mut al = AdjList::new(n);
    for e in es {
        al.add_edge(e.0, e.1);
        al.add_edge(e.1, e.0);
    }
    let mut q = VecDeque::new();
    q.push_back(0 as usize);
    while !q.is_empty() {
        let now = q.pop_front().unwrap();
        let nxts = al.out_edges(now);
        for nxt in nxts {
            if res[nxt] == bad {
                res[nxt] = now;
                q.push_back(nxt);
            }
        }
    }

    if res.contains(&bad) {
        println!("No");
    } else {
        println!("Yes");
        for i in 1..n {
            println!("{}", res[i] + 1);
        }
    }
}


Measured memory_bytes: 16832
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, vector<vector<T>> &v)
{
	for (vector<T> &x : v)
		out << x << '\n';
	return out;
}

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

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define per(i,b,a) for (int i = b; i > a; i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	ll n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}


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

int main()
{
  int N;
  std::vector<int> W;
  
  std::cin >> N;
  W.resize(N);
  
  int sum = 0;
  for(int i=0; i<N; i++){
    std::cin >> W[i];
    sum += W[i];
  }
  
  int partial_sum = 0;
  int min_diff = sum;
  for(auto& w : W){
    partial_sum += w;
    int diff = abs(sum - partial_sum * 2);
    if(diff > min_diff){
      std::cout << min_diff;
      return 0;
    } else {
      min_diff = diff;
    }
  }
  
  std::cout << sum;
  
  return 0;
}

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

long long power(long long x,long long k,long long m){
	long long ans=1;
	while(k){
		if(k&1){
			ans=(ans*x)%m;
		}
		k/=2;
		x=(x*x)%m;
	}
	return ans;
}

long long lcm(long long a,long long b,long long k,long long m){
	long long x=(a*b)/__gcd(a,b);
	// x=power(x,k,m);
	// long long ai=1;
	// while(k--)ai*=x;
	return x;
}


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;cin>>t;
	if(t>=30)cout<<"Yes\n";
  	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,tmp=(long long)1e18;
	cin>>n;
	for(long long i=1;i*i<=n;i++)
	{
		if(n%i==0)tmp=min(n/i+i-2,tmp);
	}
	cout<<tmp;
	return 0;
}


Measured memory_bytes: 256
from math import gcd

K = int(input())
ans = 0
for i in range(1, K + 1):
    ans += i
for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        ans += gcd(i, j) * 6

for i in range(1, K - 1):
    for j in range(i + 1, K):
        for k in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), k) * 6

print(ans)


Measured memory_bytes: 9204
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
using ll = int_fast64_t; using namespace std;

#ifndef __GNUC__
string text =
R"X(50)X";
stringstream iss{text};
#endif

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

	ll N; iss >> N;
	bool ok{false};
	for (ll i = 1; i < 10; ++i) {
		auto qr = div(N, i);
		if (qr.rem == 0 && qr.quot < 10) ok = true;
	}
	cout << (ok ? "Yes" : "No") << "\n";
}


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

using ll = long long;

int main() {
	ll N; cin >> N;
	int c = 0;

	ll i = 1;
	ll j = N - 1;

	while (i < j) {
		i++; j--;
		c++;
	}

	cout << c << endl;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n,m = MAP()
if n > 1 and m > 1:
    print((n - 2) * (m - 2))
elif n > 1 and m == 1:
    print(n - 2)
elif n == 1 and m > 1:
    print(m - 2)
else:
    print(1)

Measured memory_bytes: 5176
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N;
  string tmp;
  map<string, int> amap;
  set<string> st;
  for(int i=0;i<N;++i) {
    cin>>tmp;
    st.insert(tmp);
    amap[tmp]++;
  }
  cin>>M;
  for(int i=0;i<M;++i) {
    cin>>tmp;
    st.insert(tmp);
    amap[tmp]--;
  }
  int ans = 0;
  for(auto i=st.begin();i!=st.end();++i) {
    ans = max(ans, amap[*i]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3644
(* Vicfred
 * https://atcoder.jp/contests/abc130/tasks/abc130_b
 * implementation
 * *)
Scanf.scanf "%d %d\n" @@ fun n x ->
    Array.init n (fun _ -> Scanf.scanf " %d" ( + ) 0)
    |> Array.fold_left (fun (a, b) c -> (if b + c <= x then a + 1 else a), b + c) (1, 0)
    |> fst
    |> Printf.printf "%d\n"



Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SIZE (100010L)

// Author - Kevin Mathew
// Birla Institute of Technology, Mesra

ll n, a[3][SIZE];
ll dp[SIZE][3];

ll solve(ll x, ll curr){
	if(x == n)
		return 0;

	if(dp[x][curr] != -1)
		return dp[x][curr];

	ll ans = LLONG_MIN;

		for(ll i=0;i<3;i++)
			if(i != curr)
				ans = max(ans, solve(x+1, i));

		// cout << x << " " << curr << " " << state << " " << a[curr][x] + ans << "\n";  

		return dp[x][curr] = a[curr][x] + ans;
	
}

void te(){
	cin >> n;
	for(ll i=0;i<n;i++){
		cin >> a[0][i] >> a[1][i] >> a[2][i];
		for(ll j=0;j<3;j++)
			dp[i][j] = -1;
	}

	cout << max(solve(0, 0), max(solve(0, 1), solve(0, 2))) << "\n";
}

int main()
{
	//freopen("input.txt", "r", stdin);		//Comment
	//freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	te();

	return 0;
}

Measured memory_bytes: 9600
// ALDS1_3_C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include<cstdio>
#include<cstdlib>
#include<cstring>

//Nodeを定義する
struct Node {
    int key;
    Node *next, *prev;
    
};

//番兵を作成する
Node *nil;

//keyがヒットするか番兵に合うまで探索する
Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

//番兵を初期化する
void init() {
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

//番兵の次のNodeから番兵に到達するまで(すべてのNode)を出力する
void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");

}

//消したいNodeであるtの前後のNodeを辻褄合わせてtを消す
void deleteNode(Node *t) {
    //番兵を消すとリストがおかしくなって死ぬので命令を無視する
    if (t == nil) {
        return;
    }
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

//最初/最後のNodeを削除する
void deleteFirst() {
    deleteNode(nil->next);
}
void deleteLast() {
    deleteNode(nil->prev);
}

//listSearchで見つけたNodeをdeleteNodeするだけ
void deleteKey(int key) {
    deleteNode(listSearch(key));
}

//番兵とその次のNodeを辻褄合わせてNodeであるxを挿入する
void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') {
            //'i'nsert
            insert(key);
            np++; size++;
        }else if(com[0] == 'd'){
            //'d'elete
            if (strlen(com) > 6) {
                if (com[6] == 'F') {
                    //'F'irst
                    //deleteF
                    deleteFirst();
                }
                else if (com[6] == 'L') {
                    //'L'ast
                    //deleteL
                    deleteLast();
                }
            }else {
                    deleteKey(key);
                    nd++;
            }
            size--;

        }
    }
    printList();
    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します



Measured memory_bytes: 33980
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for(int i=0; i<N; i++)
        cin >> a[i] >> b[i] >> c[i];

    int N1 = N / 2;
    int N2 = N - N1;
    vector<pair<int, int>> G1((1 << N1) - 1), G2((1 << N2) - 1);
    for(int i=1; i< 1<<N1; i++){
        int aa = 0, bb = 0, cc = 0;
        for(int j=0; j<N1; j++){
            if(i & 1<<j){
                aa += a[j];
                bb += b[j];
                cc += c[j];
            }
        }
        int tmp = aa * Mb - bb * Ma;
        G1[i-1] = pair<int, int>(tmp, cc);
    }
    for(int i=1; i< 1<<N2; i++){
        int aa = 0, bb = 0, cc = 0;
        for(int j=0; j<N2; j++){
            if(i & 1<<j){
                aa += a[N1+j];
                bb += b[N1+j];
                cc += c[N1+j];
            }
        }
        int tmp = bb * Ma - aa * Mb;
        G2[i-1] = pair<int, int>(tmp, cc);
    }
    const int INF = 1000000000;
    int ans = INF;
    for(auto g : G1)
        if(g.first==0)
            ans = min(ans, g.second);
    for(auto g : G2)
        if(g.first==0)
            ans = min(ans, g.second);

    sort(G2.begin(), G2.end());
    for(int i=0; i<G1.size(); i++){
        pair<int, int> p = pair<int, int>(G1[i].first, 0);
        auto itr = lower_bound(G2.begin(), G2.end(), p);
        if(itr == G2.end() || G1[i].first != itr->first) continue;
        ans = min(ans, G1[i].second + itr->second);
    }
    if(ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define int long long
using namespace std;
const int N=1e5+100;
int n,m,k,a[N],b[N],f[N],c[N];
int fa[N][64],sum[N];
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&f[i]);
	scanf("%lld%lld",&m,&k);
	for (int i=1;i<=m;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++) b[i]=i;
	for (int i=1;i<=m;i++) swap(b[a[i]],b[a[i]+1]);
	for (int i=1;i<=n;i++) fa[i][0]=b[i];
	for (int j=1;j<=62;j++)
	{
		for (int i=1;i<=n;i++) fa[i][j]=fa[fa[i][j-1]][j-1];
	}
	for (int i=1;i<=n;i++)
	{
		int cnt=k,x=i;
		for (int j=62;j>=0;j--)
		{
			if (cnt>=(1ll<<j))
			{
				cnt-=(1ll<<j);
				x=fa[x][j];
			}
		}
		if (x==1) c[i]=f[x];
		else c[i]=f[x]-f[x-1];
	}
	for (int i=1;i<=n;i++) sum[i]=sum[i-1]+c[i];
	for (int i=1;i<=n;i++)
	{
		double ans=sum[i];
		printf("%.12lf\n",ans);
	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

vector<vector<pii>> adj;
vector<bool> reached;
vector<int32> dif;
set<int32> ans;

int32 dfs(int32 v){
  reached[v] = true;
  for(auto tmp : adj[v]){
    int32 u,e;
    tie(u,e) = tmp;
    if(reached[u])continue;
    if(dfs(u)){
      ans.insert(e);
      dif[v] ^= 1;
    }
  }
  return dif[v];
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,m;
  cin >> n >> m;
  vector<pii> ab(n);
  REP(i,n)cin >> ab[i].first >> ab[i].second;
  sort(ALL(ab));
  vector<pii> cd(m);
  REP(i,m){
    int32 l,r;
    cin >> l >> r;
    cd[i].first = lower_bound(ALL(ab), pii(l,-INF)) - ab.begin();
    cd[i].second = lower_bound(ALL(ab), pii(r+1,-INF)) - ab.begin();
  }
  vector<int32> b(n);
  REP(i,n)b[i] = ab[i].second;
  // REP(i,m){
  //   cout << cd[i].first << " " << cd[i].second << endl;
  // }
  
  dif.resize(n+1,0);
  dif[0] = b[0];
  dif[n] = b[n-1];
  FOR(i,1,n){
    dif[i] = b[i] ^ b[i-1];
  }
  // REP(i,n+1)cout << dif[i] << " ";
  // cout << endl;

  adj.resize(n+1);
  REP(i,m){
    int32 c,d;
    tie(c,d) = cd[i];
    adj[c].emplace_back(d,i);
    adj[d].emplace_back(c,i);
  }

  reached.resize(n+1,false);
  REP(i,n+1){
    if(reached[i])continue;
    if(dfs(i)){
      ANS(-1);
      return 0;
    }
  }
  cout << ans.size() << endl;
  for(auto c : ans)cout << c+1 << " "; 
  cout << endl;
  return 0;
}

Measured memory_bytes: 26624
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    int a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int tmp = 0;
        int copyi = i;
        while (true) {
            if (copyi == 0) {
                if (a <= tmp && tmp <= b) {
                    ans += i;
                }
                break;
            }
            tmp += copyi % 10;
            copyi /= 10;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
left_attention = [0 for i in range(n)]
right_attention = [0 for i in range(n)]

for i in range(1,n):
    left_attention[i]=left_attention[i-1]
    if(s[i-1]=='W'):
        left_attention[i]+=1


for i in range(n-2,-1,-1):
    right_attention[i]=right_attention[i+1]
    if(s[i+1]=='E'):
        right_attention[i]+=1


ans=n
for i in range(n):
    ans = min(ans, left_attention[i]+right_attention[i])


print(ans)

Measured memory_bytes: 17872
while n = gets.chomp.to_i
  break if n == 0

  sales = Hash.new(0)

  n.times do
    i, p, q = gets.chomp.split.map(&:to_i)
    sales[i] += p * q
  end

  if sales.select { |key, value| value >= 1_000_000 }.any?
    sales.each do |key, value|
      puts key if value >= 1_000_000
    end
  else
    puts 'NA'
  end

end

Measured memory_bytes: 8756
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
  cin>>str;
  if(str.size()==2){
    cout<<str<<endl;
  }
  else{
   cout<<str.at(2)<<str.at(1)<<str.at(0)<<endl;
  }
  return 0;
}

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

ans = 0
arr = [-1]
for i in range(N):
    A = int(input())
    if A > arr[i] + 1:
        print(-1)
        break
    if A == arr[i] + 1 and i != 0:
        ans += 1
    else:
        ans += A
    arr.append(A)
else:
    print(ans)
    


Measured memory_bytes: 10980
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }


const LL MOD = 1000000007;
const int MAX = 1000000;
LL inv[MAX+1], fact[MAX+1], fact_inv[MAX+1];

void init() {
    inv[1] = 1;
    for (int i=2; i<=MAX; i++) inv[i] = inv[MOD%i] * (MOD-MOD/i) % MOD;

    fact[0] = fact_inv[0] = 1;
    for (int i=1; i<=MAX; i++) {
	fact[i] = fact[i-1] * i % MOD;
	fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;
    }
}

LL nCk(int n, int k) {
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD;
}



int N, A[200111], B[200111];
const int BASE = 2011;
LL dp[2 * BASE + 11][2 * BASE + 11];


int main() {
    init();

    scanf("%d", &N);
    REP (i, N) scanf("%d%d", A+i, B+i);

    REP (i, N) {
	dp[BASE - A[i]][BASE - B[i]]++;
    }
    REP (i, 2 * BASE) REP (j, 2 * BASE) {
	dp[i+1][j+1] += dp[i+1][j] + dp[i][j+1];
	if (dp[i+1][j+1] >= MOD) dp[i+1][j+1] -= MOD;
    }

    LL ans = 0;

    REP (i, N) {
	ans += dp[BASE + A[i]][BASE + B[i]];
	ans -= nCk(A[i] + A[i] + B[i] + B[i], A[i] + A[i]);
    }
    ans %= MOD;
    ans = (MOD + 1) / 2 * ans;
    ans = (ans % MOD + MOD) % MOD;
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 151936
import sys
input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


def main():
    a, b, c = map(int, input().split())
    if a == b == c:
        if a % 2 == 0:
            yield -1
        else:
            yield 0
            
        return

    while all(x%2 == 0 for x in (a, b, c)):
        a_ = a//2
        b_ = b//2
        c_ = c//2
        a, b, c = b_+c_, a_+c_, a_+b_
        yield 1


print(sum(main()))


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val N = sc.next().toInt()
    var H = sc.next().toInt()
    val a = IntArray(N)
    val b = IntArray(N)
    for (i in 0 until N){
        a[i] = sc.next().toInt()
        b[i] = sc.next().toInt()
    }

    var turn = 0

    b.sort()
    b.reverse()
    val max_a = a.max()!!
    for (bb in b) {
        if (H <= 0) break
        if (bb > max_a) {
            H -= bb
            turn += 1
        } else {
            break
        }
    }

    if (H > 0) turn += (H+max_a-1) / max_a

    println(turn)
}

Measured memory_bytes: 55356
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int sz=1e7+7;
int v[sz];
int sieve(int n){
	
	for(int i=2;i<=sz;i++){
		if(v[i]==0)
		{
			for(int j=2*i;j<=sz;j+=i){
			v[j]=1;
		}
		}
		
	}
	for(int i=n;;i++){
		if(v[i]==0) return i;
	}
}
int main() {
	int n;
	cin>>n;
	cout<<sieve(n)<<endl;
	return 0;
}

Measured memory_bytes: 39296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
int nxt[100001][26];
int main() {
	string s, t;
	cin >> s >> t;
	memset(nxt, -1, sizeof(nxt));
	for (int i = s.size() - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) nxt[i][j] = nxt[i + 1][j];
		nxt[i][s[i] - 'a'] = i;
	}
	int i = 0;
	int pos = 0;
	ll cnt = 0;
	while (i < t.size()) {
		if (nxt[pos][t[i] - 'a'] == -1) {
			if (pos == 0) {
				cout << -1 << endl;
				return 0;
			}
			pos = 0;
			cnt++;
			continue;
		}
		pos = nxt[pos][t[i] - 'a'] + 1;
		i++;
	}
	cout << cnt * s.size() + pos << endl;
}

Measured memory_bytes: 10752
url = "https://atcoder.jp//contests/abc095/tasks/abc095_b"

def main():
    donut, moto = list(map(int, input().split()))
    lis = [int(input()) for i in range(donut)]
    moto -= sum(lis)
    donut += moto / min(lis)
    print(int(donut))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,n);
  long long a[212345]={};
  int i;
  int temp;
  int sum=0;
  long long sumf[212345]={};
  long long sumb[212345]={};
  cin>>a[0];
  sumf[0]+=a[0];
  loop(i,1,n)
    {
      cin>>a[i];
      sumf[i]+=sumf[i-1]+a[i];
    }
  sumb[n-1]=a[n-1];
  loop(i,1,n)
    sumb[n-i-1]+=sumb[n-i]+a[n-i-1];
  darray(sumf,n);
  darray(sumb,n);
  int min=INF;
  rep(i,n-1)
    if(min>abs(sumf[i]-sumb[i+1]))min=abs(sumf[i]-sumb[i+1]);
  
  /*
  cin>>a[0];
  for(i=1;i<n;i++)
    {
      cin>>temp;
      a[i]=temp*2+a[i-1];
    }
  *//*
  darray(a,n);
 
  dout(sum);
  int f=1,b=n-2;
  int sf=a[0],sb=a[n-1];
  rep(i,n-2)
    {
      if(abs((sf+a[f])-sb)>abs(sf-(sb+a[b])))
	sb+=a[b--],dout(sb);
      else
	sf+=a[f++],dout(sf);
    }
    cout<<abs(sf-sb)<<endl;*/
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int a,b;cin >> a >> b;
    if(a>b)swap(a,b);
    int df = b-a;
    if( df & 1)cout<<"IMPOSSIBLE\n";
    else cout<<a+df/2;
    //main();
    return 0;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
        PROGRAM-ID. AtCoder.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 INP PIC X(100).
        01 A PIC 9(15).
        01 B PIC 9(15).
        01 C PIC 9(15).
      	01 D PIC 9(15).
      	01 F PIC 9(15).
      	01 E PIC ZZZZZZZZZZZZ9.
	    01 temp1 PIC 9(15).
        01 temp2 PIC 9(15).
        01 N PIC 9(15).
      
        PROCEDURE DIVISION.
      	MAIN.
			ACCEPT INP.
        	PERFORM VARYING temp1 FROM 1 BY 1
            UNTIL INP(temp1:1) = SPACE
        	END-PERFORM.
        	SUBTRACT 1 FROM temp1.
        	MOVE INP(1:temp1) TO A.
        	ADD 2 TO temp1.
        	PERFORM VARYING temp2 FROM temp1 BY 1
            UNTIL INP(temp2:1) = SPACE
        	END-PERFORM.
        	COMPUTE N = temp2 - temp1.
        	MOVE INP(temp1:N) TO B.
      		IF A >= 13 THEN
      			MOVE B to E
      		ELSE
      			IF A >= 6 THEN
      				COMPUTE E = B / 2
      			ELSE
      				MOVE 0 TO E
      			END-IF
      		END-IF.
      		DISPLAY E.
		STOP RUN.

Measured memory_bytes: 384
n = int(raw_input())
for loop in xrange(n):
    a = []
    while len(a) < 9:
        a += map(lambda i:int(i,16),raw_input().split())
    key = 0
    for i in xrange(32):
        s = sum(a[j]^key for j in xrange(8))
        if (s^a[-1]^key) & (1 << (i+1)-1) != 0: key |= (1 << i)
    print "%x"%key

Measured memory_bytes: 4224
n = int(input())
listA = list(map(int, input().split()))

listA.sort()
listA.reverse()

pointA=0
pointB=0
index=0
while index <n:
    if index%2 ==0:
        pointA+=listA[index]
    else:
        pointB+=listA[index]
    index+=1

print(pointA-pointB)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

ull T[100];

ull gcd(ull a, ull b) {
	if (a < b) return gcd(b, a);
	ull r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main()
{
	int N;
	ull tmp, ans;

	cin >> N;
	rep(i, N) cin >> T[i];

	ans = T[0];
	rep(i, N) {
		tmp = gcd(ans, T[i]);
		ans = (ans / tmp) * T[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void sort(int k[4],int a[6]){
  int w,i;
  //for(i=0;i<6;i++)printf("%d ",a[i]);
  //printf("\n");
  w=a[k[0]-1];
  for(i=0;i<3;i++){
    a[k[i]-1]=a[k[i+1]-1];	
  }
  a[k[3]-1]=w;
  //for(i=0;i<6;i++)printf("%d ",a[i]);
  //putchar('\n');
}


int main(void){
  //int a[6]={1,2,3,4,5,6};
  int w[4]={1,3,6,4};
  int e[4]={1,4,6,3};
  int n[4]={1,2,6,5};
  int s[4]={1,5,6,2};
  int r[4]={2,3,5,4};
  int l[4]={2,4,5,3};	
  char in[30];
  int m;
  int i,j,t;
  while(scanf("%d",&m),m){
    int a[6]={1,2,3,4,5,6};
    int sum=1;
    for(i=0;i<m;i++){
      scanf("%s",in);
      if(in[0]=='N')sort(n,a);
      else if(in[0]=='N')sort(n,a);
      else if(in[0]=='W')sort(w,a);
      else if(in[0]=='S')sort(s,a);
      else if(in[0]=='E')sort(e,a);
      else if(in[0]=='R')sort(r,a);
      else if(in[0]=='L')sort(l,a);
      sum+=a[0];
    }
    printf("%d\n",sum);
  }
}

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

int dp[100010][3];
vector<int> v[100010];
int s, t;
int n, m;

int main()
{
    cin >> n >> m;
    REP(i, m)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    cin >> s >> t;
    queue<P> que;
    que.push(P(s, 1));
    dp[s][0] = 1;
    while (!que.empty())
    {
        P p = que.front();
        que.pop();
        if (p.first == t && (p.second + 2) % 3 == 0)
        {
            cout << (p.second + 1) / 3 << endl;
            return 0;
        }
        int step = (p.second + 3) % 3;
        for (auto i : v[p.first])
        {
            if (dp[i][step])
            {
                continue;
            }
            else
            {
                dp[i][step] = p.second + 1;
                que.push(P(i, p.second + 1));
            }
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 6912
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

int dp[1001][1001];
const int m = 1e9+7;

int32_t main()
{
   // shuru_krte_hai_bina_kisi_bakchodi_ke();
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        if(s[i][0]=='.'){
            dp[i][0] = 1;
        }else{
            break;
        }
    }
    for(int i=0;i<w;i++){
        if(s[0][i]=='.'){
            dp[0][i] = 1;
        }else{
            break;
        }
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(s[i][j]=='.'){
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%m;
            }
        }
    }
    cout<<dp[h-1][w-1];
    return 0;
}

Measured memory_bytes: 13228
import java.util.*;
import java.io.*;
import java.math.*;
class Main
{
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        int n=sc.nextInt();
        String s=Integer.toString(n);
        int sum=0;
        for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i)=='7')
            {
                sum=1;
            }
        }
        if(sum==1)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }


    }
}   

Measured memory_bytes: 32832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N,ans=0;
  cin>>N;
  vector<ll> vec(N);
  unordered_map<ll,ll> mp;
  for(ll i=0;i<N;i++){
    cin>>vec.at(i);
    mp[vec.at(i)+i]++;
  }
  for(ll i=0;i<N;i++){ans+=mp[i-vec.at(i)];}
  cout<<ans<<endl;
}


Measured memory_bytes: 20000
#include <stdio.h>

int temp[100000000];
void merge(int *,int,int);
int count=0;

int main(){
  
  int i,a,n,m,cont1=0,cont2=0;
  int x[5000000],y[5000000];
  
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&x[i]);
  }     

  
  merge(x, 0, a - 1);
  
  for (i = 0; i < a; i++){
    if(i!=a-1){ 
      printf("%d ", x[i]);
    }
    else printf("%d",x[i]);
  }
  printf("\n%d\n",count);
  
}


void merge(int x[ ], int left, int right)
{
  int mid, i, j, k;
  
  if (left >= right){
    return;
  }
  
  
  mid = (left + right) / 2;       
  merge(x, left, mid);
  merge(x, mid + 1, right);   
  
  
  for (i = left; i <= mid; i++)
    temp[i] = x[i];
  
  
  
  for (i = mid + 1, j = right; i <= right; i++, j--){
    
    temp[i] = x[j];
    
  }  
  i = left;        
  j = right;       
  
  for (k = left; k <= right; k++)   
    if (temp[i] <= temp[j]){
      count++;
      x[k] = temp[i++];
      
    }
    else{
      count++;
      x[k] = temp[j--];
      
    }
}



Measured memory_bytes: 5644
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	string s, t, ans, ss;
	cin >> s >> t;
	bool solved = false;
	int n = s.length(), m = t.length(), i, j, k;

	for (i = 0; i + m <= n; i++) {
		bool valid = true;
		ss = s;
		for (j = 0; j < m; j++) {
			if ((s[i + j] == t[j]) || (s[i + j] == '?')) {
				ss[i + j] = t[j];
			}
			else valid = false;
		}
		if (valid) {
			for (j = 0; j < n; j++) {
				if (ss[j] == '?') ss[j] = 'a';
			}

			if (!solved) {
				solved = true;
				ans = ss;
			}
			else if (ss < ans) ans = ss;
		}
	}

	if (!solved) cout << "UNRESTORABLE\n";
	else cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

template <typename T>
bool chmax(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    } else {
        return false;
    }
}

template <typename T>
bool chmin(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    } else {
        return false;
    }
}

int a[100010];
int dp[100010];

const int INF = 1e9;

int main() {
    int n;
    while (cin >> n) {
        int k;
        cin >> k;
        rep(i, n) cin >> a[i];
        rep(i, n) dp[i] = INF;
        dp[0] = 0;
        rep(i, n) {
            rep(j, k+1) if (j) {
                if (i+j <= n-1) {
                    chmin(dp[i+j],
                          dp[i] + abs(a[i] - a[i+j]));
                }
            }
        }
        cout << dp[n-1] << endl;
    }
}


Measured memory_bytes: 1024