akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> edge(N);
    for (ll i = 0; i < M; i++) {
        ll A, B;
        cin >> A >> B;
        edge[A - 1].push_back(B - 1);
    }

    struct Element {
        ll node, cost;
        bool operator<(const Element& rhs) const {
            return cost < rhs.cost;
        }
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };

    vector<ll> ans(N + 1);
    for (ll i = 0; i < N; i++) {
        vector<ll> cost(N, INT_MAX), pre(N, -1);
        priority_queue<Element, vector<Element>, greater<Element>> pq;

        pq.push({i, 0});
        while (!pq.empty()) {
            Element t = pq.top();
            pq.pop();
            if (t.cost > cost[t.node]) {
                continue;
            }

            for (const ll& next_node : edge[t.node]) {
                ll new_cost = t.cost + 1;
                if (new_cost < cost[next_node]) {
                    cost[next_node] = new_cost;
                    pre[next_node] = t.node;
                    pq.push({ next_node, new_cost });
                }
            }
        }

        if (pre[i] == -1) {
            continue;
        }

        vector<ll> loop;
        loop.push_back(i);
        ll node = pre[i];
        while (node != i) {
            loop.push_back(node);
            node = pre[node];
        }
        if (loop.size() < ans.size()) {
            ans = loop;
        }
    }

    if (ans.size() == N + 1) {
        cout << -1 << endl;
    } else {
        cout << ans.size() << endl;
        for (ll i = 0; i < ans.size(); i++) {
            cout << ans[i] + 1 << endl;
        }
    }
}

Measured memory_bytes: 384
import math
N=int(input())

cnt=0
for j in range(1,N+1,2):
    n=int(math.sqrt(j))
    yaku=0
    for i in range(n):
        if j%(i+1)==0:
            yaku+=1
    #print(j,yaku)
    if yaku*2==8:
        cnt+=1
print(cnt)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int main()
{
	char str[200001];
	int sum= 0, count= 0, i;

	scanf("%s", str);

	for(i= 0; i< strlen(str); i++)
	{
		if(str[i]== 'S')
			count++;
		else if(count)
			count--;
		else
			sum++;
	}

	printf("%d\n", sum+ count);

	return 0;
}

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

int main() {
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  sort(a.begin(),a.end());
  int da=a[2]-a[0]; int db=a[2]-a[1];

  int cnt=0; cnt+=db/2;
  if(db%2==1){
    cnt++; da--;
  }

  if(da%2==0)cnt+=da/2;
  else{
    cnt+=da/2+2;
  }

  cout << cnt << endl;
}


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

using std::cin;
using std::cout;
using std::vector;
using std::for_each;

int main() {
	int n;
	cin >> n;
	vector<int> v_old(n);
	vector<int> v_new(n);
	vector<bool> v_fill(n);
	for_each(v_old.begin(),v_old.end(),[](int &_e){cin >> _e;});
	int q;
	cin >> q;
	while (q--) {
		int b;
		int m;
		int e;
		cin >> b >> m >> e;
		v_fill.assign(n,false);
		for (int k = 0;k != e-b;++k) {
			v_new[b+(k+(e-m))%(e-b)] = v_old[b+k];
			v_fill[b+(k+(e-m))%(e-b)] = true;
		}
		for (int j = 0;j != n;++j) {
			if (!v_fill[j]) {
				v_new[j] = v_old[j];
			}
		}
		v_old.assign(v_new.begin(),v_new.end());
	}
	int i = 1;
	for_each(v_new.begin(),v_new.end(),[&i,n](int _e){cout << _e << (i++ == n ? "\n" : " ");});
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
int a[MX], b[MX], c[MX];

signed main(){
    int n;
    cin >> n;
    
    rep(i,n) cin >> a[i];

    b[0] = a[0];
    FOR(i,1,n) {
        b[i] += a[i] + b[i-1];
    }

    c[n-1] = a[n-1];
    RFOR(i,n-2,0) {
        c[i] += a[i] + c[i+1];
    }

    int m = 20202020200;
    rep(i,n) {
        m = min(m, abs(b[i]-c[i+1]));
    }
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 9984
N = int(input())
W = list(map(int, input().split()))

S1 = []
S2 = []
ans = []

for i in range(1, N):
    S1.append(sum(W[0:i]))
    S2.append(sum(W)-sum(W[0:i]))

for j in range(len(S1)):
    ans.append(abs(S1[j]-S2[j]))

print(min(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

using Edge = P;
using Graph = vector<vector<Edge>>;

int N;
Graph G;
vector<int> dir;

void dfs(int v, int p, int c) {
    dir[v] = c;
    for(auto e : G[v]) {
        if(e.first == p) continue;
        if(e.second & 1) dfs(e.first, v, 1 - c);
        else dfs(e.first, v, c);
    }
}

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    while(cin >> N) {
        G.resize(N);
        rep(i, N-1) {
            int u, v, w;
            cin >> u >> v >> w;
            --u; --v;
            G[u].push_back(Edge(v, w));
            G[v].push_back(Edge(u, w));
        }
        dir.assign(N, 0);
        dfs(0, -1, 1);
        for(auto v : dir) cout << v << endl;
    }
    return 0;
}

Measured memory_bytes: 11648
#!/usr/bin/env ruby

(n, m) = gets.chomp.split(/ /).map(&:to_i)
x = gets.chomp.split(/ /).map(&:to_i)

if m == 1
  puts 0
  exit
end

x.sort!
array = []
(0..(m - 2)).each do |i|
  array << (x[i] - x[i + 1]).abs
end
array.sort!
(n - 1).times do
  array.pop
end

res = array.inject(0){|sum, enum| sum += enum}
puts res


Measured memory_bytes: 10616
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
  a = B[i] - A[i]
  if a > 0:
    if A[i+1] - a < 0:
      ans = ans + A[i] + A[i+1]
      A[i+1] = 0
    else:
      ans = ans + A[i] + a
      A[i+1] = A[i+1] - a
  else:
    ans = ans + B[i]
print(ans)

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

int kangIndex[128][128];
int sum[40][40];

void countKang(char s[]){
	int len = strlen(s);
	int f_index,b_index;

	for(int i=0;i<=len-2;){
		if(kangIndex[s[i]][s[i+1]] >= 0){
			f_index = kangIndex[s[i]][s[i+1]];
			i += 2;
		}
		else{
			f_index = s[i] - 'a';
			i++;
		}

		if(i >= len){break;}

		if(i<=len-2 && kangIndex[s[i]][s[i+1]]>=0){
			b_index = kangIndex[s[i]][s[i+1]];
		}
		else{
			b_index = s[i] - 'a';
		}

		sum[f_index][b_index]++;
	}
}

void init(void){
	memset(sum,0,sizeof(sum));
	memset(kangIndex,-1,sizeof(kangIndex));

	kangIndex['l']['d'] = 26;
	kangIndex['m']['b'] = 27;
	kangIndex['m']['p'] = 28;
	kangIndex['n']['c'] = 29;
	kangIndex['n']['d'] = 30;
	kangIndex['n']['g'] = 31;
	kangIndex['n']['t'] = 32;
	kangIndex['n']['w'] = 33;
	kangIndex['p']['s'] = 34;
	kangIndex['q']['u'] = 35;
	kangIndex['c']['w'] = 36;
	kangIndex['t']['s'] = 37;
}

void printKangChar(int index){
	if(index < 26){
		char c = 'a' + index;
		cout << c;
	}
	else{
		string s;

		switch(index){
		case 26: s="ld";break;
		case 27: s="mb";break;
		case 28: s="mp";break;
		case 29: s="nc";break;
		case 30: s="nd";break;
		case 31: s="ng";break;
		case 32: s="nt";break;
		case 33: s="nw";break;
		case 34: s="ps";break;
		case 35: s="qu";break;
		case 36: s="cw";break;
		case 37: s="ts";break;
		}
		cout<<s;
	}
}

void printAns(void){
	for(int i=0;i<38;i++){
		int max_index=0;

		for(int j=0;j<38;j++){
			if(sum[i][j] > sum[i][max_index]){
				max_index = j;
			}
		}

		printKangChar(i);
		cout<<" ";
		printKangChar(max_index);
		cout<<" "<<sum[i][max_index]<<endl;
	}
}

int main(void){
	int n;
	char s[60];

	init();

	cin>>n;
	while(cin>>s){
		countKang(s);
	}
	printAns();

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int grid[h][w];
    fill(grid[0], grid[h], 0);
    int x[n], y[n], a[n];
    rep(i, n) {
        cin >> x[i] >> y[i] >> a[i];
        if (a[i] == 1) {
            rep(j, h) {
                rep(k, w) {
                    if (k < x[i]) grid[j][k] = 1;
                }
            }
        } else if (a[i] == 2) {
            rep(j, h) {
                rep(k, w) {
                    if (k >= x[i]) grid[j][k] = 1;
                }
            }
        } else if (a[i] == 3) {
            rep(j, h) {
                rep(k, w) {
                    if (j < y[i]) grid[j][k] = 1;
                }
            }
        } else if (a[i] == 4) {
            rep(j, h) {
                rep(k, w) {
                    if (j >= y[i]) grid[j][k] = 1;
                }
            }
        }
    }
    int cnt = 0;
    rep(i, h) {
        rep(j, w) {
            if (grid[i][j] == 0) cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INV2 = 5e8 + 4;
void add(int &x, int y) {
  x += y;
  if(x >= MOD) x -= MOD;
}
void sub(int &x, int y) {
  x -= y;
  if(x < 0) x += MOD;
}
int calc(int n) {
  return 1ll * n * (n + 1) % MOD * INV2 % MOD;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k; cin >> n >> k;
  int ans = 0;
  for(int i = k; i <= n + 1; i++) {
    int left = calc(i - 1), right = calc(n);
    sub(right, calc(n - i));
    sub(right, left);
    add(right, 1);    
    add(ans, right);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#define MAX 500000
#define NIL NULL
struct t{
  int val;
  struct t *parent,*left,*right;
};
typedef struct t * T;
int n;
T root=NIL;

void insert(int u){
  T next,look,z;
  z=(T)malloc(sizeof(struct t));
  z->val=u;
  z->parent=z->left=z->right=NIL;
  next=root;
  look=NIL;
  while(next!=NIL){
    look=next;
    if(z->val > look->val) next=look->right;
    else next=look->left;
  }
  z->parent=look;

  if(z->parent==NIL) root=z;
  else if(z->val > look->val) look->right=z;
  else look->left=z;

}
int find(int u){
  T look=root;
  while(look!=NIL){
    if(look->val==u) return 1;
    if(look->val > u) look=look->left;
    else look=look->right;
  }
  return -1;
}
void preorder(T u){
  if(u==NIL) return;
  printf(" %d",u->val);
  preorder(u->left);
  preorder(u->right);
}
void inorder(T u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->val);
  inorder(u->right);
}
int main(){
  int i,u;
  char com[10];
  scanf("%d",&n);
  //for(i=0;i<n;i++) tree[i].p=tree[i].l=tree[i].r=NIL;

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&u);
      insert(u);
    }else if(com[0]=='f'){
      scanf("%d",&u);
      if(find(u)==1) printf("yes\n");
      else printf("no\n");
    }else{
       inorder(root);
       printf("\n");
       preorder(root);
       printf("\n");
     }
  }
  return 0;
}



Measured memory_bytes: 20556
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let [n, x, t] = lines[0].split(' ').map( _ => parseInt(_))
    let ans
    if(n % x == 0) {
        ans = (n / x) * t
    } else {
        ans = (Math.floor(n / x) + 1) * t
    }

    console.log(ans)
});

Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;

int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	LL n;scanf("%lld", &n);
	LL ans=0;
	for (LL l=1, r,d;	l<=n; l=r+1){
		d=n/l; r=n/d;
		if ( d>=l) continue;
		if ( n%d==0 && (n-d)/d>=l && (n-d)/d<=r) ans += n/d-1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
# coding=utf-8
from __future__ import print_function


def gen(n, i=0):
    while n:
        yield '#' if i % 2 == 0 else '.'
        i += 1
        n -= 1


if __name__ == '__main__':
    while True:
        height, width = map(int, raw_input().split())
        if height + width == 0:
            break
        else:
            [print(''.join(list(gen(width, i)))) for i in xrange(height)]
            print()

Measured memory_bytes: 4220
#include <stdio.h>
//#include <math.h>
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
int A[101];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++) {
    int d;
    scanf("%d", &d);
    for (int j = 0; j < d; j++) {
      int a;
      scanf("%d", &a);
      A[a] = 1;
    }
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i] == 0) {
      sum++;
    }
  }
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

int COM(int a,int b){
    if(a==0 && b==0) return 1;
    if(a%2==0 && b%2==1) return 0;
    else return COM(a/2,b/2);
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    string s;
    cin>>n>>s;
    Vi a(n);
    REP(i,0,n){
        a[i]=ctoi(s[i])-1;
    }
    bool all2check=true;
    REP(i,0,n){
        if(a[i]==1){
            all2check=false;
            break;
        } 
    }

    int ans=0;
    if(all2check){
        Vi b(n);
        REP(i,0,n){
            if(a[i]==2) b[i]=1;
        }
        REP(i,0,n){
            ans = (ans+b[i]*COM(n-1,i))%2;
        }
        cout<<ans*2<<endl;
    }else{
        REP(i,0,n){
            ans = (ans+a[i]*COM(n-1,i))%2;
        }
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 17052
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int n, m, g[128][128], deg[128];

int rec(int ix, int rem, const vector<int>& u, const vector<int>& cs) {
    if(rem==0) {
        int ans = 0;
        rep(i, u.size()) if(u[i]==1) {
            int t = INT_MAX;
            rep(j, u.size()) if(i!=j && u[j]==1) t = min(t, g[cs[i]][cs[j]]);
            ans += t;
        }
        return ans;
    }
    int c = 0;
    for(int i=ix; i<(int)u.size(); i++) if(u[i]==0) c++;
    if(ix==(int)u.size() || c<rem) return 0;
    int ans = 0;
    if(u[ix]!=-1) {
        vector<int> w(u);
        w[ix] = 1;
        rep(i, w.size()) if(i!=ix && g[cs[ix]][cs[i]]==0) w[i] = -1;
        ans = max(ans, rec(ix+1, rem-1, w, cs));
    }
    ans = max(ans, rec(ix+1, rem, u, cs));
    return ans;
}

int main() {
    scanf("%d%d", &n, &m);
    rep(i, m) {
        int u, v, f;
        scanf("%d%d%d", &u, &v, &f);
        u--, v--;
        g[u][v] = g[v][u] = f;
        deg[u]++, deg[v]++;
    }
    int ans = 0;
    rep(i, n) rep(j, i) ans = max(ans, g[i][j]*2);
    rep(i, n) rep(j, i) if(g[i][j]) rep(k, j) if(g[k][i] && g[k][j]) {
        const int s = min(g[i][j], g[i][k])
                + min(g[j][i], g[j][k])
                + min(g[k][i], g[k][j]);
        ans = max(ans, s);
    }
    for(int k=4; k<15; k++) {
        vector<int> cs;
        rep(i, n) if(deg[i]>=k-1) cs.push_back(i);
        ans = max(ans, rec(0, k, vector<int>(cs.size(), 0), cs));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

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

        final int N = sc.nextInt();
        int[] sticks = scanSticks(sc, N);
        Arrays.sort(sticks);

        long answer = 0;

        for (int iLeft = 0; iLeft < N - 2; iLeft++) {
            int left = sticks[iLeft];
            
            for (int iMiddle = iLeft + 1; iMiddle < N - 1; iMiddle++) {
                int middle = sticks[iMiddle];
                
                for (int iRight = iMiddle + 1; iRight < N; iRight++) {
                    int right = sticks[iRight];
                    
                    if (isSatisfied(left, middle, right))
                        answer++;
                }
            }
        }

        System.out.println(answer);
    }

    private static int[] scanSticks(Scanner sc, final int N) {
        int[] sticks = new int[N];

        for (int i = 0; i < N; i++)
            sticks[i] = sc.nextInt();

        return sticks;
    }

    private static boolean isSatisfied(int left, int middle, int right) {
        return left + middle > right;
    }
}


Measured memory_bytes: 39956
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pp pair<ll,ll>
#define inf 1e9
using namespace std;
const int N=100005;

int dis[N],P[N],sz[N];
vector<int> a[N];

void dfs(int u,int par)
{
    dis[u]=dis[par]+1;sz[u]=1;P[u]=par;
    for(int i=0;i<a[u].size();i++)
    {
        if(a[u][i]!=par)
        {
            dfs(a[u][i],u);
            sz[u]+=sz[a[u][i]];
        }
    }
}

 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
        a[y].pb(x);
    }
    
    dfs(1,1);
    vector<int> s;
    s.pb(sz[n]);
    
    int p=n;
    while(p!=1)
    {
        int u=sz[P[p]]-sz[p];
        s.pb(u);
        p=P[p];
    }
    
    ll sum=0,u=0,v=0;int x=dis[n]/2;
    for(int i=0;i<s.size();i++)
    sum+=s[i];
    
    for(int i=0;i<x;i++)
    v+=s[i];
    
    u=sum-v;
    
    if(u>v)
    cout<<"Fennec\n";
    else
    cout<<"Snuke\n";
    
    return 0;
} 

Measured memory_bytes: 13820
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int r; cin >> r;
    cout << r * r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

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

int main(){
    int n, m;
    cin >> n >> m;
    cout << (n * (n-1)) / 2 + (m * (m-1)) / 2 << endl;
}

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

from fractions import gcd
from math import ceil,floor
import collections

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))


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

ans = 0

for i in range(1,N-1):
    if p[i-1] < p[i+1]:
        if p[i] < p [i+1] and p[i] >= p[i-1]:
            ans = ans+1
    if p[i-1] >= p[i+1]:
        if p[i] < p [i-1] and p[i] >= p[i+1]:
            ans = ans+1
        

print(ans)


Measured memory_bytes: 5564
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))

dx = [-1,0,1,-1,1,-1,0,1]
dy = [1,1,1,0,0,-1,-1,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        cnt = 0
        for t in range(8):
            ni=i+dx[t]
            nj=j+dy[t]
            if ni<0 or h<=ni: continue
            if nj<0 or w<=nj: continue
            if s[ni][nj] == '#':
                cnt += 1
        
        s[i][j] = str(cnt)

for i in s:
    print(''.join(i))

Measured memory_bytes: 9180
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    float x1,y1,x2,y2,x3,y3,x4,y4;
    for(int i=0;i<n;i++){
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if((y2-y1)/(x2-x1)==(y4-y3)/(x4-x3)){
        cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3128
//Minor Change

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s,t;cin>>s>>t;
    int ans = 0;
    rep(i,0,s.size())if(s[i]!=t[i])ans++;
    cout<<ans<<nnn;
    return 0;
}

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

using namespace std;

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

    int ans = 0;

    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    for (size_t i = 0; i < K; i++)
    {
        ans += A.at(i);
    }
    
    cout << ans << endl;



    return 0;
}

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

using namespace std;

typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define REPe(i, n) for(int i = 0; i <= (int)(n); ++i)
#define REPi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define REPei(i, a, b) for(int i = int(a); i <= int(b); ++i)

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

    int cnt = 0;
    int K, S;
    cin >> K >> S;

    REPe(i, K) {
        REPe(j, K) {
            if(K >= S - i - j && S >= i + j) ++cnt;
        }
    }

    cout << cnt << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k, c;
    cin >> n >> k >> c;
    c++;
    vector<char>s(n + 3);
    vector<int>dp(n + 3), dp2(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> s[i];
    }
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        dp[i] = dp[i - 1];
        if(s[i] == 'o'){
            int idx = max(i - c, 0);
            dp[i] = max(dp[i], dp[idx] + 1);
        }
    }
    if(dp[n] != k){
        return 0;
    }
    dp2[n + 1] = 0;
    for(int i = n; i >= 1; i--){
        dp2[i] = dp2[i + 1];
        if(s[i] == 'o'){
            int idx = min(i + c, n + 1);
            dp2[i] = max(dp2[i], dp2[idx] + 1);
        }
    }
    vector<int>ans;
    for(int i = 1; i <= n; i++){
        if(s[i] == 'o' && dp[i] > dp[i - 1] && dp2[i] > dp2[i + 1]){
            ans.push_back(i);
        }
    }
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 6024
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner  sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Alice=0;
        int Bob=0;
        Integer list[] =new Integer[N];
        for (int i =0;i<N;i++){
            list[i]=sc.nextInt();
        }
        Arrays.sort(list,Comparator.reverseOrder());
        for (int i=0;i<N;i++){
            if (i%2 ==0){
                Bob +=list[i];
            }else{
                Alice +=list[i];
            }
        }
        System.out.println(Math.abs(Alice-Bob));
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

ll f(ll b, ll n){
    if(n < b) return n;
    return f(b, n / b) + n % b;
}

signed main(){
    ll n,s;
    cin >> n >> s;
    if(n < s){
        cout << -1 << endl;
        return 0;
    }
    if(n == s){
        cout << n + 1 << endl;
        return 0;
    }
    for(ll b = 2; b <= sqrt(n); b++){
        if(f(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }
    for(ll p = sqrt(n); p > 0; p--){
        if((n - s) % p != 0) continue;
        ll b = (n - s) / p + 1;
        if(f(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int getLCS(string& s1, string& s2,int i, int j, int n, int m){
    if(i >= n || j >= m){
        return 0;
    }
    if(dp[i][j] != -1){
        return dp[i][j];
    }
    if(s1[i] == s2[j]){
        return dp[i][j] = 1 + getLCS(s1, s2, i+1, j+1, n, m);
    }else{
        return dp[i][j] = max(getLCS(s1, s2, i+1, j, n, m), getLCS(s1, s2, i, j+1, n, m));
    }
}
string LCS(string& s1, string& s2){
    int n = s1.length();
    int m = s2.length();
    memset(dp, -1, sizeof(dp));
    int len = getLCS(s1, s2, 0, 0, n, m);
    string res = "";
    int i = 0;
    int j = 0;
    while(i < n and j < m){
        if(s1[i] == s2[j]){
            res += s1[i];
            i++;
            j++;
        }else{
            if(dp[i+1][j] > dp[i][j+1]){
                i++;
            }else j++;
        }
    }
    return res;
}
int main() {
	string s1, s2;
	cin>>s1>>s2;
	cout<<LCS(s1, s2);
	return 0;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 101;
constexpr int INFTY = (1<<21);
int n;
vv(int, M, MAX, MAX, 0);
vi d(MAX, INFTY);
inline void bfs(int s) {
	deque<int> dq;
	dq.eb(s);
	d[s] = 0;
	int u;
	while(!dq.empty()) {
		u = dq.front(); dq.pop_front();
		rep(v, 0, n) {
			if(M[u][v] == 0 || d[v] != INFTY) continue;
			d[v] = d[u] + 1;
			dq.eb(v);
		}
	}
	rep(i, 0, n) {
		cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v;
	rep(i, 0, n) {
		cin >> u >> k;
		--u;
		rep(j, 0, k) {
			cin >> v;
			M[u][--v] = 1;
		}
	}
	bfs(0);
	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;int n;cin>>n;
    while(cin>>a>>b>>c){
        if(max({a,b,c})*max({a,b,c})*2 == a*a+b*b+c*c)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}


Measured memory_bytes: 3004
N,M=map(int,input().split())

AC=[0]*N
WA=[0]*N
WA_P=[0]*N
for i in range(M):
    p,s=map(str,input().split())
    if s=="WA" and AC[int(p)-1]==0:
        WA_P[int(p)-1]+=1
    elif AC[int(p)-1]==0 and s=="AC":
        AC[int(p)-1]=1
        WA[int(p)-1]=WA_P[int(p)-1]
print(sum(AC),sum(WA))

Measured memory_bytes: 5364
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for s in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
import sys,bisect
sys.setrecursionlimit(15000)

s1 = sys.stdin.readline().rstrip()
s2 = sys.stdin.readline().rstrip()
l1 = len(s1)
l2 = len(s2)
dp = [[float("inf")]*(l2+1) for _ in range(l1+1)]
dp[0] = list(range(l2+1))

for i in range(l1):
  dp[i][0] = i
  for j in range(l2):
    if s1[i]==s2[j]:
      dp[i+1][j+1] = dp[i][j]
    else:
      dp[i+1][j+1] = min(dp[i+1][j]+1,
                         dp[i][j+1]+1,
                         dp[i][j]+1)

#print(dp)
print(dp[-1][-1])



Measured memory_bytes: 41908
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    if(s==t){
        cout << n << endl;
        return 0;
    }
    int tmp=0;
    for(int i=1; i<n; i++){
        if(t.substr(0,i)==s.substr(n-i,i)){
            tmp = i;
        }
    }
    cout << 2 * n - tmp << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
multiset<int> mp;
map<int,multiset<int> >go;
int main()
{
	int n,mx=-2100000000,minn=2100000000,gmx=-2100000000,gminn=2100000000;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		if (x>y) swap(x,y);
		mx=max(mx,y);minn=min(minn,x);
		gmx=max(gmx,x);gminn=min(gminn,y);
		mp.insert(x);go[x].insert(y);go[y].insert(-1);
	}
	long long ans=(long long)(mx-gminn)*(gmx-minn);
	
	for (map<int,multiset<int> >::iterator it=go.begin();it!=go.end();it++)
	{
		ans=min(ans,(long long)(mx-minn)*((*(--mp.end()))-it->first));
		mp.erase(it->first);
		for (multiset<int>::iterator p=it->second.begin();p!=it->second.end();p++)
		{
			if ((*p)==-1) goto bomb;
			mp.insert(*p);
		}
	}
	bomb:;
	printf("%lld\n",ans);
}

Measured memory_bytes: 65920
#include<stdio.h>
 
int solve(int, int);
int A[2000], n, h = 0;
 
int main(){
  int i, q, M[2000];
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  } 
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &M[i]);
  } 
  for(i = 0; i < q; i++){
    h = solve(0, M[i]);
    if(h == 1)
      printf("yes\n");
    else 
      printf("no\n");
  }
 
  return 0;
}
 
int solve(int p, int t){
  if(t == 0){ 
    return 1;
  }
  else if(p == n){
    return 0;
  }
  else if(solve(p + 1, t - A[p]) || solve(p + 1, t)){
    return 1;
}
  else return 0;
  }

Measured memory_bytes: 588
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
	Scanner scn = new Scanner(System.in);
      int check = 0;
      int[] a = new int[9];
      for(int i=0; i<a.length; ++i){
        a[i] = scn.nextInt();
      }
      int x1 = a[3] - a[0];
      int x2 = a[6] - a[3];
      
      if(a[4] != a[1]+x1){
        check=1;
      } if(a[5] != a[2]+x1){
        check=1;
      } if(a[7] != a[4]+x2){
        check=1;
      } if(a[8] != a[5]+x2){
        check=1;
      }
      
      if(check==0){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
	}
}


Measured memory_bytes: 35568
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: f32,
        d: f32,
    }
    println!("{}", (n / (2.0 * d + 1.0)).ceil());
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
  int N,ans = 0;
  scanf("%d\n",&N);
  char A[N],B[N],C[N];

  scanf("%s%s%s",A,B,C);

  for(int i = 0;i < N;i++){
    if(A[i] == B[i] && B[i] == C[i]){
    }else{
      if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]){
        ans += 2;
      }else{
        ans++;
      }
    }
  }

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=200001;
const int mod=1000000007;
int a[100002];
ll fact[MAX_N+1];
int fact_tbl(int n){
    if(fact[0]==0){
        fact[0]=1;
        FOR(i,1,n+1) fact[i]=fact[i-1]*i%mod;
    }
    return 0;
}
int exgcd(int a,int b,int& x,int& y){
    int d=a;
    if(b!=0){
        d=exgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else{
        x=1;y=0;
    }
    return d;
}
int mod_inverse(int a,int m){
    int x,y;
    exgcd(a,m,x,y);
    return (m+x%m)%m;
}
int mod_fact(int n,int p,ll& e){
    e=0;
    if(n==0) return 1;
    ll res=mod_fact(n/p,p,e);
    e+=n/p;
    if(n/p%2!=0) return res*(p-fact[n%p])%p;
    return res*fact[n%p]%p;
}
ll mod_comb(int n,int k,int p){
    if(n<0||k<0||n<k) return 0;
    ll e1,e2,e3;
    ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
    if(e1>e2+e3)return 0;
    return a1*mod_inverse(a2*a3%p,p)%p;
}

int cnt[100002];
vector<int> id;
int main(){
    int n;
    cin>>n;
    rep(i,n+1){
        cin>>a[i];
        ++cnt[a[i]];
    }
    rep(i,n+1){
        if(cnt[a[i]]==2){
        id.pb(i);
        }
    }
    fact_tbl(200001);
    rep(i,n+1){
        ll ans=0;
        if(i==0){
            cout<<n<<endl;
            continue;
        }
        ans+=mod_comb(n-1,i+1,mod);
        ans+=mod_comb(n-1,i-1,mod);
        ans+=2*mod_comb(n-1,i,mod);
        ans-=mod_comb(id[0]-id[1]+n,i,mod);
        cout<<(ans%mod+mod)%mod<<endl;
    }
    return 0;
}

Measured memory_bytes: 3584
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;
    R(N);
    double s=0;
    REP(i,N){
        int x;
        R(x);
        s+=1./x;
    }
    W(1./s);
    return 0;
}


Measured memory_bytes: 256
mod = 10**9+7

h, w = map(int, input().split())
board = [list(input()) for i in range(h)]
dp = [[0]*w for i in range(h)]
dp[0][0] = 1

for i in range(h):
    for j in range(w):
        if board[i][j] == "#":
            continue
        if i != 0:
            dp[i][j] += dp[i-1][j]
        if j != 0:
            dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod
print(dp[-1][-1])

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

long long value[51];
long long dp[51][51]; 
int N,A,B;

bool comp(long long a,long long b)
{
    return a>b?true:false;
}
void init()
{
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=50;i++)
	{
		dp[i][0]=1;
		for(int j=1;j<=i;j++)
			dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
	}
}
int main()
{
	
	init();
	cin>>N>>A>>B;
	{
		double sum=0;
		for(int i=0;i<N;i++)
			cin>>value[i];
		sort(value,value+N,comp);
	//	reverse(value,value+N);//大->小
		for(int i=0;i<A;i++) 
			sum+=value[i];
		sum/=A;
		int num=0,k=0;
		for(int i=0;i<N;i++)
		{
			if(value[i]==value[A-1])
			{
				num++;
				if(i<A)
					k++;
			}
		}	
		long long ans=0; 
		if(k==A)//前A个相同,可以增加个数 
		{
			for(int i=A;i<=B;i++)
				ans+=dp[num][i];
		}
		else
			ans+=dp[num][k];

 		printf("%.15f\n",sum);
 		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
if A == 0:
    print(0)
elif B == 0:
    print(N)
else:
    ans = (N // (A + B)) * A
    D = N % (A + B)
    if D <= A:
        print(ans + D)
    else:
        print(ans + A)


Measured memory_bytes: 2940
#include<stdio.h>

long int inv(long int x){
  long int j[30],y,k;
  j[0]=x;
  for(k=1;k<=29;k++){
    j[k]=(j[k-1]*j[k-1])%1000000007;
  }
  y=(j[0]*j[2])%1000000007;
  y=(y*j[9])%1000000007;
  y=(y*j[11])%1000000007;
  y=(y*j[14])%1000000007;
  y=(y*j[15])%1000000007;
  y=(y*j[17])%1000000007;
  y=(y*j[19])%1000000007;
  y=(y*j[20])%1000000007;
  y=(y*j[23])%1000000007;
  y=(y*j[24])%1000000007;
  y=(y*j[25])%1000000007;
  y=(y*j[27])%1000000007;
  y=(y*j[28])%1000000007;
  y=(y*j[29])%1000000007;
  
  if(y<0){
    y=1000000007+y;
  }
  return y;
}

int main(void){
  long int r,R,c,C,i,p,a;
  scanf("%ld%ld%ld%ld",&r,&c,&R,&C);
  
  a=0;
  p=1;
  for(i=C+2;i<=R+C+2;i++){
    p=(p*i)%1000000007;
  }
  for(i=1;i<=R+1;i++){
    p=(p*inv(i))%1000000007;
  }
  a=a+p;
    
  p=1;
  for(i=c+1;i<=R+c+1;i++){
    p=(p*i)%1000000007;
  }
  for(i=1;i<=R+1;i++){
    p=(p*inv(i))%1000000007;
  }
  a=a-p;
    
  p=1;
  for(i=r+1;i<=r+C+1;i++){
    p=(p*i)%1000000007;
  }
  for(i=1;i<=C+1;i++){
    p=(p*inv(i))%1000000007;
  }
  a=a-p;
  
  p=1;
  for(i=c+1;i<=r+c;i++){
    p=(p*i)%1000000007;
  }
  for(i=1;i<=r;i++){
    p=(p*inv(i))%1000000007;
  }
  a=a+p;
  
  a=a%1000000007;
  if(a<0){
    a=1000000007+a;
  }
  
  printf("%ld",a);
  
  return 0;
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n, k, num, sum = 0;
	cin >> n >> k;
	priority_queue<int> health;
	for(int i = 0; i < n; i++){
		cin >> num;
		health.push(num);
	}
	for(int i = 0; i < n; i++){
		if(i >= k){
			sum += health.top();
		}
		health.pop();
	}
	cout << sum;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<stdlib.h>
#define ENORMOUS (1<<21)


int n,*d;
  
struct Ver{
    int weight;
    int key;
    struct Ver *next;
};
  
 
  
struct Ver *ver;

int Test_Set(int *S);
void Create_Vertex(int id,int u,int c);
void SSSP(void);
int Heap(int *S);
void Input(int id);


   

int main(void){
    int i;
    int id;
  
    scanf("%d",&n);
  
    d=(int*)malloc(sizeof(int)*n);
    ver=(struct Ver*)malloc(sizeof(struct Ver)*n);
    for(i=0;i<n;i++){
        ver[i].weight=-1;
        ver[i].key=-1;
        ver[i].next=NULL;
    }
  
    for(i=0;i<n;i++){
        scanf("%d",&id);
        Input(id);  
    }
  
    SSSP();
  
    for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
  
    free(d);
  
    return 0;
}


void Input(int id){
    int k,u,c;
    int i;
  
    scanf("%d",&k);
  
    for(i=0;i<k;i++){
        scanf("%d",&u);
        scanf("%d",&c);
        Create_Vertex(id,u,c);
    }
}

void Create_Vertex(int id,int u,int c){
    struct Ver *new,*work;
  
    new=(struct Ver*)malloc(sizeof(struct Ver));
    new->next=NULL;
    new->weight=c;
    new->key=u;
  
    work=&ver[id];
    while(work->next!=NULL) work=work->next;
    work->next=new;
  
}
  
void SSSP(void){
    int S[n];
    int i;
    int s,u;
    struct Ver *work;
  
    for(i=0;i<n;i++){
        S[i]=0;
        d[i]=ENORMOUS;
    }
    s=0;
    d[s]=0;
  
    while(Test_Set(S)==0){
        u=Heap(S);
        S[u]=1;
  
        work=ver[u].next;
        while(work != NULL){
            if(S[work->key]==1){}
            else if(d[u]+work->weight < d[work->key]){
                d[work->key]=d[u]+work->weight;
            }
            work=work->next;
        }
    }
}
  
int Heap(int *S){
    int i;
    int min=ENORMOUS;
    int u;
   
    for(i=0;i<n;i++){
        if(S[i]==1) continue;
           
        if(d[i]<min){
            min=d[i];
            u=i;
        }
    }
   
    return u;
}
  
int Test_Set(int *S){
    int i;
  
    for(i=0;i<n;i++){
        if(S[i]==0) return 0;
    }
    return 1;
}



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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}

void solve(){
    
    ll n = 5;
    ll a[n+1];
    ll ind;
    for(ll i=1;i<=n;i++){
        cin >> a[i];
        if(a[i] == 0)
            ind = i;
    }
    cout << ind;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<int> ans;
int n;

void dfs(int now, vector<int> &num)
{
    if (now >= n)
    {
        ans.push_back(now);
        return;
    }

    for (int i = 0; i < num.size(); i++)
    {
        dfs(now * 10 + num[i], num);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    cin >> n >> k;
    set<int> tmp;
    vector<int> number; // ???????
    for (int i = 0; i < k; i++)
    {
        int x;
        cin >> x;
        tmp.insert(x);
    }
    for (int i = 0; i < 10; i++)
    {
        if (!tmp.count(i))
        {
            number.push_back(i);
        }
    }

    for (int i = 0; i < number.size(); i++)
    {
        if (number[i] == 0)
            continue;
        dfs(number[i], number);
    }

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

    cout << ans[0] << endl;
}

Measured memory_bytes: 640
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N = I()
A = LI()

A.sort(reverse=True)
# print(A)
# half = math.ceil(len(A)/2)
q, mod = divmod(len(A),2)

if mod == 0:
    ans = A[0]
    for i in range(1,q):
        ans += 2 * A[i]
else:
    ans = A[0]
    for i in range(1,q):
        ans += 2 * A[i]
    ans += A[q]

print(ans)

Measured memory_bytes: 33028
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF = 10000000000000000;

ll n, m, k, a[20001], dp[20001];

int main() {
  scanf("%lld%lld%lld", &n, &m, &k);
  for (ll i = 1; i <= n; i++) scanf("%lld", &a[i]), dp[i] = INF;
  dp[0] = 0;
  for (ll i = 1; i <= n; i++) {
    ll minN = a[i], maxN = a[i], counter = 1;
    for (int j = i - 1; counter <= m; j--) {
      dp[i] = min(dp[i], dp[j] + k + counter * (maxN - minN));
      if (j == 0) break;
      minN = min(minN, a[j]);
      maxN = max(maxN, a[j]);
      counter++;
    }
  }
  printf("%lld\n", dp[n]);
}



Measured memory_bytes: 3032