akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int max(int num1, int num2){
    /*
     DP遷移の中でmaxを取る場面があったため関数を実装した。test
     a>bならaをreturnし、それ以外ならbをreturnする。
     */
    if (num1 > num2) {
        return num1;
    }else{
        return num2;
    }
}

int main(void){
    /*宣言フィールド*/
    int     i, j, length_1, length_2,pivot_x,pivot_y, pivot;
    //i, j -> イテレータとして使用, length -> 文字列長を表す変数として使用
    //lcs_count -> lcs_dptableの中での検索に使用
    char    input_word_1[3005];
    char    input_word_2[3005];
    int     lcs_dptable [3005][3005];
    char    anschar[3005];
    
    /*文字列長は1000以下なので改行込みでも十分*/
    /*宣言終了*/
    
    scanf("%s" , input_word_1);
    scanf("%s" , input_word_2);
    //入力.行を丸ごと受け取る。
    
    length_1 = strlen(input_word_1);
    length_2 = strlen(input_word_2);
    /*
     デバッグ用
     printf("%d %d\n", length_1, length_2);
     */
    for (i = 0; i < length_1; i++) {
        for ( j = 0; j < length_2; j++){
            if (i == 0 || j == 0){
                lcs_dptable[i][j] = 0;
            }
        }
    }
    /*
     DPテーブルを初期化する.
     lcs_dptable[i][j]はinput_word_1のi文字目までとinput_word_2のj文字目(1-indexed)までで考える最長部分列である。
     i=0,またはj=0の時はLCSの長さは0であることを用いて初期化する
     */
    
    
    for (i = 1; i <= length_1; i++) {
        for (j = 1; j <= length_2; j++) {
            if (input_word_1[i-1] == input_word_2[j-1]) {
                lcs_dptable[i][j] = lcs_dptable[i-1][j-1] + 1;
            }else{
                lcs_dptable[i][j] = max(lcs_dptable[i][j-1], lcs_dptable[i-1][j]);
            }
        }
    }
    /*
     DPテーブルを更新する.
     lcs[i][j](略記した)(文字列のそれぞれi,j文字目までのみを考えている)について考えるとき、i,j文字目が一致していた時とそうでないときに場合分けする。
     <一致していた場合>
     - lcs[i-1][j-1] + 1である。
     lcs[i][j] <= lcs[i-1][j-1] + 1という等式を満たすことが保証され、かつ
     {lcs[i-1][j-1]までのLCS + input_word_1のi文字目}という文字列がlcs[i-1][j-1] + 1文字の共通部分列であり、
     それが最大の長さだからである。
     <一致しなかった場合>
     - max(lcs[i-1][j], lcs[i][j-1])である。
     lcs[i][j] > lcs[i-1][j]となる場合,LCSにはinput_word_1のi文字目が含まれる。
     しかしながらinput_word_1のi文字目とinput_word_2のj文字目は一致していないため,lcs[i][j] = lcs[i][j-1]である。
     */
    
    /*
     デバッグ用
     for (i = 0; i <= length_1; i++){
        for ( j = 0; j <= length_2; j++){
            printf("%d " , lcs_dptable[i][j]);
        }
        printf("\n");
     }
     */
    
    pivot_x = length_1;
    pivot_y = length_2;
    pivot = 0;
    /*
     DPの復元を行う。
     LCSの長さがxである時の最小のiを探しながら復元する。
     */
    while (pivot_x != 0 || pivot_y != 0) {
        if (pivot_x > 0 && lcs_dptable[pivot_x][pivot_y] == lcs_dptable[pivot_x-1][pivot_y]) {
            /*
             上に遡る
             */
            pivot_x--;
        }else if(pivot_y > 0 && lcs_dptable[pivot_x][pivot_y] == lcs_dptable[pivot_x][pivot_y-1]){
            //左に遡る
            pivot_y--;
        }else{
            anschar[pivot] = input_word_1[pivot_x-1];
            pivot_x--;
            pivot_y--;
            pivot++;
        }
    }
    for (i = pivot-1; i >= 0; i--) {
        printf("%c" , anschar[i]);
    }
    
    printf("\n");
    
    
    return 0;
}


Measured memory_bytes: 35456
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
using namespace std;

int main(){
  
  string s; cin >> s;
  
  if (s.at(0)==s.at(1) || s.at(1)==s.at(2) || s.at(2)==s.at(3)) cout << "Bad";
  else cout << "Good";
 
  return 0;
}


Measured memory_bytes: 256
P, Q, R = map(int, input().split())

# 空港 A, B, C があり、それぞれの空港の間では、双方向に飛行機が運航しています。
# 空港 A, B 間の飛行時間は片道 P時間、空港 B, C 間の飛行時間は片道 Q時間、空港 C, A 間の飛行時間は片道 R時間です。
# いずれかの空港からスタートして他の空港に飛行機で移動し、さらにそのどちらでもない空港に飛行機で移動するような経路を考えます。
# 飛行時間の和は最短で何時間になるでしょうか。

abc = P + Q
acb = Q + R
bca = P + R
print(min(abc, acb, bca))

Measured memory_bytes: 9096
/// Zhamshitov
/// Rinat
/// Rahatovich
/// 8 "A";
///
#include <bits/stdc++.h>

using namespace std;

int b[10009], c[10009];
int main()

{
    int n, m, a[1009], mx = -9, mn = 999999, t = 0, d = 0, s = 0;
    cin >> n;
    for( int i = 0 ; i < n; i++ ){
        cin >> a[i];
        if( a[i] > 0 && a[i] < 400 )
            b[1] ++;
        if( a[i] >= 400 && a[i] < 800 )
            b[2]++;
        if( a[i] >= 800 && a[i] < 1200 )
            b[3] ++;
        if( a[i] >= 1200 && a[i] < 1600 )
            b[4] ++;
        if( a[i] >= 1600 && a[i] < 2000 )
            b[5] ++;
        if( a[i] >= 2000 && a[i] < 2400 )
            b[6] ++;
        if( a[i] >= 2400 && a[i] < 2800 )
            b[7] ++;
        if( a[i] >= 2800 && a[i] < 3200 )
            b[8] ++;
        if( a[i] >= 3200 )
            t ++;
    }
    for( int i = 1; i <= 8; i++ )
    {
        if( b[i] > 0 )
        {
            d++;
        }
    }
    if( d == 0 && t != 0 )
        cout << 1 << " "<<  t;
    else
    cout << d << " " << d + t;

}


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

int main()
{
    string s;
    int a[2] = {0};
    cin >> s;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'A') a[0]++;
        if (s[i] == 'B') a[1]++;
    }
    if (a[0] && a[1]) cout << "Yes";
    else cout << "No";
    return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

void solve() {
    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No") << endl;
}

int main() {
	header();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int fac[(1 << 16) + 5],invfac[(1 << 16) + 5],inv[(1 << 16) + 5],N,M;
int A[25],f[(1 << 16) + 5],dp[17][(1 << 16) + 5],cnt[(1 << 16) + 5];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int lowbit(int x) {
    return x & (-x);
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= M ; ++i) read(A[i]);
    inv[1] = 1;
    for(int i = 2 ; i <= (1 << N) ; ++i) inv[i] = mul(inv[MOD % i],MOD - MOD / i);
    fac[0] = invfac[0] = 1;
    for(int i = 1 ; i <= (1 << N) ; ++i) {
    fac[i] = mul(fac[i - 1],i);
    invfac[i] = mul(invfac[i - 1],inv[i]);
    }
    sort(A + 1,A + M + 1);
    dp[0][0] = 1;
    for(int i = 1 ; i <= M ; ++i) {
    int t = M - i + 1;
    for(int S = 0 ; S < (1 << N) ; ++S) {
        for(int j = 0 ; j < N ; ++j) {
        if(!(S >> j & 1)) {
            update(dp[i][S ^ (1 << j)],mul(dp[i - 1][S],mul(C((1 << N) - A[t] - S,(1 << j) - 1),fac[1 << j])));
        }
        }
        update(dp[i][S],dp[i - 1][S]);
    }
    }
    int ans = 0;
    for(int S = 0 ; S < (1 << N) ; ++S) {
    if(S) cnt[S] = cnt[S - lowbit(S)] + 1;
    int t = mul(dp[M][S],fac[(1 << N) - 1 - S]);
    if(cnt[S] & 1) update(ans,MOD - t);
    else update(ans,t);
    }
    ans = mul(ans,1 << N);
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

Measured memory_bytes: 5376
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cou = 0

for ai in range(a+1):
	for bi in range(b+1):
		for ci in range(c+1):
			if (500*ai) + (100*bi) + (50*ci) == x:
				cou = cou + 1
				
print(cou)

Measured memory_bytes: 3060
package main

import "fmt"

func f(n int) int {
	var sum int
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	var ans int
	for i := 1; i <= n; i++ {
		if t := f(i); a <= t && t <= b {
			ans += i
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
number = input().split(" ")
X = int(number[0])
Y = int(number[1])

if Y % 2 == 1:
    print("No")
else:
    if X * 4 >= Y:
        if X * 2 <= Y:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

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

const int N = (int)1e5 + 50;
typedef pair<int, int> P;

int n, m, k;
vector<int> G[N];
int res[N];

int main() {
    cin >> n;
    memset(res, -1, sizeof(res));
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    priority_queue<P, vector<P>, greater<> > pque;
    cin >> k;
    for(int i = 0; i < k; i++) {
        int v, val; cin >> v >> val; v--;
        pque.push({val, v});
        res[v] = val;
    }
    while(!pque.empty()) {
        P p = pque.top(); pque.pop();
        int val = p.first, v = p.second;
        for(int nxt : G[v]) {
            if(res[nxt] != -1) {
                if(abs(res[v] - res[nxt]) != 1) return cout << "No" << endl, 0;
            }
            else {
                res[nxt] = val + 1;
                pque.push({val + 1, nxt});
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }


}

Measured memory_bytes: 7924
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

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

  int a,b,c;
  cin >> a >> b >> c;
  cout << max({a*10+b+c, a+b*10+c, a+b+c*10}) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve(){
    int n; cin >> n;
    ll ans = 0;
    Rep(i, 1, n){
        if(i%3 != 0){
            if(i%5 != 0){
                ans += i;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    long long m1=a*c,m2=a*d,m3=b*c,m4=b*d;
    cout<<max(m1,max(m2,max(m3,m4)));
}

Measured memory_bytes: 3612
#include <cstdio>

using namespace std;

int main()
{
	int H, W;
	int Hs[1024] = {0}, Ws[1024] = {0};
	static int mp[1024][1024];
	
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			int x;
			scanf("%d", &x);
			Hs[i] += x; Ws[j] += x;
			mp[i][j] = x;
		}
	}
	
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++)
			printf("%d%c", 1 - (Hs[i] + Ws[j] + mp[i][j]) % 2, j == W - 1 ? '\n' : ' ');
	
	return (0);
}

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

import math

ans = []

def calc(N):
  ans_q = math.ceil((2*N+1/4)**(1/2)-1/2)
  ans.append(ans_q)
  return N-ans_q

while N != 0:
  N = calc(N)

[print(x) for x in sorted(ans)]

Measured memory_bytes: 9584
a,b,c,d = map(int,input().split())

def mul_count(v,w,n):
  if v % n == 0:
    s = v//n
  else:
    s = v//n + 1
  e = w // n
  if s > e:
    return 0
  else:
    return e - s + 1

def koyaku(x,y):
  big = max(x,y)
  small= min(x,y)
  amari = big % small
  if amari == 0:
    return small
  else:
    return koyaku(small,amari)

c_mul = mul_count(a,b,c)
d_mul = mul_count(a,b,d)

cd_common = koyaku(c,d)
cd_mul = c * d // cd_common
common_mul = mul_count(a,b,cd_mul)
yobun = c_mul + d_mul - common_mul
print(b - a + 1 - yobun)


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

int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<bool>> seen(n+2,vector<bool>(m+2,true));
	vector<pair<int,int>> all = {{1,0},{0,1},{-1,0},{0,-1}};
	char ch[n+2][m+2];
	queue<pair<int,int>> q;
	for(int i = 1 ; i <= n ; i += 1){
		for(int j = 1 ; j <= m ; j += 1){
			char a;
			cin >> a;
			ch[i][j] = a;
			seen[i][j] = false;
			if(a == '#'){
				q.push({i,j});
				seen[i][j] = true;
			}
		}
	}
	int ans = -1;
	while(q.size() > 0){
		ans += 1;
		int t = q.size();
		while(t--){
			pair<int,int> val = q.front();
			q.pop();
			seen[val.first][val.second] = true;
			for(pair<int,int> i : all){
				int v1 = val.first + i.first;
				int v2 = val.second + i.second;
				if(!seen[v1][v2] && ch[v1][v2] == '.'){
					q.push({v1,v2});
					seen[v1][v2] = true;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9616
#include<stdio.h>

int n, s;

int dfs(int now, int manyused, int sum){
	if (manyused == n){
		return sum == s;
	}
	if (now == 10 || sum > s){
		return 0;
	}
	return dfs(now + 1, manyused + 1, sum + now) + dfs(now + 1, manyused, sum);
}

int main(){
	while (~scanf("%d %d", &n, &s) && n){
		printf("%d\n", dfs(0, 0, 0));
	}
	return 0;
}

Measured memory_bytes: 600
//c
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
 
#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair
 
using namespace std;
 
static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;   
 
int m, n;
bool see[1000][1000]={0};
int cntr[1000]={0};
bool vis[1000]={0};
 
int main(){

	cin>>m>>n;
	CLR(see);

	for(int i=0; i<n; ++i){
		int a, b;
		cin>>a>>b;
		see[a][b]=true;
		cntr[b]++;
	}
	
	cntr[2]=m-1;
	
	int cnt=0;

	while(cnt<m-1){

		int dc = 0;

		for(int i=1; i<=m; ++i){
			if(cntr[i]==0&&!vis[i]){
				cout << i << endl;
				vis[i]=true;
				
				for(int j=1; j<=m; ++j){
					if(see[i][j])
						cntr[j]--;
				}
				
				cnt++;
			}
		}
	}
	
	cout << 2 << endl;

	return 0;   
}

Measured memory_bytes: 2148
#include <iostream>
using namespace std;
int main(void){
    int n,m=1;
    int num=1;
    int a[10]={},b[10]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i]%2;
        if(b[i]==0) b[i]=2;
        num*=3;
    }
    for(int i=0;i<n;i++){
        m*=b[i];
    }
    num-=m;
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll p1,p2;
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
ll fun(ll n)
{
    if(n==0)
        return 0;
    ll ans=0;
    for(int a=0;a<2;a++)
    {
        for(int b=0;b<2;b++)
        {
            ll counting =0;
            ll dis=1;
            if(a)
            {
                dis=lcm(p1,dis);
                counting++;
            }
            if(b)
            {
                dis=lcm(p2,dis);
                counting++;
            }
            ll sign = counting%2==1?1:-1;
            if(counting==0)
                continue;
            ans+=sign*n/dis;
        }
    }
    return n-ans;
}
int main()
{
    ll a,b;
    cin>>a>>b>>p1>>p2;
    cout<<fun(b)-fun(a-1)<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#define INF 100000000
#define MAX_C 100
using namespace std;
map<int, int> mp;
int main()
{
	int n;
	string s;
	cin >> n >> s;
	int d[26], e[26];
	int maxn = 0;
	for (int i = 0; i < 26; i++) {
		d[i] = 0;
		e[i] = 0;
	}
	for (int i = 1; i <= (int)s.size() - 1; i++) {
		string v1 = s.substr(0, i);
		string v2 = s.substr(i, s.size() - i);
		for (int j = 0; j < 26; j++) {
			d[j] = 0;
			e[j] = 0;
		}
		for (int j = 0; j < v1.size(); j++) d[v1[j] - 'a']++;
		for (int j = 0; j < v2.size(); j++) e[v2[j] - 'a']++;
		int cnt = 0;
		for (int j = 0; j < 26; j++) {
			if (d[j] >= 1 && e[j] >= 1) cnt++;
		}
		maxn = max(maxn, cnt);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Acrophobia
public class Main{

	int w, h, si, sj, gi, gj, S, G, M, INF = 1<<29, res;
	int[][] adj;
	int[][] dist;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
	boolean[] v;
	void f(int id, int sum){
		if(id==G){
			res = Math.min(res, sum); return;
		}
		if(res<=sum)return;
		boolean f = true;
		for(int i=0;i<M;i++)if(i!=G && !v[i]){
			f = false;
			v[i] = true;
			f(i, sum+adj[id][i]);
			v[i] = false;
		}
		if(f)f(G, sum+adj[id][G]);
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		w = sc.nextInt(); h = sc.nextInt();
		char[][] m = new char[h][w];
		M = 0;
		int[][] cost = new int[h][w];
		int[][] id = new int[h][w];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			cost[i][j]=1;
			id[i][j] = -1;
		}
		for(int i=0;i<h;i++){
			m[i] = sc.next().toCharArray();
			for(int j=0;j<w;j++){
				if(m[i][j]=='S'){
					m[i][j] = '.';
					si = i; sj = j;
					S = M;
					id[i][j] = M++;
				}
				if(m[i][j]=='G'){
					m[i][j] = '.';
					gi = i; gj = j;
					G = M;
					id[i][j] = M++;
				}
				if(m[i][j]=='M'){
					m[i][j] = '.';
					id[i][j] = M++;
				}
				if(m[i][j]=='#'){
					for(int y=i-2;y<=i+2;y++)for(int x=j-2;x<=j+2;x++){
						if(0<=y&&y<h&&0<=x&&x<w)cost[y][x] = Math.max(cost[y][x], 2);
					}
					for(int y=i-1;y<=i+1;y++)for(int x=j-1;x<=j+1;x++){
						if(0<=y&&y<h&&0<=x&&x<w)cost[y][x] = Math.max(cost[y][x], 3);
					}
				}
			}
		}
		adj = new int[M][M];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(id[i][j]!=-1){
			int now = id[i][j];
			dist = new int[h][w];
			for(int[]d:dist)Arrays.fill(d, INF);
			dist[i][j] = 0;
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(h*w, new Comparator<int[]>() {
				public int compare(int[] o1, int[] o2) {
					return dist[o1[0]][o1[1]] - dist[o2[0]][o2[1]];
				}
			});
			q.add(new int[]{i, j});
			while(!q.isEmpty()){
				int[] V = q.poll();
				int pi = V[0], pj = V[1];
				for(int k=0;k<4;k++){
					int ni = pi+d[k][0], nj = pj+d[k][1];
					if(0<=ni&&ni<h&&0<=nj&&nj<w&&m[ni][nj]!='#'){
						int w = dist[pi][pj] + cost[pi][pj];
						if(w < dist[ni][nj]){
							dist[ni][nj] = w; q.add(new int[]{ni, nj});
						}
					}
				}
			}
			for(int y=0;y<h;y++)for(int x=0;x<w;x++)if(id[y][x]!=-1)adj[now][id[y][x]] = dist[y][x];
		}
		res = INF;
		v = new boolean[M];
		v[S] = true;
		f(S, 0);
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 1; i < n; i++){
    int a[26] = {};
    for(int j = 0; j < i; j++)a[s[j]-'a']++;
    int b[26] = {};
    for(int j = i; j < n; j++)b[s[j]-'a']++;
    int tmp = 0; 
    for(int j = 0; j < 26; j++)if(a[j] && b[j]) tmp++;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> g[N];
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000;
}

Measured memory_bytes: 5988
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define REPll(i,m,n) for(ll i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<char>v(26,0),foo;

int main() {
	string s;
	cin >> s;
	REP(i, 0, s.size()) {
		v[s[i] - 'a']++;
	}
	if (s.size() < 26) {
		REP(i, 0, 26) {
			if (v[i] == 0) {
				s.push_back(char(i + 'a'));
				cout << s << endl;
				return 0;
			}
		}
	}
	else {
		REP(i, 0, 25) {
			foo.push_back(s[25 - i]);
			if (s[25 - i] > s[24 - i]) {
				char vane = s[24 - i];
				s.resize(24 - i);
				while (1) {
					vane++;
					REP(j, 0, foo.size()) {
						if (vane == foo[j]) {
							s.push_back(foo[j]);
							cout << s << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = Integer.parseInt(sc.next());
        }

        int res = 0;

        for (int i = 1; i < n - 1; i++) {
            if (p[i - 1] < p[i] && p[i] < p[i + 1]) {
                res++;
            } else if (p[i + 1] < p[i] && p[i] < p[i - 1]) {
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 21716
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string n;
    cin >> n;
    int res1 = 0;
    int res2 = 0;
    REP(i, n.size()) {
        res1 += (n[i] - 48);
        if (i == 0) {
            res2 += (n[i] - 48) - 1;
        } else {
            res2 += 9;
        }
    }
    cout << max(res1, res2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

struct edge {
    int to, cost;
};
vector<edge> G[100050];
int ans[100050];

void dfs(int v, int p, int color){
    ans[v] = color;
    for(auto e : G[v]) {
        if(e.to == p) continue;
        if(e.cost % 2) dfs(e.to, v, 1-color);
        else dfs(e.to, v, color);
    }
}

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

rep(i,N-1) {
    int u,v,w;
    cin >> u >> v >> w;
    u--;v--;
    G[u].pb({v, w});
    G[v].pb({u, w});
}
dfs(0,-1,0);
rep(i,N) cout << ans[i] << endl;

return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define fi first
#define se second

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    double x;
    cin>>x;
    double r=1.01;
    int c=0;
    ll num=100;
    while(num<x){
        c+=1;
        num=num*r;
    }
    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
const int MOD = 1e9 + 7;

ll dp[100005][2];
vi g[100005];
//0 if the edge is black and 1 if it is white

void dfs(int c, int p){
	dp[c][0] = dp[c][1] = 1;
	for(int u : g[c]) if(u != p){
		dfs(u, c);
		//if it is white, the next one could be either color
		//if it is black, the next one could only be white
		dp[c][0] = (dp[c][0] * dp[u][1]) % MOD;
		dp[c][1] = (dp[c][1] * (dp[u][0] + dp[u][1])) % MOD;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0, -1);
	cout << (dp[0][0] + dp[0][1]) % MOD << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ld long double
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i, j, k, l, n, m;
    cin >> n >> k;
    ll data[n + 1];
    long double res[n + 1];
    long double comp[n + 1];
    for (i = 1; i <= n;i++)
        cin >> data[i];
    res[0] = 0.0000000;
    for (i = 1; i <= n;i++){
        res[i] = (res[i - 1] + (ld)log10((ld)data[i]));
    }
    for (i = k; i <= n;i++){
        comp[i] = res[i] - res[i - k];
    }
    for (i = k; i < n;i++){
        if(comp[i]<comp[i+1])
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 11520
n=int(raw_input())
p=[0,0]
for i in range(n):
        c=[0 for i in range(100)]
        c=map(list,raw_input().split())
        m=0
        while 1:
                try:
                        if c[0]==c[1]:
                                p[0]+=1
                                p[1]+=1
                                break
                        elif c[0][m]<c[1][m]:
                                p[1]+=3
                                break
                        elif c[1][m]<c[0][m]:
                                p[0]+=3
                                break
                        m+=1
                except IndexError:
                        if len(c[0])<len(c[1]):
                                p[1]+=3
                                break
                        if len(c[1])<len(c[0]):
                                p[0]+=3
                                break
print p[0], p[1]

Measured memory_bytes: 4272
H,W=map(int,input().split())
a=[input() for _ in range(H)]
answers1=[]
for h in range(H):
    a1=a[h]
    if '#' in a1:
        answers1.append(a1)
answers2=['' for _ in range(len(answers1[0]))]
for answer in answers1:
    for n in range(len(answer)):
        answers2[n]+=answer[n]
answers=[]
for answer in answers2:
    if '#' in answer:
        answers.append(answer)
for x in range(len(answers[0])):
    kotae=''
    for y in range(len(answers)):
        kotae+=answers[y][x]
    print(kotae)
    

Measured memory_bytes: 67404
// g++ -std=c++14

//Difficulty according to solve count during contest:
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W

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

#define int long long
const int mod = 1e9 + 7;

int n;
vector<int> a;
vector<vector<int> > dp;

int func(int l, int r){
  if(dp[l][r] != -1)
    return dp[l][r];
  if(l == r)
    return 0;
  dp[l][r] = 1e18;
  int tot = 0;
  for(int i = l; i <= r; i++)
    tot += a[i];
  for(int i = l; i < r; i++){
      dp[l][r] = min(dp[l][r], func(l, i) + func(i + 1, r) + tot);
  }
  return dp[l][r];
}

int32_t main(){
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; i++)
    cin >> a[i];
  dp.resize(n, vector<int> (n, -1));
  int ans = func(0, n - 1);
  cout << ans << endl;
}


Measured memory_bytes: 4916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	long mod = 1_000_000_007;

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int n = fs.nextInt();
		long[] aArr = fs.nextLongArr(n);
		
		long[] sumArr = new long[n];
		sumArr[n-1] = aArr[n-1];
		for(int i=n-2; i>= 0; i--) {
			sumArr[i] = (sumArr[i+1] + aArr[i])%mod;
		}
		
		long sum = 0;
		
		for(int i = 0; i < n-1; i++) {
			sum = (sum + (aArr[i] * sumArr[i+1]))%mod;
		}
		
		System.out.println(sum);
		
		
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 55908
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pr pair<int,int>
vector<pr> vec[200001],_left,_right;
int mid;
vector<pr> dfs(int id,int from){
    //cout<<id<<" "<<from<<endl;
    vector<pr> lc,rc,now;
    int cl=-1,cr;
    if(vec[id].size()==1&&from){
        now.push_back(make_pair(0,0));
        return now;
    }
    for(int i=0;i<vec[id].size();i++){
        pr l=vec[id][i];
        if(l.first==from) continue;
        vector<pr> t=dfs(l.first,id);//返回的(a,b)的a递增，因而b递减
        if(cl<0) lc=t,cl=l.second;
        else rc=t,cr=l.second;
    }
    int j=0;
    for(int i=0;i<lc.size();i++){//选取起点在左子树，满足条件的、最优的(a,b)，新的(a,b)=(lc[i].first,rc[i].second)
        while(j+1<rc.size() && lc[i].second+rc[j+1].first+cl+cr<=mid) j++;//寻找rc中满足条件的b最小的(a,b)。因为a相同时只取最小的b
        if(rc.size()&&lc[i].second+rc[j].first+cl+cr<=mid) _left.push_back(make_pair(lc[i].first+cl,rc[j].second+cr));//前面的(a,b)肯定会比当前的要差，因此不用查找rc[1~j-1]
    }
    j=0;
    for(int i=0;i<rc.size();i++){//选取起点在右子树，满足条件的、最优的(a,b)，新的(a,b)=(rc[i].first,lc[i].second)
        while(j+1<lc.size() && rc[i].second+lc[j+1].first+cl+cr<=mid) j++;
        if(lc.size()&&rc[i].second+lc[j].first+cl+cr<=mid) _right.push_back(make_pair(rc[i].first+cr,lc[j].second+cl));
    }
    //此时的_left和_right一定是有序的，现在要合成一个a递增，递减的数组
    int l=0,r=0,last=0x7FFFFFFFFFFFFFFF;
    while(l<_left.size()||r<_right.size()){//类似归并排序的思想
        if(l<_left.size()&&(r>=_right.size()||_left[l]<=_right[r])){
            if(_left[l].second<last){//为了保证now里都是最优，b要递减
                last=_left[l].second;
                now.push_back(_left[l]);
            }
            l++;
        }
        else{
            if(_right[r].second<last){
                last=_right[r].second;
                now.push_back(_right[r]);
            }
            r++;
        }
    }
    _left.clear(),_right.clear();
    return now;
}
signed main(){
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        int a,v;
        scanf("%lld%lld",&a,&v);
        vec[a].push_back(make_pair(i,v));
        vec[i].push_back(make_pair(a,v));
    }
    int l=0,r=17179869184;
    while(r-l>1){
        mid=(l+r)/2;
        //cout<<l<<" "<<mid<<" "<<r<<endl;
        if(!dfs(1,0).empty()) r=mid;
        else l=mid;
    }
    mid=l;
    if(!dfs(1,0).empty()) cout<<l;
    else cout<<r;
}

Measured memory_bytes: 26368
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,d,x,y,r=0;
    cin>>n>>d;
    while(n--)
    {
        cin>>x>>y;
        r+=(x*x + y*y) <= d*d;
    }
    cout<<r;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
int fa[maxn],n,deg[maxn];
int vis[maxn],a[maxn],cnt[maxn];
queue<int> que;
vector<int> g[maxn];
bool check(int st,int ed)
{
	for(int x=fa[st];x!=ed;x=fa[x])
	{
		for(int i=0;i<g[x].size();i++)
		{
			cnt[a[g[x][i]]]++;
		}
		a[x]=0;
		while(cnt[a[x]])a[x]++;
		for(int i=0;i<g[x].size();i++)
		{
			cnt[a[g[x][i]]]--;
		}
	}
	
	for(int i=0;i<g[ed].size();i++)
	{
		cnt[a[g[ed][i]]]++;
	}
	bool ok=1;
	if(cnt[a[ed]])ok=0;
	for(int i=0;i<g[ed].size();i++)
	{
		cnt[a[g[ed][i]]]--;
	}
	return ok;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&fa[i]);
		deg[fa[i]]++;
		g[fa[i]].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		if(!deg[i])
		{
			que.push(i);
			vis[i]=1;
			a[i]=0;
		}
	}
	while(!que.empty())
	{
		int x=que.front();
		que.pop();
		deg[fa[x]]--;
		if(!deg[fa[x]])
		{
			que.push(fa[x]);
			vis[fa[x]]=1;
			for(int i=0;i<g[fa[x]].size();i++)
			{
				cnt[a[g[fa[x]][i]]]++;
			}
			a[fa[x]]=0;
			while(cnt[a[fa[x]]])a[fa[x]]++;
			for(int i=0;i<g[fa[x]].size();i++)
			{
				cnt[a[g[fa[x]][i]]]--;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
	//	cout<<i<<endl;
		int son;
		for(int j=0;j<g[i].size();j++)
		{
			if(!vis[g[i][j]])
			{
				son=g[i][j];
				continue;
			}
			cnt[a[g[i][j]]]++;
		}
		a[i]=0;
		while(cnt[a[i]])a[i]++;
		int rec=a[i],tmp=a[i]+1;
		while(cnt[tmp])tmp++;
		for(int j=0;j<g[i].size();j++)
		{
			if(!vis[g[i][j]])
			{
				continue;
			}
			cnt[a[g[i][j]]]--;
		}
		
		vis[i]=1;
		if(check(i,i))
		{
		//	cout<<"1\n";
			printf("POSSIBLE\n");
			return 0;
		}
		
		vis[son]=1;
		a[son]=a[i];
		a[i]=tmp;
		if(check(i,son))
		{
		//	cout<<"2\n";
			for(int x=i;x!=son;x=fa[x])
			{
		//		cout<<x<<' '<<a[x]<<endl;
			}
			printf("POSSIBLE\n");
			return 0;
		}
		printf("IMPOSSIBLE\n");
		return 0;
	}
}

Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
int main()
{
 unsigned long long sum = 0;
  int i=0;
  int s;
 cin>>s;
 while(++i<=s){
      if(!(i%3==0 || i%5==0))sum+=i;
    }
 cout<<sum<<endl;
 return 0;
}


Measured memory_bytes: 3636
import sys
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
input = sys.stdin.readline
n = int(input())
xy = [list(map(int,input().split()))+[i] for i in range(n)]
evv = set()
for Key in range(2):
  xy_s = sorted(xy,key = lambda x:x[Key])
  for i in range(1,n):
    evv.add((xy_s[i][2],xy_s[i-1][2],min(abs(xy_s[i-1][0]-xy_s[i][0]),abs(xy_s[i-1][1]-xy_s[i][1]))))
v1,v2,edge = zip(*evv)
csr = csr_matrix((edge,(v1,v2)),shape = (n,n))
mst = minimum_spanning_tree(csr)
print(int(mst.sum()))

Measured memory_bytes: 86016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
    ll n,k,ma=0;
    cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        ma=max(ma,a[i]);
    }
    if(ma<k)cout<<"IMPOSSIBLE"<<endl;
    else{
        ll g=a[0];
        for(ll i=1;i<n;i++)g=gcd(g,a[i]);
        if(g==1){
            cout<<"POSSIBLE"<<endl;
        }
        else{
            if(k%g==0)cout<<"POSSIBLE"<<endl;
            else cout<<"IMPOSSIBLE"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,sum;
    long long int i,p=0,y=0;
    double x=0;
    cin>>a>>b;
    sum=a+b;
    for(i=0; i<sum.size(); i++)
    {
        p=p*10+sum[i]-'0';
    }
    //cout<<p<<endl;
    x=sqrt(p);
    y=sqrt(p);
    if(x==y)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }



}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.Array.IArray

adjacencyList :: (Ix a) => a -> a -> [(a,a)] -> Array a [a]
adjacencyList bgn end = accumArray (flip (:)) [] (bgn,end)

solve :: Array Int [Int] -> Int -> Bool
solve g n = elem n p2
  where
    p1 = g!1
    p2 = concat [ g!p | p <- p1 ]

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    ab <- map ((\[a,b] -> (a,b)) . map (fst . fromJust . BS.readInt) . BS.words)
        . BS.lines <$> BS.getContents :: IO [(Int,Int)]
    let g = adjacencyList 1 (max n m) ab
    putStrLn $ if solve g n then "POSSIBLE" else "IMPOSSIBLE"

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    double cnt=0,cnt2=1e9;
    rep(i,n){
        cin>>a[i];
        cnt+=a[i];
    }
    cnt/=n;
    int ans=-1;
    rep(i,n){
        double x=abs(cnt-a[i]);
        if(cnt2>x){
            cnt2=x;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-


# input
a = list(raw_input())
b = list(raw_input())
c = list(raw_input())

user = 'a'
while(True):
    if user == 'a':
        if len(a) == 0:
            print 'A'
            break
        user = a.pop(0)

    if user == 'b':
        if len(b) == 0:
            print 'B'
            break
        user = b.pop(0)

    if user == 'c':
        if len(c) == 0:
            print 'C'
            break
        user = c.pop(0)


Measured memory_bytes: 2568
//                     بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
//                   لآ اِلَهَ اِلّا اللّهُ مُحَمَّدٌ رَسُوُل اللّهِ
#include <bits/stdc++.h>

using namespace std;
#define endl "\n"

const int MOD = 1000000007;
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	int a;
	cin >> a;
	
	int ara[a];
	for(int i  = 0 ;i < a; i++) cin >> ara[i];
	sort(ara,ara+a);
	cout << ara[a-1]- ara[0] << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3576
import java.util.*;

public class Main {
	private static final int MAX = 100000;

	public static void main(String[] args) {
		boolean[] notPrime = new boolean[MAX + 1];
		int[] like = new int[MAX + 1];

		notPrime[0] = true;
		notPrime[1] = true;
		for (int num = 2; num <= MAX; num++) {
			if (notPrime[num]) {
				like[num] = like[num - 1];
			}
			else {
				for (int i = (num * 2); i <= MAX; i += num) {
					notPrime[i] = true;
				}

				if (notPrime[(num + 1) / 2]) {
					like[num] = like[num - 1];
				}
				else {
					like[num] = like[num - 1] + 1;
				}
			}
		}

		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int inQ = stdin.nextInt();

		for (int i = 0; i < inQ; i++) {
			int inL = stdin.nextInt();
			int inR = stdin.nextInt();

			System.out.println(like[inR] - like[inL - 1]);
		}
	}
}


Measured memory_bytes: 64936
#include <iostream>
#include <cstdio>
            
int main() {
    int a, b = 0;
    char op;
    bool end = false;
            
    while(!end) {
        std::cin >> a >> op >> b;
        switch(op) {
            case '+':
                std::cout << a + b << std::endl;
                break;
            case '-':
                std::cout << a - b << std::endl;
                break;
            case '*':
                std::cout << a * b << std::endl;
                break;
            case '/':
                std::cout << a / b << std::endl;
                break;
            case '?':
                end = true;
                break;
        }   
    }       
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
const int N=300005;
int n,a[N];
bool b[N];
inline void O(){cout<<"No\n";exit(0);}
inline void solve(int l,int r){
	if(l==r){if(a[l]!=l)O();return;}
	int i,mi=1<<30,ma=0,x,y;
	for(i=r;i>=l;i--)mi=min(mi,a[i]),ma=max(ma,a[i]);x=y=0;
	for(i=l;i<=r;i+=2)
		if(a[i]<i){if(x>a[i])O();x=a[i];}
			else{if(y>a[i])O();y=a[i];}
	if(mi!=l || ma!=r)O();
}
int main(){
	int i,j=0,x;
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(i=1;i<=n;++i)cin>>a[i],b[i]=a[i]==i;
	for(i=1;i<=n;i=j)if(!b[i]){
		x=0,j=i;
		for(;j<=n && b[j]==x;x^=1,++j);
		solve(i,j-1);
	}else j=i+1;
	cout<<"Yes\n";
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;

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

	int m;
	for(m=0;(1<<m)<=n;m++);
	cout<<(1<<(m-1))<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, b[114514];
signed main() {
	cin >> n;
	map<int, int>mp;
	rep(i, n) {
		cin >> b[i];
		mp[b[i]]++;
	}
	sort(b, b + n);
	if (b[n - 1] != 0 && n % 3) {
		cout << "No" << endl; return 0;
	}
	if (b[n - 1] == 0) {
		cout << "Yes" << endl; return 0;
	}
	int a[3];
	for (auto p : mp) {
		if (p.second % (n / 3)) {
			cout << "No" << endl; return 0;
		}
	}
	rep(i, 3) {
		a[i] = b[i * (n / 3)];
	}
	if ((a[0] ^ a[1] ^ a[2]) == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int n;
int heights[100005];
int dp[100005];

int32_t main(){
    cin >> n;
    loop(n) cin >> heights[i+1];
    dp[n] = 0;
    dp[n-1] = abs(heights[n] - heights[n-1]);
    for(int i = n-2; i > 0; i--){
        dp[i] = min(
            dp[i+1] + abs(heights[i] - heights[i+1]), 
            dp[i+2] + abs(heights[i] - heights[i+2])
        );
    }

    
    cout << dp[1] << endl;
}

Measured memory_bytes: 5172