akhauriyash/Code-Regression huggingface dataset:
var q, n, m;
var x = [];
var s, t, g, d;

function dfs(i){
	d[i] = 1;
	for(var j in g[i]){
		if(!d[j]){
			if(dfs(j)){
				return true;
			} 
		}
		else if(d[j] === 1){
			return true;
		}
	}
	d[i] = 2;
	return false;
}

function main(){
	q = scan();
	rep(q, function(z){
		s = {};
		t = {};
		g = {};
		d = {};

		n = scan();
		m = scan();
		rep(n, function(i){
			x[i] = scan_string().split('');
		});

		rep(n, function(i){
			rep(m, function(j){
				var a = x[i][j];
				if(a == '.'){
					return;
				}
				if(!s[a]){
					s[a] = [i, j];
					t[a] = [i, j];
				}
				else{
					s[a] = [Math.min(i, s[a][0]), Math.min(j, s[a][1])];
					t[a] = [Math.max(i, t[a][0]), Math.max(j, t[a][1])];
				}
			});
		});

		for(var a in s){
			g[a] = {};
		}

		var b = true;
		for(var a in s){
			rep(s[a][0], t[a][0] + 1, function(i){
				rep(s[a][1], t[a][1] + 1, function(j){
					if(x[i][j] == '.'){
						b = false;
						return false;
					}
					else if(x[i][j] != a){
						g[a][x[i][j]] = true;
					}
				});
				if(!b){
					return false;
				}
			});
			if(!b){
				break;
			}
		}
		if(!b){
			print('SUSPICIOUS');
			return;
		}

		for(var a in s){
			if(!d[a] && dfs(a)){
				print('SUSPICIOUS');
				return;
			}
		}

		print('SAFE');
	});
}

function rep(a, b, c){
	if(c === undefined){
		c = b;
		b = a;
		a = 0;
	}
	for(var i = a; i < b; ++i){
		if(c(i) === false){
			break;
		}
	}
}
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var input = '';
var input_index = 0;
 
function scan(){
	return +input[input_index++];
}

function scan_string(){
	return input[input_index++];
}
 
function print(val){
	console.log(val);
}
 
process.stdin.on('data', function(chunk){
	input += chunk;
});
process.stdin.on('end', function(){
	input = input.trim().split(/\s+/);
	main();
});

Measured memory_bytes: 26372
#include <stdio.h>
#include <iostream>
using namespace std;

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

    if (a + b > c + d)
    {
        cout << "Left" << endl;
    }
    else if (a + b < c + d)
    {
        cout << "Right" << endl;
    }
    else
    {
        cout << "Balanced" << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v[i] = {a, b};
    }

    int ret = n;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int p = v[i][0] - v[j][0];
            int q = v[i][1] - v[j][1];

            int now = n;
            for (int k = 0; k < n; k++) {
                for (int l = 0; l < n; l++) {
                    if (v[k][0] - v[l][0] == p && v[k][1] - v[l][1] == q) now--;
                }
            }
            ret = min(ret, now);
        }
    }

    cout << ret << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    for(int i = 0;i<s.size();i++){
        if(s[i] + n > 'Z') s[i] = s[i] + n -26;
        else s[i] += n;
    }
    cout << s << endl;
}

Measured memory_bytes: 3660
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

void Counting_Sort(int *A, int *B, int k, int length){
	int i, j, C[100000];
	for (i = 0; i <= k; i++){
		C[i] = 0;
	}
	for (j = 1; j <= length; j++){
		C[A[j]]++;
	}
	/* C[i]にはiの出現数が記録されている*/
	for (i = 1; i <= k; i++){
		C[i] = C[i] + C[i - 1];
	}
	/* C[i]にはi以下の数の出現数が記録されている*/
	for (j = length; j >= 1; j--){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
}

int main(){
	int n, i, *A, *B, max = -1;
	scanf("%d", &n);
	A = (int *)malloc(sizeof(int)*n);
	B = (int *)malloc(sizeof(int)*n);
	for (i = 1; i <= n; i++){
		scanf("%d", &A[i]);
		if (max<A[i]){ max = A[i]; }
	}

	Counting_Sort(A, B, max, n);

	for (i = 1; i <= n; i++){
		printf("%d", B[i]);
		if (i < n){
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 16280
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
int n;
int sw[2005][4005],sb[2005][4005];
int dp[2005][2005];
int b[2005],w[2005];
int c[4005],s[4005];
int main(void){
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++){
        char q;
        scanf(" %c %d",&q,&s[i]);
        if(q=='B'){
            c[i]=1;
            b[s[i]]=i;
        }else{
            c[i]=-1;
            w[s[i]]=i;
        }
    }
    for(int i=1;i<=n;i++){
        int x=b[i],y=w[i];
        for(int j=i;j<=n;j++)sb[j][x]++;
        for(int j=i;j<=n;j++)sw[j][y]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=2*n;j++){
            sb[i][j]+=sb[i][j-1];
            sw[i][j]+=sw[i][j-1];
        }
    }
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=16000000;
    dp[0][0]=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i<n){
                int x=b[i+1];
                int u=x-sw[j][x]-sb[i][x]-1;
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+u);
            }
            if(j<n){
                int x=w[j+1];
                int u=x-sw[j][x]-sb[i][x]-1;
                dp[i][j+1]=min(dp[i][j+1],dp[i][j]+u);
            }
        }
    }
    printf("%d\n",dp[n][n]);
}

Measured memory_bytes: 78720
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(a, max(b, c))
#define MIN(x, y, z) min(a, min(b, c))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll ans = 0;
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    ans += b - a + 1;
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3644
from sys import stdin
input = stdin.readline

# map(int, input().rstrip().split())

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Divisor(n):
  ret = []
  for i in range(1, n+1):
    if i*i > n:
      break
    else:
      if n % i == 0:
        ret.append(i)
        if i*i != n:
          ret.append(n//i)
  ret.sort()
  return ret

N = int(input().rstrip())
ans = 0
for i in range(1, N+1):
  divs = Divisor(i)
  if (len(divs) == 8) and (i&1) :
    ans += 1

print(ans)


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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s;
	cin >> s;

	cout << s.substr(0, 3);

	return 0;
}

Measured memory_bytes: 3608
n, m = map(int, input().split())

a = [list(map(int, input().split())) for i in range(n)]

ans = 0
for i in range(1, m+1):
    ans += 1
    for j in range(n):
        if i not in a[j][1:]:
            ans -= 1
            break
print(ans)


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

int main() {
    ll n; cin >> n;
    vector <ll> v(n);
    ll sum = 0;
    rep(i, n) {
        cin >> v.at(i);
        sum += v.at(i);
    }
    ll mean1 = sum/n, mean2 = sum/n+1;
    ll res1 = 0, res2 = 0;
    rep(i, n) {
        res1 += (ll)pow(v.at(i)-mean1, 2);
        res2 += (ll)pow(v.at(i)-mean2, 2);
    }
    cout << min(res1, res2) << endl;
}

Measured memory_bytes: 3632
// They can't break me, as long as I know who I am...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn = 1e5 + 10, mod = 1e9 + 7;
const ll inf = 1e18;

int a[maxn];

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

    int n,m,v,p; cin>>n>>m>>v>>p;
    for(int i=0; i<n; i++){
	cin>>a[i];
    }
    sort(a, a+n, greater<int>() );
    int ans = p;
    ll sm = a[p-1];
    for(int i=p; i<n; i++){
	if(v<=p){
	    ans+= a[i] + m >= a[p-1];
	}
	else{
	    int v2 = n - v;
	    ll sum = sm - 1ll * (i-p+1) * a[i];
	    ll mx = a[p-1] - a[i];
	    ans+= ( (sum + v2 - 1) / v2 ) <= m && mx <= m;
	}
	sm+= a[i];
    }
    return cout << ans << endl, 0;
}
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
string k;
ll d;
ll dp[20000][500][2];

ll solve(ll n,ll md,ll s){
    if((n==k.length())&&(md==0))
        return 1;
    if(n==k.length())
        return 0;
    if(dp[n][md][s]!=-1)
        return dp[n][md][s];
    dp[n][md][s]=0;
    int mx=(s==0?k[n]:'9')-'0';
    for(ll i=0;i<=mx;i++){
        ll nmd=(md+i)%d;
        ll ns=(s||(i<mx))?1:0;
        dp[n][md][s]=(dp[n][md][s]+solve(n+1,nmd,ns))%mod;
    }
    return dp[n][md][s];
}
int main(){
    cin>>k>>d;
    for(ll i=0;i<=k.length();i++)
        for(ll j=0;j<d;j++)
            dp[i][j][0]=dp[i][j][1]=-1;
    cout<<((solve(0,0,0)+mod-1)%mod)<<endl;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 100000

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b<c){
        No;
    }else{
        Yes;
    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#define CLASS_NUM 9
using namespace std;


int main() {
  for(int i = 0; i < CLASS_NUM; i++) {
    string str;
    int num1, num2;
    cin >> str >> num1 >> num2;
    cout << str << ' ' << num1+num2 << ' ' << num1*200+num2*300 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    string S; cin >> S;

    vi w(N, 0), e(N, 0);
    if (S[0] == 'W') w[0] = 1;
    else e[0] = 1;
    FOR(i,1, N) {
        if (S[i]=='W'){
            w[i] = w[i - 1] + 1;
            e[i] = e[i - 1];
        } else {
            w[i] = w[i - 1];
            e[i] = e[i - 1] + 1;
        }
    }

    int ans = INF;
    REP(i,N){
        int cost;
        if (i==0){
            cost = e[N - 1] - e[0];
        } else if (i==N-1) {
            cost = w[N - 2];
        } else {
            cost = w[i - 1] + e[N - 1] - e[i];
        }
        ans = min(ans, cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2964
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

int min(int x, int y){
    if(x<y)return x;
    return y;
}

int d[100][100][3];
int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0;i < 100;i++){
        for(int j = 0;j < 100;j++){
            if(i != j){
                d[i][j][0] = mod;
                d[i][j][1] = mod;
                d[i][j][2] = 0;
            }
            else{
                d[i][j][0] = 0;
                d[i][j][1] = 0;
                d[i][j][2] = 0;
            }
        }
    }
    for(int i = 0;i < m;i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--;
        b--;
        d[a][b][0] = c;
        d[b][a][0] = c;
        d[a][b][1] = c;
        d[b][a][1] = c;
        d[a][b][2] = 1;
        d[b][a][2] = 1;
    }
    for(int k = 0;k < n;k++){
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                d[i][j][0] = min(d[i][j][0], d[i][k][0] + d[k][j][0]);
            }
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < n;k++){
                if(d[i][j][0] == d[i][k][0] + d[j][k][1])d[j][k][2] = 0;
            }
        }
    }
    int count = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            if(d[i][j][2] == 1)count++;
        }
    }
    /*for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            printf("%d ", d[i][j][0]);
        }
        printf("\n");
    }*/
    printf("%d\n", count/2);
    return 0;
}

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

using namespace std;

int dp[1000000];

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

    vector<int> h(n);

    for(int i = 0; i < n; i++) cin >> h[i];

    dp[0] = 0;

    for(int i = 1; i < n; i++){
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        if (i > 1) dp[i] = min(dp[i],dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] <<"\n";
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d;

    // 処理
    e = c - a;
    f = d - b;

    //表示
    cout << c - f << " " << d + e << " " << a - f << " " << b + e << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let (x, y) = (io.read::<i64>(), io.read::<i64>());

    // // x*
    // let mut v = Vec::new();
    // v.push(x);
    let mut ans = 0;
    let mut xx = x;
    while xx <= y {
        xx *= 2;
        ans += 1;
    }
    io.writeln(ans);
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2132
V, E = map(int, input().split())
INF = 10 ** 10
dp = [[INF for i in range(V)] for j in range(V)]
for i in range(V):
  dp[i][i] = 0

for i in range(E):
  s, t, d = map(int, input().split())
  dp[s][t] = d

for k in range(V):
  for i in range(V):
    if dp[i][k] == INF:
      continue
    for j in range(V):
      if dp[k][j] == INF:
        continue
      dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])

is_negative = False
for i in range(V):
  if dp[i][i] < 0:
    is_negative = True
    break

if is_negative:
  print("NEGATIVE CYCLE")
else:
  for i in range(V):
    print(" ".join(map(lambda x: "INF" if x == INF else str(x), dp[i])))



Measured memory_bytes: 6008
using System;

namespace GoldenApple{
    public class SilverApple{
        static void Main(string[] args){
            
            string BronzeApple = Console.ReadLine();
            string[] NomalApple = BronzeApple.Split();
            int N = int.Parse(NomalApple[0]);
            int D = int.Parse(NomalApple[1]);
            int Q = D * 2 + 1;

            if(N % Q == 0){
                Console.WriteLine(N / Q);
            }
            else{
                Console.WriteLine(N /Q + 1);
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
    int n; cin>>n;
    ll a[n],s,ans;
    map<ll,ll> mp;
    rep(i,n) cin>>a[i],mp[a[i]]++;
    s=0;
    for(auto p:mp) {auto v=p.second;s+=v*(v-1)/2;}
    rep(i,n){
    	ans=s;
    	ans-=mp[a[i]]*(mp[a[i]]-1)/2;
    	ans+=(mp[a[i]]-1)*(mp[a[i]]-2)/2;
    	cout<<ans<<endl;
	}


}


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

const int nm = 1e6;
int n, c[nm + 1];
long long ans = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		++c[a];
	}
	for (int i = 1; i <= nm; ++i) {
		if (!c[i])
			continue;
		if (c[i] > 1)
			c[i] = 0;
		for (int j = i * 2; j <= nm; j += i)
			if (c[j])
				c[j] = 0;
	}
	for (int i = 0; i <= nm; ++i)
		ans += c[i];
	cout << ans << endl;
}


Measured memory_bytes: 7536
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
long long a[1005];
int main(void){
	int n; cin>>n;
    for(int i=1;i<=n;i++){
        int k=i;
        for(int j=2;j*j<=k;j++){
            while(k%j==0){
                a[j]++;
                k/=j;
            }
        }
        if(k!=1){
            a[k]++;
        }
    }
    long long ans=1;
    for(int i=0;i<1005;i++){
		ans=ans*(a[i]+1)%1000000007;
	}
	cout<<ans<<endl;
    
}


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  double n, m, d;
  cin >> n >> m >> d;

  if (d == 0) {
    cout << fixed << setprecision(9) << (m - 1) / n << '\n';
  } else {
    cout << fixed << setprecision(9) << 2 * (n - d) / (n * n) * (m - 1) << '\n';
  }

  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define ll long long
#define vi vector<long long>
#define pi pair<long long, long long>
#define mp make_pair
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)998244353;
const ll INF = (ll)1e9;
const ll N = (1<<5);
const double PI = 3.1415926535897;

int h, w, ans=0;
char a[21][21];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int cnt(pair<int, int> s, pair<int, int> e){
    int v[21][21] = {0};
    v[s.F][s.S] = 1;
    queue< pair<int, int> > q;
    q.push(s);
    while(!q.empty()){
        auto cur = q.front();
        q.pop();
        if(cur==e) return v[cur.F][cur.S];
        for(int i=0; i<4; i++){
            if(cur.F+dx[i]<0||cur.F+dx[i]>=h||cur.S+dy[i]<0||cur.S+dy[i]>=w||v[cur.F+dx[i]][cur.S+dy[i]]||a[cur.F+dx[i]][cur.S+dy[i]]=='#') continue;
            v[cur.F+dx[i]][cur.S+dy[i]] = v[cur.F][cur.S] + 1;
            q.push({cur.F+dx[i], cur.S+dy[i]});
        }
    }
    return -1;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> h >> w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(a[i][j]=='#') continue;
            pair<int, int> s = {i, j};
            for(int k=0; k<h; k++){
                for(int l=0; l<w; l++){
                    if(a[k][l]=='#') continue;
                    pair<int, int> e = {k, l};
                    ans = max(ans, cnt(s, e));
                }
            }
        }
    }
    cout << ans - 1 << endl;
}




Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			String S = in.next();
			int ans = 0;
			for(int i = 0; i < N - 2; i++) {
				if(S.substring(i, i + 3).equals("ABC")) {
					ans++;
				};
			}
			System.out.println(ans);
		}
	}

	static boolean permutation_2(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}

		int[] letters = new int[256];

		char[] s_array = s.toCharArray();
		for (char c : s_array) {
			letters[c]++;
		}

		for (int i = 0; i < t.length(); i++) {
			int c = (int) t.charAt(i);
			if (--letters[c] < 0) {
				return false;
			}
		}
		return true;
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 21460
import System.IO
import Control.Applicative

main = do
  -- "L M N" ---> [L,M,N]
  n <- fmap (read :: String -> Int) . words <$> getLine
  -- ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  print $ digit $ foldl (+) 0 n
  eof <- isEOF
  if eof
    then return ()
    else do main

digit :: Int -> Int
digit n = length $ show n

Measured memory_bytes: 4132
N = int(input())
T = [list(map(int, input().split())) for k in range(N-1)]

for k in range(N):
	t = 0
	for i in range(k,N-1):
		if t < T[i][1]:
			t = T[i][0]+T[i][1]
		else:
			t += T[i][0]+ (T[i][2]-t%T[i][2])%T[i][2]
	print(t)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	int N;
	scanf("%d", &N);
	int a[N];
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	ll ans = INF;

	for (ll x = -100; x <= 100; x++) {
		ll tmp = 0;
		for (int i = 0; i < N; i++) {
			tmp += (a[i] - x)*(a[i] - x);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;


class cd {
public:
   int x;
   int y;
   int height;
};
bool comp(const cd& a,const cd& b) {
   return b.height < a.height;
}


int main() {
   int n;
   cin >> n;
   vector<cd> mp(n);
   int a, b, c;
   rep(i, n) {
	  cin >> a >> b >> c;
	  mp[i].x = a;mp[i].y = b;mp[i].height = c;
   }
   sort(mp.begin(), mp.end(),comp);
   int h = 0;
   bool flg = true;
   for (int i = 0; i <= 100; i++)
   {
	  for (int j = 0; j <= 100; j++)
	  {
		 flg = true;
		 h = mp[0].height + abs(mp[0].x - j) + abs(mp[0].y - i);
		 for (int k = 1; k < n; k++)
		 {
			if (mp[k].height!=max(h - abs(mp[k].x - j) - abs(mp[k].y - i),0)) {
			   flg = false;
			   break;
			}
		 }
		 if (flg) {
			cout << j << " ";break;
		 } 
	  }
	  if (flg) {
		 cout << i << " ";break;
	  }
   }
   cout << h << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(sign i=(sign)a;i>=(sign)b;--i)
const int N=200000+5,inf=2100000000;
inline sign read()
{
	sign ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
char a[N];
ll num;
ll len;
ll book[30];
void work()
{
	scanf("%s",a+1);
	len=strlen(a+1);
	For(i,1,len)book[a[i]-'a']++;
	For(i,0,25)
	{
		num+=book[i]*(book[i]-1)/2;
	}
	printf("%lld\n",len*(len-1)/2-num+1);
}
int main()
{
	work();
	return 0;
}


Measured memory_bytes: 384
N,M = map(int,input().split())
PS =[""]*N
PS2 =[0]*N

PENALTY = 0
AC = 0
for m in range(M):
    p,s = map(str,input().split())
    p=int(p)-1
    if PS[p]!="AC" and s=="WA":
        PS2[p]+=1
    elif PS[p]!="AC" and s=="AC":
        AC+=1
        PENALTY+=PS2[p]
        PS[p]="AC"
        
print(AC,PENALTY)

Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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;}

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

int main(){
    int N,D,X;
    cin>>N>>D>>X;
    int A[N],sum=N;
    rep(i,N)cin>>A[i];
    rep(i,N){
        for(int j=1;j<D+1;j++){
            if(j*A[i]+1<=D) sum++;
        }
    }
    cout<<X+sum<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
        long long int a;
        string B;
        cin >> a >> B;
        long long b=0;
        for(int i=0;i<B.size();i++){
                if(B[i]=='.')
                        continue;
                b*=10;
                b+=B[i]-'0';
        }
        long long lit = (a * b);
        cout << lit/100;
}


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

int main() {
  vector<vector<int>> c(3, vector<int>(3));
  rep(i, 3) cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2);

  vector<int> x(3);
  vector<int> y(3);
  rep(i, 3) y.at(i) = c.at(0).at(i) - x.at(0);
  rep(i, 3) x.at(i) = c.at(i).at(0) - y.at(0);
  bool correct = true;
  rep(i, 3) {
    rep(j, 3) {
      if (c.at(i).at(j) != x.at(i) + y.at(j)) correct = false;
    }
  }

  if (correct) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1010,P=998244353;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
#include<vector>
vector<int>v[N];
int a[N][N],b[N][N],n,m,del[N];
bool check(int md){
	int i,j,k,mx;
	for(i=1;i<=m;i++)v[i].clear(),del[i]=0;
	for(i=1;i<=n;i++)
		v[a[i][1]].push_back(i);
	mx=0;
	for(i=1;i<=m;i++)if(v[i].size()>v[mx].size())mx=i;
	while((int)v[mx].size()>md){
		del[mx]=1;
		for(i=v[mx].size()-1;i>=0;i--){
			k=v[mx][i];
			for(j=b[k][mx];del[a[k][j]];j++);
			if(j>m)return 0;v[a[k][j]].push_back(k);
		}
		mx=0;
		for(i=1;i<=m;i++)if(!del[i]&&v[i].size()>v[mx].size())mx=i;
	}return 1;
}
int main(){
	//freopen("1.out","w",stdout);
	int i,l,r;
	n=read();m=read();
	for(i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		a[i][j]=read();
		b[i][a[i][j]]=j;
	}
	l=0;r=n;
	while(l<r-1)
	check((l+r)>>1)?r=(l+r)>>1
	:l=(l+r)>>1;printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 6144
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
	ll n,A,B,C;
	cin>>n>>A>>B>>C;
	vector<ll> vt;
	rep(i,0,n){
		ll a;
		cin>>a;
		vt.pb(a);
	}
	ll mn = 1000000000;
	rep(i,0,pow(4,n)){
		vector<ll> v(3,0);
		ll d = i;
		ll e = 0;
		rep(j,0,n){
			ll a = d%4;
			d /= 4;
			if(a==3)continue;
			if(v[a]!=0)e++;
			v[a]+=vt[j];
		}
		ll flag = 0;
		rep(j,0,3){
			if(v[j]==0)flag = 1;
		}
		if(flag==1)continue;
		ll cost = 0;
		mn = min(mn,abs(A-v[0])+abs(B-v[1])+abs(C-v[2])+e*10);		
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X = int(rl())
    
    a = 100
    ans = 0
    while a < X:
        a = a + int(a * 0.01)
        ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


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

int main() {
	long long n;
	cin >> n;
	string ans;
	while (n > 0) {
	    n--;
	    ans += char('a' + n % 26);
	    n = n / 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}


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

int main() {
  int x, i, j;
  int a, b;
  cin >> x;
  for (i=-118; i<120; i++) {
    for (j=-119; j<119; j++) {
      if (pow(i, 5)-pow(j, 5)==x) {
        a = i;
        b = j;
        break;
      }
    }
  }
  
  cout << a << " " << b << endl;
}

Measured memory_bytes: 4028
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        pass
    elif a[i] != b[i] and b[i] != c[i] and c[i] != a[i]:
        ans += 2
    else:
        ans += 1
print(ans)

Measured memory_bytes: 9192
#include <iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<=n;i+=4){
		if(!((n - i) % 7)){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
def intlog10(n):
    if n <= 0:
        return -1
    i = 0
    while 10**i <= n:
        i += 1
    return i-1

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
    
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]



best = sorted(B, key = lambda x: x[1]*10-x[0])[0]

adj = 0
if N > 500:
    adj = (N - 500)//best[1]
    N -= best[1] * adj

X = [0] + [-10**9] * N
bpre = -1
ll = 1
for i in range(1, N+1):
    if i > 50 and i < N-50:
        X[i] = X[i-best[1]]*10 + best[0]
    else:
        for b in B:
            if b[1] <= i:
                if X[i-b[1]] == 0:
                    if b[0] > X[i]:
                        X[i] = b[0]
                        bpre = b
                        ll = 0
                else:
                    if X[i-b[1]]*10 + b[0] < X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])):
                        lll = 1

                    if max(X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]]))) > X[i]:
                        X[i] = max(X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])))
                        ll = lll
                        bpre = b
                

ans = str(X[N])
if adj > 0:
    ans = ans[:50] + str(best[0]) * adj + ans[50:]

print(ans)
# print(len(ans))


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

typedef long long ll;
typedef unsigned long long ull;
typedef array<ll,3> XYZ;

int main()
{
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    ll Ai, Bi, Ci;
    vector<ll> A, B, C;
    for(int i=0;i<X;i++){
        cin >> Ai;
        A.push_back(Ai);
    }
    for(int i=0;i<Y;i++){
        cin >> Bi;
        B.push_back(Bi);
    }
    for(int i=0;i<Z;i++){
        cin >> Ci;
        C.push_back(Ci);
    }
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());

    priority_queue<pair<ll, XYZ>> q;
    set<XYZ> s;

    XYZ istart = {0, 0, 0};
    q.push(make_pair(A.front()+B.front()+C.front(), istart));

    ll count = 0;
    while(!q.empty()){
        cout<<q.top().first<<endl;
        count++;
        auto u = q.top().second; q.pop();
        if(count >= K) break;

        vector<XYZ> candidate;
        candidate.push_back(XYZ{u[0]+1, u[1]  , u[2]  });
        candidate.push_back(XYZ{u[0]  , u[1]+1, u[2]  });
        candidate.push_back(XYZ{u[0]  , u[1]  , u[2]+1});
        for(auto v : candidate){
            if(s.count(v)) continue;
            if(v[0] >= X) continue;
            if(v[1] >= Y) continue;
            if(v[2] >= Z) continue;
            auto w = A[v[0]] + B[v[1]] + C[v[2]];
            q.push(make_pair(w, v));
            s.insert(v);
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

pair<int, int> A[200200];
int R[200200];
void proc()
{
	int N; scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i].first), A[i].second = i;
	sort(A, A + N);

	for (int i = 0; i < N; i++) {
		if (i < N / 2) R[A[i].second] = A[N / 2].first;
		else R[A[i].second] = A[N / 2 - 1].first;
	}
	for (int i = 0; i < N; i++) printf("%d\n", R[i]);
}

int main()
{
#ifdef __LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	proc();
	return 0;
}

Measured memory_bytes: 4480
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
count = 0
bonus = 0
for i in a:
    count += b[i-1]
    if i == bonus:
        count += c[i-2]
    bonus = i+1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
signed main(){
        char s[100];
        while( fgets(s, 100, stdin) != NULL ){
                for(int i=0;i<26;i++){
                        for(int j=0;j<100;j++){
                                if(s[j]=='a') s[j] = 'z';
                                else if('a'<s[j]&&s[j]<='z') s[j]-=1;
                        }
                        if(strstr(s,"the")!=NULL ||
                                        strstr(s,"this")!=NULL ||
                                        strstr(s,"that")!=NULL){
                                printf("%s",s);
                                break;
                        }
                }
        }
        return 0;
}

Measured memory_bytes: 3148
def multiply2(A):
    res = 1
    if 0 in A:
        return 0
    for item in A:
        res *= item
        if res > 10**18:
            return -1
    return res

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(multiply2(A))

Measured memory_bytes: 21632
#include<iostream>
using namespace std;
int main(){
  int a[10],b[10];
  for(int i=0;i<7;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<7;i++){
    cout<<a[i]-b[i]<<"\n";
  }
  return 0;
}



Measured memory_bytes: 3088
import sys,math,copy,queue,itertools
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
N = int(input())
A = LI()

CA = [0 for _ in range(N+1)]
for i in range(N):
    CA[A[i]] += 1

tc = 0
for i in range(1,N+1):
    tc += CA[i] * (CA[i]-1) // 2

for i in range(N):
    ans = tc
    cnt = CA[A[i]]
    if cnt > 1:
        ans -= cnt * (cnt - 1) // 2 - (cnt - 1) * (cnt - 2) // 2
    print (ans)


Measured memory_bytes: 84424
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
char state[300];
const ll MOD = 1e+9 + 7;
int memo[210][210][210];
ll calc(int depth, int rest, int down) {
  if (rest < 0) { return 0; }
  if (depth == n) {
    return rest == 0 && down == 0;
  }
  if (memo[depth][rest][down] != -1) { return memo[depth][rest][down]; }
  ll ret = 0;
  if (state[depth] == '-') {
    ret = calc(depth + 1, rest, down);
  } else if (state[depth] == 'D') {
    if (down > 0) {
      ret = (ret + calc(depth + 1, rest - 1, down - 1) * rest % MOD * down) % MOD;
    }
    ret = (ret + calc(depth + 1, rest, down) * rest) % MOD;
  } else if (state[depth] == 'U') {
    if (down > 0) {
      ret = (ret + calc(depth + 1, rest, down) * down) % MOD;
    }
    ret = (ret + calc(depth + 1, rest + 1, down + 1)) % MOD;
  }
  return memo[depth][rest][down] = ret;
}

int main() {
  while (scanf("%d", &n) > 0) {
    MEMSET(memo, -1);
    REP(i, n) {
      scanf(" %c ", &state[i]);
    }
    cout << calc(0, 0, 0) << endl;
  }
}

Measured memory_bytes: 37408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int n; cin >> n;
    map<int, int> mp1, mp2;
    for (int i = 0; i < n/2; i++) {
        int a, b; cin >> a >> b;
        mp1[a]++; mp2[b]++;
    }

    vector<pair<int, int>> a, b;
    a.push_back(make_pair(0, 0));
    b.push_back(make_pair(0, 0));
    for (auto e : mp1) a.push_back(make_pair(e.second, e.first));
    for (auto e : mp2) b.push_back(make_pair(e.second, e.first));

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());

    int ans;
    if (a[0].second == b[0].second) {
        ans = min(n - a[0].first - b[1].first, n - b[0].first - a[1].first);
    }
    else ans = n - a[0].first - b[0].first;

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 8928
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  std::vector<int64_t> a(n),vec;
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  a.insert(a.begin(),0L);
  a.emplace_back(0L);
  int64_t sum=0;
  for (int i = 0; i < n+1; ++i)
  {
    sum+=abs(a[i+1]-a[i]);
  }
  std::vector<bool> sign;
  for (int i = 1; i <=n ; ++i)
  {
    if(a[i]-a[i-1]>=0&&a[i+1]-a[i]>=0){
      sign.emplace_back(true);
    }
    else if(a[i]-a[i-1]<=0&&a[i+1]-a[i]<=0){
      sign.emplace_back(true);
    }
    else sign.emplace_back(false);
  }
  
  for (int i = 0; i < n; ++i)
  {
    if(sign[i]){
      cout<<sum<<endl;
      continue;
    }
    cout<<sum-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i])<<endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> score(3);
  for (ll i = 0; i < 3; ++i) {
    cin >> score[i];
  }

  string t;
  cin >> t;

  vector<ll> r;
  ll ans = 0;
  for (ll i = 0; i < k; ++i) {
    if (t[i] == 's') {
      ans += score[0];
      r.push_back(0);
    } else if (t[i] == 'p')  {
      ans += score[1];
      r.push_back(1);
    } else if (t[i] == 'r')  {
      ans += score[2];
      r.push_back(2);
    }
  }

  for (ll i = k; i < n; ++i) {
    if (t[i] == 's' && r[i-k] != 0) {
      ans += score[0];
      r.push_back(0);
    } else if (t[i] == 'p' && r[i-k] != 1)  {
      ans += score[1];
      r.push_back(1);
    } else if (t[i] == 'r' && r[i-k] != 2)  {
      ans += score[2];
      r.push_back(2);
    } else {
      r.push_back(3);
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<double> v(N);

  for(int i=0;i<N;i++) {
    cin >> v[i];
  }

  sort(v.begin(), v.end());

  double start = v[0];

  for(int i=1;i<N;i++) {
    start = (start + v[i]) / 2;
  }

  cout << start << endl;

  return 0;
}

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

  int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    int next = 1, count = 0;
    for (int i = 0; i < N; i++) {
      cin >> a.at(i);
    }
    for (;;) {
      if (next == 2) {
        cout << count << endl;
        break;
      }
      next = a.at(next-1);
      count += 1;
      if (next == 1 || count > N*10) {
        cout << "-1" << endl;
        break;
      }
    }
  }

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var s string
	con.Scan(&s)
	a := "consonant"
	switch s {
	case "a", "e", "i", "o", "u":
		a = "vowel"
	}
	con.Println(a)
	return nil
}


Measured memory_bytes: 640