akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
//#include <vector>
//#include <functional>
template<typename Abel>
struct WeightedUnionFind {
    using OP = function<Abel(Abel, Abel)>;

    vector<int> parent;
    vector<Abel> diff_weight; // distance from root
    const OP add;
    const OP sub;
    const Abel e;
    
    WeightedUnionFind(int nmemb,
                      const Abel &e = 0,
                      const OP &add = [](Abel x, Abel y){return x+y;},
                      const OP &sub = [](Abel x, Abel y){return x-y;}):
        e(e), add(add), sub(sub)
    {
        parent.assign(nmemb, -1);
        diff_weight.assign(nmemb, e);
    };

    int root(int x) {
        if (parent[x] < 0) {
            return x;
        }
        
        int p = root(parent[x]);
        diff_weight[x] = add(diff_weight[x], diff_weight[parent[x]]);
        parent[x] = p;

        return p;
    };

    bool unite(int x, int y, Abel w) {
        Abel wx = weight(x);
        Abel wy = weight(y);
        x = root(x);
        y = root(y);

        if (x == y) return false;
        w = sub(add(w, wx), wy);
        if (size(x) < size(y)) swap(x, y), w = -w;

        parent[x] += parent[y];
        parent[y] = x;
        diff_weight[y] = w;
        
        return true;
    };
    
    bool same(int x, int y) {
        return root(x) == root(y);
    };
    
    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    };

    Abel diff(int x, int y) {
        return sub(weight(y), weight(x));
    };

    int size(int x) {
        return -parent[root(x)];
    };
};
//===

WeightedUnionFind<llong> uf(100005);
llong n, m;
llong l, r, d;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> d;

        if (uf.same(l, r)) {
            if (uf.diff(l, r) != d) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            uf.unite(l, r, d);
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
const int MAX = 1000000;
int main(){
  int prime[MAX] = { 0 };
  int a, d, n;
  for ( int i = 0; i < MAX; i++ ) prime[i] = 1;
  prime[0] = 0;
  prime[1] = 0;
  for ( int i = 2; i < MAX; i++ ){
    if ( prime[i] ){
      for ( int j = i * 2; j < MAX; j += i ){
	prime[j] = 0;
      }
    }
  }
  while ( 1 ){
    cin >> a >> d >> n;
    if ( a == 0 && d == 0 && n == 0 ) break;
    int i;
    for( i = a; n > 0; i += d ){
      if ( prime[i] ){
	n--;
      }
    }
    cout << i - d << endl;
  }
  return 0;
}

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

int main(){
    long long n,d,a;
    cin >> n >> d >> a;
    vector<pair<long long,long long>> xh;
    for(int i=0; i<n; i++){
        long long x,h;
        cin >> x >> h;
        xh.push_back(make_pair(x,h));
    }
    sort(xh.begin(),xh.end());
    vector<pair<long long,long long>> v;
    long long sub = 0;
    long long ans = 0;
    for(int i=0; i<n; i++){
        pair<long long,long long> p = xh[i];
        while(!v.empty()){
            if(v[0].first < xh[i].first){
                sub -= v[0].second;
                v.erase(v.begin());
            }
            else break;
        }
        p.second -= sub;
        if(p.second > 0){
            long long plus = 0;
            if(p.second % a) plus = a*(p.second/a + 1);
            else plus = p.second;
            v.push_back(make_pair(p.first+2*d,plus));
            sub += plus;
            ans += plus/a;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7020
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,ans=999999999;
	cin>>n>>k;
	int f[n];
	for(int i=0;i<n;i++) cin>>f[i];
	sort(f,f+n);
	for(int i=0;i<n-k+1;i++)
	ans=min(f[i+k-1]-f[i],ans);
	cout<<ans;
}

Measured memory_bytes: 640
n = int(input())
a=[0]*n
b=list(map(int,input().split()))
a[n-1]=b[n-2]
for i in reversed(range(n-1)):
    if i!=0:
        if b[i]>=b[i-1]:
            a[i]=b[i-1]
        else:
            a[i]=b[i]
    else:
        a[i]=b[i]
        
ans=sum(a)
print(ans)


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

int main() {
 vector<int>v(9);
 vector<int>b(11);
 for(int i = 0; i<9; i++){
   cin >> v.at(i);
 }
 for(int i = 0; i<11; i++){
   cin >> b.at(i);
 }
 for(int i = 0; i<9; i++){
   auto aa = find(b.begin(),b.end(),v.at(i));
   if(aa != b.end()) v.at(i) = 'A';
 }
 int ans = 0;
 if(v.at(0)=='A'&&v.at(1)=='A'&&v.at(2)=='A') ans++; 
 else if(v.at(3)=='A'&&v.at(4)=='A'&&v.at(5)=='A') ans++;
 else if(v.at(6)=='A'&&v.at(7)=='A'&&v.at(8)=='A') ans++;
 else if(v.at(0)=='A'&&v.at(3)=='A'&&v.at(6)=='A') ans++;
 else if(v.at(1)=='A'&&v.at(4)=='A'&&v.at(7)=='A') ans++;
 else if(v.at(2)=='A'&&v.at(5)=='A'&&v.at(8)=='A') ans++;
 else if(v.at(0)=='A'&&v.at(4)=='A'&&v.at(8)=='A') ans++;
 else if(v.at(2)=='A'&&v.at(4)=='A'&&v.at(6)=='A') ans++;
  
 if(ans>0) cout << "Yes" << endl;
 else cout << "No" << endl;
  
  return 0;
}







Measured memory_bytes: 256
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(len(a)):
  c += [i + 1] * a[i]
for i in range(h):
  if i % 2 == 0:
    print(*c[i*w:(i+1)*w])
  else:
    print(*c[(i+1)*w-1:i*w-1:-1])


Measured memory_bytes: 3828
import java.util.Scanner;

public class Main
{
    public static void main (String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int product = a * b;

        boolean even = product % 2 == 0;

        String out = even ? "Even" : "Odd";

        System.out.print(out);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int D;
    cin>>D;
    string ara[4];
    ara[3]="Christmas";
    ara[2]="Christmas Eve";
    ara[1]="Christmas Eve Eve";
    ara[0]="Christmas Eve Eve Eve";

    cout<<ara[D-22]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

const int N = 1e3 + 5 , M = 15 , mod = 1e9 + 7;
using namespace std;

char C[N][N];
queue <pair <pair <int , int> , int> > Q;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n , m , ans = 0; cin >> n >> m;
    for (int i=1; i<=n; i++) for (int j=1; j<=m; j++){
        cin >> C[i][j];
        if (C[i][j] == '#')
        Q.push({{i , j} , 0});
    }

    while (Q.size()){
        int x = Q.front().F.F , y = Q.front().F.S , step = Q.front().S;
        Q.pop();
        if (C[x-1][y] == '.'){
            C[x-1][y] = '#';
            Q.push({{x-1 , y} , step + 1});
            ans = step + 1;
        }
        if (C[x+1][y] == '.'){
            C[x+1][y] = '#';
            Q.push({{x+1 , y} , step + 1});
            ans = step + 1;
        }
        if (C[x][y-1] == '.'){
            C[x][y-1] = '#';
            Q.push({{x , y-1} , step + 1});
            ans = step + 1;
        }
        if (C[x][y+1] == '.'){
            C[x][y+1] = '#';
            Q.push({{x , y+1} , step + 1});
            ans = step + 1;
        }
    }

    cout << ans;
}


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

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

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

Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int n; cin >> n;
    vector<long long> ads(n);
    long long sum=0;
    for(int i=0; i<n; ++i){
        long long a; cin >> a;
        ads[i]=a+sum;
        sum+=a;
    }

    long long ans1=0;
    long long sum1=0;
    for(int i=0; i<n; ++i){
        if(i%2==0){
            if(ads[i]+sum1<=0){
                ans1+=abs(1-ads[i]-sum1);
                sum1=1-ads[i];
            }
        } else{
            if(ads[i]+sum1>=0){
                ans1+=abs(-1-ads[i]-sum1);
                sum1=-1-ads[i];
            }
        }
    }

    long long ans2=0;
    long long sum2=0;
    for(int i=0; i<n; ++i){
        if(i%2==1){
            if(ads[i]+sum2<=0){
                ans2+=abs(1-ads[i]-sum2);
                sum2=1-ads[i];
            }
        } else{
            if(ads[i]+sum2>=0){
                ans2+=abs(-1-ads[i]-sum2);
                sum2=-1-ads[i];
            }
        }
    }

    cout << min(ans1, ans2) << endl;
    return 0;
}


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

using namespace std;

#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)
#define ll long long int

void solve()
{
    int n;
    cin>>n;
    int p[n];
    int q[n];
    int temp[n];
    for(int i=1;i<=n;i++)
    {
        temp[i-1]=i;
    }
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>q[i];
    }
    int i1=-1;
    int i2=-1;
    int c=0;
    do{
        c++;
        if(i1!=-1&&i2!=-1)
        break;
        else{
        int k=0;
        for(int i=0;i<n;i++)
        {
            if(temp[i]!=p[i])
            {
                k=1;
                break;
            }
        }
        if(k==0)
        i1=c;
        int flag=0;
        for(int i=0;i<n;i++)
        {
            if(temp[i]!=q[i])
            {
                flag=1;
                break;
            }
        }
        if(!flag)
        i2=c;
        }
    }while(next_permutation(temp,temp+n));
    cout<<abs(i1-i2);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    str s;
    cin >> s;
    REP(i, s.length()) {
        cout << "x"s;
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = map(int, input().split())

    boss = defaultdict(int)
    for i, n in enumerate(A, start=2):
        boss[n] += 1
    for i in range(1, N + 1):
        print(boss[i])


main()


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

int main() {
    int N; cin >> N;
    int X[100010];
    for(int i=0; i<N; ++i) cin >> X[i];
    sort(X, X+N, greater<int>());
    int P=1;
    while(X[P]*2>X[0] && P<N) ++P;
    if(P==N) cout << X[0] << " " << X[N-1] << endl;
    else if(X[P]>=X[0]-X[P-1]) cout << X[0] << " " << X[P] << endl;
    else cout << X[0] << " " << X[P-1] << endl;
	return 0;
}


Measured memory_bytes: 640
// AOJ Volume 0 Problem 0057

#include <stdio.h>

#define GET_FLG(n)  (flg_prime[((n) / 2) - 1])
#define SET_FLG(n)  (flg_prime[((n) / 2) - 1] = 1)

char flg_prime[50000];

int main(void)
{
    int n;
    int i;
    int div;

	while (scanf("%d", &n) != EOF){
		div = 2;
		for (i = 2; i <= n; i++){
			div += i;
		}
		printf("%d\n", div);
	}
    
    return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string s;
	cin >> s;
	int i = 0, j = s.length() - 1;

	int cnt = 0;
	while(i < j){
		if(s[i] == 'x' && s[j] != 'x'){
			cnt++;
			i++;
		}else if(s[i] != 'x' && s[j] == 'x'){
			cnt++;
			j--;
		}
		else if(s[i] != s[j]){
			printf("-1\n");
			return 0;
		}
		else if(s[i] == s[j]){
			i++;
			j--;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 512
// TP1_5_C:   Print a Chessboard
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 0; h < H; h++) {
			for (w = 0; w < W; w++) {
				putchar(((h & 1) ^ (w & 1)) == 0 ? '#' : '.');		}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n,m,q;
	cin>>n;
	int a[100001]={0};
	long long int z=0;
	for(int i=0;i<n;i++)
    {
        cin>>m;
        a[m]++;
        z+=m;
    }
    cin>>q;
    while(q--)
    {
        cin>>n>>m;
        z+=a[n]*(m-n);
        a[m]+=a[n];
        a[n]=0;
        cout<<z<<endl;
    }
	return 0;
}


Measured memory_bytes: 4032
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e7 + 5, LG = 19, MOD = 998244353;
const int SQ =225;
const long double EPS = 1e-6;
vector<int> ord;
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  string s;
  cin >> s;
  
  cout << s.substr(0,3) << endl;

  return 0;
}


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


int main()
{
    int n,x,y;
    cin >> n;
    cin >> x >> y;
    
    vector<int> dist_count(n,0);
    Graf dist(n+1,vector<int>(n+1));
    vector<bool> found(n+1,false);
    queue<P> q;
    int count=0;
    FOR(i,n+1,1){
        FOR(j,n+1,1){
            found[j]=false;
        }
        
        q.push(mp(i,0));
        
        while(!q.empty()){
            P p=q.front();
            int now=p.first;
            int val=p.second;
            q.pop();
            if(found[now]!=true){
                found[now]=true;
                dist[i][now]=val;
                dist[now][i]=val;
                
                if(now-1>0){
                    if(found[now-1]==false)
                        q.push(mp(now-1,val+1));
                }
                if(now+1<=n){
                    if(found[now+1]==false)
                        q.push(mp(now+1,val+1));
                }
                if(now==x){
                    if(found[y]==false)
                        q.push(mp(y,val+1));
                }
                if(now==y){
                    if(found[x]==false)
                        q.push(mp(x,val+1));
                }
            }
        }
    }
    FOR(i,n,1){
        for(int j=i+1;j<n+1;++j){
            dist_count[dist[i][j]]++;
        }
    }
    rep(i,n-1){
        cout << dist_count[i+1] << endl;
    }
}

Measured memory_bytes: 19036
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<functional>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<set>
#include<map>

#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 2e9
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
const double PI = acos(-1);

using namespace std;

int main(void) {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//	freopen("input.txt", "r", stdin);

	string S, T; cin >> S >> T;
	int ans = 5000;
	for (int i = 0; i < S.size(); i++) {
		int t = 0;
		if (i + T.size() > S.size()) break;
		for (int j = 0; j < T.size(); j++) {
			if (S[i+j] != T[j]) t++;
		}
		ans = min(ans, t);
	}
	cout << ans;
}


Measured memory_bytes: 3640
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
L = [0]*(N+1)
for a in A:
  L[a]=-1
L[0] = 1
L[1] += 1
for i in range(2, N+1):
  if L[i]==-1:
    L[i]=0
  else:
    L[i] = L[i-1]+ L[i-2]
print(L[-1]%(10**9+7))

Measured memory_bytes: 465776
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let n = read::<usize>();
    let mut a = vec![0; n];
    let mut b = vec![0; n];
    let mut c = vec![0; n];
    for i in 0..n {
        a[i] = read::<i64>();
        b[i] = read::<i64>();
        c[i] = read::<i64>();
    }

    let mut dp = vec![vec![-1; n+2]; 3];
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];

    for i in 1..n {
        let m = max(dp[1][i-1], dp[2][i-1]) + a[i];
        dp[0][i] = max(m, dp[0][i]);
        let m = max(dp[0][i-1], dp[2][i-1]) + b[i];
        dp[1][i] = max(m, dp[1][i]);
        let m = max(dp[1][i-1], dp[0][i-1]) + c[i];
        dp[2][i] = max(m, dp[2][i]);
    }

    println!("{}", max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])))
}

Measured memory_bytes: 10492
n = int(input())
a = list(map(int, input().split()))
ans = 0
"""
ai + i = j - aj
"""
cnt = [0] * (n + 1)
for i in range(n):
    if 0 <= a[i] + i < n+1:
        cnt[a[i] + i] += 1

for i in range(n):
    if i - a[i] >= 0:
        ans += cnt[i - a[i]]

print(ans)

Measured memory_bytes: 32380
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<list>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void anser(list<ll>& p){
  cout << p.size()<<endl;
  for(auto i:p){
    cout << i+1<<" ";
  }
  cout << endl;
}
signed main(){
  ll n,m;
  cin >> n >> m;
  ll a[m],b[m];
  bool used[n];
  fill(used,used+n,false);
  list<ll> path;
  vector<ll> G[n];
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  path.push_back(a[0]);
  path.push_back(b[0]);
  bool end=true;
  used[a[0]]=used[b[0]]=true;
  while(end){
    end = false;
    ll v = path.back();
    for(auto np:G[v]){
      if(!used[np]){
        end = true;
        used[np]=true;
        path.push_back(np);
        break;
      }
    }

    v = path.front();
    for(auto np:G[v]){
      if(!used[np]){
        end = true;
        used[np]=true;
        path.push_front(np);
        break;
      }
    }
  }
  anser(path);
}


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

int main(void){

    int n;
    double a, sum = 0;
    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> a;
        sum += 1.0/a;
    }

    cout << 1.0/sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1009];
bool p[40009];
int x[40009],lx;
long long ans;
bool cmp(int x,int y){return x<y;}
void pd(int x){
    if(x==1) return;
    long long sum=0;
    for(int j=1;j<=n;j++)
        if(a[j]%x==0) sum+=a[j];
    ans=max(ans,sum);
}
int main(){
    scanf("%d",&n);
    for(int j=1;j<=n;j++)
        scanf("%d",&a[j]);
    sort(a+1,a+n+1,cmp);
    for(int j=2;j*j<=a[n];j++){
        if(p[j]==0){
            x[++lx]=j;
            pd(j);
        }
        for(int i=1;i<=lx;i++){
            if(j*x[i]>40000) continue;
            p[j*x[i]]=1;
            if(j%x[i]==0) break;
        }
    }
    for(int j=1;j<=n;j++)
        pd(a[j]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3332
#include <stdio.h>
int main(void)
{
    char c[10];

    scanf("%s", c);

    if(c[0]=='a' || c[0]=='i' || c[0]=='u' || c[0]=='e' || c[0]=='o')
        printf("vowel\n");
    else
        printf("consonant\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int INF2 = 1e15;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int L,R,D;
    cin >> L >> R >> D;
    cout << R/D-(L-1)/D << endl;
}


Measured memory_bytes: 3616
#include <iostream>

using namespace std;

int main() {
  int n;
  long long ans;
  long long a, b;

  cin >> n;
  ans = 0;
  cin >> b;

  if (b != 0) {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 0; i < n-1; i++) {
    cin >> a;
    if (a-b > 1) {
      cout << -1 << endl;
      return 0;
    } else {
      if (a-b == 1)
        ans ++;
      else
        ans += a;
    }

    b = a;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#include <iostream> 
using namespace __gnu_pbds; 
using namespace std;
#define int unsigned long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 9000000000000000000
#define imin -1000000000000000000
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
 
int modinverse(int a)
{
    return power(a,mod-2);
}
map<int,int>m;
int a,b,c,d,n;
int recurse(int x)
{
    if(x==0)
    {
        return 0;
    }
    if(x==1)
    {
        return d;
    }
    if(m.find(x)!=m.end())
    {
        return m[x];
    }
    int res=x*d;

    res=min(res,recurse(x/5)+c+d*(x%5));
    res=min(res,recurse(x/5+1)+c+d*(5-x%5));

    res=min(res,recurse(x/3)+b+d*(x%3));
    res=min(res,recurse(x/3+1)+b+d*(3-x%3));

    res=min(res,recurse(x/2)+a+d*(x%2));
    if(x!=2)
    res=min(res,recurse(x/2+1)+a+d*(2-x%2));

    // m[x]=min(d*x,imax);
    m[x]=res;
    return res;
}
void its_her_choice()
{
    cin>>n>>a>>b>>c>>d;
    cout<<recurse(n);el
    m.clear();
}
signed main()
{
    fastio;
    cases(t)
    {
        its_her_choice();
    }
}

Measured memory_bytes: 4684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] name = new String[3];
		for (int i = 0; i < 3; i++) {
			name[i] = sc.next();
		}

		for (int i = 0; i < 3; i++) {
			System.out.print(name[i].charAt(0));
		}

	}

}


Measured memory_bytes: 21844
#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 x1,x2,x3,x4,x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1==0) cout << 1 << endl;
  if (x2==0) cout << 2 << endl;
  if (x3==0) cout << 3 << endl;
  if (x4==0) cout << 4 << endl;
  if (x5==0) cout << 5 << endl;
  return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int oddcounter = 0;
		for (int i = 0; i < N; i++) {
			if (sc.nextInt() % 2 != 0) {
				oddcounter++;
			}
		}
		if(oddcounter%2==0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 48360
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

const int MAX_P = 1000000; //max
bool prime[MAX_P+1];

void Eratosthenes(void){
  for(int i=2;i<=MAX_P;i++)
    prime[i]=true;
  
  for(int i=2;i*i<=MAX_P;i++)
    if(prime[i])  
      for(int j=i;i*j<=MAX_P;j++)
        prime[i*j]=false;
}


int dp[SIZE][2];


int main(){
  int n;
  int q[SIZE];
  
  Eratosthenes();

  scanf("%d",&n);

  for(int i=1;i<=n;i++){
    scanf("%d",q+i);
  }
  q[0] = 1;

  dp[0][0] = 1;
  
  for(int i=0;i<n;i++){
    if(prime[q[i+1]]){
      if(i < n-1){
        if(q[i] < q[i+1])            dp[i+2][1] = (dp[i+2][1] + dp[i][0])%mod;
        if(i > 0 && q[i-1] < q[i+1]) dp[i+2][1] = (dp[i+2][1] + dp[i][1])%mod;
      }
      if(q[i] < q[i+1])              dp[i+1][0] = (dp[i+1][0] + dp[i][0])%mod;
      if(i > 0 && q[i-1] < q[i+1])   dp[i+1][0] = (dp[i+1][0] + dp[i][1])%mod;
    } 
  }

  printf("%d\n",(dp[n][0] + dp[n][1])%mod);
  
  return 0;
}




Measured memory_bytes: 5348
#pragma optimize("unroll-loops,no-stack-protector")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// #include <ext/pb_ds/assoc_container.hpp>
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)

const ll N=1e5+5;
vector<ll>v[N];
ll n,m;
bool vis[N];

void dfs(ll u)
{
    vis[u]=1;
    for(ll x:v[u])
    {
        if(!vis[x])
        {
            dfs(x);
        }
    }
}

void solve()
{
   ll ans=0;
   cin>>n>>m;
   rep(i,m)
   {
       ll x,y;
       cin>>x>>y;
       v[x].pb(y);
       v[y].pb(x);
   }
   f(i,1,n+1)
   {
       if(!vis[i])
       {
           dfs(i);
           ans++;
       }
   }
   cout<<ans-1;
}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


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

void input(vector<vector<char>>& rvvcColor, int& rnRemain)
{
  int nySiz, nxSiz;
  cin >> nySiz >> nxSiz >> rnRemain;
  rvvcColor.resize(nySiz);

  for (int ny = 0; ny < rvvcColor.size(); ny++)
  {
    rvvcColor[ny].resize(nxSiz);

    for (int nx = 0; nx < rvvcColor[ny].size(); nx++)
      cin >>  rvvcColor[ny][nx];
  }
}

void paintColorRed(int nEach, vector<vector<char>>& rvvcColor)
{
  if (nEach < rvvcColor.size())
  {
    for (int nx = 0; nx < rvvcColor[nEach].size(); nx++)
      rvvcColor[nEach][nx] = ' ';
  }
  else
  {
    nEach -= rvvcColor.size();
    for (int ny = 0; ny < rvvcColor.size(); ny++)
      rvvcColor[ny][nEach] = ' ';
  }
}

int calcNumOfCase(const vector<vector<char>>& cnrvvcColor, int nRemain)
{
  int nNumOfCase = 0;
  int nSize = cnrvvcColor.size() + cnrvvcColor[0].size();

  for (int nCtl = 0; nCtl < ( 1 << nSize ) ; nCtl++)
  {
    vector<vector<char>> vvcColor(cnrvvcColor);

    for (int nEach = 0; nEach < nSize; nEach++)
      if (nCtl & ( 1 << nEach ))
        paintColorRed(nEach, vvcColor);

    int nCntTrg = 0;

    for (int ny = 0; ny < vvcColor.size(); ny++)
      for (int nx = 0; nx < vvcColor[ny].size(); nx++)
        if (vvcColor[ny][nx] == '#') nCntTrg++;

    if (nCntTrg == nRemain) nNumOfCase++;
  }
  return nNumOfCase;
}
 
int main()
{
  vector<vector<char>> vvcColor;
  int nRemain;

  input(vvcColor, nRemain);
  cout << calcNumOfCase(vvcColor, nRemain) << endl;

  return 0;
}

Measured memory_bytes: 3640
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, A, B;
    cin >> N >> A >> B;

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

    int q1 = 0;
    int q2 = 0;
    int q3 = 0;

    for (int i = 0; i < N; i++) {
        if (P[i] <= A) {
            q1++;
        } else if (P[i] >= B + 1) {
            q3++;
        } else {
            q2++;
        }
    }

    cout << min(min(q1, q2), q3) << endl;

    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

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

    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    REP(i, n) cin >> a[i] >> b[i] >> c[i];
    vector<vector<vector<int>>> dp(45, vector<vector<int>>(405, vector<int>(405)));
    REP(i, 45) REP(j, 405) REP(k, 405) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    REP(i, n) REP(j, 401) REP(k, 401)
    {
        if(a[i] <= j && b[i] <= k) dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a[i]][k-b[i]] + c[i]);
        else dp[i+1][j][k] = dp[i][j][k];
    }

    int ans = INF;
    for(int i = ma, j = mb; i <= 400 && j <= 400; i += ma, j += mb)
    {
        ans = min(ans, dp[n][i][j]);
    }
    cout << (ans == INF ? -1 : ans) << endl;

}

Measured memory_bytes: 30336
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
int main() {
  cin >> n >> k;
  i64 ans = k;
  for (i64 i = 1; i < n; ++i) ans *= k - 1;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
const long long MAXN = 5e3+5;
const long long MOD = 998244353;
long long dp[MAXN][MAXN];
long long arr[MAXN];
int main(){
    long long n,S;
    cin>>n>>S;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
    }
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
    }
    dp[0][0] = 1;
    for(long long i=1;i<=n;i++){
        for(long long j=0;j<=S;j++){
            dp[i][j] = 2LL*dp[i-1][j];
            dp[i][j]%=MOD;
            if(j-arr[i]>=0){
                dp[i][j]+=dp[i-1][j-arr[i]];
                dp[i][j]%=MOD;
            }
        }
    }
    cout<<dp[n][S]<<endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
ll mod = 1000000007;


int main(){
    double l;
    cin >> l;
    l =  pow(l, 3) / 27;
    cout << fixed << setprecision(6);
    cout << l << endl;
}

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

int main() {
  int N, X, m[1000], count = 0;
  cin >> N >> X;
  for(int i = 0; i < N; ++i) cin >> m[i];
  sort(m, m + N);

  for(int i = 0; i < N; ++i) {
    X -= m[i];
    ++count;
  }

  while(X >= m[0]) {
    X -= m[0];
    ++count;
  }

  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define len(s) s.length()
#define all(v) v.begin(),v.end()
const ll INF = INT_MAX;
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;
	// cin >> tc;
	while (tc--) {

		ll n, m, l, r;
		ll i, j;
		ll  y;

		ll x[5];

		for (i = 0; i < 5; i++) cin >> x[i];

		for (i = 0; i < 5; i++) {
			if (x[i] == 0) {
				cout << i + 1 << endl;
				return 0;
			}
		}



	}
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = 0;
  int curMin = 1e9;
  rep(i, n) {
    curMin = min(curMin, p[i]);
    if (curMin == p[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
#include <stdio.h>
int main()
{
	int N;
	scanf("%d",&N);
	int a[55];
	int i;
	for(i=0;i<=N-1;i++)
	{
		scanf("%d",&a[i]);
	}
	int sum=0;
	int x;
	int t=0;
	for(x=N-1;x>=1;x--)
	{
		t+=a[x];
		sum+=t*a[x-1];
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
a, b = list(map(int, input().split()))
num = b - a + 1
a_odd = (a % 2 == 1)
num_odd = (num % 2 == 1)


if a_odd:
    if num_odd:
        if ((num-1)/2) % 2 == 1:
            ans = a ^ 1
        else:
            ans = a
    else:
        if ((num-2)/2) % 2 == 1:
            ans = a ^ b ^ 1
        else:
            ans = a ^ b
else:
    if num_odd:
        if ((num-1)/2) % 2 == 1:
            ans = b ^ 1
        else:
            ans = b
    else:
        if (num/2) % 2 == 1:
            ans = 1
        else:
            ans = 0
print(ans)


Measured memory_bytes: 3064
n = int(input())
s = [input().split() for i in range(n)]
m = int(input())
t = [input().split() for i in range(m)]
ans = 0
for i in range(n):
    temp = s.count(s[i]) - t.count(s[i])
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 9104
from math import degrees
from math import atan
a,b,x = list(map(int, input().split()))
if(2 * x > a**2 * b):
  print(degrees(atan(2 * (a ** 2 * b - x) / a ** 3)))
else:
  print(degrees(atan(a * b ** 2 / 2 / x)))

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	
	int A,B,C,S,Sf,max;
	scanf("%d%d%d",&A,&B,&C);
	
	S=A+B+C;
	
	if(A<B){
		max=B;
	}else {
		max=A;
	}
	if(max<C){
		max=C;
	}
	
	Sf=max*3;
	
	if((Sf-S)%2==0){
		printf("\n%d\n\n",(Sf-S)/2);
	}else {
		printf("\n%d\n\n",(Sf+3-S)/2);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x_max = max(x)
y_min = min(y)

if x_max >= y_min or x_max >= Y or y_min <= X + 1:
    print('War')
else:
    print('No War')


Measured memory_bytes: 2940
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        int x,y;
        
        while(true){
            y = scan.nextInt();
            x = scan.nextInt();
            
            if(x == 0 && y == 0){
                break;
            }
            for(int j = 0; j < y;j++){
                for(int i = 0;i < x;i++){
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }
}


Measured memory_bytes: 34448
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n =0;
    scanf("%d", &n);
    if( n<3 || n>20 ) exit(0);
    //printf("n:%d\n", n);

    int p[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&p[i]);
        //printf("%d", p[i]);
    }

    int count = 0;
    for(int j = 1; j<n-1; j++){
        if((p[j-1]<=p[j] && p[j]<p[j+1])
        || (p[j+1]<=p[j] && p[j]<p[j-1])){
            //printf("%d",p[j-1]);
            //printf("j:%d\n", j);
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
def main():
    N=int(input())
    v=list(map(int, input().split()))
    v.sort(reverse=True)
    while len(v) > 1:
        v1 = v.pop()
        v2 = v.pop()
        v.append((v1+v2)/2)
    print(v[0])

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 2940
#include<algorithm>
#include <cstdio>
using namespace std;
int main() {
	int n, m;
  scanf("%d %d", &n, &m);
  int all = 0;
  while (m --) {
  	int x;
    scanf("%d", &x);
    all += x;
  }
  all >= n ? puts("Yes"):puts("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

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

    string S;
    cin >> S;
    for(auto c : S){
        if(c == '7')
            drop("Yes");
    }
    drop("No");

    return 0;
}

Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Scanner;				
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			Scanner sc =new Scanner(System.in);
			int N = sc.nextInt();
			int temp = 1000000000;
			int S = sc.nextInt();
			int lol = S-1;
			int[]A = new int[N];
			for(int i =0; i<N; i++) {
				A[i] = sc.nextInt();
			}
			
			Arrays.sort(A);
			for(int i =0; i<A.length; i++) {
			if(A.length - i == lol) {
					break;
				}
				if(A[i+lol]-A[i]<temp) {
				temp = A[i+lol] - A[i];
				}
				
				}
			System.out.println(temp);
	}

}


Measured memory_bytes: 59224
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;

const int MAXV = 100000;
const long long INF = 2e18;

long long dp[101][100001];

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

	int N, W;
	cin >> N >> W;
	vector<int> w(N+1), v(N+1);
	for (int i = 1; i <= N; ++i) cin >> w[i] >> v[i];

	// dp[i][j]: minimum weight to get total value of j at element i.
	for (int i = 0; i <= N; ++i) {
		dp[i][0] = 0;
		for (int j = 1; j <= MAXV; ++j) dp[i][j] = INF;
	}

	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= MAXV; ++j) {
			dp[i][j] = dp[i-1][j];
			if (j >= v[i]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
		}
	}

	int ans = -1;
	for (int j = MAXV; j >= 0; --j) {
		if (dp[N][j] <= W) {
			ans = j;
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 79232
n = int( raw_input( ) )
minv = int( raw_input( ) )
maxv = 0 - 1000000000
 
for j in range( n-1 ):
  num = int( raw_input( ) )  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
 
print maxv

Measured memory_bytes: 12688
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a,const void* b){
  return *(int *)a - *(int *)b;
}


int main(){
  int n;
  int d[100000];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  qsort(d,n,sizeof(int),compare);
  int mid1 = d[(n/2) - 1];
  int mid2 = d[n/2];
  printf("%d\n",mid2 - mid1);
  return 0;
  
}

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

int main(){
	
	string s,t; cin>>s>>t;
	int ans = (int)t.size();
	for(int i = 0; i+t.size()-1 < s.size(); i++){
		int co = 0;
		for(int j = 0; j < (int)t.size(); j++){
			if(s[i+j] == t[j]) co++;
		}
		ans = min(ans, (int)t.size()-co);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void){
	int n;
	scanf("%d", &n);
	int in = 0;
	int sum = 0;
	scanf("%d", &in);
	sum += in;
	for(int i = 0; i < n - 2; i++){
		int old = in;
		scanf("%d", &in);
		sum += (old < in ? old : in);
	}
	sum += in;
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 2104
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int h, w;
	cin >> h >> w;
	vector<string> arr(h+1);
	vector<vector<int>> dp(h+1, vector<int>(w+1, INF));
	string x;
	for(int i = 1; i <= h; i++) {
		cin >> x;
		arr[i]="."+x;
	}
	for(int i = 0; i <= w; i++) {
		arr[0][i]='.';
	}
	arr[0][1]=1;
	dp[0][1]=0;
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			if(arr[i][j]=='.') {
				dp[i][j]=min(dp[i-1][j], dp[i][j-1]);
			}
			else {
				dp[i][j]=min(dp[i-1][j]+1-(arr[i-1][j]=='#'), dp[i][j-1]+1-(arr[i][j-1]=='#'));
			}
		}
	}
	cout << dp[h][w];

	return 0;
}


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

int main() {
    int N, x;
    vector<int> X;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x;
        X.push_back(x);
    }
    
    int a, mina = 100*100*100;
    for (int i = 1; i <= 100; i++) {
        a = 0;
        for (int j = 0; j < N; j++) {
            a += (X[j] - i) * (X[j] - i);
        }
        if (mina > a) mina = a;
    }
    cout << mina << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import bisect_right

read = sys.stdin.read

N, D, A, *XH = map(int, read().split())
X = XH[::2] + [-1]
H = XH[1::2] + [-1]
D *= 2
X, H = zip(*sorted(zip(X, H)))

damages = [0] * (N + 2)
answer = 0

for i in range(1, N + 1):
    damages[i] += damages[i - 1]
    h = H[i]
    if damages[i] >= h:
        continue
    else:
        h -= damages[i]

    x = X[i]
    cnt = (h + A - 1) // A
    answer += cnt
    damage = A * cnt
    damages[i] += damage
    damages[bisect_right(X, x + D)] -= damage

print(answer)


Measured memory_bytes: 54100
#include <stdio.h>
#include<math.h>
int main()
{
long   long int a=0,b=0,w=0,i,str1=0,str2=0,flag;

scanf("%lld",&w);
flag=1;
for(i=1;i<=w;i++)
{
flag=(flag*i)%1000000007;
}
printf("%lld",flag);
    return 0;
}


Measured memory_bytes: 128