akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#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 rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e8;

void solve()
{
  int n,m; cin>>n>>m;
  vector<vector<int>> g(n, vector<int>(n, inf));
  rep(i,n) g[i][i]=0;
  vector<int> a(m, 0);
  vector<int> b(m, 0);
  vector<int> c(m, 0);
  for (int i=0; i<m; i++) {
    cin>>a[i]>>b[i]>>c[i];
    a[i]--; b[i]--;
    g[a[i]][b[i]] = min(c[i], g[a[i]][b[i]]);
    g[b[i]][a[i]] = min(c[i], g[b[i]][a[i]]);
  }

  for (int k=0; k<n; k++) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
      }
    }
  }

  int ans=m;
  for (int i=0; i<m; i++) {
    if (g[a[i]][b[i]]==c[i]&&g[b[i]][a[i]]==c[i]) ans--;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
num = int(input())
base = []
count = 0
t = -10**9

for i in range(num):
  temp = list(map(int,input().split()))
  base.append([temp[0]-temp[1],temp[0]+temp[1]])
  
base.sort(key=lambda x:x[1])

for temp in base:
  if t <= temp[0]:
    count = count + 1
    t = temp[1]
    
print(count)

Measured memory_bytes: 21800
#include <iostream>
#include<stdio.h>
#include<string.h>
#define maxn 100010
#define ll long long
using namespace std;

int w[maxn];
ll v[maxn],dp[maxn];
int n,ww;

int main()
{
    scanf("%d%d",&n,&ww);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&w[i]);
        scanf("%d",&v[i]);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=ww;j>=w[i];j--)
            dp[j]=max(dp[j],1ll*dp[j-w[i]]+v[i]);
    }
    printf("%lld\n",dp[ww]);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

template <class T>
class LazySegTree{
public:
    vector<T> arr, lazy;
    T ini;
    uint n;
    LazySegTree(int N, T ini_){
        ini=ini_;
        n=1;
        while(n<N)n<<=1u;
        arr.assign(2*n-1, ini);
        lazy.assign(2*n-1, 0);
    }

    void add(uint s, uint t, T val){
        __add(s,t,0,0,n, val);
    }

    void eval(){
        __eval(0,0,n,0);
    }
private:
    void __add(uint s, uint t, uint k, uint l, uint r, T val){
        if(t<=l || s>=r)return;
        if(s<=l && t>=r){
            lazy[k] += val;
            return;
        }
        __add(s,t,2*k+1,l,(l+r)/2, val);
        __add(s,t,2*k+2, (l+r)/2, r, val);
    }

    void __eval(uint k, uint l, uint r, T val){
        val += lazy[k];
        if(k >= n-1){
            arr[k] += val;
            return;
        }
        __eval(2*k+1,l,(l+r)/2, val);
        __eval(2*k+2, (l+r)/2, r, val);
    }
};

const string YES = "YES";
const string NO = "NO";

void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b){
    LazySegTree<LL> lst(N, 0);
    rep(i, M){
        LL c = min(a[i], b[i]);
        LL d = max(a[i], b[i]);
        lst.add(c-1, d-1, 1);
    }
    lst.eval();
    rep(i, N-1){
        if(lst.arr[lst.n-1+i]%2==1){
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(M);
    std::vector<long long> b(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, M, std::move(a), std::move(b));
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int t = (h2-h1)*60 + m2-m1;
  cout << max(0, t-k) << endl;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n;
	cin>>n;
	vl a(n), b(n);
	rep(i, n) cin>>a[i];
	rep(i, n) cin>>b[i];
	ll sa = 0, sb = 0;
	rep(i, n) sa += a[i];
	rep(i, n) sb += b[i];
	if(sa>sb){
		cout<<"No"<<endl;
		return 0;
	}
	ll t = sb-sa;
	rep(i, n){
		if(a[i]<b[i]) t -= (b[i]-a[i]+1)/2;
	}
	if(t<0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 384
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        getAns(n, s);
    }
    static void getAns(int n, string s)
    {
        var s1 = n - s.Replace("1", "").Length;
        var r0 = new int[n];
        var r1 = new int[n];
        var r0mod = s1 - 1;
        var r1mod = s1 + 1;
        r1[0] = 1 % r1mod;
        if (r0mod != 0)
        {
            r0[0] = 1 % r0mod;
            for (int i = 1; i < n; i++)
            {
                r0[i] = (r0[i - 1] * 2) % r0mod;
                r1[i] = (r1[i - 1] * 2) % r1mod;
            }
        }
        else
        {
            for (int i = 1; i < n; i++)
                r1[i] = (r1[i - 1] * 2) % r1mod;
        }
        var smr0 = 0;
        var smr1 = 0;
        if (r0mod != 0)
        {
            for (int i = 0; i < n; i++)
            {
                if (s[n - 1 - i] == '1')
                {
                    smr0 += r0[i];
                    smr0 %= r0mod;
                    smr1 += r1[i];
                    smr1 %= r1mod;
                }
            }
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                if (s[n - 1 - i] == '1')
                {
                    smr1 += r1[i];
                    smr1 %= r1mod;
                }
            }
        }
        var res = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '1')
            {
                if (r0mod != 0)
                {
                    var targ = smr0 - r0[n - 1 - i];
                    if (targ < 0) targ += r0mod;
                    targ %= r0mod;
                    res = f(targ) + 1;
                }
                else
                {
                    res = 0;
                }
            }
            else
            {
                var targ = smr1 + r1[n - 1 - i];
                targ %= r1mod;
                res = f(targ) + 1;
            }
            Console.WriteLine(res );
        }
    }
    static int f(long a)
    {
        var count = 0;
        var p = a;
        while (p > 0)
        {
            p %= bitCount((ulong)p);
            count++;
        }
        return count;
    }
    static int bitCount(ulong bits)
    {
        bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
        bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
        bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
        bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
        bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
        return (int)(bits & 0x00000000ffffffff) + (int)(bits >> 32);
    }
}


Measured memory_bytes: 31080
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#define MIN 100000
using namespace std;
int main()
{
    int a[6];
    int flag=0,ans;
    for(int i=1; i<6; i++)
    {
        cin>>a[i];
        if(i>1)if(a[i]!=a[i-1])flag=1;
    }
    if(!flag)
    {
        if(a[1]%10==0){
            cout<<a[1]*5<<endl;
        }
        else
        {
            int rem=a[1]%10;
            int add=10-rem;
            a[1]=a[1]+add;
            int m=a[1]*4;
            ans=m+a[2];
            cout<<ans;
            return 0;
        }
    }

    else if(flag)
    {
        int sum=0,ANS = MIN;
        for(int turn=1; turn<6; turn++)
        {
            swap(a[turn],a[5]);
            for(int i=1; i<5; i++)
            {
                int n=a[i];
                if(n%10==0)sum+=n;
                else{
                    int rem=n%10;
                    int add=10-rem;
                    n=n+add;
                    sum+=n;
                }
            }
            sum+=a[5];
            //cout<<sum<<endl;
            ANS=min(ANS,sum);
            swap(a[turn],a[5]);
            sum=0;
        }
        cout<<ANS<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S  = sc.next();
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList <String>List = new ArrayList<>();
        List.add("A");
        List.add("T");
        List.add("G");
        List.add("C");
        int num=0;
        for(int i=0;i<S.length();i++){
            char s = S.charAt(i);
            if(List.contains(String.valueOf(s))==true){
                num+=1;
                list.add(num);
            }
            else{
                num=0;
                list.add(num);
            }
        }
        System.out.println(Collections.max(list));
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	string c;
	cin >> c;

	if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u")cout << "vowel\n";
	else cout << "consonant\n";
	

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int N,K,X,Y;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N<=K){
		printf("%d",X*N);
	}
	else if(N>K){
		printf("%d",K*X+(N-K)*Y);
	}
	return 0;
}

Measured memory_bytes: 128
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

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

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

int main () {
    int n, r;
    cin >> n >> r;
    if (n >= 10) cout << r << endl;
    else cout << r + (100*(10 - n)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int tot;
int a1, a2, n;
vector<int>v1, v2;
bool vis[10];
void dfs(vector<int>v, vector<int>v1, vector<int>v2) {
	if (a1 && a2) return;
	if (v.size() == n) tot++;
	if (v == v1) { a1 = tot; return; }
	if (v == v2) { a2 = tot; return; }
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			v.push_back(i);
			vis[i] = 1;
			dfs(v,v1,v2);
			vis[i] = 0;
			v.pop_back();
		}
	}
}
int main() {
	cin >> n;
	int k;
	vector<int>v1, v2;

	for (int i = 0; i < n; i++) { cin >> k; v1.push_back(k); }
	for (int i = 0; i < n; i++) { cin >> k; v2.push_back(k); }
	vector<int>v;
	dfs(v,v1,v2);
	if (v1 == v2) cout << 0;
	else
	cout << abs(a1 - a2);
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    swap(A, B);
    swap(A, C);
    cout << A << " " << B << " " << C << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define RREP(i, n) for(int i=0; i>(int)(n); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
typedef long long ll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return 1;}return 0;}

using namespace std;

double dp[3000][3000];
double p[3000];

int main(void)
{
	int N;
	cin >> N;
	REP(i, N){
		cin >> p[i];
	}
	dp[0][0] = 1.0;
	REP(i, N){
		REP(k, i+1){
			dp[i+1][k+1] += dp[i][k]*p[i];
			dp[i+1][k] += dp[i][k]*(1-p[i]);
		}
	}
	double ans = 0.0;
	for(int i=(N+1)/2; i<=N; i++){
		ans += dp[N][i];
	}
	cout << fixed << setprecision(10) << ans << "\n";
}


Measured memory_bytes: 68992
// AOJ 2249: Road Construction
// 2017.11.15 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 16010
typedef struct { int t, node, c; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && (que[l].t < que[i].t ||
		que[l].t == que[i].t && que[l].c < que[i].c)) min = l; else min = i;
	if (r < qsize && (que[r].t < que[min].t ||
		que[r].t == que[min].t && que[r].c < que[min].c)) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

int deq(int *n, int *t, int *c)
{
	if (qsize == 0) return 0;
	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
	return 1;
}

void enq(int n, int t, int c)
{
	int i, min;

	i = qsize++;
	que[i].node = n, que[i].t = t, que[i].c = c;
	while (i > 0 && (que[min = PARENT(i)].t > que[i].t ||
		   que[min].t == que[i].t && que[min].c > que[i].c)) {
		QUE tt = que[i]; que[i] = que[min]; que[min] = tt;
		i = min;
	}
}

#define INF 0x55555555
#define TOSIZE 100
typedef struct { int len, lim, *to, *d, *c; } TBL;
TBL *tbl; char *visited; int size;

int dijkstra(int start)
{
	int i, s, e, c, d, ans = 0;
	TBL *tp;

	qsize = 0;
	memset(visited, 0, sizeof(char)*size);
	enq(start, 0, 0);
	while(deq(&s, &d, &c)) {
//		if (s == goal) break;
		if (visited[s]) continue;
		visited[s] = 1;
		ans += c;
		for (tp = tbl+s, i = 0; i < tp->len; i++) {
			e = tp->to[i];
			if (visited[e]) continue;
			enq(e, d + tp->d[i], tp->c[i]);
		}
	}
	return ans;
}


char buf[40], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

void checkMem(TBL *p)
{
	int *to;
	if (p->len < p->lim) return;
	to = calloc(2 * p->lim + 2, sizeof(int));
	memcpy(to, p->to, p->lim * sizeof(int));
	p->lim *= 2;
	free(p->to);
	p->to = to;
}

int main()
{
	int n, m, i, k, u, v, d, c;
	TBL *tp;

	while (fgets(p=buf, 40, stdin) && *p != '0') {
		size = n = getint(), p++, m = getint();

		tbl = calloc(size+2, sizeof(TBL));
		visited = calloc(size+2, sizeof(char));
		for (i = 0; i < size; i++) {
			tbl[i].len = 0, tbl[i].lim = TOSIZE;
			tbl[i].to = calloc(TOSIZE+2, sizeof(int));
			tbl[i].c = calloc(TOSIZE+2, sizeof(int));
			tbl[i].d = calloc(TOSIZE+2, sizeof(int));
		}
		for (i = 0; i < m; i++) {
			fgets(p=buf, 40, stdin);
			u = getint()-1, p++, v = getint()-1, p++, d = getint(), p++, c = getint();
			tp = tbl+u; //checkMem(tp);
			k = tp->len, tp->to[k] = v, tp->d[k] = d, tp->c[k] = c, tp->len++;
			tp = tbl+v; //checkMem(tp);
			k = tp->len, tp->to[k] = u, tp->d[k] = d, tp->c[k] = c, tp->len++;
		}
		printf("%d\n", dijkstra(0));

		for (i = 0; i < size; i++) free(tbl[i].d), free(tbl[i].c), free(tbl[i].to);
		free(visited), free(tbl);
	}
	return 0;
}

Measured memory_bytes: 12868
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    a.sort()
    a_max=a[-1]
    b_max=-1
    for i in range(n-1):
        if b_max<min(a[i],a_max-a[i]):
            b_max=a[i]

    print(a_max,b_max)

if __name__=="__main__":
    main()

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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

template<class T>
inline bool change_max(T&a, const T&b){
  if(b > a){
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool change_min(T&a, const T&b){
  if(a > b){
    a = b;
    return true;
  }
  return false;
}


int main(){
  string s; cin >> s;
  int n = static_cast<int>(s.size());
  for(int i = 0; i < n; ++i){
    if(i % 2 == 0 && s[i] == 'L'){
      cout << "No\n"; return 0;
    }
    if(i % 2 == 1 && s[i] == 'R'){
      cout << "No\n"; return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[1001];
  char *w[1001]={0};
  int c[1000]={1};
  int max,mi,len,li,i,j;
  fgets(s,1000,stdin);
  w[0]=strtok(s," ");
  mi=0;
  max=1;
  len=strlen(w[0]);
  li=0;
  for(i=1;(w[i]=strtok(NULL," \n"))!=NULL;i++){
    c[i]=1;
    for(j=0;j<i;j++){
      if(strcmp(w[i],w[j])==0){//printf("%s\n",w[i]);
	c[j]++;
	i--;
	if(max<c[j]){
	  max=c[j];
	  mi=j;
	}
      }
      else if(len<strlen(w[i])){
	len=strlen(w[i]);
	li=i;
      }	     
    }
  }
  printf("%s %s\n",w[mi],w[li]);
  return 0;
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        if(s[i] != s[i+1]) ans++;  
    }   
    cout << ans << endl;
}

Measured memory_bytes: 512
void main() {
    int n = readln.chomp.to!int;
    string s = readln.chomp;
    int x, xmax;
    foreach (c; s) {
        if (c == 'I') ++x;
        else --x;
        xmax = max(xmax, x);
    }
    xmax.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> st(M);
  vector<int> en(M);
  
  for ( int i=0; i<M; i++) {
    cin >> st.at(i) >> en.at(i);
  }
  
  vector<int> counter(N,0);
  
  for ( int i=0; i<M; i++) {
    
    for ( int p=0; p<N; p++) {
      
      if ( st.at(i) == p+1) {
        
        counter.at(p)++;
      }
      else if ( en.at(i) == p+1) {
        
        counter.at(p)++;
      }
    }
    
  }
  
  for (int i=0; i<N; i++) {
    
    cout << counter.at(i) << endl;
  }
}

Measured memory_bytes: 256
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        String S = scanString(), T = scanString();
        if (T.startsWith(S) && T.length() == S.length()+ 1) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 32844
int N;
int f[10001];
int main()
{
	scanf("%d",&N);
	for(int x=1;x<=100;x++)for(int y=1;y<=100;y++)for(int z=1;z<=100;z++)
	{
		int t=x*x+y*y+z*z+x*y+y*z+z*x;
		if(t<=N)f[t]++;
	}
	for(int n=1;n<=N;n++)printf("%d\n",f[n]);
}

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

using namespace std;

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

    long long n, ans;
    cin >> n;
    vector<int> v;

    for (long long i = 2; i * i <= n; i++)
        if (n % i == 0) {
            int cnt = 0;
            while (n % i == 0)
                n /= i, cnt++;
            v.push_back(cnt);
        }
    ans = (n > 1);

    for (int &x : v)
        for (int i = 1; x - i >= 0; i++)
            ans++, x -= i;
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3652
d=[0]*13
d[0]=1
mul=1
mulmod=1
t=input()[::-1]
mod=10**9+7
zero=[0]*13

for c in t:
    e=zero[:]
    if c=="?":
        for i in range(10):
            for j in range(13):
                k=(i*mul+j)%13
                e[k]+=d[j]
                e[k]%=mod
    else:
        for j in range(13):
            k=(int(c)*mul+j)%13
            e[k]+=d[j]
            e[k]%=mod
    d=e
    mul=10*mul%13
print(d[5])


Measured memory_bytes: 43372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(int argc, char const *argv[])
{
	ll n; cin >> n;
	vector<ll> v;
	rep(i, 5) {
		ll d; cin >> d;
		v.emplace_back(d);
	}
	sort(v.begin(), v.end());

	ll min = v.front();
	ll time = (n + min - 1) / min;
	ll ans = time + 4;
	printf("%lld\n", ans);
	return 0;
}

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a:i64 = iter.next().unwrap().parse().unwrap();
    let b:i64 = iter.next().unwrap().parse().unwrap();
    println!("{}", 6 - a - b);
}


Measured memory_bytes: 4352
import math
list1 = [int(i) for i in input().split()]
def prime(n):
    for i in range(2, int(n**0.5) + 1):
        if(n%i == 0):
            return False
    return True
a = list1[0]
b = list1[1]
count = 0 
diva = []
divb = []
for i in range(1,int(a**0.5) + 1):
    if(a%i == 0):
        diva.append(i)
        diva.append(a//i)
for i in range(1,int(b**0.5) + 1):
    if(b%i == 0):
        divb.append(i)
        divb.append(b//i)

set1 = set(diva)
set2 = set(divb)
l = []
set3 = list(set1.intersection(set2))
for i in set3:
    if(prime(i)):
      
        l.append(i)
        
print(len(l))

    
    


Measured memory_bytes: 5260
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

LL n;
int ans = 0;

void func(LL i, int use) {
	if (i > n) return;
	if (use == 0b111) ans++;

	func(i * 10 + 7, use | 0b001);
	func(i * 10 + 5, use | 0b010);
	func(i * 10 + 3, use | 0b100);
}

int main() {
	cin >> n;
	func(0, 0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,q,x,s[100005]={},t[100005]={};
  cin >> a >> b >> q;
  for(int i=1; i<=a; i++) {
    cin >> s[i];
    s[0]=-1e18,s[a+1]=1e18;
  }
  for(int i=1; i<=b; i++) {
    cin >> t[i];
  }
  t[0]=-1e18,t[b+1]=1e18;
  while(q--) {
    cin >> x;
    ll pos_s,pos_t;
    pos_s=lower_bound(s,s+a+2,x)-s;
    pos_t=lower_bound(t,t+b+2,x)-t;
    cout << min({s[pos_s]-t[pos_t-1]+min(x-t[pos_t-1],s[pos_s]-x),t[pos_t]-s[pos_s-1]+min(x-s[pos_s-1],t[pos_t]-x),max(s[pos_s]-x,t[pos_t]-x),max(x-s[pos_s-1],x-t[pos_t-1])}) << endl;
  }             
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



const double INF = 1e10;

struct D{

	vector<double> L,R;

	D(){

		for(int i = 0; i < 3; i++){
			L.push_back(INF);
			R.push_back(-INF);
		}
	}

	void add(double x, int v){
		v++; //速さを0,1,2にする
		L[v] = min(L[v],x); //vごとの左端
		R[v] = max(R[v],x); //vごとの右端
	}

	double get(double t){
		double nl = INF,nr = -INF;
		for(int i = 0; i < 3; i++){

			nl = min(nl,L[i]+i*t);
			nr = max(nr,R[i]+i*t);
		}
		return nr-nl;
	}

	vector<double> events(){
		vector<double> ret;

		for(int i = 0; i < 2; i++){
			for(int k = i+1; k < 3; k++){
				double t = (L[i]-L[k])/(k-i);
				if(t > 0){
					ret.push_back(t);
				}
			}
		}
		for(int i = 0; i < 2; i++){
			for(int k = i+1; k < 3; k++){
				double t = (R[i]-R[k])/(k-i);
				if(t > 0){
					ret.push_back(t);
				}
			}
		}
		return ret;
	}
};

int main(){

	int N;
	scanf("%d",&N);

	D X,Y;
	char buf[2];

	for(int i = 0; i < N; i++){
		int x,y;

		scanf("%d %d %s",&x,&y,buf);

		switch(buf[0]){
		case 'L':
			X.add(x,-1),Y.add(y,0);
			break;
		case 'R':
			X.add(x,1),Y.add(y,0);
			break;
		case 'U':
			X.add(x,0),Y.add(y,1);
			break;
		case 'D':
			X.add(x,0),Y.add(y,-1);
			break;
		}
	}


	vector<double> T;
	T.push_back(0);
	T.push_back(INF);

	vector<double> tmp = X.events();
	for(int i = 0; i < tmp.size(); i++){

		T.push_back(tmp[i]);
	}
	tmp = Y.events();
	for(int i = 0; i < tmp.size(); i++){

		T.push_back(tmp[i]);
	}

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

	double ans = HUGE_NUM;

	for(int i = 0; i < T.size(); i++){

		ans = min(ans,X.get(T[i])*Y.get(T[i]));
	}

	printf("%.10lf\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector<int> G[100010];
int h[100010];
int main(){
    int i,n,m;
    cin >> n >> m;
    for(i=0;i<n;i++){
        cin >> h[i];
    }
    for(i=0;i<m;i++){
        int a,b; cin >> a >> b; a--; b--;
        G[a].push_back(b); G[b].push_back(a);
    }
    int ans = 0;
    for(i=0;i<n;i++){
        int mx = -1;
        for(int e:G[i]){
            mx = max(mx,h[e]);
        }
        if(h[i]>mx) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9084
N=int(input())
C=sorted(map(int,input().split()),reverse=1)
m=10**9+7
x=pow(2,N-1,m)
r=0
for i in range(N):
    r+=C[i]*x%m
    if N>1:
        x+=pow(2,N-2,m)
print(pow(2,N,m)*r%m)

Measured memory_bytes: 26800
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;


void solve(){
	string s;
	cin >> s;
	int ans = 0;
	map<char,int> m;
	for(int i =s.size()-1;i>=0;i--){
		for(char c = 'a';c<='z';c++){
			if(c != s[i]){
				ans += m[c];
			}
		}
		m[s[i]]++;
	}
	ans++;
	cout << ans << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

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

int main(){
    ll n,a,b;
    cin>>n;
    a=n/100;
    b=n%100;
    if(1<=a and a<=12 and 1<=b and b<=12){
        cout<<"AMBIGUOUS"<<endl;
    }else if(1<=a and a<=12){
        cout<<"MMYY"<<endl;
    }else if(1<=b and b<=12){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }
}

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

using namespace std;

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

  vector<int> x(N);
  for(int i=0;i<N;i++) cin>>x[i];
  
  int ans=-1;
  for(int i=0;i<(N-K+1);i++){
    int temp1=abs(x[i])+(abs(x[i+K-1]-x[i]));
    int temp2=abs(x[i+K-1]-x[i])+abs(x[i+K-1]);
    int temp=min(temp1,temp2);
    if(temp<ans||ans==-1) ans=temp;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

int a,b,c,d,e,f;
int x;
int i,j;

using namespace std;

int int_cmp(const int *a, const int *b)
{
    if (*a < *b)
        return (-1);
    else if (*a > *b)
        return (1);
    return (0);
}

int max(int *p, int n){
	int max = 0;
	for(int x = 1; x < n; ++x){
		if(p[max] < p[x]){
			max = x;
		}
	}
	return p[max];
}

int main(void){
	int n;
	cin >> n;
	
	int d[n];
	for(i = 0; i < n; ++i){
		cin >> d[i];
	}
	
	int arc;
	int abc;
	int cnt = 0;
	int MaxValue = max(d, n);
	
	if(n % 2 == 1){
		cout << 0 << endl;
		return 0;
	}
	
	qsort(d, n, sizeof(int), (int(*)(const void*, const void*))int_cmp);
	
	int k = n/2;
	cout << (d[k] - d[k-1]) << endl;
	
	return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <ios>
#include <iomanip>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define setp(x) setprecision(x)
using ll = long long;
using ull = unsigned long long;

int main() {
	int n;
	cin >> n;
	vector<ll> h(n);
	rep(i, 0, n) cin >> h[i];

	string ans = "Yes";
	rem(i, n - 1, 0) {
		if (h[i] >= h[i - 1]) continue;
		h[i - 1]--;
	}
	rep(i, 1, n) {
		if (h[i - 1] > h[i]) ans = "No";
	}

	cout << ans << endl;

	return 0;
}

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

#define f first
#define s second
#define ll long long
#define ld long double
#define pf push front
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define gcd(a,b) __gcd(a,b)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pll,vector<pll>,greater<pll> >

const int mod = 1e9+7;



int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll sm = 0;
	ll d;
	for (int i = 0; i < m; ++i)
	{
		cin>>d;
		sm += d;
	}
	if(sm>n) cout<<-1;
	else cout<<n-sm;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(V) V.begin,V.end
const int N = 100005;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin >> a >> b;
    if(a>=13)cout << b;
    else if(a>=6 && a<13)cout << b/2;
    else cout << 0;
}

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

int main()
{
  int n, k;
  std::cin >> n >> k;
  
  std::vector<int> price(n);
  
  for(int i = 0; i < n; ++i)
  {
    std::cin >> price[i];
  }
  
  std::sort(price.begin(), price.end());
  
  int sum = 0;
  for(int i = 0; i < k; ++i)
  {
    sum += price[i];
  }
  
  std::cout << sum << std::endl;
}

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

int main(void){
   int X,A,B;
   cin>>X>>A>>B;
   if(B-A<=0){
      cout<<"delicious"<<endl;
   }else if(B-A>=X+1){
      cout<<"dangerous"<<endl;
   }else{
      cout<<"safe"<<endl;
   }
   return 0;
}



Measured memory_bytes: 3632
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def ret_ans(n):
    li = [1]
    li.extend([6 ** i for i in range(0, 15) if 6 ** i <= n])
    li.extend([9 ** i for i in range(1, 15) if 9 ** i <= n])
    li.sort(reverse=True)
    
    s = set([n])
    cnt = 1
    while True:
        ts = set(s)
        for e in li:
            for c in s:
                if c - e == 0:
                    return cnt
                if c - e > 0:
                    ts.add(c - e)
        s = ts
        cnt += 1
 

def solve():
    print(ret_ans(int(input())))

if __name__=="__main__":
    solve()

Measured memory_bytes: 14356
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<62;

int main(){
    int n;
    cin>>n;
    ll sum = 0ll;
    vector<int> b(n-1);
    for(auto &a : b) cin>>a;
    sum += b[0];
    sum += b[n-2];
    for(int i=0;i<n-2;++i){
        sum += min(b[i],b[i+1]);
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <math.h>

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define vstr vector<string>

using namespace std;

int main()
{
	//cout << "ans: " << endl;

	ll n;
	cin >> n;
	vll arr(n);
	for (ll i = 0; i < n; i++) cin >> arr[i];
	sort(arr.rbegin(), arr.rend());
	
	if (n % 2 == 0)
	{
		ll ans = 0;
		for (ll i = 0; i < (n / 2) - 1; i++)
		{
			ans += arr[i];
		}

		for (ll i = 1; i < (n / 2) ; i++)
		{
			ans += arr[i];
		}
		ans += arr[n / 2 - 1];

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

	else
	{
		ll ans = 0;
		for (ll i = 0; i < (n / 2); i++)
		{
			ans += arr[i];
		}

		for (ll i = 1; i < (n / 2) + 1; i++)
		{
			ans += arr[i];
		}
		//ans += arr[n / 2 - 1];

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


}

Measured memory_bytes: 4412
#include <cstdio>
#include <iostream>
using namespace std;
long long n,n1,len=0,ans=0;
int main(){
	scanf("%d",&n);
	n1=n;
	while(n1>=10){
		ans+=n1%10;
		n1/=10;
	}
	ans+=n1;
	if(n%ans==0){
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
K = int(input())
count = 9
lunlun = [1,2,3,4,5,6,7,8,9]
i = 0

while count < K:
  if (lunlun[i]%10) != 0:
    lunlun.append(lunlun[i]*10+lunlun[i]%10-1)
    count = count + 1
  lunlun.append(lunlun[i]*10+lunlun[i]%10)
  count = count + 1
  if (lunlun[i]%10) != 9:
    lunlun.append(lunlun[i]*10+lunlun[i]%10+1)
    count = count+1
  i= i+1
print(lunlun[K-1])

Measured memory_bytes: 7188
X = int(input())

ok = 10**9 # 解が存在する値
ng = 0 # 解が存在しない値
def bisearch(function, ok, ng):
    while abs(ok-ng) > 1:
        mid = (ok + ng)//2
        if function(mid):
            ok = mid
        else:
            ng = mid
    return ok

def check(mid):
    return mid*(mid+1)/2 >= X
    
print(bisearch(check, ok, ng))

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if a[i]%2 == 1:
        cnt += 1
if cnt%2 == 0:
    ans = 'YES'
else:
    ans = 'NO'
print(ans)

Measured memory_bytes: 14048
# ABC152F

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")





from collections import defaultdict
from queue import deque
import itertools
import functools
def find(start,goal):
    q = deque([start])
    seen = [None] * n
    seen[start] = -1
    while q:
        u = q.pop()
        d = seen[u]
        if u==goal:
            break
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = u
                q.appendleft(v)
    u = goal
    es = []
    while True:
        t = (min(u, seen[u]), max(u, seen[u]))
        es.append(t)
        if seen[u]==start:
            break
        u = seen[u]
    return set(es)

n = int(input())
ns = defaultdict(set)
for _ in range(n-1):
    u,v = map(int, input().split())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)
ans = 0
m = int(input())
paths = [None] * m
for i in range(m):
    u, v = map(int, input().split())
    paths[i] = find(u-1,v-1)

ans = 0

def dfs(ind, s, ans):
    if len(ind)==m:
        if True in ind:
            ans += 2**(n-1-len(s)) * (-1)**(sum(ind)+1)
        return ans
    ans = dfs(ind + [True], s | paths[len(ind)], ans)
    ans = dfs(ind + [False], s, ans)
    return ans
        
# for ind in itertools.product(*[(False, True) for _ in range(m)]):
#     num = sum(ind)+1
#     if num==1:
#         continue
#     c = 2**(n - 1 - len(functools.reduce(lambda x,y: x|y, (paths[i] for i in range(m) if ind[i]), set())))
#     ans += (-1)**num * c
ans = dfs([], set(), 0)
print(2**(n-1) - ans)

Measured memory_bytes: 53592
import java.util.Scanner;

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


        for (int i = 0; i < line.length(); i++) {//文字が小文字であるかを検討
            if( Character.isLowerCase(line.charAt(i))){
                System.out.print(Character.toUpperCase(line.charAt(i)));
            }else if( Character.isUpperCase(line.charAt(i))){//文字が大文字であるかを検討
                System.out.print(Character.toLowerCase(line.charAt(i)));
            }else{
                System.out.print(line.charAt(i));
            }

        }

        System.out.println();

    }
}


Measured memory_bytes: 26672
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);

bool check(vector<int> v){
	int judge = v[1]-v[0];
	rep(i, v.size()-1){
		if((v[i+1]-v[i]) != judge)return false;
	}
	return true;
}

int main(void){
	int N;
	while(cin >> N, N){
		vector<int> v;
		rep(i, N+1){
			int a;
			cin >> a;
			v.pb(a);
		}
		rep(i, v.size()){
			vector<int> cpy = v;
			cpy.erase(cpy.begin() + i);
			if(check(cpy)){
				FIN(v[i]);
				break;
			}
		}
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1228
//
//  D.cpp
//  AtCoder
//
//  Created by edamame88 on 2019/07/02.
//  Copyright © 2019 edamame88. All rights reserved.
//
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    map<char,int> mp;
    for(char c: s) mp[c]++;
    if(mp.size() == 2){
        bool flag = true;
        for(auto x: mp){
            if(x.second != 2) flag = false;
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1000000007;
const int N = 10010;
ll fact[N], invf[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

void init_f(){
    fact[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
    }
    invf[N-1] = divll(1, fact[N-1]);
    FORR(i,N-1,1){
        invf[i-1] = (invf[i] * i) % mod;
    }
}

int main() {
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    if (b % 2){
        cout << 0 << endl;
        return 0;
    }

    init_f();

    ll ans = 0;
    REP(x,a+1) REP(y,c+1){
        if (b == 0 && y > 0) continue;
        int z = a - x;
        if (z + y > c || (c - z - y) % 3) continue;
        int w = (c - z - y) / 3;
        ll tmp = (b ? nCr(y + b / 2 - 1, y) : 1);
        ll s = x + z + w + b / 2;
        for (ll p : VL({x, z, w, b / 2})){
            tmp = (tmp * nCr(s, p)) % mod;
            s -= p;
        }
        // cout << x << " " << y << " " << z << " " << w << " " << tmp << endl;
        ans = (ans + tmp) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;
int main(){
  char h[] = {'A', 'B', 'C', 'D', 'E', 'F'};
  
  char X, Y;
  int x, y;
  cin >> X >> Y;
  
  for(int i=0; i < 6; i++){
    if(h[i] == X)
      x = i+10;
    if(h[i] == Y)
      y = i+10;
  }
  if(x == y)
    cout << '=';
  else
    cout << ((x < y) ? ('<'):('>'));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define all(a) (a).begin(),(a).end()
using namespace std;

const int N = 1e5+1;
vector<int>adj[N];
bool visited[N];

void dfs(int cur){
    visited[cur] = true;
    for(int child : adj[cur]){
        if(!visited[child])
            dfs(child);
    }
}

signed main(){
    ios_base::sync_with_stdio(false);

    int n , m;
    cin >> n >> m;

    for(int i=0;i<m;i++){
        int u , v ;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int ans = 0;

    for(int i=1;i<=n;i++){
        if(!visited[i]){
            dfs(i);
            ans++;
        }
    }

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


Measured memory_bytes: 10404