akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
 
public class Main {
	public void exec() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        Prime p = new Prime();
        int n = Integer.parseInt(br.readLine());
        int[] v = new int[n];
        int max = 0;
        for(int i=0; i<n; i++) {
        	v[i] = Integer.parseInt(br.readLine());
        	if(max < v[i])
        		max=v[i];
        }
        p.checkPrime(10000);
        int countPrime = 0;
        for(int i=0; i<n; i++) {
        	if(p.isPrime(v[i]))
        		countPrime++;
        }
        out.println(countPrime);
        out.flush();
    }

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

class Prime {
	private static final int CAPACITY = 10001;
	private boolean[] isNotPrime = new boolean[CAPACITY];
	private int checkMax = 1;
	private int[] primes = new int[CAPACITY];
	private int ptrPrimes = 0;
	
	public boolean isPrime(int n) {
		if(CAPACITY*CAPACITY <= n) {
			throw new IllegalArgumentException();
		}else if(CAPACITY <= n){
			return checkPrimeSub(n);
		}else{
			return !isNotPrime[n];
		}
	}
	
	public void checkPrime(int target) {
		if(CAPACITY<target) throw new IllegalArgumentException();
		if(target<checkMax) return;
		for(int i=checkMax+1; i<=target; i++) {
			if (checkPrimeSub(i)) {
				primes[ptrPrimes++]=i;
			} else {
				isNotPrime[i]=true;
			}
		}
		checkMax=target;
	}
	
	public boolean checkPrimeSub(int i) {
		boolean isPrime = true;
		int maxPrime = i;
		for(int j=0; j<ptrPrimes; j++) {
			if(maxPrime <= primes[j]){
				break;
			}else if(i % primes[j] == 0) {
				isPrime = false;
				break;
			}else{
				maxPrime = i / primes[j];
			}
		}
		return isPrime;
	}
}

Measured memory_bytes: 30952
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool flag = false;
  if (S.at(2) == S.at(3) and S.at(4) == S.at(5)) flag = true;
  cout << (flag ? YES : NO) << endl;
}

signed main(){
  std::string S;
  std::cin >> S;
  solve(S);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,n) for(ll i=0;i<n;i++)
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n;
    cin>>n;
    ll a[n], z=0;
    map<ll,ll> m;
    forn(i,n){
        cin>>a[i];
        m[a[i]]++;
    }
    map<ll,ll>::iterator it;
    vlli ans(n, 0);
    
    for(it = m.begin(); it != m.end(); it++){
        z += (it->S * (it->S - 1))/2;
    }
    
    forn(i,n){
        ll x=m[a[i]];
        ans[i] = z - (x*(x-1))/2 + ((x-1)*(x-2))/2;
    }
    
    print(ans,0,ans.size());
    cout<<endl;

}

Measured memory_bytes: 14260
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int a[100005],idx[100005];
bool cmp(int x,int y){
	return a[x]<a[y];
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		idx[i]=i;
	}
	sort(idx,idx+n,cmp);
	int cnt=0;
	for(int i=0;i<n;i++){
		if(i%2!=idx[i]%2) cnt++;
	}
	cout<<cnt/2;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	// TLEとれないので答え見た がびーん 過去に解けてたのに....

	n := nextInt()
	s := []rune(next())
	a := 0
	for i := 0; i < 1000; i++ {
		t := []rune(fmt.Sprintf("%03d", i))
		idx := 0
		for j := 0; j < n; j++ {
			if string(s[j]) == string(t[idx]) {
				idx += 1
			}
			if idx == 3 {
				a += 1
				break
			}
		}
	}
	fmt.Fprintln(out, a)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 896
n = int(input())
s=0
num = [int(i) for i in input().split()]
mx = num[0]
mn = num[0]
for i in range(n):
        s = s+num[i]
        if(mx < num[i]):
            mx = num[i]
        if(mn > num[i]):
            mn = num[i]
print("{} {} {}".format(mn,mx,s))


Measured memory_bytes: 6600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

int main() {
  ll a;
  long double b;
  cin >> a >> b;
  ll ans = a * b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	double x1, x2, y1, y2;

	cin >> x1 >> y1 >> x2 >> y2;
	printf("%.10lf\n", sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2)));
	
	return 0;
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define N 101
#define INF 1e9
using namespace std;
int n,g[N][N],ans;
vector<int> V;
 
void calc(){
  int sum=0;
  for(int i=0;i<V.size();i++){
    int mn=INF;
    for(int j=0;j<V.size();j++)if(i!=j) mn=min(mn,g[V[i]][V[j]]);
    sum+=mn;
  }
  ans=max(ans, (V.size()>1)*sum);
}
 
 
set<int> used;
void solve(int pos){
  if(pos==n){calc();return;}
  solve(pos+1);
if(used.count(pos))V.push_back(pos),solve(pos+1),V.pop_back();
}
 
vector<int> G[N];
int can[N];
set<set<int> > S;
void dfs(int pos,int cnt){
  int flg=1,len=G[pos].size();
  used.insert(pos);
  if(S.count(used)){used.erase(pos);return;}
  S.insert(used);
  for(int i=0;i<len;i++) can[G[pos][i]]++;
   
  for(int i=0;i<len;i++){
    int nx=G[pos][i];
    if(!used.count(nx)&&can[nx]==cnt)flg=0,dfs(nx,cnt+1);
  }
  if(flg)solve(0);
  used.erase(pos);
  for(int i=0;i<len;i++) can[G[pos][i]]--;
}
 
 
int main(){
  int m;
  cin>>n>>m;
  for(int i=0,a,b,c;i<m;i++){
    cin>>a>>b>>c;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
    g[a][b]=g[b][a]=c;
  }
   
  for(int i=0;i<n;i++)dfs(i,1);
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 10100
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	int k, s;
	cin >> k >> s;
	ll ans = 0;
	REP(i, k + 1) {
		REP(j, k + 1) {
			if (s - i - j >= 0 && s - i - j <= k)ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define x first
#define y second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define szz(x) (int) (x).size()
#define FOR(i,a,b) for (int i = (a), _for = (b); i < _for; i++)
#define REP(i,n) FOR(i,0,(n))
#define _ << " " <<
const ll MOD = 1000000007ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
inline ll SUB(ll a, ll b) { return a-b >= 0ll ? a-b : a-b+MOD; }
inline ll ADD(ll a, ll b) { return a+b >= MOD ? a+b-MOD : a+b; }
inline ll MUL(ll a, ll b) { return a*b % MOD; }

int n, W;
ll dp[103][100003];
ll w[103], v[103];

ll f(int i, ll j) {
  if (i == 0) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  ll ret = 0;
  if (j - w[i-1] >= 0) ret = max(ret, v[i-1] + f(i-1, j - w[i-1]));
  ret = max(ret, f(i-1, j));
  dp[i][j] = ret;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> W;
  REP(i,n) cin >> w[i] >> v[i];
  memset(dp, -1, sizeof(ll) * 103 * 100003);
  cout << f(n, W) << endl;
}



Measured memory_bytes: 80768
#include <iostream>
#include "stdio.h"
using namespace std;
int main (){
    int a,b;
    int d,r;
    double f;
    cin >> a >>b;
    d = a/b;
    r = a% b;
    f = (double)a / (double) b;
   printf("%d %d %.8lf", d,r,f);
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

vector<int> foo(200001);

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k,n;
    cin>>n>>k;

    int counter = 0;
    rep(i,n)
    {
        int x;cin>>x;
        if(foo[x]==0)counter++;
        foo[x]++;
    }
    if(k>counter){cout<<0<<endl;return 0;}
    sort(all(foo),greater<int>());

    int ans = 0;
    for(size_t i = 0; i<foo.size(); i++ )
    {
        while(i<k)i++;
        ans+=foo[i];
        if(foo[i]==0)break;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M, R; cin >> N >> M >> R;
    vl r(R); REP(i, R) {cin >> r[i]; r[i]--;};
    vvl dist(N, vl(N, LINF));
    REP(i, M){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    REP(i, N) dist[i][i] = 0;
    REP(k, N) REP(i, N) REP(j, N){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    
    vvl ans(1ll << R, vl(R, LINF));
    REP(i, R) ans[0][i] = 0;
    
    queue<PL> q;
    REP(i, R) q.push({0, i});
    
    while(!q.empty()){
        ll state = q.front().ff; ll now = q.front().ss; q.pop();
        REP(i, R){
            if((state >> i) & 1) continue;
            ll nxst = state | (1ll << i);
            if(ans[nxst][i] > ans[state][now] + dist[r[now]][r[i]]){
                ans[nxst][i] = ans[state][now] + dist[r[now]][r[i]];
                q.push({nxst, i});
            }
        }
    }
    ll ansll = LINF;
    REP(i, R) ansll = min(ansll, ans[(1ll << R)-1][i]);
    cout << ansll << endstr;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
using namespace std;

#define MAX_V 1004

struct Edge { int to, cap, rev; };
int m, n, b[500], r[500];
vector< Edge > E[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
  E[from].push_back((Edge){to, cap, E[to].size()});
  E[to].push_back((Edge){from, 0, E[from].size()-1});
}

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a%b);
}

void make() {
  rep(i, MAX_V) {
    E[i].clear();
  }
  rep(i, m) {
    rep(j, n) {
      if(gcd(b[i], r[j]) > 1) {
	add_edge(i, m+j, 1);
      }
    }
  }
  rep(i, m) add_edge(m+n, i, 1);
  rep(j, n) add_edge(m+j, m+n+1, 1);
}

int dfs(int pos) {
  if(pos == m+n+1) {
    return 1;
  }
  used[pos] = true;
  rep(i, E[pos].size()) {
    Edge &e = E[pos][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to);
      if(d > 0) {
	e.cap -= d;
	E[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

void solve() {
  make();
  int ans = 0;
  while(true) {
    fill(used, used+MAX_V, false);
    int res = dfs(m+n);
    if(res == 0) break;
    ++ans;
  }
  cout << ans << endl;
}

main() {
  while((cin >> m >> n) && (m || n)) {
    rep(i, m) cin >> b[i];
    rep(i, n) cin >> r[i];
    solve();
  }
}

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

abcd = []
for i in range(q):
    abcd.append(tuple(map(int, input().split())))

ans = 0


def solve(A):
    if len(A) >= n + 1:
        global ans
        now = 0
        for a, b, c, d in abcd:
            if A[b] - A[a] == c:
                now += d
        ans = max(ans, now)
        return
    for i in range(A[-1], m + 1):
        solve(A + [i])


solve([1])
print(ans)


Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
int a[maxn];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    if(a[n]-a[1]>1)
    {
        puts("No");
        exit(0);
    }
    else if(a[n]-a[1]==1)
    {
        int now=1;
        while(a[now]==a[1]) ++now;
        int tmp=a[n];
        tmp-=(now-1);
        if(tmp>0&&(n-now+1)%tmp==0) puts("Yes");
        else puts("No");
    }
    else
    {
        if(a[n]==n-1)
        {
            puts("Yes");
            exit(0);
        }
        if(n%a[n]==0) puts("Yes");
        else puts("No");
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    string s, t;
    string ans;

    cin >> n >> s >> t;

    for (int i = 0; i < s.size(); i++) {
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
  { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 1e9 + 7;
class {
 public:
  vector<int> V[maxn];
  i64 pw(i64 a, i64 b) {
    i64 c = 1;
    while (b) {
      if (b & 1)
        c = c * a % MOD;
      a = a * a % MOD;
      b >>= 1;
    }
    return c;
  }
  i64 P;
  i64 pw2[maxn];
  int n;
  void solve() {
    cin >> n;
    pw2[0] = 1;
    for (int i = 1; i < maxn; ++i) pw2[i] = pw2[i - 1] * 2 % MOD;
    P = 0;
    for (int i = 1; i < n; ++i) {
      int u, v;
      cin >> u >> v;
      V[v].push_back(u);
      V[u].push_back(v);
    }
    dfs(1, 1);
    P = P * pw(pw2[n], MOD - 2) % MOD;
    cout << (P % MOD + MOD) % MOD;
  }
  i64 sz[maxn];
  void dfs(int u, int f) {
    sz[u] = 1;
    for (int v : V[u]) {
      if (f != v) {
        dfs(v, u);
        sz[u] += sz[v];
      }
    }
    if (V[u].size() == 1)
      return;
    i64 szfa = n - sz[u];
    i64 res = pw2[n - 1] - 1;
    for (int v : V[u]) {
      if (v == f) {
        res = res - (pw2[szfa] - 1);
      } else {
        res = res - (pw2[sz[v]] - 1);
      }
      res = res % MOD;
    }
    P = (P + res) % MOD;
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 21248
import sys
from io import StringIO
import unittest


def recursive(base, lunluns):

    lunluns.append(base)

    # 想定される最大値を超える場合何もせず戻る（再帰の終わり)
    if len(base) > 10 or len(base) > 9 and int(base[0]) > 3:
        return
    target = int(base[-1])

    if target is 0:
        add_num = ["0", "1"]
    elif target is 9:
        add_num = ["8", "9"]
    else:
        add_num = [str(target - 1), str(target), str(target+1)]

    for i in add_num:
        recursive("".join(base + str(i)), lunluns)


def resolve():

    k = int(input())

    # 1桁は全てルンルンNoなので、初期値に設定(0も加えておくことで、kと数え方を合わせる)
    lunluns = ["0"]

    # 再帰的処理
    for i in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
        recursive(i, lunluns)

    lunluns = list(map(int, lunluns))
    lunluns.sort()

    print(lunluns[k])


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """15"""
        output = """23"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """13"""
        output = """21"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """100000"""
        output = """3234566667"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

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

using namespace std;

#define pb push_back
#define mp make_pair
#define NL endl
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1e9+7
#define FOR(i,j,n)    for(ull i=j;i<n;i++)
#define RFOR(i,j,n)    for(ull i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    fastIO;
    string s;
    cin>>s;
    FOR(i,0,s.size()) cout<<'x';
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
class ListOfTopThreeHills
{
	static void Main(string[] args)
	{
		List<int> inputList = new List<int>();
		string line = null;
		int lineCount = 0;
		do {
			line = Console.ReadLine();
			if (string.IsNullOrEmpty(line))
			{
				break;
			}
			int inputNum = 0;
			try
			{
				inputNum = Convert.ToInt32(line);
			}
			catch (FormatException)
			{
				return;
			}
			inputList.Add(inputNum);
			lineCount++;
			if (lineCount == 10)
			{
				break;
			}
		} while (true);
		// 引数リストソート
		inputList.Sort();
		// 降順に変更
		inputList.Reverse();
		// 上位3つを出力
		for (int i = 0; i < 3; i++)
		{
			Console.WriteLine(inputList[i]);
		}
		return;
	}
}

Measured memory_bytes: 5772
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static char[] s;
	public static void main(String[] args) throws IOException{
		Scanner in = new Scanner(System.in);
		while(true){
			s = in.next().toCharArray();
			int idx = in.nextInt();
			if(s[0] == '0') break;
			Node base = new Node(1);
			cur = 0;
			while(cur < s.length){
				base.edge.add(gen());
			}
//			for(int i=0; i<100; i++){
//				int val = (int)base.dfs(i);
//				if(val >= 0) break;
//				System.out.print(res);
//			}
//			System.out.println();
			System.out.println(base.dfs(idx) < 0 ? res : '0');
		}
	}
	
	public static char res;
	public static int cur;
	public static Node gen(){
		if(Character.isDigit(s[cur])){
			int num = 0;
			while(Character.isDigit(s[cur])){
				num *= 10;
				num += s[cur++]-'0';
			}
			if(Character.isUpperCase(s[cur])){
				return new Node(s[cur++]+"", num);
			}
			cur++;
			Node node = new Node(num);
			while(cur < s.length && s[cur] != ')')
				node.edge.add(gen());
			cur++;
			return node;
		}else{
			return new Node(getStr(), 1);
		}
	}
	
	public static String getStr(){
		StringBuilder sb = new StringBuilder();
		while(cur < s.length && Character.isUpperCase(s[cur]))
			sb.append(s[cur++]);
		return sb.toString();
	}
}

class Node{
	ArrayList<Node> edge;
	String str;
	int num;
	public Node(int num){
		edge = new ArrayList<Node>();
		this.num = num;
	}
	
	public Node(String str, int num){
		this.str = str;
		this.num = num;
	}
	
	public String toString(){
		if(str != null){
			return (num>1?num:"")+str;
		}
		StringBuilder sb = new StringBuilder();
		if(num>1) sb.append(num+"<");
		for(Node v: edge) sb.append(v);
		if(num>1) sb.append('>');
		return sb.toString();
	}
	
	public long dfs(long sidx){
		// sidx : ??????????????¢
		if(str != null){
			if(sidx <= str.length()*num-1){
				sidx = sidx % str.length();
				Main.res = str.charAt((int)sidx);
				return -1;
			}
			return sidx-str.length()*num;
		}
		long origin = sidx;
		for(Node v: edge){
			sidx = v.dfs(sidx);
			if(sidx<0) return sidx;
		}
		long len = origin - sidx;
		if((origin+len)/len <= num){
			return dfs(origin % len);
		}
		return origin - num*len;
	}
}

Measured memory_bytes: 26508
#import sys
#input = sys.stdin.readline

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

dp = [float("inf") for i in range(n)]
dp[0] = 0
dp[1] = abs(a[1] - a[0])

for i in range(n-2):
    for j in range(k):
        if i+1-j >= 0:
            dp[i+2] = min(dp[i+2], dp[i+1-j] + abs(a[i+2] - a[i+1-j]))

print(dp[-1])

Measured memory_bytes: 57184
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N, K;
    vector<int> score(3);
    string T;
    cin >> N >> K >> score[0] >> score[1] >> score[2] >> T;
    auto get_num = [](char ch) {
        if(ch == 'r')   return 0;
        else if(ch == 's')  return 1;
        else    return 2;
    };
    vector<int> cabinet(N);
    for(int i = 0; i < N; ++i)  cabinet[i] = get_num(T[i]);

    vector<vector<int>> dp(N, vector<int>(3, 0));
    auto get_result = [](int x, int y) {
        int res = y - x;
        return res < 0 ? res + 3 : res;
    };
    for(int i = 0; i < N; ++i){
        if(i - K < 0){
            for(int j = 0; j < 3; ++j){
                if(get_result(j, cabinet[i]) == 1)  dp[i][j] = score[j];
            }
        }
        else{
            for(int nxt = 0; nxt < 3; ++nxt){
                int total = 0;
                if(get_result(nxt, cabinet[i]) == 1)    total += score[nxt];
                for(int prev = 0; prev < 3; ++prev){
                    if(nxt == prev) continue;
                    total += dp[i - K][prev];
                    chmax(dp[i][nxt], total);
                    total -= dp[i - K][prev];
                }
            }
        }
    }
    
    int ans = 0;
    for(int i = N - K; i < N; ++i){
        ans += max({dp[i][0], dp[i][1], dp[i][2]});
    }
    cout << ans << endl;
}

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

int main(){
	int n;
	string s;
	cin >> n >> s;
	
	int e = 0;
	for(int i=0; i<n; i++) if(s[i]=='E') e++;
	
	int w = 0, ans = 1e9;
	for(int i=0; i<n; i++){
		if(s[i]=='E') e--;
		if(i!=0 && s[i-1]=='W') w++;
		//cout << e << " + " << w << " = " << e + w << endl;
		ans = min(ans, e + w);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;
int aa[1000][1000]={};
int main()
{
    int  i=0,j=0,n=0,a1=0,a2=0,a3=0,mini=0,maxx=0;
    char s1;
    while(1){
    cin >> n;
    if(n==0)break;
    maxx=0;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            cin >> s1;
            if(s1=='.'){
                aa[i][j]=1;
            }
            if(s1=='*'){
                aa[i][j]=0;
            }
        }
    }
       /* for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cout << aa[i][j];
            }
            cout <<endl;
        }*/
        for(i=1;i<n;i++){
            for(j=1;j<n;j++){
                if(aa[i][j]==1){
                    a1=aa[i-1][j-1];
                    a2=aa[i-1][j];
                    mini = min(a1,a2);
                    a3=aa[i][j-1];
                    mini = min(mini,a3);

                    if(mini==0){
                        aa[i][j]=1;
                    }
                    else{
                        aa[i][j]=mini+1;
                        if(maxx<aa[i][j])maxx=aa[i][j];
                    }
                }
            }
        }
        cout << maxx << endl;

    }
}

Measured memory_bytes: 5064
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define pii     pair<ll,ll>
#define vi      vector<ll>
#define mp      make_pair
#define pb      push_back
#define F       first
#define S       second
#define pf(n)   printf("%lld\n",n)
#define sf(n)   scanf("%lld",&n)
#define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)  x.begin(),x.end()
#define ms(n,i) memset(n,i,sizeof n)
#define sz(x)   (ll)x.size()
#define pi      3.141592653589793238
#define hell    1000000007
#define hell2   1000000009
#define endl    '\n'
#define inf     1e18
#define N       100005

ll n,m,deg[N],dp[N];
vi v[N];

void solve()
{
    ll i,j;
    queue<pii> q;
    for(i=1;i<=n;i++){
        if(deg[i]==0)q.push({i,0}),dp[i]=0;
    }
    while(!q.empty()){
        pii k=q.front();
        q.pop();
        for(auto j:v[k.F]){
            deg[j]--;
            dp[j]=max(dp[j],k.S+1);
            if(deg[j]==0)q.push({j,dp[j]});
        }
    }
    ll maxi=0;
    for(i=1;i<=n;i++){
        maxi=max(maxi,dp[i]);
    }
    cout<<maxi<<endl;
}
int main()
{   
    ll i,j,k,x,y;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>x>>y;
        v[x].pb(y);
        deg[y]++;
    }
    solve();
}

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


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

    long answ;
    answ = 1;


    for(int i=0;i<N;i++){
        answ*=(i+1);
        answ%=1000000007;
    }

    cout << answ << endl;


}



Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut g = vec![vec![]; n];
    for k in 0..(n - 1) {
        let a = it.next().unwrap().parse::<usize>().unwrap() - 1;
        let b = it.next().unwrap().parse::<usize>().unwrap() - 1;
        g[a].push((b, k));
        g[b].push((a, k));
    }
    let mut q = vec![];
    let mut parent = vec![(0, 0); n];
    let mut depth = vec![0; n];
    let mut stack = vec![0];
    while let Some(v) = stack.pop() {
        q.push(v);
        if let Some(k) = g[v].iter().position(|u| u.0 == parent[v].0) {
            g[v].swap_remove(k);
        }
        for &(u, k) in g[v].iter() {
            parent[u] = (v, k);
            depth[u] = depth[v] + 1;
            stack.push(u);
        }
    }
    let m: usize = it.next().unwrap().parse().unwrap();
    let mut mask = vec![0];
    for _ in 0..m {
        let a = it.next().unwrap().parse::<usize>().unwrap() - 1;
        let b = it.next().unwrap().parse::<usize>().unwrap() - 1;
        let mut x = a;
        let mut y = b;
        let mut z = 0usize;
        while x != y {
            if depth[x] <= depth[y] {
                z |= 1 << parent[y].1;
                y = parent[y].0;
            } else {
                z |= 1 << parent[x].1;
                x = parent[x].0;
            }
        }
        let mut next = mask.clone();
        for mask in mask.into_iter() {
            next.push(mask | z);
        }
        mask = next;
    }
    let mut ans = 0i64;
    for (i, bit) in mask.iter().enumerate() {
        let c = i.count_ones();
        let sign = if c % 2 == 0 {1} else {-1};
        ans += sign * (1usize << (n - 1 - bit.count_ones() as usize)) as i64;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 16680
#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;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 13;
const int m_max =1004;
const int joutai_max = 10000;

struct key{
    int cost;
    int ake;
};

signed main(){
    int n,m;
    cin >> n >> m;
    key K[m];
    int beki[14];
    beki[0] = 1;
    REP(i,13) beki[i+1] = beki[i] * 2;
    REP(i,m){
        int a,b;
        cin >> a >> b;
        K[i].cost = a;
        K[i].ake = 0;
        REP(j,b){
            int tmp;
            cin >> tmp;
            tmp --;
            K[i].ake += beki[tmp];
        }
    }

    int dp[m_max][joutai_max];
    REP(i,m + 1) REP(j,joutai_max) dp[i][j] = INF;
    dp[0][0] = 0;

    REP(i,m){
        REP(j,beki[n]){
            dp[i + 1][j] = min(dp[i][j],dp[i][j & (~K[i].ake)] + K[i].cost);
        }
    }
    if(dp[m][beki[n]-1] == INF){
        cout << - 1 << endl;
        return 0;
    }
    cout << dp[m][beki[n] - 1] << endl;

}

Measured memory_bytes: 78464
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var r =Console.ReadLine().Split();
    var N = int.Parse(r[0]);
    var M = int.Parse(r[1]);
    var zennbu = Console.ReadLine().Split();
    int yaru = 0;
    for(var i = 0;i<M;i++){
      yaru +=int.Parse(zennbu[i]);
    }
    if(N-yaru <0){
      Console.WriteLine("-1");
    }
    else{
      Console.WriteLine(N-yaru);
    }
   
  }
}

Measured memory_bytes: 19268
// B - 0 or 1 Swap

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

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

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

	sort(ans, ans+N);

	int mismatch = 0;
	for (int i=0; i<N; i++) {
		if (p[i] != ans[i]) mismatch++;
	}

	if (mismatch == 0 || mismatch == 2) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {

	body, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Println(err)
	}
	scanner := bufio.NewScanner(strings.NewReader(string(body)))
	scanner.Split(bufio.ScanWords)
	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading input:", err)
	}
	inputs := make([]int, 0)
	for scanner.Scan() {
		word, _ := strconv.Atoi(scanner.Text())
		inputs = append(inputs, word)
	}

	alice := make([]int, 0)
	bob := make([]int, 0)

	cards := inputs[1:]
	sort.Sort(sort.Reverse(sort.IntSlice(cards)))
	turn := 1
	for i := 0; i < len(cards); i++ {
		if turn%2 == 1 {
			alice = append(alice, cards[i])
		} else {
			bob = append(bob, cards[i])
		}
		turn++
	}

	aliceSum := 0
	for _, i := range alice {
		aliceSum = aliceSum + i
	}
	bobSum := 0
	for _, i := range bob {
		bobSum = bobSum + i
	}

	fmt.Println(aliceSum - bobSum)
}


Measured memory_bytes: 640
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S;

LL ans = 0;

void solve(){
	int N = S.size();
	int remain_p = N/2;
	int numof_p = 0;
	int numof_g = 0;
	for(int i=0;i<N;i++){
		if(S[i]=='p') numof_p++;
		if(S[i]=='g') numof_g++;
	}
	//相手のグーに合わせてパーを最大限出す
	//
	if(numof_g>=remain_p){
		ans = remain_p - numof_p;
	}else{
		ans = numof_g - (N-remain_p);
	}
}
 
int main(){
    cin >> S;
 
    solve();

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

Measured memory_bytes: 512
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    h,n=MI()
    a = LI()
    s = sum(a)
    if h-s<=0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 14396
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
    s = input()
    if s == "AC":
        ac += 1
    elif s == "WA":
        wa += 1
    elif s == "TLE":
        tle += 1
    elif s == "RE":
        re += 1

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

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

using namespace std;
typedef long long ll;

ll MOD = 1000000007;

ll mypow(ll x, ll n) {
	ll ans = 1;
	while(n) {
		if(n & 1) ans = (ans * x) % MOD;
		x = (x * x) % MOD;
		n>>=1;
	}
	return ans;
}

int main(int, char**) {
	int n, k;
	cin >> n >> k;
	vector<long long> vec(k);
	ll ret = 0;
	for (int i=k; i>0; i--) {
		int c = k/i;
		ll now = mypow(c, n);
		for (int j=2; j*i<=k; j++) {
			now = (now - vec[j*i-1])%MOD;
			if (now<0) now += MOD;
		}
		vec[i-1] = now;
		ret = (ret + i%MOD * now%MOD)%MOD;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4048
import java.io.File

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

var n: Int = 0

fun main(args: Array<String>) {
    val (n, m) = readInts()
    println(Math.max(0, (n * (n - 1) / 2)) + Math.max(0, m * (m - 1) / 2))
}


Measured memory_bytes: 37924
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;
	cin>>h>>w;
	vector<vector<char>> g(h+2,vector<char>(w+2,'#'));
	FOR(i,1,h+1){
		FOR(j,1,w+1){
			cin>>g[i][j];
		}
	}
	vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
	auto bfs=[&](Pi s,Pi go){
		queue<Pi> que;
		vector<vector<int>> dist(h+1,vector<int>(w+1,INF));
		que.push(s);
		dist[s.fi][s.se]=0;
		while(!que.empty()){
			Pi now=que.front();
			que.pop();
			rep(i,4){
				int nx=now.fi+dx[i],ny=now.se+dy[i];
				if(1<=nx && nx<=h && 1<=ny && ny<=w){
					if(g[nx][ny]!='#' && dist[nx][ny]==INF){
						dist[nx][ny]=dist[now.fi][now.se]+1;
						que.push(Pi(nx,ny));
					}
				}
			}
		}
		return dist[go.fi][go.se];
	};
	int ans=0;
	FOR(i,1,h+1)FOR(j,1,w+1){
		FOR(k,1,h+1)FOR(l,1,w+1){
			if(g[i][j]=='#' || g[k][l]=='#'){
				continue;
			}
			int ret=bfs(Pi(i,j),Pi(k,l));
			//cout<<ret<<endl;
			if(ret!=INF) chmax(ans,ret);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] vs, int[] cs) {
    int ans = 0;
    foreach (v, c; vs.zip(cs)) {
        if (v > c) ans += v - c;
    }
    return ans;
}

void main() {
    readint;
    auto vs = readints;
    auto cs = readints;
    writeln(calc(vs, cs));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	int S[2000], T[2000];
	rep(i, N) cin >> S[i];
	rep(i, M) cin >> T[i];

	ll mod = 1e9 + 7;
	ll dp[4001];

	rep(i, N + M + 1) dp[i] = 1;
	for (int i = N; i > 0; i--) {
		for (int j = i; j < i + M; j++) {
			if ((i & 7) || (j & 7)) {
				if (S[N - i] == T[j - i]) dp[j] = (dp[j - 1] + dp[j + 1]) % mod;
				else dp[j] = (dp[j - 1] + dp[j + 1] - dp[j]) % mod;
			}
			else {
				if (S[N - i] == T[j - i]) dp[j] = dp[j - 1] + dp[j + 1];
				else dp[j] = dp[j - 1] + dp[j + 1] - dp[j];
			}
		}
	}
	co((dp[M] % mod + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> cnt(n,0);
  int a,b;
  REP(i,m){
    cin>>a>>b;
    a--;b--;
    cnt[a]++;cnt[b]++;
  }
  REP(i,n){
    cout<<cnt[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby

N = gets.chomp.to_i

$table = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
]

1.upto(N){|i|
  a_i = gets.chomp.to_i
  1.upto(a_i){|j|
    x_i_j,  y_i_j = gets.chomp.split(" ").map(&:to_i)
    $table[i][j] = [x_i_j, y_i_j]
    #puts "table[#{i}][#{j}] = (#{x_i_j}, #{y_i_j})"
  }
}

# people = [dummy, 1,0,0...]
def isGood( people )
  i = 1;
  while i < people.length
    if people[i] == 1
      #puts"people[#{i}] = 1"
      1.upto($table[i].length-1){|j|
        #puts "#{i}, #{j}"
        t = $table[i][j]
        #puts "table[#{i}]= #{t.class}"
        #puts t[0]
        x, y = t
        #puts "x, people[x],y = #{x}, #{people[x]}, #{y}"
        return false if people[x] != y
      }

    end
    i+=1
  end

  return true
end

max = 0

(2**N - 1).downto(0){|i|
  people = i.to_s(2).split("").map(&:to_i)
  while people.length != N
    people.unshift(0)
  end
  people.unshift("d")

  if true == isGood(people)
      c = people.count{|e| e == 1}
      max = c if max < c
  end
}

puts max


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

int main() {
    int a;
    cin >> a;
    if(a==25) cout<<"Christmas"<<endl;
  else if(a==24)cout<<"Christmas Eve"<<endl;
  else if(a==23)cout<<"Christmas Eve Eve"<<endl;
  else if(a==22)cout<<"Christmas Eve Eve Eve"<<endl;
}
 


Measured memory_bytes: 256
import math
D,G = map(int,input().split())
pc = list(list(map(int,input().split()))for i in range(D))
ans = float('inf')
for i in range(2**D):    
    score = 0
    AC = 0
    b = bin(2**D+i)[3:]
    for j in range(D):
        if b[j] == "1":
            score += pc[j][1]+pc[j][0]*(j+1)*100
            AC += pc[j][0]
        else:
            hoge = j
    if G <= score + pc[hoge][0]*(hoge+1)*100:
        a = max(0,math.ceil((G-score)/((hoge+1)*100)))
        score = G
        AC+= a
    if score >= G:
        ans = min(ans,AC)
print(ans)

Measured memory_bytes: 3188