akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;


int main() {

	ll N;

	cin >> N;

	vector<ll> A(N + 2), B(N + 1);
	ll sum = 0;

	A[0] = 0;
	rep(i, N) {
		cin >> A[i + 1];
		B[i] = A[i + 1] - A[i];
		sum += abs(B[i]);
	}
	
	sum += abs(A[N]);

	ll tmp, O, C;

	rep(i, N) {
		O = abs(A[i + 2] - A[i + 1]) + abs(A[i + 1] - A[i]);
		C = abs(A[i + 2] - A[i]);
		tmp = sum - O + C;
		cout << tmp << endl;
	}

	return 0;
}


Measured memory_bytes: 4856
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };


int main()
{
	int N;
	scanf("%d", &N);
	int A[114514];
	bool B[114514];
	memset(B, 0, sizeof(B));
	B[0] = true;
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
		A[i]--;
	}
	int now = 0;
	int cnt = 0;
	while (true)
	{
		cnt++;
		now = A[now];
		if (now == 1)
		{
			printf("%d\n", cnt);
			return 0;
		}
		if (B[now])
		{
			printf("-1\n");
			return 0;
		}
		B[now] = true;
	}


	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

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






















int main(){
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3592
n,m,q = map(int,input().split(" "))
LR_2d = [[0 for i in range(n+1)] for i in range(n+1)]
for i in range(m):
    L,R = map(int,input().split(" "))
    LR_2d[L][R] += 1

LR_2dsum = [[0 for i in range(n+1)] for i in range(n+1)]
for j in range(1,n):
    LR_2dsum[0][j] = LR_2dsum[0][j-1] + LR_2d[0][j]
for i in range(1,n+1):
    for j in range(1,n+1):
        LR_2dsum[i][j] = LR_2dsum[i-1][j] + LR_2dsum[i][j-1] - LR_2dsum[i-1][j-1] + LR_2d[i][j]

for i in range(q):
    p_i,q_i = map(int,input().split(" "))
    ans = LR_2dsum[p_i-1][p_i-1] - LR_2dsum[p_i-1][q_i] - LR_2dsum[q_i][p_i-1] + LR_2dsum[q_i][q_i]
    print(ans)

Measured memory_bytes: 15472
#include <stdio.h>

int main(void) {
	int i;
	long long A, B, C, tmp;
	scanf("%lld%lld%lld", &A, &B, &C);

	if (A % 2LL == 0LL && A == B && B == C) {
		printf("-1\n");
	} else {
		i = 0;
		while (A % 2LL == 0LL && B % 2LL == 0LL && C % 2LL == 0LL) {
			tmp = C;
			C = A/2LL + B/2LL;
			B = A/2LL + tmp/2LL;
			A = C - A/2LL + tmp/2LL;
			i++;
		}
		printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n=0;
string s;
cin >>s;
ll k=s.size();
rep(i,k){
if(s.at(i)=='o'){
n++;}}
if(15-k+n>=8){
cout <<"YES" << endl;}
else{
cout <<"NO"<< endl;}}

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll ;

ll a[100010] ;

int main()
{
    ll n,m ;
    cin >> n >> m ;
    for (int i=0 ; i<n ; i++)
    {
        cin >> a[i] ;
    }
    sort(a,a+n) ;
    reverse(a,a+n) ;
    ll sum=0 ;
    for (int i=0 ; i<m ; i++)
    {
        sum+=a[i] ;
    }
    cout << sum << endl ;
    return 0;
}


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

string join_vector(std::vector<int> data)
{
  ostringstream buf;
  auto delimiter = " ";
  for (auto i = data.begin(); i != data.end(); i++)
  {
    buf << *i;
    if (std::distance(i, data.end()) > 1)
    {
      buf << delimiter;
    }
  }

  return buf.str();
}

void print_vector(std::vector<int> data)
{
  cout << join_vector(data) << endl;
}

tuple<vector<int>, int> bubble_sort(vector<int> a, int n)
{
  auto flag = 1;
  auto count = 0;
  while (flag)
  {
    flag = 0;
    for (auto j = n - 1; j >= 1; j--)
    {
      if (a[j] < a[j - 1])
      {
        auto temp = a[j - 1];
        a[j - 1] = a[j];
        a[j] = temp;
        flag = 1;
        count++;
      }
    }
  }

  return make_tuple(a, count);
}

int main()
{
  int n;
  auto a = std::vector<int>{};

  cin >> n;
  for (auto i = 0; i < n; i++)
  {
    int number;
    cin >> number;
    a.push_back(number);
  }

  auto result = bubble_sort(a, n);
  print_vector(std::get<0>(result));
  cout << std::get<1>(result) << endl;

  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
double x,nx=100;
long long ct;
void solve(){
    while(true) {
        if(x<=nx) {
            break;
        }
        nx*=1.01;
        nx=int64_t(nx);
        ct++;
    }
    cout<<ct<<endl;
}

int main(){
    cin>>x;

    solve();
    return 0;
}


Measured memory_bytes: 3724
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll ans = 0;
    FOR(i, 1, N+1) {
        ll lo = i;
        ll hi = (N / i) * i;
        ll cnt = hi / i - lo / i + 1;
        ans += (cnt * (lo + hi)) / 2;
    }
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3652
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np


mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,6)))
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("../output.txt", "w")
except:
    pass


# @lru_cache(None)




def pos(m):
    ans=0
    for ele in A:
        ans+=((ele-1)//m)
    return ans<=k

n,k=L()
A=L()
l=1
r=max(A)
ans=r
while(l<=r):
    m=(l+r)//2
    if pos(m):
        r=m-1
        ans=m
    else:
        l=m+1
print(ceil(ans))

Measured memory_bytes: 32108
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, c, ans = 0, count = 0;
    cin >> n >> m >> c;
    int b[m], a[n][m];
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            count += a[i][j] * b[j];
        }
        if (count > -1 * c) {
            ans++;
        }
        count = 0;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
import Data.List
import Data.Bits
import Text.Printf
import Text.Regex
import Data.Function
import Data.List.Split
import Control.Monad

main = do
  b <- map read.words <$> getLine
  let a = sort b
  putStrLn $ if ((a!!0)+(a!!1)==a!!2) then "Yes" else "No"

Measured memory_bytes: 508
def main():
    from bisect import bisect_right as br
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())), reverse=True)
    m = n % 2
    xor = 0
    for i in b:
        xor ^= i
    for i in range(n):
        b[i] = 2**28 - b[i]
    ans = 0
    for loop in range(28, -1, -1):
        j = pow(2, loop)
        k = (xor & j) // j
        temp = br(b, j-1)
        for i in range(temp, n):
            b[i] -= j
        b.sort()
        temp = br(a, j-1)
        for i in a[:temp]:
            k += (i & j) // j
        for i in range(temp, n):
            k += (a[i] & j) // j
            a[i] -= j
        x = (k+br(b, 0))*m % 2
        a.sort()
        l = 0
        for i in a:
            while l < n:
                if i >= b[l]:
                    l += 1
                else:
                    break
            x += l % 2
        ans += (x % 2)*j
    print(ans)


main()


Measured memory_bytes: 124548
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

map<int, int> m[100010];

signed main() {
	int N, M;
	cin >> N >> M;

	rep(i, M) {
		int P, Y;
		cin >> P >> Y;
		m[P][Y] = i;
	}

	map<int, string> ret;

	REP(i, 1, N) {
		int cnt = 1;
		for (auto &pr : m[i]) {
			int idx = pr.second;
			int P = i;
			string PS = to_string(P);
			string cntS = to_string(cnt);
			ret[idx] = string(6 - PS.size(), '0') + PS + string(6 - cntS.size(), '0') + cntS;
			cnt++;
		}
	}

	rep(i, M) {
		cout << ret[i] << endl;
	}

    return 0;
}


Measured memory_bytes: 24960
#include <stdio.h>
#include <inttypes.h>

int64_t zettaiti(int64_t kitaeri) {
	return kitaeri >= 0 ? kitaeri : -kitaeri;
}

int32_t N;
int64_t a[271828];

int main(void) {
	int32_t i;
	int64_t sum = 0;
	int64_t asumikana = 0;
	int64_t tamurayukari;
	if (scanf("%" SCNd32, &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNd64, &a[i]) != 1) return 1;
		sum += a[i];
	}
	asumikana = a[0];
	sum -= a[0];
	tamurayukari = zettaiti(asumikana - sum);
	for (i = 1; i < N; i++) {
		int64_t horieyui = zettaiti(asumikana - sum);
		if (horieyui < tamurayukari) tamurayukari = horieyui;
		asumikana += a[i];
		sum -= a[i];
	}
	printf("%" PRId64 "\n", tamurayukari);
	return 0;
}


Measured memory_bytes: 1664
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    REP(i,10){
      c = a*c-b;
      cout << c << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n;
  cin >> n;
  int a[n] = {0};
  for(int i = 0;i<n-1;i++)
  {
      int j;
      cin >> j;
      a[j-1]++;
  }
  for(int i = 0;i<n;i++) cout << a[i] << endl;
  return 0;
}


Measured memory_bytes: 4304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main(){
    ll a,b,c,d;
  	ll w,x,y,z;
    cin >> a >> b >> c >> d;
  
  	//1
  	w = a * c;
  	x = a * d;
  	//2
	y = b * c;
  	z = b * d;
	
  	//1と2の比較
  	if(w <= x){
      if(x <= y){
        if(y <= z){
          cout << z << endl;
        }
        else if(y > z){
          cout << y << endl; 
        }
      }
      else{
        if(x >= z){
          cout << x << endl;
        }
        else if(x < z){
          cout << z << endl;
        }
      }
    }
  	else if(w >= x){
      if(w >= y){
       	if(w >= z){
         	cout << w << endl; 
        }
        else if(w < z){
          if(y <= z){
          	cout << z << endl;
          }
          else if(y > z){
            cout << y << endl;
          }
        }
      }
      else if(w < y){
        if(y <= z){
       		cout << z << endl; 
        }
        else if(y > z){
          	cout << y << endl;
        }
      }
    }
    return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;





int main(){

	string s;
	int n, k;

	cin >> n >> k >> s;


	s[k - 1] = s[k - 1] - 'A' + 'a';


	cout << s << endl;;


}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

public class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] d = Console.ReadLine()
            .Split(' ')
            .Select(int.Parse)
            .ToArray();
        Array.Sort(d);

        Console.WriteLine(d[n / 2] - d[n /2 - 1]);
    }
}

Measured memory_bytes: 20064
import sys

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])


def main():
    N = I()
    S = sorted(LI(),reverse=True)

    flag = [True]*len(S)

    cur = []
    cur.append(S[0])
    flag[0] = False

    for i in range(N):
        nxt = [x for x in cur]
        j = 0

        for k in range(len(S)):
            if j >= len(cur):
                break
            elif flag[k] and S[k]<cur[j]:
                nxt.append(S[k])
                j+=1
                flag[k] = False
        if len(cur) != j:
            return("No")
        cur = sorted(nxt,reverse=True)
    return("Yes")

if __name__ == "__main__":
    print(main())

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

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int m;
		cin >> m;
		int tmp,tmp2;
		int mx=0,mn=0;
		for(int i = 0; i < m; i++){
			if(i!=0){
				tmp2 = tmp;
				cin >> tmp;
				if(tmp-tmp2>0)mx = max(mx,tmp-tmp2);
				if(tmp2-tmp>0)mn = max(mn,tmp2-tmp);
			}
			else cin >>tmp;
		}
		cout <<mx <<" " << mn <<endl;
	}
	return 0;
}


Measured memory_bytes: 2972
<?php
 
fscanf(STDIN, "%d", $N);
 
$sum= 0;
 
$array1 = [];
$array2 = [];

for ($i = 1; $i <= $N; $i++) {
  for ($j = 1; $j <= $N; $j++) {
    if ($i === $j) {
      array_push($array1, $i);
    } else if ($i < $j) {
      array_push($array2, gmp_gcd($i, $j));
    }
  }
}

for ($i = 1; $i <= $N; $i++) {
  for ($j = 0; $j < count($array1); $j++) {
    $sum += gmp_gcd($i, $array1[$j]);
  }
}

for ($i = 1; $i <= $N; $i++) {
  for ($j = 0; $j < count($array2); $j++) {
    $sum += (gmp_gcd($i, $array2[$j]) * 2);
  }
}

echo $sum;

Measured memory_bytes: 19012
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 405;

LL res[N][N], sum[N];
int tab[N], i, j, n;

LL go(int a, int b) {
	if (res[a][b] != -1) return res[a][b];
	if (a == b) return 0;
	LL r = INF * 1LL * INF;
	for (int i = a;i<b;i++) r = min(r, go(a, i) + go(i + 1, b) + sum[b] - sum[a - 1]);
	res[a][b] = r;
	return r;
}

int main() {
scanf("%d", &n);
sum[0] = 0;
for (i=1;i<=n;i++) {
	scanf("%d", &tab[i]);
	sum[i] = sum[i - 1] + tab[i];
	for (j=i;j<=n;j++) res[i][j] = -1;
}
printf("%lld\n", go(1, n));
return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


int main(){
  int N;
  while(cin >> N){
    vector<LLI> B(N-1); cin >> B;

    LLI ans = 0;

    ans += B.front();

    REP(i,(int)B.size()-1){
      ans += min(B[i], B[i+1]);
    }

    ans += B.back();

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef pair< P , P > L;
typedef pair< P , P > S;
typedef vector<P> vecP;

double eps = 1e-8;

bool eq(double a,double b){
  return -eps < a-b && a-b < eps;  
}

double cross(P a,P b){
  return imag( b*conj(a) );
}

double dot(P a,P b){
  return real( b*conj(a) );
}

bool isParallel(L a,L b){
  a.first -= a.second;
  b.first -= b.second;
  return eq(cross( a.first,b.first ),0);
}

P getCrossLL(L l0,L l1){
  P a=l0.first, b=l0.second;
  P c=l1.first, d=l1.second;
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

int N;
P t[50];
L lines[1250];
P u[1250*1250];

int main(){
  while(1){
    scanf("%d",&N);
    if(N==0)break;
    for(int i=0;i<N;i++){
      int x,y;
      scanf("%d %d",&x,&y);
      t[i]=P(x,y);
    }
    
    int cc=0;    
    for(int i=0;i<N;i++)
      for(int j=0;j<i;j++)
        lines[cc++]=L(t[i],t[j]);

    int uc=0;
    for(int i=0;i<cc;i++)
      for(int j=0;j<i;j++)
        if( !isParallel(lines[i],lines[j]) )
          u[uc++]=getCrossLL(lines[i],lines[j]);

    int ans=0;
    for(int i=0;i<uc;i++){
      bool flg=true;
      P cen=u[i];
      for(int j=0;j<N;j++){
        P a=t[j];
        P b=t[ (j+1==N?0:j+1) ];
        
        if( cross(a-cen,b-cen) < -eps ){
          flg=false;
          break;
        }
        
      }
      
      if(flg){
        ans=1;
        break;
      }
    }

    printf("%d\n",ans);
  }
  
  return 0;
}

Measured memory_bytes: 27560
#include <bits/stdc++.h>
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 5e5 + 1, mod = 1e9 + 7;

using namespace std;

int a[maxn], b[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; i++)
        cin >> b[i];
    stack<int> st;
    for (; n >= 1; n--) {
        int ci = -1;
        for (int i = n - 1; i >= 0; i--) {
            if (b[i] == i + 1) {
                ci = i;
                break;
            }
        }
        if (ci == -1) {
            cout << -1;
            return 0;
        }
        st.push(ci + 1);
        for (int i = ci + 1; i < n; i++)
            swap(b[i], b[i - 1]);
    }
    while (!st.empty()) {
        cout << st.top() << '\n';
        st.pop();
    }
    return 0;
}


Measured memory_bytes: 3656
import math
import sys
input = sys.stdin.readline

def lcm(a, b):
    return (a * b) // math.gcd(a, b)

N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7
# A全体の最小公倍数
a_lcm = 1
for a in A:
    a_lcm = lcm(a_lcm, a)

# Bの総和
b_sum = 0
for i in range(N):
    b_sum += a_lcm // A[i]

print(b_sum % mod)


Measured memory_bytes: 75100
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <limits>
using ll = long long;
using ld = long double;
ll MOD = 1e9 + 7;
using namespace std;
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    ll n;
    cin >> n;
    vector<bool> vec(1e9 + 1,false);
    vector<ll> can;
    for (int i = 0;i<n;i++){
        ll x;
        cin >> x;
        if(vec[x]){
            can.push_back(x);
            vec[x]=false;
        }else{
            vec[x] = true;
        }
    }
    sort(can.begin(), can.end(),greater<ll>());
 //   unique(can.begin(), can.end());
    //cout<<can.size()<<endl;
    if(can.size()<2){
        cout << 0 << endl;
    }else{
        //cout<<vec[0]<<" "<<vec[1]<<endl;
        cout << can[0] * can[1] << endl;
    }

}


Measured memory_bytes: 123132
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;
typedef pair<ll, Pa> program;

vector<int> x, y;

bool dpx[8001][16001], dpy[8001][16001];
int main() {

	memset(dpx, false, 16001);
	memset(dpy, false, 16001);

	string s;
	cin >> s;
	int start;
	int end_x, end_y;
	cin >> end_x >> end_y;
	int prev = start = s.find('T');
	prev++;
	int state = 1; //y軸方向の移動:1 x:0
	while (s.find('T', prev) != s.npos) {
		int next = s.find('T', prev);
		if (state == 1) {
			y.push_back(next - prev);
			state = 0;
		}
		else {
			x.push_back(next - prev);
			state = 1;
		}
		prev = next + 1;
	}
	if (start != -1) {
		if (state == 1) {
			y.push_back(s.size() - prev);
		}
		else {
			x.push_back(s.size() - prev);
		}
	}
	else {
		dpx[0][s.size() + 8000] = true;
	}


	dpx[0][start + 8000] = dpy[0][8000] = true;
	rep(j, x.size()) {
		rep(i, 16001) {
			if (dpx[j][i]) {
				dpx[j + 1][i + x[j]] = true;
				dpx[j + 1][i - x[j]] = true;
			}
		}
	}
	rep(j, y.size()) {
		rep(i, 16001){
			if (dpy[j][i]) {
				dpy[j + 1][i + y[j]] = true;
				dpy[j + 1][i - y[j]] = true;
			}
		}
	}

	if (dpx[x.size()][end_x + 8000] && dpy[y.size()][end_y + 8000]) cout << "Yes";
	else cout << "No";
}


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


int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  int retval;
  if (K<=A) retval = K;
  else if (K<=A+B) retval = A;
  else retval = 2*A + B -K;

  cout << retval << endl;
}
 

Measured memory_bytes: 3636
#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() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  rep(i, m) cin >> a[i];
  rep(i, m) {
    n -= a[i];
    if(n < 0 ){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3668
def join(i1,i2)
	return (i1.to_s + i2.to_s).to_i
end

K = gets.chomp.to_i
queue = [1,2,3,4,5,6,7,8,9]
ix = 9

while ix < K
	f = queue.first
	
	if f % 10 > 0
		ix += 1
		queue.push(join(f,f%10-1))
	end
	if ix != K
		ix += 1
		queue.push(join(f,f%10))
	end
	
	if f % 10 < 9 && ix != K
		ix += 1
		queue.push(join(f,f%10+1))
	end
	queue.shift
end

if K < 10
	puts queue[K-1]
else
	puts queue.last
end

Measured memory_bytes: 15196
#include <iostream>
#include <vector>
#include <algorithm>
#include <string> 
#include <set>

using namespace std;

  
int main(){
  int n;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++){
    int k;
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(), v.end());
  string ans = "YES";
  for (int i = 0; i < n-1; i++){
    if(v[i] == v[i+1]){
      ans = "NO";
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 1400
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int a,b;
    cin >> a >> b;
    if(b%a==0){
        cout << a + b << endl;
    }else{
        cout << b-a << endl;
    }
}


Measured memory_bytes: 384
N = int(input())
xyh = []

for i in range(N):
    xyh.append([int(i) for i in input().split()])

for x in range(101):
    for y in range(101):

        ##Reference Height##

        for i in range(len(xyh)):
            if(xyh[i][2] != 0):
                reference_index = i
        height = abs(x - xyh[reference_index][0]) + \
            abs(y - xyh[reference_index][1]) + xyh[reference_index][2]
        ####################

        counter = 0

        for n in range(N):
            if(xyh[n][2]==0):
                if not (height <= abs(x - xyh[n][0]) +
                        abs(y - xyh[n][1]) + xyh[n][2]):
                    counter += 1

            else:
                if not (height == abs(x - xyh[n][0]) +
                        abs(y - xyh[n][1]) + xyh[n][2]):
                    counter += 1

        if(counter == 0):
            print("{} {} {}".format(x, y, height))


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = Integer.parseInt(strArr[i]);
		}
		cnt++;

		if (N == 2) {
			if (a[0] == a[1])
				System.out.println(1);
			else
				System.out.println(0);
			return;
		}

		int ans = 0;
		for (int i = 1; i < N - 1; i++) {
			if (a[i] == a[i - 1] && a[i] == a[i + 1]) {
				a[i] = a[i - 1] + a[i + 1];
				ans++;
			}
		}
		for (int i = 1; i < N - 1; i++) {
			if (a[i] == a[i - 1] || a[i] == a[i + 1]) {
				a[i] = a[i - 1] + a[i + 1];
				ans++;
			}
		}
		System.out.println(ans);
	}

	public void solve() {

	}
}


Measured memory_bytes: 20436
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

ll mod;

template<class T>

struct Mat{
    vector<vector<T>> A;
    Mat(){}
    Mat(size_t n,size_t m):A(n,vector<T>(m,0)){}
    Mat(size_t n):A(n,vector<T>(n,0)){};
    size_t height() const{
        return A.size();
    }
    size_t width() const{
        return A[0].size();
    }
    inline const vector<T> &operator[](int k) const{
        return A.at(k);
    }
    inline vector<T> &operator[](int k){
        return A.at(k);
    }
    static Mat I(size_t n){
        Mat mat(n);
        for(int i=0;i<n;i++){
            mat[i][i]=1;
        }
        return mat;
    }
    Mat &operator+=(const Mat &B){
        size_t n=height(),m=width();
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                (*this)[i][j]=((*this)[i][j]+B[i][j])%mod;
            }
        }
        return (*this);
    }
    Mat &operator-=(const Mat &B){
        size_t n=height(),m=width();
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                (*this)[i][j]=((*this)[i][j]-B[i][j])%mod;
                if((*this)[i][j]<0)(*this)[i][j]+=mod;
            }
        }
        return (*this);
    }
    Mat &operator*=(const Mat &B){
        int n=height(),m=B.width(),p=width();
        assert(p==B.height());
        vector<vector<T>> C(n,vector<T>(m,0));
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                for(int k=0;k<p;k++){
                    C[i][j]=(C[i][j]+(*this)[i][k]*B[k][j])%mod;
                }
            }
        }
        A.swap(C);
        return (*this);
    }
    Mat &operator^=(ll k){
        Mat B=Mat::I(height());
        while(k){
            if(k%2)B*=(*this);
            (*this)*=(*this);
            k>>=1LL;
        }
        A.swap(B.A);
        return (*this);
    }
    Mat operator+(const Mat &B) const{
        return (Mat(*this)+=B);
    }
    Mat operator-(const Mat &B) const{
        return (Mat(*this)-=B);
    }
    Mat operator*(const Mat &B) const{
        return (Mat(*this)*=B);
    }
    Mat operator^(const Mat &B) const{
        return (Mat(*this)^=B);
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    while(1){
        int n,m,a,b,c,t; cin >> n >> m >> a >> b >> c >> t;
        if(n==0)break;
        mod=m;
        Mat<ll> mat(n),res(n,1);
        for(int i=0;i<n;i++){
            cin >> res[i][0];
        }
        for(int i=0;i<n;i++){
            mat[i][i]=b;
            if(i-1>=0)mat[i][i-1]=a;
            if(i+1<n)mat[i][i+1]=c;
        }
        mat^=t;
        res=mat*res;
        for(int i=0;i<n;i++){
            if(i)printf(" ");
            printf("%lld",res[i][0]);
        }
        printf("\n");
    }
}


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

#define pb push_back

int main()
{
    int i,j,n,a,ar[10][10];
    for(i=1; i<=3; i++)
    {
        for(j=1; j<=3; j++)
        {
            cin>>ar[i][j];
        }
    }
    cin>>n;
    vector<int>v;
    for(i=1; i<=n; i++)
    {
        cin>>a;
        v.pb(a);
    }
    for(i=0; i<v.size(); i++)
    {
        if(v[i]==ar[1][1])
            ar[1][1]=0;
        else if(v[i]==ar[1][2])
            ar[1][2]=0;
        else if(v[i]==ar[1][3])
            ar[1][3]=0;
        else if(v[i]==ar[2][1])
            ar[2][1]=0;
        else if(v[i]==ar[2][2])
            ar[2][2]=0;
        else if(v[i]==ar[2][3])
            ar[2][3]=0;
        else if(v[i]==ar[3][1])
            ar[3][1]=0;
        else if(v[i]==ar[3][2])
            ar[3][2]=0;
        else if(v[i]==ar[3][3])
            ar[3][3]=0;
    }
    if(ar[1][1]==0&&ar[2][1]==0&&ar[3][1]==0)
        cout<<"Yes\n";
    else if(ar[1][2]==0&&ar[2][2]==0&&ar[3][2]==0)
        cout<<"Yes\n";
    else if(ar[1][3]==0&&ar[2][3]==0&&ar[3][3]==0)
        cout<<"Yes\n";
    else if(ar[1][1]==0&&ar[1][2]==0&&ar[1][3]==0)
        cout<<"Yes\n";
    else if(ar[2][1]==0&&ar[2][2]==0&&ar[2][3]==0)
        cout<<"Yes\n";
    else if(ar[3][1]==0&&ar[3][2]==0&&ar[3][3]==0)
        cout<<"Yes\n";
    else if(ar[1][1]==0&&ar[2][2]==0&&ar[3][3]==0)
        cout<<"Yes\n";
    else if(ar[1][3]==0&&ar[2][2]==0&&ar[3][1]==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
const ll MOD = (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

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

void solve()
{
    ll h,w;
    cin >> h >> w;
    ll dp[1001][1001];
    for(ll i=0;i<=h;i++) {
        for(ll j=0;j<=w;j++) {
            dp[i][j] = 0;
        }
    }
    string s[h];
    for(ll i=0;i<h;i++) {
        cin >> s[i];
    }
    dp[1][1] = 1;
    for(ll i=1;i<=h;i++) {
        for(ll j=1;j<=w;j++) {
            if(i == 1 && j==1) {
                continue;
            }
            if(s[i-1][j-1] == '#') {
                dp[i][j] = 0;
            } else {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
            }
        }
    }
    cout << dp[h][w] << "\n";
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
      // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

char t;

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int x[110];
    int y[110];
    int a[110];
    rep(i, N)cin >> x[i] >> y[i] >> a[i];

    int xa = 0, xb = W, ya = 0, yb = H;

    rep(i, N) {
        switch (a[i]) {
        case 1:
            xa = max(xa, x[i]);
            break;
        case 2:
            xb = min(xb, x[i]);
            break;
        case 3:
            ya = max(ya, y[i]);
            break;
        case 4:
            yb = min(yb, y[i]);
            break;
        }
    }
    if((xb - xa)>=0&&(yb - ya)>=0)
    cout << (xb - xa)*(yb - ya) << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()


using namespace std;
const int MAXN = 10e5 + 5;
const int INF = 0x7f7f7f7f;
typedef long long ll;
int m[MAXN];

int main() {
#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
#endif
    int n, q, a;

    memset(m, 0, sizeof(m));
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        cin >> a;
        ans += a;
        ++m[a];
    }
    cin >> q;
    int b, c;
    rep(i, q) {
        cin >> b >> c;
        ans += m[b] * (c - b);
        m[c] = m[c] + m[b];
        m[b] = 0;
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 7496
#include<stdio.h>

char tmp[200000 + 1];
bool flag[200000 + 1]={0};
int n,k,r,s,p;

int janken(char x){
    
    if(x=='r') return p;
    if(x=='s') return r;
    if(x=='p') return s;
    
}

int main(){
    
    long long ans=0;
    
    scanf("%d%d%d%d%d",&n,&k,&r,&s,&p);
    
    scanf("%s",tmp);
    
    for(int i=0;i<n;i++){
        
        if(i<k){
            ans+=janken(tmp[i]);
        }
        
        else if(tmp[i]!=tmp[i-k]){
            ans+=janken(tmp[i]);
        }
        else if(flag[i-k]){
            ans+=janken(tmp[i]);
        }
        else{
            flag[i]=true;
        }
    }
    
    printf("%lld\n",ans);
    return 0;
    
}

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

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

  vector<string> w('Z');
  w['S']="Cloudy";
  w['C']="Rainy";
  w['R']="Sunny";

  cout << w[S[0]] << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int cnts[100005];

int main() {
  int n;
  cin >> n;
  bool is_valid = true;
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    if (a % 2 == n % 2) {
      is_valid = false;
    }
    cnts[a]++;
  }

  if (!is_valid || (n % 2 != 0 && cnts[0] != 1)) {
    puts("0");
    return 0;
  }

  ll ans = 1;
  for (int i = n % 2 == 0? 1: 2; i < n; i += 2) {
    if (cnts[i] != 2) {
      puts("0");
      return 0;
    }
    ans *= 2;
    ans %= MOD;
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    ll l[2005][2005]; ll r[2005][2005];ll u[2005][2005]; ll d[2005][2005];

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

    int h,w;
    cin>>h>>w;
    vector<string> fi(h);    
    rep(i,h){
        cin>>fi[i];
    }

    rep(i,h){
        int cur = 0;
        rep(j,w){
            if(fi[i][j]=='#') cur=0;
            else cur++;
            l[i][j]=cur;
        }
    }

    rep(i,h){
        int cur = 0;
        for(int j=w-1; j>=0; j--){
            if(fi[i][j]=='#') cur=0;
            else cur++;
            r[i][j]= cur;
        }
    }    

    rep(j,w){
        int cur = 0;
        rep(i,h){
            if(fi[i][j]=='#') cur=0;
            else cur++;
            u[i][j]=cur;
        }
    }   

    rep(j,w){
        int cur = 0;
        for(int i=h-1; i>=0; i--){
            if(fi[i][j]=='#') cur=0;
            else cur++;
            d[i][j]=cur;
        }
    }

    ll ans=0;
    rep(i,h)rep(j,w){
        if(fi[i][j]=='#') continue;
        ans=max(ans,l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
    }

    cout << ans <<endl;

    return 0;
}

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

A = [input() for i in range(N)]

dic = {}

for i in A:
        if i not in dic:
                dic[i] = 1
        else:
                dic[i] += 1

de = 0

ans_list = []
#dic2 =　sorted(dic.values(), reverse=True)

for k, v in sorted(dic.items(), key=lambda x: x[1], reverse = True):
        if v != de and de !=0:
                break
        else:
                ans_list.append(k)
        de = v

ans_list_n = sorted(ans_list)


for i in ans_list_n:
        print(i)

Measured memory_bytes: 44804
#include<iostream>
 using namespace std;
 
 int main()
 {
 	int n;
 	long long int x[10000+5],y[10000+5];
 	while(cin>>n)
 	{
 	   long long int a=0;
 	   long long int b=0;
 	   int cnt=0;
 	   for(int i=0;i<n;i++) cin>>x[i];
 	   for(int i=0;i<n;i++) cin>>y[i];
 	   for(int i=0;i<n;i++)
	  {
	       if(x[i]>y[i]) b=b+2*(x[i]-y[i]);	    	
		}	 
		for(int i=0;i<n;i++)
		{
			if(x[i]<y[i])
			{
				int kk=(y[i]-x[i])/2;
				a=a+2*kk;
			}
		 } 
		 if(b>a) cout<<"No"<<endl;
		 else cout<<"Yes"<<endl; 
	 }
 	return 0;
  } 
  
  
  
  

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e6+10;
const ll MOD=17;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
bool notprime[MAXN];
vector<int> get_prime(){
    vector<int>primes;
    notprime[0]=notprime[1]=true;
    for(int u=2;u<MAXN;u++){
        if(notprime[u])continue;
        for(int v=u+u;v<MAXN;v+=u){
            notprime[v]=true;
        }
    }
    for(int u=2;u<MAXN;u++){
        if(!notprime[u])primes.push_back(u);
    }
    return primes;
}
void solve(){
    int n;
    cin>>n;
    unordered_map<int,int>cnt;
    for(int u=0;u<n;u++){
        int a;
        cin>>a;
        for(int p=2;p*p<=a;p++){
            bool has=false;
            while(a%p==0){
                a/=p;
                has=true;
            }
            if(has)cnt[p]++;
        }
        if(a>1)cnt[a]++;
    }
    int pmax=0;
    for(auto p:cnt){
        pmax=max(pmax,p.second);
    }
    if(pmax==1||pmax==0)cout<<"pairwise coprime\n";
    else if(pmax!=n)cout<<"setwise coprime\n";
    else cout<<"not coprime\n";
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 6704