akhauriyash/Code-Regression huggingface dataset:
N=int(input().strip())
p=list(map(int,input().split()))

ans=0
flag=0
for i in range(len(p)):
    if i+1 == p[i]:
        if flag==0:
            ans+=1
            flag=1
        else: # if flag == 1
            flag=0
    else: # if i+1 != p[i] 
        flag=0

print(ans)

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


main(){
    int i,j,n,m;
    cin >> n >> m;
    vector<int> sw(n);
    for(i=0;i<m;i++){
        int k;
        cin >> k;
        for(j=0;j<k;j++){
            int s;
            cin >> s;
            s --;
            sw[s] |= 1 << i;
        }
    }
 
    int OK=0;    
    for(i=0;i<m;i++){
        int p;
        cin >> p;
        OK |= p << i;
    }
   

    int push;
    int all_light;
    int ans=0;
    for(push=0;push<(1<<n);push++){
        int all_light = 0;
        for(i=0;i<n;i++){
            if(push & (1<<i)) all_light ^= sw[i];
        }
    if(OK==all_light) ans++;
    }
    cout << ans << endl;
}
    
    

Measured memory_bytes: 256
H,W = map(int,input().split())
A = [input() for i in range(H)]
from collections import Counter
ctr = Counter()
for row in A:
    ctr.update(row)

if H%2==0 and W%2==0:
    print('Yes' if all(v%4==0 for v in ctr.values()) else 'No')
elif H%2 and W%2:
    odd = 0
    for k,v in ctr.items():
        if v%2:
            odd += 1
            ctr[k] -= 1
    if odd != 1:
        print('No')
        exit()
    four = 0
    for v in ctr.values():
        four += (v//4)*4
    want = (H-H%2)*(W-W%2)
    print('Yes' if four >= want else 'No')
else:
    if any(v%2 for v in ctr.values()):
        print('No')
        exit()
    four = 0
    for v in ctr.values():
        four += (v//4)*4
    want = (H-H%2)*(W-W%2)
    print('Yes' if four >= want else 'No')

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

using namespace std;

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

	int a[3] = {};
	for (int i = 0; i < s.length(); i++) {
		a[s[i] - 'a']++;
	}

	int mx = max({ a[0], a[1], a[2] }), mn = min({ a[0], a[1], a[2] });
	if (mx - mn <= 1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const long long maxn=200010LL;
long long n,d,a,xx,yy,res=0LL,pre[maxn];
pair<long long,long long> v[maxn];
long long num(long long x)
{
	long long ans=x/a;
	if(x%a) ++ans;
	return ans;
}
int main()
{
	cin>>n>>d>>a;
	long long ld=d*2+1LL; 
	for(long long i=1LL;i<=n;i++) cin>>v[i].first>>v[i].second;
	sort(v+1LL,v+1LL+n);
	v[n+1]=make_pair(1e18,1e18);
	for(long long i=1LL;i<=n;i++)
	{
		pre[i]+=pre[i-1];
		long long di=v[i].second-pre[i];
		if(di<=0LL) continue;
		long long tim=num(di);
		res+=tim;
		long long att=tim*a;
		long long ind=upper_bound(v+1LL,v+2LL+n,make_pair(v[i].first+ld,0LL))-v-1;
		pre[i]+=att;
		pre[ind+1]-=att;
	}
	cout<<res<<endl;
	return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

    FAST;

    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>

typedef struct
{
	char mark;
	int id,num;
} card;

int isstable(card *a,int n)
{
	int i;
	for(i=0;i<n-1;i++)
	{
		if(a[i].num==a[i+1].num && a[i+1].id<=a[i].id)
		{
			return 0;
		}
	}

	return 1;
}
void swap(card *a,card *b)
{
		card tmp=*a;
		*a=*b;
		*b=tmp;
}
int partition(card *A,int p,int r)
{
	int x=A[r].num;
	int i=p-1;
	int j;
	for(j=p;j<=r-1;j++)
	{
		if(A[j].num<=x)
		{
			i=i+1;
			swap(&A[i],&A[j]);
		}
	}
	
	swap(&A[i+1],&A[r]);
	
	return i+1;
}	
void quicksort(card *A,int p,int r)
{
	if(p<r)
	{
		int q=partition(A,p,r);
		quicksort(A,p,q-1);
		quicksort(A,q+1,r);
	}
}

int main(void)
{
	int i,n;
	card A[500000];
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf(" %c %d",&A[i].mark,&A[i].num);
		A[i].id=i;
	}
	quicksort(A,0,n-1);
	
	printf("%s\n",isstable(A,n)?"Stable":"Not stable");
	for(i=0;i<n;i++)
	{
		printf("%c %d\n",A[i].mark,A[i].num);
	}
	return 0;
}


Measured memory_bytes: 3032
using namespace std;
#include<iostream>
#include<vector>
int N,M;
int ans=1;
const int maxW=100001;
const int maxN=101;


long DP[maxW][maxN];
long w[maxN];
long v[maxN];


int main(){
    int N,W;
    int a,b;
    cin >> N >> W;  
    for(int i = 1; i<= N;i++){
        cin >> a >> b; 
        w[i]=a;
        v[i]=b;
    }
    for(int wj = 0; wj <=W; wj++){
        DP[wj][0] = 0; 
    }

    for(int i = 1; i<= N; i++){
        for(int wj = 0; wj <= W; wj++){
            if(wj < w[i]){
                DP[wj][i] = DP[wj][i-1]; 
            } else {
                DP[wj][i] = max(DP[wj][i-1], DP[wj - w[i]][i-1] + v[i]);  
            }
        }
    }
    cout << DP[W][N]  << endl;

}


Measured memory_bytes: 79104
#[allow(dead_code)]
fn main() {
    let mut aa = i::i();
    let mut bb = i::i();
    let mut num1 = 0;

    if (aa>bb){
        num1+=aa;
        aa-=1;
    }else{
        num1+=bb;
        bb-=1;
    }
    if (aa>bb){
        num1+=aa;
        aa-=1;
    }else{
        num1+=bb;
        bb-=1;
    }


    println!("{}",num1);
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }
    pub fn strv(n: usize) -> Vec<String> {
        (0..n).map(|_| str()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

using namespace std;
typedef long long int ll;

int main()
{
    int N, K, x;
    cin >> N >> K;
    vector<int> p;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        p.push_back(x);
    }
    std::sort(p.begin(), p.end());
    int sum = 0;
    for (int i = 0; i < K; i++)
        sum += p[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> A(N);
    for (int &a: A)
        scanf("%d", &a);

    vector<int> B = A;
    sort(B.begin(), B.end());
    for (int a: A)
        if (a==B[N-1])
            printf("%d\n", B[N-2]);
        else
            printf("%d\n", B[N-1]);
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int x=0;
	string s,t;
	cin>>s>>t;
	if(s[0]==t[0])x++;
	if(s[1]==t[1])x++;
	if(s[2]==t[2])x++;
	cout<<x<<endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int f( int n )
{
    if( n % 2 == 0 ) return n / 2;
    return 3 * n + 1;
}

int main()
{
    int s;
    cin >> s;
    VEC( bool, 10000010, p, false );
    int ans = 1;
    int num = s;
    p[s] = true;

    while( true )
    {
        ++ans;
        num = f( num );
        if( p[num] )
        {
            break;
        }
        p[num] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int culculate(int n, int x) {
	int i, j, k, amari, count = 0;
	
	for (i = 1; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			amari = x - ( i + j );
			if (amari >= j + 1 && amari <= n)
			{
				count++;
			}
		}
	}
	
	return count;
}

int main(void) {
	int n, x;
	
	do
	{
		scanf("%d %d", &n, &x);
		if (n != 0 || x != 0)
		{
			printf("%d\n", culculate(n, x));
		}
	} while (n != 0 || x != 0);
	
	return 0;
}

Measured memory_bytes: 2756
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 1000010;
const int mod = 1000000000 + 7;

bool isPrime(int x) {
	for (int i = 2;i*i <= x; ++i) 
		if (x % i == 0)
			return false;
	return true;
}

int pot(ll a, int wyk) {
	ll res = 1;
	while (wyk) {
		if (wyk & 1) {
			res = (res * a) % mod;
		}
		a = (a * a) % mod;
		wyk >>= 1;
	}
	return res;
}

int odwr(ll a) {
	return pot(a, mod- 2);
}

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vi primes, odw;
	vi kt(nax);
	FOR(i, 2, 1000000) {
		if (isPrime(i)) {
			primes.pb(i);
			odw.pb(odwr(i));
			kt[i] = primes.size() - 1;
		}
	}
	vi a(n);
	vi lcm(primes.size());
	vector<map<int, int>> rozklad(n);
	REP(i, n) {
		cin >> a[i];
		int wsk = 0;
		while (primes[wsk] * primes[wsk] <= a[i]) {
			if (a[i] % primes[wsk] == 0) {
				// printf("dzieli sie prze")
				int cnt = 0;
				while (a[i] % primes[wsk] == 0) {
					++cnt;
					a[i] /= primes[wsk];
				}
				rozklad[i][wsk] = cnt;
				lcm[wsk] = max(lcm[wsk], cnt);
			}
			++wsk;
		}
		if (a[i] > 1) {
			int ktora = kt[a[i]];
			rozklad[i][ktora] = 1;
			lcm[ktora] = max(lcm[ktora], 1);
		}
	}
	// REP(i, 3) printf("lcm[%d] = %d\n", i, lcm[i]);
	// REP(i, n) {
	// 	REP(j, 3) printf("rozk[%d][%d]: %d\n", i, j,rozklad[i][j]);
	// }
	ll lcmr = 1;
	REP(pr, sz(primes)) {
		REP(wyk, lcm[pr]) {
			lcmr = (lcmr * primes[pr]) % mod;
		}
	}
	int res = 0;
	REP(i, n) {
		ll b = lcmr;
		for (auto roz : rozklad[i]) {
			int prim = roz.st;
			int wyk = roz.nd;
			while (wyk > 0) {
				b = (b * odw[prim]) % mod;
				--wyk;
			}
		}
		// printf("for %d - b: %lld\n", i, b);
		res = (res + b) % mod;
	}
	cout << res << endl;
}

Measured memory_bytes: 10852
#include<bits/stdc++.h>
using namespace std;
#define int long
#define pi pair<int,int>
main(){
  int n,m,inp;
  cin>>n>>m;
  auto func=[](int a,int b){return a>b;};
  priority_queue<int,vector<int>,decltype(func)> que(func);
  vector<pi> b(m);
  for(int i=0;i<n;++i){
    cin>>inp;
    que.push(inp);
  }
  for(auto& p:b)cin>>p.first>>p.second;
  sort(b.begin(),b.end(),[](pi x,pi y){return x.second>y.second;});
  int cnt=0;
  for(int i=0;cnt<n&&i<m;++i){
    for(int j=0;j<b[i].first&&que.top()<b[i].second;++j){que.pop(); que.push(b[i].second);}
  }
  int s=0;
  while(!que.empty()){
    s+=que.top();
    que.pop();
  }
  cout<<s;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    int N;
    cin >> N;
    V<int> points(400);
    FOR(i, 0, N) {
        int s, l, p;
        cin >> s >> l >> p;
        FOR(j, s, l + 1) {
            points[j] = max(points[j], p);
        }
    }

    V<LL> dp(401, -1);
    dp[0] = 0;
    FOR(i, 0, points.size()) {
        FOR(j, 0, dp.size()) {
            if (dp[j] == -1) {
                continue;
            }
            if (j + i < dp.size()) {
                dp[j + i] = max(dp[j + i], dp[j] + points[i]);
            }
        }
    }

    int M;
    cin >> M;
    V<LL> ans(M);
    FOR(i, 0, M) {
        int w;
        cin >> w;
        ans[i] = dp[w];
        if (ans[i] == 0) {
            print(-1);
            return 0;
        }
    }

    FOR(i, 0, M) {
        print(ans[i]);
    }

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  int now = 0;
  int count = 0;
  if ( n != 1) {
    rep(i, n-1) {
      if ((now == 0) && (a.at(i) < a.at(i+1))) {
        now = 1;
      }
      else if ((now == 0) && (a.at(i) > a.at(i+1))) {
        now = 2;
      }
      if ((now == 1) && (a.at(i) > a.at(i+1))) {
        now = 0;
        count++;
      }
      else if ((now == 2) && (a.at(i) < a.at(i+1))) {
        now = 0;
        count++;
      }
      if (i == n - 2) {
        count++;
      }
    }
    cout << count << endl; 
  }
  else {
    cout << 1 << endl;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>
 
using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
 
int main(){
    int n;
    cin>>n;
    multiset<int> s;
    for(int i=0;i<n;++i){
        int a;cin>>a;
        auto it = s.lower_bound(a);
        if(s.begin() == it){
            s.insert(a);
        }else{
            it--;
            s.erase(it);
            s.insert(a);
        }
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 4992
def read_input():
    n, m = map(int, input().split())

    students = []
    for i in range(n):
        a, b = map(int, input().split())
        students.append((a, b))

    checkpoints = []
    for j in range(m):
        c, d = map(int, input().split())
        checkpoints.append((c, d))

    return n, m, students, checkpoints


def search_nearest_checkpoint(st, checks):
    def manhattan_dist(a, b):
        return abs(a[0] - b[0]) + abs(a[1] - b[1])

    mindist = float('inf')
    minid = None
    for i, check in enumerate(checks):
        mdist = manhattan_dist(st, check)
        if mdist < mindist:
            mindist = mdist
            minid = i + 1

    return minid

def submit():
    n, m, students, checkpoints = read_input()


    for student in students:
        print(search_nearest_checkpoint(student, checkpoints))


if __name__ == '__main__':
    submit()


Measured memory_bytes: 39792
#include <stdio.h>


int main(){


	int r, c, x, y;
	int table[100][100];
	int sum, total;

	scanf( "%d %d", &r, &c );

	for( y=0; y<r; y++){
	for( x=0; x<c; x++){
		scanf( "%d", &table[x][y] );
	}}

	for( y=0; y<r; y++){ sum=0;
	for( x=0; x<c; x++){
		printf( "%d ", table[x][y] );
		sum += table[x][y];
	}printf( "%d\n", sum );}

	total=0;
	for( x=0; x<c; x++ ){sum=0;
	for( y=0; y<r; y++ ){
		sum += table[x][y];
		total += table[x][y];
	}printf( "%d ", sum );}

	printf( "%d\n", total );


	return 0;

}

Measured memory_bytes: 640
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
maxi = 0

for i in range(1, len(A)):
    ans += abs(A[i]-A[i-1])
    if maxi < abs(A[i]-A[i-1]): maxi = abs(A[i]-A[i-1])
    
if A[0]==0:
    if maxi < N-A[-1]: maxi = N-A[-1]
    ans += N-A[-1]
else :
    if maxi < N-A[-1]+A[0]: maxi = N-A[-1]+A[0]
    ans += N-A[-1]+A[0]
    
print(ans-maxi)


Measured memory_bytes: 26444
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

#define int long long
#define double long double
#define incin(n) int (n); cin >> (n)
#define uniq(v) sort((v).begin(),(v).end()); (v).erase(unique((v).begin(),(v).end()),(v).end());
#define steprap(i,n,s) for(int (i)=0;i<(s)*(n);(i)+=(s))
#define rap(i,n) steprap((i),(n),1)

using intV = std::vector<int>;

using namespace std;
namespace math
{
	double PI = 3.14159265359;
	int step(int n);
	int ncr(int n,int r);
	int npr(int n,int r);
	int gcm(int a,int b);
	int lcm(int a,int b);

	int step(int n){
		if(n<=1){
			return 1;
		}else{
			return n * step(n-1);
		}
	}
	int ncr(int n,int r){
		for(int i=1;i<r;i++){
			n *= n-i;
		}
		for(int i=1;i<r;i++){
			r *= r-1;
		}
		return n/r;
	}
	int npr(int n,int r){
		for (int i = 1; i < r; ++i)
		{
			n *= n-1;
		}
		return n;
	}
	int gcm(int a,int b){
		int p=max(a,b);
		int q=min(a,b);
		int r;
		while(true){
			if(p%q==0){
				return q;
			}
			r = p%q;
			p=q;
			q=r;
		}
	}
}

using namespace std;
// using StringMap = std::vector<std::vector<char>> map(h+2,vector<char>(w+2,'#'));
namespace tmp {
    template <typename T> bool inArry(T x,vector<T> v);
    template <typename T> void input(int n,vector<T> &v);

    template <typename T> bool inArry(T x,vector<T> v){
        int l = v.size();
        for(int i=0;i<l;i++){
            if(x==v[i]){
                return true;
            }
        }
        return false;
    }
    
    template <typename T> void input(int n,vector<T> &v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
    }
    
}

using namespace std;

signed main (){
	string s;
	cin >> s;
	rap(i,s.size()){
		if(s[i]==','){
			s[i] = ' ';
		}
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
data =[]
while input = gets.chomp

  data << input.to_s
  break if data.length % 2 != 0 && input.to_i == 0
  
  if data.length == 2 
    str = data[1]
    for i in 1..data[0].to_i
      temp_str = ""
      count = 1
      for j in 0..str.length-1
        if str[j] == str[j+1] then
          count += 1
        else
          temp_str << "#{count}#{str[j]}"
          count = 1
        end
      end
      str = temp_str
    end
    puts str
    data = []
  end
end

Measured memory_bytes: 8944
//秒単位の時間 S が与えられるので、h:m:s の形式へ変換して出力してください。ここで、h は時間、m は 60 未満の分、s は 60 未満の秒とします。

using System;

class Program
{
    static void Main()
    {
        const int secPerHour = 3600;
        const int secPerMinute = 60;
        var x = int.Parse(Console.ReadLine());
        int H = x / secPerHour;
        int M = (x - H * secPerHour) / secPerMinute;
        int S = x - (H * secPerHour + M * secPerMinute);
        Console.WriteLine("{0}:{1}:{2}", H, M, S);
    }
}


Measured memory_bytes: 7832
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

bool xy[500][500];
vector<int> xz[500];
vector<int> yz[500];

int main() {
  int n, h;
  while (scanf("%d%d", &n, &h), n|h) {
    memset(xy, false, sizeof(xy));
    REP(i, n) { xz[i].clear(); yz[i].clear(); }
    REP(i, h) {
      char c[3]; int a, b; scanf("%s%d%d", c, &a, &b); --a; --b;
      if (c[1] == 'z') {
        if (c[0] == 'x') { xz[a].push_back(b); }
        else { yz[a].push_back(b); }
      } else {
        xy[b][a] = true;
      }
    }
    REP(i, n) { sort(ALL(xz[i])); sort(ALL(yz[i])); }
    int ans = 0;
    REP(y, n) REP(x, n) {
      if (xy[y][x]) { continue; }
      int cx = xz[x].size(), cy = yz[y].size();
      int i = 0, j = 0, intersection = 0;
      while (i < cx && j < cy) {
        if (xz[x][i] == yz[y][j]) {
          ++intersection; ++i; ++j; }
        else if (xz[x][i] < yz[y][j]) { ++i; }
        else { ++j; }
      }
      ans += n - cx - cy + intersection;
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
from itertools import product
from collections import defaultdict,Counter

h,w,n = map(int,input().split())

dic = defaultdict(int)

for _ in range(n):
    y,x= map(int,input().split())
    for i,j in product([-1,0,1],repeat=2):
        nx = x+i
        ny = y+j
        if 2 <= nx <= w-1 and 2 <= ny <= h-1:
            dic[nx,ny] += 1

c = Counter(dic.values())
c[0] = (w-2)*(h-2)-sum(c.values())

for i in range(10):
    print(c[i])

Measured memory_bytes: 166896
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
const int MOD = 1000000009;

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

const int MAX_N = 15;
const int MAX_W = 110000;
int dp[MAX_N][MAX_W];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int W;
  cin >> W;
  
  vector<int> weight;
  for(int i=1;i <=W;i*=6) weight.push_back(i);
  for(int i=9;i <= W; i*=9) weight.push_back(i);
  int n = (int)weight.size();

  //DP初期条件
  REP(i,MAX_N) REP(w,MAX_W) dp[i][w] = INF;
  for(int i=0; i<=n;++i) dp[i][0] = 0;

  //DPループ
  REP(i,n){
      for(int w=0;w<=W;w++){
          dp[i+1][w] = min(dp[i+1][w], dp[i][w]);
          if(w >= weight[i]) dp[i+1][w] = min(dp[i+1][w], dp[i+1][w-weight[i]]+1);
      }
  }

  cout << dp[n][W] << endl;
}

Measured memory_bytes: 6656
import bisect

N=int(input())
ans=0
i=2
a=[j*(j+1)//2 for j in range(64)]
while i*i<=N:
    cnt=0
    while N%i==0:
        N//=i
        cnt+=1
    ans+=bisect.bisect_right(a,cnt)-1
    i+=1
if N>1:
    ans+=1
print(ans)


Measured memory_bytes: 9112
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

lint fac[510000],finv[510000],inv[510000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<510000;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
lint COM(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
lint facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}


int main(void){
    COMinit();
    int N;
    cin >> N;
    int A[N+1];
    rep(i,N+1) cin >> A[i],A[i]--;
    int cnt[N+1]={};
    rep(i,N+1) cnt[A[i]]++;
    int same[2];
    int now=0;
    rep(i,N+1) if(cnt[A[i]]==2) same[now++]=i;
    int left=same[0],right=N-same[1];
    for(int i=1;i<=N+1;i++){
       lint ans=COM(N+1,i);
       lint minus=0;
       if(left+right>=i-1) minus=(minus+COM(left+right,i-1))%MOD;
       cout << (ans-minus+MOD)%MOD << endl;
    }
}

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

using namespace std;

#define ll long long

int main()
{
	int N, K;
	cin >> N >> K;
	vector < ll > x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	ll minDist = LLONG_MAX;

	for (int i = 0; i <= N - K; i++) {
		ll minus = x[i];
		ll plus = x[i + K - 1];
		ll dist = plus - minus;
		dist += min(abs(minus), abs(plus));
		minDist = min(minDist, dist);
	}

	cout << minDist << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;


long prime_factorization(long n) {
    vector<pair<long, long>> res;
    long res2=1;
    for (long i = 2; i * i <= n; ++i) {
        if (n % i != 0) {
            continue;
        }

        long ex = 0;

        while (n % i == 0) {
            ex += 1;
            n = n / i;
        }

        res.emplace_back(i, ex);
    }

    if (n != 1) {
        res.emplace_back(n, 1);
    }

    for (int i = 0; i < res.size(); ++i) {
        res2 *= (1+res[i].second);
    }

    return res2;

}
int main() {

    int N;
    cin >> N;
    long res = 0;
    for (int c = 1; c < N; ++c) {
        res += prime_factorization(N - c);
    }

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 3632
inp = input().split()
for a in inp:
    out = int(a)
inp.pop(1)
for a in inp:
    i = int(a)
    
n = 1
while (i*n-(n-1)) < out:
    n += 1

else:
    if out == 1:
        print(0)
    else:
        print(n)


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

#define FALSE 1
#define TRUE  0

int main()
{
    int w, h, x, y, r, result;

    result = 0;

    cin >> w >> h >> x  >> y >> r;

    if((x - r < 0) || (w - x < r))
        result = FALSE;
    if((y - r < 0) || (h - y < r))
        result = FALSE;

    if(result == FALSE)
        cout << "No" << endl;
    else if(result == TRUE)
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    double xa, ya, ra, xb, yb, rb, d;
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    complex<double> c1(xa, ya), c2(xb, yb);
    d = abs(c1 - c2);
    cout << ((d > ra + rb) ? 0 : (d >= abs(ra - rb)) ? 1 : (ra > rb) ? 2 : -2) << endl;
  }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;

void solve(ll x)
{
	if(!x) return ;
	if(x%26==0)
	{
		solve(x/26-1);
		cout<<"z";
	}
	else
	{
		solve(x/26);
		cout<<char(x%26+'a'-1);
	}
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin>>x;
	solve(x);
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>

int main() {
	char s[4], tmp[2];
	bool flag = false;
	std::cin >> s;
	tmp[0] = s[0];
	for (int i = 1; i < 3; i++) {
		if (tmp[0] != s[i]) {
			tmp[0] = s[i];
			flag = true;
		}
	}

	if (flag)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}

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

int main() {
    int x, y;
    cin >> x;
    y = pow(x,3);
    cout << y << endl;
    return 0;
}


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

int main() {
  int A,B,C;
  bool x=0;
  
  cin >> A;
  cin >> B;
  cin >> C;
  
  if(A==B && A != C) x=0;
  else  if(B == C && B != A) x=0;
  else  if(C == A && C != B) x=0;
  else x = 1;
  
  if(x == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var ans = YesNo(GetStr().ToCharArray().Any(a => a == '9'));

            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;
using pr  = pair<int, int>;

const ll MOD = 998244353;

int main()
{
	for (int i = 1; i <= 5; ++i)
	{
		int x; cin >> x;
		if (x == 0)
		{
			cout << i << endl;
		}
	}

	return 0;
}

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

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

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

    while (1)
    {
        /* code */

        c = c - b;

        if (a <= 0)
        {
            cout << "No";
            break;
        }
        else if (c <= 0)
        {
            cout << "Yes";
            break;
        }
        else
        {
            a = a - d;
            if (a <= 0)
            {
                cout << "No";
                break;
            }
            else if (c <= 0)
            {
                cout << "Yes";
                break;
            }
            else
            {
            }
        }
    }
}

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

using namespace std;

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

typedef pair <long long, int> P;

const long long inf = 1000000000000000;

int main()
{
	int n, m, s, t;
	cin >> n;
	cin >> m;
	cin >> s >> t;
	s--;
	t--;
	vector<int> edge[100010], yen[100010], snuke[100010];
	int x, y;
	long long a, b;
	rep(i, m)
	{
		cin >> x >> y >> a >> b;
		x--;
		y--;
		edge[x].push_back(y);
		yen[x].push_back(a);
		snuke[x].push_back(b);
		edge[y].push_back(x);
		yen[y].push_back(a);
		snuke[y].push_back(b);
	}
	long long ds[100010]={}, dt[100010]={};
	priority_queue<P, vector<P>, greater<P> > qs, qt;
	
	//sからのダイクストラ
	rep(i, n)
	{
		if(i==s) ds[i]=0;
		else ds[i]=inf;
		qs.push(P(ds[i], i));
	}
	while(!qs.empty())
	{
		P tmp=qs.top();
		qs.pop();
		int u=tmp.second;
		rep(j, edge[u].size())
		{
			int v=edge[u][j];
			long long alt=tmp.first + yen[u][j];
			if(ds[v]>alt)
			{
				ds[v]=alt;
				qs.push(P(alt, v));
			}
		}
	}
  	//rep(i, n) cout << ds[i] << endl;

	//tからのダイクストラ
	rep(i, n)
	{
		if(i==t) dt[i]=0;
		else dt[i]=inf;
		qt.push(P(dt[i], i));
	}
	while(!qt.empty())
	{
		P tmp=qt.top();
		qt.pop();
		int u=tmp.second;
		rep(j, edge[u].size())
		{
			int v=edge[u][j];
			long long alt=tmp.first + snuke[u][j];
			if(dt[v]>alt)
			{
				dt[v]=alt;
				qt.push(P(alt, v));
			}
		}
	}
  	//rep(i, n) cout << ds[i] << ' ' << dt[i] << endl;

	P ans[100010];
	rep(i, n)
	{
		ans[i].second=i;
		ans[i].first=ds[i]+dt[i];
	}
	sort(ans, ans+n);
	int tmp=0, year=0;
	while(year < n)
	{
		if(ans[tmp].second >= year)
		{
			cout << inf - ans[tmp].first << endl;
			year++;
		}
		else tmp++;
	}

	return 0;
}

Measured memory_bytes: 31728
#include <stdio.h>

int N,M,P[100100],C[100100],S[100100],E[100100];
long long U[100100][3];

int find(int x)
{
	if (P[x] != x){
		int c = C[x], p = P[x];
		P[x] = find(p);
		C[x] = (C[p] + c) % 3;
	}
	return P[x];
}

int main()
{
	scanf ("%d %d",&N,&M);
	for (int i=1;i<=N;i++) P[i] = i;
	for (int i=0;i<M;i++){
		int x,y;
		scanf ("%d %d",&x,&y);

		int X = find(x), Y = find(y);
		if (X == Y){
			if ((C[x] + 1) % 3 != C[y])
				S[X] = 1;
		}
		else{
			P[Y] = X;
			C[Y] = (C[x] - C[y] + 4) % 3;
			S[X] |= S[Y];
			E[X] += E[Y];
		}
		E[X]++;
	}

	for (int i=1;i<=N;i++){
		int x = find(i);
		U[x][C[i]]++;
	}

	long long ans = 0;
	for (int i=1;i<=N;i++) if (find(i) == i){
		if (S[i])
			ans += (U[i][0] + U[i][1] + U[i][2]) * (U[i][0] + U[i][1] + U[i][2]);
		else if (U[i][0] > 0 && U[i][1] > 0 && U[i][2] > 0)
			ans += U[i][0] * U[i][1] + U[i][1] * U[i][2] + U[i][2] * U[i][0];
		else
			ans += E[i];
	}

	printf ("%lld\n",ans);

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; i++) {
        cin >> a.at(i);
    }

    int count=0;
    int j = 0;

    for(int i=0; i<N; i++) {
        count++;
        if(a.at(j)==2) {
            break;
        }
        j=a.at(j)-1;
    }
    if(count<N) {
        cout << count << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3788
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

vector<ll>g[MAXN];
ll res[MAXN], k;

void dfs(ll curr, ll par)
{
    if(curr==1)
    {
        for(int i=0,j=0; i<g[curr].size(); i++)
        {
            int v = g[curr][i];

            if(v!=par)
            {
                res[v] = k-1-j;
                j++;
                dfs(v,curr);
            }
        }
    }
    else
    {
        for(int i=0, j=0; i<g[curr].size(); i++)
        {
            int v = g[curr][i];

            if(v!=par)
            {
                res[v] = k-2-j;
                j++;
                dfs(v,curr);
            }
        }
    }
}

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n>>k;

    For(i,1,n-1)
    {
        cin>>u>>v;

        g[u].push_back(v);
        g[v].push_back(u);
    }

    res[1] = k;

    dfs(1,-1);

    ll ans = 1;
    for(i=1; i<=n; i++)
    {
       // cout<<res[i]<<" ";
        ans*=res[i]%MOD;
        ans%=MOD;
    }

    cout<<ans%MOD<<endl;

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 11136
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var n, l int
	var s []string
	fmt.Scan(&n, &l)

	for i := 0; i < n; i++ {
		s = append(s, next())
	}

	sort.Strings(s)
	fmt.Println(strings.Join(s, ""))
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long N, p[5]{}, a{};
  cin >> N;
  string S;
  while (cin >> S)
    if (auto j = "MARCH"s.find(S[0]); j != string::npos) ++p[j];
  for (int i = 0; i != 3; ++i)
    for (int j = i + 1; j != 4; ++j)
      for (int k = j + 1; k != 5; ++k) a += p[i] * p[j] * p[k];
  cout << a << endl;
}


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


int main() {
  
  string s;
  cin >> s;
  int acount, zcount;
  int kazu = s.size();
  int i = 0;
  
  while ( s.at(i) != 'A' ) {
    // ( int i = 0; i < s.size(); i++ ) {
    //if ( s.at(i) == 'A' ) break;
    i++;
    acount++;
    }
  
  reverse ( s.begin(), s.end() );
  
  i = 0;
  
    while ( s.at(i) != 'Z' ) {
    i++;
    zcount++;
    }
  
//    for ( int i = 0; i < kazu; i++ ) {
//    if ( s.at(i) == 'Z' ) break;
//    zcount++;
//    }
    
    
  cout << kazu - ( acount + zcount ) << endl;
  
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define mod 1000000007
#define pb push_back  
#define endl "\n"
#define fi first
#define se second 
#define ll long long
#define inf 9000000000000000000
#define PI 3.14159265359

int power(int a,int b,int m=mod)
{
     if(b==0)	return 1;
     if(b==1)	return a;
	 int res=power(a,b/2,m);
	 res=(res*res)%m;
     if(b&1)	res=(res*a)%m;
     return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}


int32_t main()
{
   IOS
   
   int x;
   cin>>x;
   
   cout<<1-x<<endl;
	
	
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    bool f = false;
    rep(i, 0, n){
        ll tmp;
        cin >> tmp;
        if(tmp % 2 == 1){
            f = true;
        }
    }
    if(f){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean[] isPrime = new boolean[1000000];
	static int[] a;
	static int[] sum;
	static{
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		int count=0;
		int[] b = new int[100000];
		for(int i = 2; i*i<=isPrime.length; i++){
			if(isPrime[i]){
				
				for(int j = i+i; j < isPrime.length; j+=i){
					isPrime[j]=false;
				}
			}
		}
		
		for(int i = 0; i < isPrime.length; i++){
			if(isPrime[i]){
				b[count++]=i;
			}
		}
		a = new int[count];
		sum = new int[count+1];
		for(int i = 0; i < count; i++){
			
			a[i]=b[i];
			sum[i+1] = sum[i]+a[i];
		}
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			System.out.println(sum[n]);
			
		}
	}

}

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

using namespace std;
typedef long long LL;
typedef pair <LL, int> P;
const int Maxn = 2e5 + 5;
LL a[Maxn], f[Maxn];
int n;
LL k;
P vec[Maxn];
bool check(LL x){
    LL cnt = 0;
    for (int i = n; i >= 1; i--){
        if (vec[i].first <= x) return true;
        cnt += (vec[i].first - x - 1) / vec[i].second + 1;
        if (cnt > k) return false;
    }
    return true;
}
int main(){
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &f[i]);
    sort(a + 1, a + n + 1);
    sort(f + 1, f + n + 1);
    for (int i = 1; i <= n; i++){
        vec[i] = P(f[i] * a[n + 1 - i], f[i]);
    }
    sort(vec + 1, vec + n + 1);
    LL l = 0, r = vec[n].first;
    while(l < r){
        LL m = (l + r) >> 1;
        if (check(m))
            r = m;
        else
            l = m + 1;
    }
    cout << l << endl;
}



Measured memory_bytes: 6528
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll=long long;
using namespace std;


int main() {
	ll N;
	ll g;
	vector<ll>A;
	vector<ll>B;
	cin >> N;
	for (ll i = 0; i < N; i++) {
		cin >> g;
		A.push_back(g);
		B.push_back(0);
	}
	sort(A.begin(),A.end());
	ll count=0;
	for (ll j = 0; j <N; j++) {
		B[N-1] += A[j];
	}
	for (ll i=N-2; 0<=i; i--) {

			B[N-1] -= A[i+1];
		
		if (B[N-1]*2 >= A[i+1] ) {
			count++;
		}
		else {
			break; }
	}
	cout << count+1;
}


Measured memory_bytes: 2036